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 89c1f2d4..a52bf1e7 100644 --- a/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java +++ b/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java @@ -4,12 +4,14 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Dict; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.glxp.api.annotation.AuthRuleAnnotation; +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.*; import com.glxp.api.controller.purchase.PurOrderController; import com.glxp.api.constant.BasicProcessStatus; import com.glxp.api.constant.ConstantStatus; +import com.glxp.api.dao.BaseMapperPlus; import com.glxp.api.dao.auth.*; import com.glxp.api.dao.basic.BasicBusTypeChangeDao; import com.glxp.api.dao.basic.BasicBusTypePreDao; @@ -148,6 +150,107 @@ public class SpsSyncDownloadController { return baseResponse; } + // 下发基础数据 ,供给中继服务,UDI管理系统下载 + @AuthRuleAnnotation("") + @GetMapping("sps/sync/data") + public BaseResponse data(BasicExportTypeEnum exportType) { + BaseResponse baseResponse = new BaseResponse<>(); + BasicExportStatusEntity one = basicExportService.getOne(Wrappers.lambdaQuery(BasicExportStatusEntity.class) + .eq(BasicExportStatusEntity::getType, exportType.getRemark()) + .orderByDesc(BasicExportStatusEntity::getStartTime) + .last("limit 1") + ); + Object result = null; + if (one != null) { + if (BasicExportStatusEnum.WAIT_TRIGGERED.getCode().equals(one.getStatus())) { + basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) + .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_BUILT.getCode()) + .set(BasicExportStatusEntity::getUpdateTime, new Date()) + .eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_TRIGGERED.getCode()) + .eq(BasicExportStatusEntity::getId, one.getId()) + ); + } else if (BasicExportStatusEnum.WAIT_SYNC.getCode().equals(one.getStatus())) { + switch (exportType) { + case BASIC_DATA: + result = this.readBasicDataFile(one); + break; + case OTHER_DATA: + result = this.readOtherDataFile(one); + break; + case COUNTRY_DI_DATA: + } + // 修改任务状态 +// basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) +// .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.COMPLETED.getCode()) +// .set(BasicExportStatusEntity::getUpdateTime, new Date()) +// .set(BasicExportStatusEntity::getEndTime, new Date()) +// .eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode()) +// .eq(BasicExportStatusEntity::getId, one.getId()) +// ); + } + } + baseResponse.setCode(ResultEnum.SUCCESS.getCode()); + baseResponse.setData(result); + return baseResponse; + } + + private SpsSyncBasicDataResponse readBasicDataFile(BasicExportStatusEntity one) { + + // 读取文件数据 + try { + FileReader reader = new FileReader(one.getCacheFilePath()); + StringBuilder str = new StringBuilder(); + int data; + while ((data = reader.read()) != -1) { + str.append((char) data); + } + reader.close(); + Dict map = JsonUtils.parseMap(str.toString()); + + SpsSyncBasicDataResponse spsSyncBasicDataResponse = new SpsSyncBasicDataResponse(); + // 组装返回数据 + spsSyncBasicDataResponse.setTaskId(one.getId()); + spsSyncBasicDataResponse.setHospTypeList((List) map.get(BasicHospTypeEntity.class.getSimpleName())); + spsSyncBasicDataResponse.setUdiRelevanceList((List) map.get(UdiRelevanceEntity.class.getSimpleName())); + spsSyncBasicDataResponse.setProductsList((List) map.get(BasicProductsEntity.class.getSimpleName())); + spsSyncBasicDataResponse.setRelevanceList((List) map.get(CompanyProductRelevanceEntity.class.getSimpleName())); + spsSyncBasicDataResponse.setCorpList((List) map.get(BasicCorpEntity.class.getSimpleName())); + spsSyncBasicDataResponse.setSupCertList((List) map.get(SupCertEntity.class.getSimpleName())); + spsSyncBasicDataResponse.setSupCertSetList((List) map.get(SupCertSetEntity.class.getSimpleName())); + spsSyncBasicDataResponse.setSupCompanyList((List) map.get(SupCompanyEntity.class.getSimpleName())); + spsSyncBasicDataResponse.setSupManufacturerList((List) map.get(SupManufacturerEntity.class.getSimpleName())); + spsSyncBasicDataResponse.setSupProductList((List) map.get(SupProductEntity.class.getSimpleName())); + return spsSyncBasicDataResponse; + } catch (FileNotFoundException e) { + throw new RuntimeException("系统异常,未找到对应数据文件"); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private SpsSyncOtherDataResponse readOtherDataFile(BasicExportStatusEntity one) { + // 读取文件数据 + try { + FileReader reader = new FileReader(one.getCacheFilePath()); + StringBuilder str = new StringBuilder(); + int data; + while ((data = reader.read()) != -1) { + str.append((char) data); + } + reader.close(); + Dict map = JsonUtils.parseMap(str.toString()); + SpsSyncOtherDataResponse spsSyncOtherDataResponse = new SpsSyncOtherDataResponse(); + // 组装返回数据 + spsSyncOtherDataResponse.setTaskId(one.getId()); + spsSyncOtherDataResponse.setIoCodeLostList((List) map.get(IoCodeLostEntity.class.getSimpleName())); + spsSyncOtherDataResponse.setIoCodeRelList((List) map.get(IoCodeRelEntity.class.getSimpleName())); + return spsSyncOtherDataResponse; + } catch (FileNotFoundException e) { + throw new RuntimeException("系统异常,未找到对应数据文件"); + } catch (IOException e) { + throw new RuntimeException(e); + } + } // 下发基础数据 ,供给中继服务,UDI管理系统下载 @AuthRuleAnnotation("")