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