|
|
@ -68,6 +68,14 @@ public class UpdateService {
|
|
|
|
@PostConstruct
|
|
|
|
@PostConstruct
|
|
|
|
public void upload() {
|
|
|
|
public void upload() {
|
|
|
|
initLianZhongPatPicDir();
|
|
|
|
initLianZhongPatPicDir();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExecutorService syncExecutors = Executors.newFixedThreadPool(2);
|
|
|
|
|
|
|
|
syncExecutors.execute(this::syncNotStart);
|
|
|
|
|
|
|
|
syncExecutors.execute(this::sycDirNotExistsJob);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void syncNotStart(){
|
|
|
|
log.info("联众同步数据启动>>>>>>>>>>>>>>>>>>>>");
|
|
|
|
log.info("联众同步数据启动>>>>>>>>>>>>>>>>>>>>");
|
|
|
|
String syncDir = FilePathUtil.currentPath() + File.separator + "lianzhong-sync";
|
|
|
|
String syncDir = FilePathUtil.currentPath() + File.separator + "lianzhong-sync";
|
|
|
|
FilePathUtil.mkdirs(syncDir);
|
|
|
|
FilePathUtil.mkdirs(syncDir);
|
|
|
@ -236,6 +244,131 @@ public class UpdateService {
|
|
|
|
log.error("联众同步数据异常:" + ex.getMessage(), ex);
|
|
|
|
log.error("联众同步数据异常:" + ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sycDirNotExistsJob() {
|
|
|
|
|
|
|
|
while (true){
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
sycDirNotExists();
|
|
|
|
|
|
|
|
TimeUnit.SECONDS.sleep(600);
|
|
|
|
|
|
|
|
}catch (Exception ex){
|
|
|
|
|
|
|
|
log.error("补偿异常 ,"+ex.getMessage(),ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void sycDirNotExists() {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
UpdateService updateService = new UpdateService();
|
|
|
|
UpdateService updateService = new UpdateService();
|
|
|
@ -434,119 +567,6 @@ 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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|