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 a52bf1e7..57428fe7 100644 --- a/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java +++ b/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java @@ -2,6 +2,7 @@ package com.glxp.api.controller.sync; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Dict; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.common.enums.ResultEnum; @@ -61,10 +62,7 @@ import javax.validation.Valid; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; @RestController public class SpsSyncDownloadController { @@ -154,13 +152,13 @@ public class SpsSyncDownloadController { @AuthRuleAnnotation("") @GetMapping("sps/sync/data") public BaseResponse data(BasicExportTypeEnum exportType) { - BaseResponse baseResponse = new BaseResponse<>(); + 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; + RelaySyncResponse relaySyncResponse = null; if (one != null) { if (BasicExportStatusEnum.WAIT_TRIGGERED.getCode().equals(one.getStatus())) { basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) @@ -170,81 +168,36 @@ public class SpsSyncDownloadController { .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: + if (StrUtil.isBlank(one.getCacheFilePath())) { + throw new RuntimeException("系统异常,文件名为空"); } - // 修改任务状态 -// 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()) -// ); + relaySyncResponse = RelaySyncResponse.builder() + .taskId(one.getId()) + .filePath(one.getCacheFilePath()) + .fileContent(this.readDataFile(one.getCacheFilePath())) + .build(); } } baseResponse.setCode(ResultEnum.SUCCESS.getCode()); - baseResponse.setData(result); + baseResponse.setData(relaySyncResponse); return baseResponse; } - private SpsSyncBasicDataResponse readBasicDataFile(BasicExportStatusEntity one) { + private String readDataFile(String fileFullPath) { // 读取文件数据 try { - FileReader reader = new FileReader(one.getCacheFilePath()); - StringBuilder str = new StringBuilder(); - int data; - while ((data = reader.read()) != -1) { - str.append((char) data); + if (StrUtil.isBlank(fileFullPath)) { + throw new RuntimeException("系统异常,文件名为空"); } - 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()); + FileReader reader = new FileReader(fileFullPath); 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; + return str.toString(); } catch (FileNotFoundException e) { throw new RuntimeException("系统异常,未找到对应数据文件"); } catch (IOException e) { diff --git a/src/main/java/com/glxp/api/res/sync/RelaySyncResponse.java b/src/main/java/com/glxp/api/res/sync/RelaySyncResponse.java new file mode 100644 index 00000000..6c08fcc0 --- /dev/null +++ b/src/main/java/com/glxp/api/res/sync/RelaySyncResponse.java @@ -0,0 +1,16 @@ +package com.glxp.api.res.sync; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class RelaySyncResponse { + String taskId; + String filePath; + String fileContent; +} 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 3037be40..26628222 100644 --- a/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java +++ b/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java @@ -363,7 +363,7 @@ public class SpsSyncDownloadService { total += l.size(); } try { - //插入一条任务数据 + //修改任务数据 boolean update = basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode()) .set(BasicExportStatusEntity::getUpdateTime, new Date()) @@ -450,7 +450,7 @@ public class SpsSyncDownloadService { total += l.size(); } try { - //插入一条任务数据 + //修改任务数据 boolean update = basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode()) .set(BasicExportStatusEntity::getUpdateTime, new Date())