提供一个统一下发数据接口

master
wj 2 years ago
parent b77913fd6f
commit bea7af1593

@ -2,6 +2,7 @@ package com.glxp.api.controller.sync;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Dict; import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.enums.ResultEnum;
@ -61,10 +62,7 @@ import javax.validation.Valid;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
@RestController @RestController
public class SpsSyncDownloadController { public class SpsSyncDownloadController {
@ -154,13 +152,13 @@ public class SpsSyncDownloadController {
@AuthRuleAnnotation("") @AuthRuleAnnotation("")
@GetMapping("sps/sync/data") @GetMapping("sps/sync/data")
public BaseResponse data(BasicExportTypeEnum exportType) { public BaseResponse data(BasicExportTypeEnum exportType) {
BaseResponse<Object> baseResponse = new BaseResponse<>(); BaseResponse<RelaySyncResponse> baseResponse = new BaseResponse<>();
BasicExportStatusEntity one = basicExportService.getOne(Wrappers.lambdaQuery(BasicExportStatusEntity.class) BasicExportStatusEntity one = basicExportService.getOne(Wrappers.lambdaQuery(BasicExportStatusEntity.class)
.eq(BasicExportStatusEntity::getType, exportType.getRemark()) .eq(BasicExportStatusEntity::getType, exportType.getRemark())
.orderByDesc(BasicExportStatusEntity::getStartTime) .orderByDesc(BasicExportStatusEntity::getStartTime)
.last("limit 1") .last("limit 1")
); );
Object result = null; RelaySyncResponse relaySyncResponse = null;
if (one != null) { if (one != null) {
if (BasicExportStatusEnum.WAIT_TRIGGERED.getCode().equals(one.getStatus())) { if (BasicExportStatusEnum.WAIT_TRIGGERED.getCode().equals(one.getStatus())) {
basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class)
@ -170,81 +168,36 @@ public class SpsSyncDownloadController {
.eq(BasicExportStatusEntity::getId, one.getId()) .eq(BasicExportStatusEntity::getId, one.getId())
); );
} else if (BasicExportStatusEnum.WAIT_SYNC.getCode().equals(one.getStatus())) { } else if (BasicExportStatusEnum.WAIT_SYNC.getCode().equals(one.getStatus())) {
switch (exportType) { if (StrUtil.isBlank(one.getCacheFilePath())) {
case BASIC_DATA: throw new RuntimeException("系统异常,文件名为空");
result = this.readBasicDataFile(one);
break;
case OTHER_DATA:
result = this.readOtherDataFile(one);
break;
case COUNTRY_DI_DATA:
} }
// 修改任务状态 relaySyncResponse = RelaySyncResponse.builder()
// basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) .taskId(one.getId())
// .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.COMPLETED.getCode()) .filePath(one.getCacheFilePath())
// .set(BasicExportStatusEntity::getUpdateTime, new Date()) .fileContent(this.readDataFile(one.getCacheFilePath()))
// .set(BasicExportStatusEntity::getEndTime, new Date()) .build();
// .eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode())
// .eq(BasicExportStatusEntity::getId, one.getId())
// );
} }
} }
baseResponse.setCode(ResultEnum.SUCCESS.getCode()); baseResponse.setCode(ResultEnum.SUCCESS.getCode());
baseResponse.setData(result); baseResponse.setData(relaySyncResponse);
return baseResponse; return baseResponse;
} }
private SpsSyncBasicDataResponse readBasicDataFile(BasicExportStatusEntity one) { private String readDataFile(String fileFullPath) {
// 读取文件数据 // 读取文件数据
try { try {
FileReader reader = new FileReader(one.getCacheFilePath()); if (StrUtil.isBlank(fileFullPath)) {
StringBuilder str = new StringBuilder(); throw new RuntimeException("系统异常,文件名为空");
int data;
while ((data = reader.read()) != -1) {
str.append((char) data);
} }
reader.close(); FileReader reader = new FileReader(fileFullPath);
Dict map = JsonUtils.parseMap(str.toString());
SpsSyncBasicDataResponse spsSyncBasicDataResponse = new SpsSyncBasicDataResponse();
// 组装返回数据
spsSyncBasicDataResponse.setTaskId(one.getId());
spsSyncBasicDataResponse.setHospTypeList((List<BasicHospTypeEntity>) map.get(BasicHospTypeEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setUdiRelevanceList((List<UdiRelevanceEntity>) map.get(UdiRelevanceEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setProductsList((List<BasicProductsEntity>) map.get(BasicProductsEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setRelevanceList((List<CompanyProductRelevanceEntity>) map.get(CompanyProductRelevanceEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setCorpList((List<BasicCorpEntity>) map.get(BasicCorpEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSupCertList((List<SupCertEntity>) map.get(SupCertEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSupCertSetList((List<SupCertSetEntity>) map.get(SupCertSetEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSupCompanyList((List<SupCompanyEntity>) map.get(SupCompanyEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSupManufacturerList((List<SupManufacturerEntity>) map.get(SupManufacturerEntity.class.getSimpleName()));
spsSyncBasicDataResponse.setSupProductList((List<SupProductEntity>) 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(); StringBuilder str = new StringBuilder();
int data; int data;
while ((data = reader.read()) != -1) { while ((data = reader.read()) != -1) {
str.append((char) data); str.append((char) data);
} }
reader.close(); reader.close();
Dict map = JsonUtils.parseMap(str.toString()); return str.toString();
SpsSyncOtherDataResponse spsSyncOtherDataResponse = new SpsSyncOtherDataResponse();
// 组装返回数据
spsSyncOtherDataResponse.setTaskId(one.getId());
spsSyncOtherDataResponse.setIoCodeLostList((List<IoCodeLostEntity>) map.get(IoCodeLostEntity.class.getSimpleName()));
spsSyncOtherDataResponse.setIoCodeRelList((List<IoCodeRelEntity>) map.get(IoCodeRelEntity.class.getSimpleName()));
return spsSyncOtherDataResponse;
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new RuntimeException("系统异常,未找到对应数据文件"); throw new RuntimeException("系统异常,未找到对应数据文件");
} catch (IOException e) { } catch (IOException e) {

@ -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;
}

@ -363,7 +363,7 @@ public class SpsSyncDownloadService {
total += l.size(); total += l.size();
} }
try { try {
//插入一条任务数据 //修改任务数据
boolean update = basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) boolean update = basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class)
.set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode()) .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode())
.set(BasicExportStatusEntity::getUpdateTime, new Date()) .set(BasicExportStatusEntity::getUpdateTime, new Date())
@ -450,7 +450,7 @@ public class SpsSyncDownloadService {
total += l.size(); total += l.size();
} }
try { try {
//插入一条任务数据 //修改任务数据
boolean update = basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) boolean update = basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class)
.set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode()) .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode())
.set(BasicExportStatusEntity::getUpdateTime, new Date()) .set(BasicExportStatusEntity::getUpdateTime, new Date())

Loading…
Cancel
Save