feat: 添加后期人工处理接口

厦门中医院联众-XiaMenZhongLianZhong
wyb 5 months ago
parent a5ff268a86
commit dc62b04aee

@ -0,0 +1,36 @@
package com.jiashi.controller;
import com.jiashi.CommonResult;
import com.jiashi.service.UpdateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author YongBin Wen
* @date 2025/2/13 19:50
*/
@RestController
@Slf4j
@Api(tags = "厦门中医院联众同步接口")
@RequestMapping("/xiamenzyy/lianzhong")
public class LianZhongSyncController {
@Autowired
private UpdateService updateService;
@ApiOperation(value = "补偿状态为4的患者状态为2原因是没找到患者目录的手动处理后添加目录并且状态改为4")
@GetMapping("/sync/dirnotexists")
public CommonResult<String> sycDirNotExists() {
try {
updateService.sycDirNotExists();
return CommonResult.success("补偿完毕!");
} catch (Exception ex) {
log.error("补偿异常 ");
return CommonResult.failed("补偿异常!");
}
}
}

@ -42,6 +42,8 @@ public class CardInfo {
private Date patbirthday;
private Integer state;
private String describe;
@Column(name="findpicpath")
private String findpicpath;
private String icdecode11;

@ -8,6 +8,7 @@ import com.jiashi.dao.DataQuery;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@ -43,6 +44,8 @@ public class UpdateService {
@Autowired
private DataQuery dataQuery;
@Value("${lz.uploadUrl:http://129.7.1.25:9511/lianzhong/batchFileUploadJpg}")
private String uploadUrl;
private Set<String> lianZhongPatPicDirs = new HashSet<>();
@ -182,7 +185,7 @@ public class UpdateService {
List<FormField> params = new ArrayList<>();
String s = new Gson().toJson(uploadInfo);
params.add(new FormField("uploadFileParams", s));
CommonResult commonResult = FileUploader.uploadFilesWithParams(batch, "http://129.7.1.25:9511/lianzhong/batchFileUploadJpg", params);
CommonResult commonResult = FileUploader.uploadFilesWithParams(batch, uploadUrl, params);
boolean res = commonResult.getCode() == 0;
success = success && res;
uploadInfo.setDelAllFile(0);
@ -192,7 +195,7 @@ public class UpdateService {
List<FormField> params = new ArrayList<>();
String s = new Gson().toJson(uploadInfo);
params.add(new FormField("uploadFileParams", s));
CommonResult commonResult = FileUploader.uploadFilesWithParams(files, "http://129.7.1.25:9511/lianzhong/batchFileUploadJpg", params);
CommonResult commonResult = FileUploader.uploadFilesWithParams(files, uploadUrl, params);
success = commonResult.getCode() == 0;
}
@ -392,12 +395,12 @@ public class UpdateService {
// gestno 或者 patno 进行 识别
if (StringUtils.hasText(gestno)) {
Set<String> picsByGestno = maybeMap.get(removeLeadingZeros(gestno));
if(!CollectionUtils.isEmpty(picsByGestno) && picsByGestno.size() == 1){
return new ArrayList<>(picsByGestno).get(0);
if (!CollectionUtils.isEmpty(picsByGestno) && picsByGestno.size() == 1) {
return new ArrayList<>(picsByGestno).get(0);
}
}
Set<String> picsByPatno = maybeMap.get(removeLeadingZeros(patno));
if(!CollectionUtils.isEmpty(picsByPatno) && picsByPatno.size() == 1){
if (!CollectionUtils.isEmpty(picsByPatno) && picsByPatno.size() == 1) {
return new ArrayList<>(picsByPatno).get(0);
}
return null;
@ -431,4 +434,119 @@ public class UpdateService {
}
public void sycDirNotExists() throws Exception {
initLianZhongPatPicDir();
log.info("联众补偿数据启动>>>>>>>>>>>>>>>>>>>>");
String syncDir = FilePathUtil.currentPath() + File.separator + "lianzhong-makeup-sync";
FilePathUtil.mkdirs(syncDir);
List<CardInfo> cardInfos = dataQuery.dateQuery(4);
if (!CollectionUtils.isEmpty(cardInfos)) {
for (CardInfo cardInfo : cardInfos) {
String picDir = syncDir + File.separator + cardInfo.getId();
FilePathUtil.mkdirs(picDir);
List<Picture> pictures = dataQuery.getPictures(cardInfo.getId());
String lianZhongDir = cardInfo.getFindpicpath();
if (lianZhongDir == null) {
FilePathUtil.deleteDir(picDir);
continue;
}
for (Picture picture : pictures) {
String tifFilePath = lianZhongDir + File.separator + removeFileExtension(picture.getPicname()) + ".tif";
File tifFile = new File(tifFilePath);
if (tifFile.exists()) {
try {
BufferedImage read = ImageIO.read(tifFile);
Thumbnails.of(read)
.scale(1)
.outputFormat("jpg")
.rotate(picture.getRotatedegree())
.toFile(picDir + File.separator + removeFileExtension(picture.getPicname()) + ".jpg");
read.flush();
} catch (IOException e) {
log.error("补偿转换文件失败pictureId=" + picture.getPicid() + "," + e.getMessage(), e);
}
}
}
LianZhongUploadInfo.PatientInfo patientInfo = convert(cardInfo);
List<LianZhongUploadInfo.FileInfo> fileInfos = new ArrayList<>();
List<String> faultFileNames = new ArrayList<>();
List<File> files = new ArrayList<>();
for (Picture picture : pictures) {
File pictureFile = new File(picDir + File.separator + removeFileExtension(picture.getPicname()) + ".jpg");
if (!pictureFile.exists()) {
faultFileNames.add(picture.getPicname());
continue;
}
files.add(pictureFile);
LianZhongUploadInfo.FileInfo fileInfo = new LianZhongUploadInfo.FileInfo();
fileInfo.setFileTitle(picture.getPicname());
fileInfo.setUploadFileName(pictureFile.getName());
fileInfo.setAssortId(picture.getPickind());
fileInfo.setSort(picture.getPicno());
fileInfos.add(fileInfo);
}
if (files.isEmpty()) {
dataQuery.updateBatchState(cardInfo, 2, "未获取到图片!");
// 删除文件
FilePathUtil.deleteDir(picDir);
continue;
}
LianZhongUploadInfo uploadInfo = new LianZhongUploadInfo();
uploadInfo.setPatientInfo(patientInfo);
uploadInfo.setFileInfos(fileInfos);
uploadInfo.setDelAllFile(1);
Map<String, LianZhongUploadInfo.FileInfo> fileInfoMap = fileInfos.stream()
.collect(Collectors.toMap(LianZhongUploadInfo.FileInfo::getUploadFileName, Function.identity()));
boolean success = true;
// 上传
int totalSize = files.size();
int batchSize = 500;
if (totalSize > batchSize) {
for (int i = 0; i < totalSize; i += batchSize) {
ArrayList<File> batch = new ArrayList<>();
List<LianZhongUploadInfo.FileInfo> uploadFileInfoList = new ArrayList<>();
// 计算当前批次的结束索引
int end = Math.min(i + batchSize, totalSize);
for (int j = i; j < end; j++) {
batch.add(files.get(j));
uploadFileInfoList.add(fileInfoMap.get(files.get(j).getName()));
}
uploadInfo.setFileInfos(uploadFileInfoList);
// 额外的表单字段参数
List<FormField> params = new ArrayList<>();
String s = new Gson().toJson(uploadInfo);
params.add(new FormField("uploadFileParams", s));
CommonResult commonResult = FileUploader.uploadFilesWithParams(batch, uploadUrl, params);
boolean res = commonResult.getCode() == 0;
success = success && res;
uploadInfo.setDelAllFile(0);
}
} else {
// 额外的表单字段参数
List<FormField> params = new ArrayList<>();
String s = new Gson().toJson(uploadInfo);
params.add(new FormField("uploadFileParams", s));
CommonResult commonResult = FileUploader.uploadFilesWithParams(files, uploadUrl, params);
success = commonResult.getCode() == 0;
}
if (success) {
dataQuery.updateBatchState(cardInfo, 3);
}
if (!faultFileNames.isEmpty()) {
// 不完整
dataQuery.updateBatchState(cardInfo, 2, String.join(",", faultFileNames + " 无法转换jpg图片"));
}
// 删除文件
FilePathUtil.deleteDir(picDir);
}
}
}
}

@ -4,6 +4,7 @@ server:
lz:
disdate-range: 2024-01-01 00:00:00,2024-08-01 00:00:00
uploadUrl: http://129.7.1.25:9511/lianzhong/batchFileUploadJpg
spring:
datasource:

Loading…
Cancel
Save