diff --git a/src/main/java/com/glxp/api/constant/BasicExportTypeEnum.java b/src/main/java/com/glxp/api/constant/BasicExportTypeEnum.java index d8f662fc..9a58fba1 100644 --- a/src/main/java/com/glxp/api/constant/BasicExportTypeEnum.java +++ b/src/main/java/com/glxp/api/constant/BasicExportTypeEnum.java @@ -19,7 +19,7 @@ public enum BasicExportTypeEnum { /** * 国家库DI数据 */ -// COUNTRY_DI_DATA("country_di_data", "国家库DI数据"), + COUNTRY_DI_DATA("country_di_data", "国家库DI数据"), /** * 单据类型 @@ -45,6 +45,11 @@ public enum BasicExportTypeEnum { * 第三方数据 */ SYS_SET_DATA("sys_set_data", "系统设置数据"), + + /** + * 单据信息 + */ + IO_ORDER("io_order", "单据信息"), ; @EnumValue private String key; diff --git a/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java b/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java index 7a34a3a8..2cf91d82 100644 --- a/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java +++ b/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java @@ -66,10 +66,8 @@ import javax.validation.Valid; import java.io.*; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.stream.Collectors; @RestController @Api(tags = "同步下载相关") @@ -335,28 +333,28 @@ public class SpsSyncDownloadController { @ApiOperation("上传同步数据") @PostMapping("sps/sync/upload/data") + @Transactional public Object uploadData(@RequestBody SyncUpLoadRequest upLoadRequest) { try { JSONObject obj = JSONUtil.parseObj(upLoadRequest.getData()); - String log = ""; switch (upLoadRequest.getExportType()) { case BASIC_DATA: - log = saveUploadBasicData(JSONUtil.toBean(obj, SpsSyncBasicDataResponse.class)); + saveUploadBasicData(JSONUtil.toBean(obj, SpsSyncBasicDataResponse.class)); break; case OTHER_DATA: - log = saveUploadOtherData(JSONUtil.toBean(obj, SpsSyncOtherDataResponse.class)); + saveUploadOtherData(JSONUtil.toBean(obj, SpsSyncOtherDataResponse.class)); break; case DOCUMENT_TYPE_DATA: - log = saveUploadDocumentTypeData(JSONUtil.toBean(obj, SpsSyncBusResponse.class)); + saveUploadDocumentTypeData(JSONUtil.toBean(obj, SpsSyncBusResponse.class)); break; case USER_DATA: - log = saveUploadUserData(JSONUtil.toBean(obj, SpsSyncDataResponse.class)); + saveUploadUserData(JSONUtil.toBean(obj, SpsSyncDataResponse.class)); break; case THIRD_DATA: - log = saveUploadThrData(JSONUtil.toBean(obj, SpsSyncThrDataResponse.class)); + saveUploadThrData(JSONUtil.toBean(obj, SpsSyncThrDataResponse.class)); break; case SYS_SET_DATA: - log = saveUploadSysSettingData(JSONUtil.toBean(obj, SpsSyncSysSettingResponse.class)); + saveUploadSysSettingData(JSONUtil.toBean(obj, SpsSyncSysSettingResponse.class)); break; } String taskId = obj.getStr("taskId"); @@ -370,15 +368,14 @@ public class SpsSyncDownloadController { .type(upLoadRequest.getExportType().getRemark()) .idDatas(upLoadRequest.getExportType().getKey()) .scheduleType(1) - .execInfo(log) .build(); String fileFullPath = writeFile(filePrefix, upLoadRequest.getExportType().getRemark(), JSONUtil.toJsonStr(upLoadRequest.getData())); downloadStatus.setCacheFilePath(fileFullPath); basicDownloadService.insertDownloadStatus(downloadStatus); - return ResultVOUtils.success(log); + return ResultVOUtils.success(); } catch (Exception e) { e.printStackTrace(); - return ResultVOUtils.error(ResultEnum.NOT_NETWORK.getCode(), e.getMessage()); + return ResultVOUtils.error(ResultEnum.NOT_NETWORK, e.getMessage()); } } @@ -416,120 +413,40 @@ public class SpsSyncDownloadController { private final BasicBusTypeChangeDao basicBusTypeChangeDao; - private String saveUploadSysSettingData(SpsSyncSysSettingResponse bean) { - List success = new ArrayList<>(); - List fail = new ArrayList<>(); + private void saveUploadSysSettingData(SpsSyncSysSettingResponse bean) { + if (CollectionUtil.isNotEmpty(bean.getSystemParamConfigEntities())) { - String desc = "运行参数设置信息:"; - try { - systemParamConfigDao.insertOrUpdateBatch(bean.getSystemParamConfigEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + systemParamConfigDao.insertOrUpdateBatch(bean.getSystemParamConfigEntities()); } if (CollectionUtil.isNotEmpty(bean.getEntrustReceEntities())) { - String desc = "委托验收设置信息:"; - try { - entrustReceDao.insertOrUpdateBatch(bean.getEntrustReceEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + entrustReceDao.insertOrUpdateBatch(bean.getEntrustReceEntities()); } if (CollectionUtil.isNotEmpty(bean.getSystemPDFModuleEntities())) { - String desc = "系统模板模块信息:"; - try { - systemPDFModuleDao.insertOrUpdateBatch(bean.getSystemPDFModuleEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + systemPDFModuleDao.insertOrUpdateBatch(bean.getSystemPDFModuleEntities()); } if (CollectionUtil.isNotEmpty(bean.getSystemPDFTemplateEntities())) { - String desc = "模板信息:"; - boolean flag = true; - int failCount = 0; - try { - for (SystemPDFTemplateEntity systemPDFTemplateEntity : bean.getSystemPDFTemplateEntities()) { - try { - systemPDFTemplateDao.insertOrUpdate(systemPDFTemplateEntity); - } catch (Exception e) { - e.printStackTrace(); - flag = false; - failCount++; - } - } - success.add(desc + "成功" + (bean.getSystemPDFTemplateEntities().size() - failCount) + "条"); - } catch (Exception e) { - fail.add(desc + "失败" + failCount + "条"); - } + for (SystemPDFTemplateEntity systemPDFTemplateEntity : bean.getSystemPDFTemplateEntities()) + systemPDFTemplateDao.insertOrUpdate(systemPDFTemplateEntity); } if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceCodeEntities())) { - String desc = "扫码单据关联模板信息:"; - try { - sysPdfTemplateRelevanceCodeDao.insertOrUpdateBatch(bean.getSysPdfTemplateRelevanceCodeEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + sysPdfTemplateRelevanceCodeDao.insertOrUpdateBatch(bean.getSysPdfTemplateRelevanceCodeEntities()); } if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceBizEntities())) { - String desc = "业务单据关联模板信息:"; - try { - sysPdfTemplateRelevanceBizDao.insertOrUpdateBatch(bean.getSysPdfTemplateRelevanceBizEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + sysPdfTemplateRelevanceBizDao.insertOrUpdateBatch(bean.getSysPdfTemplateRelevanceBizEntities()); } if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceLabelEntities())) { - String desc = "标签关联模板信息:"; - try { - sysPdfTemplateRelevanceLabelDao.insertOrUpdateBatch(bean.getSysPdfTemplateRelevanceLabelEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + sysPdfTemplateRelevanceLabelDao.insertOrUpdateBatch(bean.getSysPdfTemplateRelevanceLabelEntities()); } if (CollectionUtil.isNotEmpty(bean.getSysPdfTemplateRelevanceStatemenEntities())) { - String desc = "报表关联模板信息:"; - try { - sysPdfTemplateRelevanceStatemenDao.insertOrUpdateBatch(bean.getSysPdfTemplateRelevanceStatemenEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + sysPdfTemplateRelevanceStatemenDao.insertOrUpdateBatch(bean.getSysPdfTemplateRelevanceStatemenEntities()); } if (CollectionUtil.isNotEmpty(bean.getBasicBusTypePreEntities())) { - String desc = "出入库单自动补单设置信息:"; - try { - basicBusTypePreDao.insertOrUpdateBatch(bean.getBasicBusTypePreEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + basicBusTypePreDao.insertOrUpdateBatch(bean.getBasicBusTypePreEntities()); } if (CollectionUtil.isNotEmpty(bean.getBasicBusTypeChangeEntities())) { - String desc = "业务单自动补单设置信息:"; - try { - basicBusTypeChangeDao.insertOrUpdateBatch(bean.getBasicBusTypeChangeEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + basicBusTypeChangeDao.insertOrUpdateBatch(bean.getBasicBusTypeChangeEntities()); } - success.addAll(fail); - return String.join(",", success); + } @@ -538,147 +455,50 @@ public class SpsSyncDownloadController { private final ThrProductsDao thrProductsDao; private final ThrCorpDao thrCorpDao; - private String saveUploadThrData(SpsSyncThrDataResponse bean) { - List success = new ArrayList<>(); - List fail = new ArrayList<>(); + private void saveUploadThrData(SpsSyncThrDataResponse bean) { + if (CollectionUtil.isNotEmpty(bean.getDeptEntities())) { - String desc = "第三方部门信息:"; - try { - thrDeptDao.insertOrUpdateBatch(bean.getDeptEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + thrDeptDao.insertOrUpdateBatch(bean.getDeptEntities()); } if (CollectionUtil.isNotEmpty(bean.getInvWarehouseEntities())) { - String desc = "第三方仓库信息:"; - try { - thrInvWarehouseDao.insertOrUpdateBatch(bean.getInvWarehouseEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + thrInvWarehouseDao.insertOrUpdateBatch(bean.getInvWarehouseEntities()); } if (CollectionUtil.isNotEmpty(bean.getProductsEntityList())) { - String desc = "第三方产品信息:"; - try { - thrProductsDao.insertOrUpdateBatch(bean.getProductsEntityList()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + thrProductsDao.insertOrUpdateBatch(bean.getProductsEntityList()); } if (CollectionUtil.isNotEmpty(bean.getCorpEntities())) { - String desc = "第三方往来信息:"; - try { - thrCorpDao.insertOrUpdateBatch(bean.getCorpEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + thrCorpDao.insertOrUpdateBatch(bean.getCorpEntities()); } - success.addAll(fail); - return String.join(",", success); } - private String saveUploadUserData(SpsSyncDataResponse bean) { - List success = new ArrayList<>(); - List fail = new ArrayList<>(); + private void saveUploadUserData(SpsSyncDataResponse bean) { + if (CollectionUtil.isNotEmpty(bean.getAuthAdminList())) { - String desc = "系统用户信息:"; - try { - authAdminDao.insertOrUpdateBatch(bean.getAuthAdminList()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + authAdminDao.insertOrUpdateBatch(bean.getAuthAdminList()); } if (CollectionUtil.isNotEmpty(bean.getDeptEntityList())) { - String desc = "部门信息:"; - try { - deptDao.insertOrUpdateBatch(bean.getDeptEntityList()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + deptDao.insertOrUpdateBatch(bean.getDeptEntityList()); } if (CollectionUtil.isNotEmpty(bean.getDeptUserEntities())) { - String desc = "部门用户信息:"; - try { - deptUserDao.replaceBatch(bean.getDeptUserEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + deptUserDao.replaceBatch(bean.getDeptUserEntities()); } if (CollectionUtil.isNotEmpty(bean.getInvWarehouseEntities())) { - String desc = "仓库字典信息:"; - try { - invWarehouseDao.insertOrUpdateBatch(bean.getInvWarehouseEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + invWarehouseDao.insertOrUpdateBatch(bean.getInvWarehouseEntities()); } if (CollectionUtil.isNotEmpty(bean.getWarehouseUserEntities())) { - String desc = "仓库用户信息:"; - try { - warehouseUserDao.insertOrUpdateBatch(bean.getWarehouseUserEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + warehouseUserDao.insertOrUpdateBatch(bean.getWarehouseUserEntities()); } if (CollectionUtil.isNotEmpty(bean.getWarehouseBussinessTypeEntities())) { - String desc = "仓库单据类型信息:"; - boolean flag = true; - int failCount = 0; - try { - for (WarehouseBussinessTypeEntity warehouseBussinessTypeEntity : bean.getWarehouseBussinessTypeEntities()) { - try { - warehouseBussinessTypeDao.insertOrUpdate(warehouseBussinessTypeEntity); - } catch (Exception e) { - e.printStackTrace(); - flag = false; - failCount++; - } - } - success.add(desc + "成功" + (bean.getWarehouseBussinessTypeEntities().size() - failCount) + "条"); - } catch (Exception e) { - fail.add(desc + "失败" + failCount + "条"); + for (WarehouseBussinessTypeEntity warehouseBussinessTypeEntity : bean.getWarehouseBussinessTypeEntities()) { + warehouseBussinessTypeDao.insertOrUpdate(warehouseBussinessTypeEntity); } } if (CollectionUtil.isNotEmpty(bean.getInvSpaces())) { - String desc = "货位信息:"; - try { - invSpaceDao.insertOrUpdateBatch(bean.getInvSpaces()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + invSpaceDao.insertOrUpdateBatch(bean.getInvSpaces()); } if (CollectionUtil.isNotEmpty(bean.getInvBusUserEntities())) { - String desc = "用户关联单据信息:"; - try { - invBusUserDao.insertOrUpdateBatch(bean.getInvBusUserEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + invBusUserDao.insertOrUpdateBatch(bean.getInvBusUserEntities()); } - success.addAll(fail); - return String.join(",", success); } private final BasicBussinessTypeDao basicBussinessTypeDao; @@ -691,41 +511,16 @@ public class SpsSyncDownloadController { * * @param bean */ - private String saveUploadDocumentTypeData(SpsSyncBusResponse bean) { - List success = new ArrayList<>(); - List fail = new ArrayList<>(); + private void saveUploadDocumentTypeData(SpsSyncBusResponse bean) { if (CollectionUtil.isNotEmpty(bean.getBussinessTypeEntities())) { - String desc = "扫码单据类型信息:"; - try { - basicBussinessTypeDao.insertOrUpdateBatch(bean.getBussinessTypeEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + basicBussinessTypeDao.insertOrUpdateBatch(bean.getBussinessTypeEntities()); } if (CollectionUtil.isNotEmpty(bean.getBusTypeChangeEntities())) { - String desc = "业务单据类型:"; - try { - busTypeChangeDao.insertOrUpdateBatch(bean.getBusTypeChangeEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + busTypeChangeDao.insertOrUpdateBatch(bean.getBusTypeChangeEntities()); } if (CollectionUtil.isNotEmpty(bean.getThrBusTypeOriginEntities())) { - String desc = "第三方单据类型信息:"; - try { - thrBusTypeOriginDao.insertOrUpdateBatch(bean.getThrBusTypeOriginEntities()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + thrBusTypeOriginDao.insertOrUpdateBatch(bean.getThrBusTypeOriginEntities()); } - success.addAll(fail); - return String.join(",", success); } @@ -737,31 +532,14 @@ public class SpsSyncDownloadController { * * @param bean */ - private String saveUploadOtherData(SpsSyncOtherDataResponse bean) { - List success = new ArrayList<>(); - List fail = new ArrayList<>(); + private void saveUploadOtherData(SpsSyncOtherDataResponse bean) { if (CollectionUtil.isNotEmpty(bean.getIoCodeLostList())) { - String desc = "UDI码补齐信息:"; - try { - ioCodeLostMapper.insertOrUpdateBatch(bean.getIoCodeLostList()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + ioCodeLostMapper.insertOrUpdateBatch(bean.getIoCodeLostList()); } if (CollectionUtil.isNotEmpty(bean.getIoCodeRelList())) { - String desc = "UDI码关联关系:"; - try { - ioCodeRelMapper.insertOrUpdateBatch(bean.getIoCodeRelList()); - success.add(desc + "成功"); - } catch (Exception e) { - e.printStackTrace(); - fail.add(desc + "失败"); - } + ioCodeRelMapper.insertOrUpdateBatch(bean.getIoCodeRelList()); } - success.addAll(fail); - return String.join(",", success); + } private final BasicHospTypeDao basicHospTypeDao; @@ -780,101 +558,37 @@ public class SpsSyncDownloadController { * * @param bean */ - private String saveUploadBasicData(SpsSyncBasicDataResponse bean) { - List success = new ArrayList<>(); - List fail = new ArrayList<>(); + private void saveUploadBasicData(SpsSyncBasicDataResponse bean) { if (CollectionUtil.isNotEmpty(bean.getHospTypeList())) { - String desc = "物资字典分类信息:"; - try { - basicHospTypeDao.insertOrUpdateBatch(bean.getHospTypeList()); - success.add(desc + "成功"); - } catch (Exception e) { - fail.add(desc + "失败"); - } + basicHospTypeDao.insertOrUpdateBatch(bean.getHospTypeList()); } if (CollectionUtil.isNotEmpty(bean.getUdiRelevanceList())) { - String desc = "物资字典主表信息:"; - try { - udiRelevanceDao.insertOrUpdateBatch(bean.getUdiRelevanceList()); - success.add(desc + "成功"); - } catch (Exception e) { - fail.add(desc + "失败"); - } + udiRelevanceDao.insertOrUpdateBatch(bean.getUdiRelevanceList()); } if (CollectionUtil.isNotEmpty(bean.getProductsList())) { - String desc = "供应商物资字典信息:"; - try { - basicProductsDao.insertOrUpdateBatch(bean.getProductsList()); - success.add(desc + "成功"); - } catch (Exception e) { - fail.add(desc + "失败"); - } + basicProductsDao.insertOrUpdateBatch(bean.getProductsList()); } if (CollectionUtil.isNotEmpty(bean.getRelevanceList())) { - String desc = "物资字典子表信息:"; - try { - relevanceDao.insertOrUpdateBatch(bean.getRelevanceList()); - success.add(desc + "成功"); - } catch (Exception e) { - fail.add(desc + "失败"); - } + relevanceDao.insertOrUpdateBatch(bean.getRelevanceList()); } if (CollectionUtil.isNotEmpty(bean.getCorpList())) { - String desc = "往来单位信息:"; - try { - corpDao.insertOrUpdateBatch(bean.getCorpList()); - success.add(desc + "成功"); - } catch (Exception e) { - fail.add(desc + "失败"); - } + corpDao.insertOrUpdateBatch(bean.getCorpList()); } if (CollectionUtil.isNotEmpty(bean.getSupCertList())) { - String desc = "资质证书信息:"; - try { - supCertDao.insertOrUpdateBatch(bean.getSupCertList()); - success.add(desc + "成功"); - } catch (Exception e) { - fail.add(desc + "失败"); - } + supCertDao.insertOrUpdateBatch(bean.getSupCertList()); } if (CollectionUtil.isNotEmpty(bean.getSupCertSetList())) { - String desc = "资质证书要求设置信息:"; - try { - supCertSetDao.insertOrUpdateBatch(bean.getSupCertSetList()); - success.add(desc + "成功"); - } catch (Exception e) { - fail.add(desc + "失败"); - } + supCertSetDao.insertOrUpdateBatch(bean.getSupCertSetList()); } if (CollectionUtil.isNotEmpty(bean.getSupCompanyList())) { - String desc = "供应商资质信息:"; - try { - supCompanyDao.insertOrUpdateBatch(bean.getSupCompanyList()); - success.add(desc + "成功"); - } catch (Exception e) { - fail.add(desc + "失败"); - } + supCompanyDao.insertOrUpdateBatch(bean.getSupCompanyList()); } if (CollectionUtil.isNotEmpty(bean.getSupManufacturerList())) { - String desc = "生产企业资质信息:"; - try { - supManufacturerDao.insertOrUpdateBatch(bean.getSupManufacturerList()); - success.add(desc + "成功"); - } catch (Exception e) { - fail.add(desc + "失败"); - } + supManufacturerDao.insertOrUpdateBatch(bean.getSupManufacturerList()); } if (CollectionUtil.isNotEmpty(bean.getSupProductList())) { - String desc = "配送产品资质信息:"; - try { - supProductDao.insertOrUpdateBatch(bean.getSupProductList()); - success.add(desc + "成功"); - } catch (Exception e) { - fail.add(desc + "失败"); - } + supProductDao.insertOrUpdateBatch(bean.getSupProductList()); } - success.addAll(fail); - return String.join(",", success); } @Resource diff --git a/src/main/java/com/glxp/api/controller/sync/SpsSyncExportStatusController.java b/src/main/java/com/glxp/api/controller/sync/SpsSyncExportStatusController.java index 1c4ce2b2..36be3643 100644 --- a/src/main/java/com/glxp/api/controller/sync/SpsSyncExportStatusController.java +++ b/src/main/java/com/glxp/api/controller/sync/SpsSyncExportStatusController.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.annotation.Log; +import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.*; @@ -13,16 +14,23 @@ import com.glxp.api.entity.sync.BasicExportStatusEntity; import com.glxp.api.entity.sync.BasicExportStatusTimeEntity; import com.glxp.api.req.sync.BasicExportStatusRequest; import com.glxp.api.req.sync.BasicExportTimeRequest; +import com.glxp.api.req.sync.ManualSyncDataReq; import com.glxp.api.req.system.DeleteRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.sync.SpSyncUdiResponse; import com.glxp.api.res.sync.SpsSyncBusResponse; import com.glxp.api.res.sync.SpsSyncDataResponse; import com.glxp.api.res.sync.SpsSyncOrderResponse; +import com.glxp.api.res.system.SyncDataSetResponse; import com.glxp.api.service.sync.BasicExportService; import com.glxp.api.service.sync.BasicExportTimeService; +import com.glxp.api.service.sync.SpsSyncDownloadService; +import com.glxp.api.service.sync.SyncDataSetService; +import com.glxp.api.task.TaskExecutorConfig; import com.glxp.api.util.CustomUtil; import com.glxp.api.util.RedisUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -36,8 +44,10 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.List; +import java.util.concurrent.CompletableFuture; @RestController +@RequiredArgsConstructor public class SpsSyncExportStatusController { @@ -229,6 +239,43 @@ public class SpsSyncExportStatusController { } + private final SpsSyncDownloadService spsSyncDownloadService; + private final SyncDataSetService syncDataSetService; + private final ThreadPoolTaskExecutor executorConfig; + + /** + * 手动同步数据 + * + * @param req 参数 + * @return 结果 + */ + @AuthRuleAnnotation("") + @PostMapping("/spssync/udiinfo/syncData") + public BaseResponse syncData(@RequestBody ManualSyncDataReq req) { + + if (req.getExportType() == null || req.getSyncTime() == null) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); + } + SyncDataSetResponse syncDataSetEntity = syncDataSetService.selectSet(); + + if (syncDataSetEntity.getSyncTime() == null) { + return ResultVOUtils.error(ResultEnum.NOT_NETWORK.getCode(), "缺少初始化数据"); + } + CompletableFuture future = CompletableFuture.runAsync(() -> { + switch (req.getExportType()) { + case IO_ORDER: + spsSyncDownloadService.syncOrderTask(); + break; + case COUNTRY_DI_DATA: + spsSyncDownloadService.syncDiProductsTask(); + break; + default: + spsSyncDownloadService.syncData(syncDataSetEntity, req.getExportType(), req.getSyncTime()); + } + }, executorConfig); + + return ResultVOUtils.success(); + } } diff --git a/src/main/java/com/glxp/api/entity/sync/BasicDownloadStatusEntity.java b/src/main/java/com/glxp/api/entity/sync/BasicDownloadStatusEntity.java index eb64afa7..688a7830 100644 --- a/src/main/java/com/glxp/api/entity/sync/BasicDownloadStatusEntity.java +++ b/src/main/java/com/glxp/api/entity/sync/BasicDownloadStatusEntity.java @@ -35,5 +35,4 @@ public class BasicDownloadStatusEntity { private String remark; @TableField(value = "cacheFilePath") private String cacheFilePath; - private String execInfo; } diff --git a/src/main/java/com/glxp/api/req/sync/ManualSyncDataReq.java b/src/main/java/com/glxp/api/req/sync/ManualSyncDataReq.java new file mode 100644 index 00000000..e4738caa --- /dev/null +++ b/src/main/java/com/glxp/api/req/sync/ManualSyncDataReq.java @@ -0,0 +1,18 @@ +package com.glxp.api.req.sync; + +import com.glxp.api.constant.BasicExportTypeEnum; +import lombok.Data; + +import java.util.Date; + +/** + * 手动调用同步数据 + */ +@Data +public class ManualSyncDataReq { + + private BasicExportTypeEnum exportType; + + private Date syncTime; + +} diff --git a/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java b/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java index f3a2acfb..31cdbdc6 100644 --- a/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java +++ b/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java @@ -176,78 +176,33 @@ public class SpsSyncDownloadService { * @param info 同步设置 * @param exportType 数据模块类型 */ - public void syncData(SyncDataSetResponse info, BasicExportTypeEnum exportType) { + public void syncData(SyncDataSetResponse info, BasicExportTypeEnum exportType, Date syncTime) { Date now = new Date(); switch (exportType) { case BASIC_DATA: if (needExec(info.getBasicProducts(), info.getBasicCorp(), info.getSupCert())) { basicExportInfoCreate(exportType, now - , x -> x.generateBasicDataFile(info, now, false) - , x -> x.generateBasicDataFile(info, now, true)); + , x -> x.generateBasicDataFile(info, now, false, syncTime) + , x -> x.generateBasicDataFile(info, now, true, syncTime)); } break; case OTHER_DATA: if (needExec(info.getUdiCodeLost(), info.getUdiCodeRel())) { basicExportInfoCreate(exportType, now - , x -> x.generateOtherDataFile(info, now, false) - , x -> x.generateOtherDataFile(info, now, true)); + , x -> x.generateOtherDataFile(info, now, false, syncTime) + , x -> x.generateOtherDataFile(info, now, true, syncTime)); } break; case DOCUMENT_TYPE_DATA: if (needExec(info.getTypeBus(), info.getTypeScan(), info.getTypeThird())) { basicExportInfoCreate(exportType, now - , x -> x.generateDocumentTypeDataFile(info, now, false) - , x -> x.generateDocumentTypeDataFile(info, now, true)); + , x -> x.generateDocumentTypeDataFile(info, now, false, syncTime) + , x -> x.generateDocumentTypeDataFile(info, now, true, syncTime)); } break; } } - /** - * 同步基础数据模块 - * - * @param info 同步设置 - */ - public void syncBasicData(SyncDataSetResponse info) { - - Date now = new Date(); - //是否需要执行 - boolean needExec = info.getBasicProducts() == 2 || info.getBasicCorp() == 2 || info.getSupCert() == 2; - if (!needExec) { - return; - } - try { - basicExportInfoCreate(BasicExportTypeEnum.BASIC_DATA, now - , x -> x.generateBasicDataFile(info, now, false) - , x -> x.generateBasicDataFile(info, now, true)); - } catch (Exception e) { - throw new RuntimeException(e); - } - - } - - /** - * 同步其他模块 - * - * @param info 同步设置 - */ - public void syncOtherData(SyncDataSetResponse info) { - - Date now = new Date(); - //是否需要执行 - boolean needExec = info.getUdiCodeLost() == 2 || info.getUdiCodeRel() == 2; - if (!needExec) { - return; - } - try { - basicExportInfoCreate(BasicExportTypeEnum.OTHER_DATA, now - , x -> x.generateOtherDataFile(info, now, false) - , x -> x.generateOtherDataFile(info, now, true)); - } catch (Exception e) { - throw new RuntimeException(e); - } - - } /** * 判断是否需要执行 @@ -315,17 +270,25 @@ public class SpsSyncDownloadService { * @param createFile 是否创建文件 * @return 是否有数据 true/false 有新数据/无新数据 */ - protected boolean generateBasicDataFile(SyncDataSetResponse info, Date now, boolean createFile) { + protected boolean generateBasicDataFile(SyncDataSetResponse info, Date now, boolean createFile, Date syncTime) { BasicExportTypeEnum exportType = BasicExportTypeEnum.BASIC_DATA; //文件数据 Map jsonMap = new WeakHashMap<>(4); List syncFiles = new ArrayList<>(); Map> totalTimeMap = new WeakHashMap<>(10); StringBuffer remark = new StringBuffer(); + Map syncTimeMap = new WeakHashMap<>(3); + syncTimeMap.put("isNew", true); try { //确认有开启物资字典由外向内同步 if (needExec(info.getBasicProducts())) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_PRODUCTS, createFile); + Map map; + if (syncTime == null) { + map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_PRODUCTS, createFile); + } else { + map = syncTimeMap; + now = syncTime; + } totalTimeMap.put(BasicExportStatusTimeEnum.BASIC_PRODUCTS, map); List hospTypeList = hospTypeService.list(Wrappers.lambdaQuery(BasicHospTypeEntity.class) .le((boolean) map.get("isNew"), BasicHospTypeEntity::getUpdateTime, now) @@ -366,7 +329,13 @@ public class SpsSyncDownloadService { } //确认有开启往来单位字典同步 if (needExec(info.getBasicCorp())) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_CORP, createFile); + Map map; + if (syncTime == null) { + map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_CORP, createFile); + } else { + map = syncTimeMap; + now = syncTime; + } totalTimeMap.put(BasicExportStatusTimeEnum.BASIC_CORP, map); List corpList = corpService.list(Wrappers.lambdaQuery(BasicCorpEntity.class) .le((boolean) map.get("isNew"), BasicCorpEntity::getUpdateTime, now) @@ -381,7 +350,13 @@ public class SpsSyncDownloadService { //确认有开启首营资质同步 if (needExec(info.getSupCert())) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.SUP_CERT, createFile); + Map map; + if (syncTime == null) { + map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.SUP_CERT, createFile); + } else { + map = syncTimeMap; + now = syncTime; + } totalTimeMap.put(BasicExportStatusTimeEnum.SUP_CERT, map); List supCertList = supCertService.list(Wrappers.lambdaQuery(SupCertEntity.class) .le((boolean) map.get("isNew"), SupCertEntity::getUpdateTime, now) @@ -488,16 +463,24 @@ public class SpsSyncDownloadService { * @param createFile 是否创建文件 * @return 是否有数据 true/false 有新数据/无新数据 */ - protected boolean generateOtherDataFile(SyncDataSetResponse info, Date now, boolean createFile) { + protected boolean generateOtherDataFile(SyncDataSetResponse info, Date now, boolean createFile, Date syncTime) { StringBuffer remark = new StringBuffer(); BasicExportTypeEnum exportType = BasicExportTypeEnum.OTHER_DATA; //文件数据 Map jsonMap = new WeakHashMap<>(4); Map> totalTimeMap = new WeakHashMap<>(10); + Map syncTimeMap = new WeakHashMap<>(3); + syncTimeMap.put("isNew", true); try { //确认有开启物资字典由外向内同步 if (info.getUdiCodeLost() == 2) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_LOST, createFile); + Map map; + if (syncTime == null) { + map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_LOST, createFile); + } else { + map = syncTimeMap; + now = syncTime; + } totalTimeMap.put(BasicExportStatusTimeEnum.IO_CODE_LOST, map); List ioCodeLostList = ioCodeLostService.list(Wrappers.lambdaQuery(IoCodeLostEntity.class) .le((boolean) map.get("isNew"), IoCodeLostEntity::getUpdateTime, now) @@ -511,7 +494,13 @@ public class SpsSyncDownloadService { } //确认有开启udi关联关系同步 if (info.getUdiCodeRel() == 2) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_REL, createFile); + Map map; + if (syncTime == null) { + map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_REL, createFile); + } else { + map = syncTimeMap; + now = syncTime; + } totalTimeMap.put(BasicExportStatusTimeEnum.IO_CODE_REL, map); List ioCodeRelList = ioCodeRelService.list(Wrappers.lambdaQuery(IoCodeRelEntity.class) .le((boolean) map.get("isNew"), IoCodeRelEntity::getUpdateTime, now) @@ -572,16 +561,24 @@ public class SpsSyncDownloadService { * @param createFile 是否创建文件 * @return 是否有数据 true/false 有新数据/无新数据 */ - protected boolean generateDocumentTypeDataFile(SyncDataSetResponse info, Date now, boolean createFile) { + protected boolean generateDocumentTypeDataFile(SyncDataSetResponse info, Date now, boolean createFile, Date syncTime) { StringBuffer remark = new StringBuffer(); BasicExportTypeEnum exportType = BasicExportTypeEnum.DOCUMENT_TYPE_DATA; //文件数据 Map jsonMap = new WeakHashMap<>(4); Map> totalTimeMap = new WeakHashMap<>(10); + Map syncTimeMap = new WeakHashMap<>(3); + syncTimeMap.put("isNew", true); try { //确认有开启业务单据类型同步 if (needExec(info.getTypeBus())) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSSINESS_TYPE, createFile); + Map map; + if (syncTime == null) { + map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSSINESS_TYPE, createFile); + } else { + map = syncTimeMap; + now = syncTime; + } totalTimeMap.put(BasicExportStatusTimeEnum.BASIC_BUSSINESS_TYPE, map); List bussinessTypeEntities = bussinessTypeService.list(Wrappers.lambdaQuery(BasicBussinessTypeEntity.class) .le((boolean) map.get("isNew"), BasicBussinessTypeEntity::getUpdateTime, now) @@ -595,7 +592,13 @@ public class SpsSyncDownloadService { } //确认有开启扫码单据类型同步 if (needExec(info.getTypeScan())) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSTYPE_CHANGE, createFile); + Map map; + if (syncTime == null) { + map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSTYPE_CHANGE, createFile); + } else { + map = syncTimeMap; + now = syncTime; + } totalTimeMap.put(BasicExportStatusTimeEnum.BASIC_BUSTYPE_CHANGE, map); List busTypeChangeEntities = busTypeChangeService.list(Wrappers.lambdaQuery(BasicBusTypeChangeEntity.class) .le((boolean) map.get("isNew"), BasicBusTypeChangeEntity::getUpdateTime, now) @@ -609,7 +612,13 @@ public class SpsSyncDownloadService { } //确认有开启第三方单据类型同步 if (needExec(info.getTypeThird())) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_BUSTYPE_ORIGIN, createFile); + Map map; + if (syncTime == null) { + map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_BUSTYPE_ORIGIN, createFile); + } else { + map = syncTimeMap; + now = syncTime; + } totalTimeMap.put(BasicExportStatusTimeEnum.THR_BUSTYPE_ORIGIN, map); List thrBusTypeOriginEntities = thrBusTypeOriginService.list(Wrappers.lambdaQuery(ThrBusTypeOriginEntity.class) .le((boolean) map.get("isNew"), ThrBusTypeOriginEntity::getUpdateTime, now) diff --git a/src/main/java/com/glxp/api/task/AsyncHeartTask.java b/src/main/java/com/glxp/api/task/AsyncHeartTask.java index 85afa253..2812ef7e 100644 --- a/src/main/java/com/glxp/api/task/AsyncHeartTask.java +++ b/src/main/java/com/glxp/api/task/AsyncHeartTask.java @@ -68,7 +68,7 @@ public class AsyncHeartTask implements SchedulingConfigurer { spsSyncDownloadService.syncDiProductsTask(); // todo 生成任务都写在这 Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> { - spsSyncDownloadService.syncData(syncDataSetEntity, i); + spsSyncDownloadService.syncData(syncDataSetEntity, i, null); }); // spsSyncDownloadService.syncBasicData(syncDataSetEntity); // spsSyncDownloadService.syncOtherData(syncDataSetEntity); diff --git a/src/main/resources/schemas/schema_v2.1.sql b/src/main/resources/schemas/schema_v2.1.sql index 38fba94f..a5e1798a 100644 --- a/src/main/resources/schemas/schema_v2.1.sql +++ b/src/main/resources/schemas/schema_v2.1.sql @@ -1,7 +1,5 @@ # 字段新增 (表名,字段名,字段类型,修改方式(1:新增,2:修改,3:删除) -CALL Pro_Temp_ColumnWork('basic_download_status', 'execInfo', - 'varchar(255) ', 1); CALL Pro_Temp_ColumnWork('basic_download_status', 'cacheFilePath', 'varchar(255) ', 1);