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

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.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<Object> baseResponse = new BaseResponse<>();
BaseResponse<RelaySyncResponse> 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<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());
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<IoCodeLostEntity>) map.get(IoCodeLostEntity.class.getSimpleName()));
spsSyncOtherDataResponse.setIoCodeRelList((List<IoCodeRelEntity>) map.get(IoCodeRelEntity.class.getSimpleName()));
return spsSyncOtherDataResponse;
return str.toString();
} catch (FileNotFoundException e) {
throw new RuntimeException("系统异常,未找到对应数据文件");
} 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();
}
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())

Loading…
Cancel
Save