package com.product.patch.controller; import com.product.common.utils.StringUtils; import com.product.core.cache.DataPoolCacheImpl; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; import com.product.core.exception.BaseException; import com.product.module.sys.version.ApiVersion; import com.product.patch.config.ErrorCode; import com.product.patch.service.PatchExportService; import com.product.util.BaseUtil; import com.product.util.support.AbstractBaseController; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; /** * @Author cheng * @Date 2024/10/23 10:05 * @Desc 补丁导出 */ @RestController @RequestMapping("/api/patch/export") public class PatchExportController extends AbstractBaseController { @Resource private PatchExportService patchExportService; @PostMapping("/get-table-field-reference/{version}") @ApiVersion(1) public String getTableFieldReference(HttpServletRequest request) { try { FieldSetEntity fse = BaseUtil.getFieldSetEntity(request); String tableUuid = fse.getString("table_uuid"); String[] uuids = tableUuid.split(","); DataTableEntity fields = new DataTableEntity(); for (String uuid : uuids) { DataTableEntity f = DataPoolCacheImpl.getInstance().getCacheData("所有字段信息并按表分组", new String[]{uuid}); BaseUtil.dataTableMerge(fields, f); } List result = new ArrayList<>(); for (int i = 0; i < fields.getRows(); i++) { if (StringUtils.isEmpty(fields.getString(i, "field_reference"))) { result.add(fields.getString(i, "field_reference")); } } return BaseUtil.success(result); } catch (BaseException e) { return error(e); } catch (Exception e) { e.printStackTrace(); return error(ErrorCode.GET_TABLE_FIELD_REFERENCE_FAIL, e); } } @PostMapping("/execute/{version}") @ApiVersion(1) public String exportPath(HttpServletRequest request, HttpServletResponse response) { try { FieldSetEntity fse = BaseUtil.getFieldSetEntity(request); patchExportService.export(fse, response); return OK(); } catch (BaseException e) { return error(e); } catch (Exception e) { e.printStackTrace(); return error(ErrorCode.EXTRACT_FAIL, e); } } }