You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jp2demo/src/main/java/com/docus/demo/service/SyncBasicFileImpl.java

137 lines
4.9 KiB
Java

package com.docus.demo.service;
import cn.hutool.core.util.ObjectUtil;
import com.docus.demo.entity.CommonResult;
import com.docus.demo.entity.TPicture;
2 years ago
import com.docus.demo.entity.sqlserver2.BasicInfo;
import com.docus.demo.entity.sqlserver2.Tscan;
import com.docus.demo.facade.ISyncBasicFileService;
import com.docus.demo.mapper.mysql.BasicMapper;
import com.docus.demo.mapper.mysql.ScanAssortMapper;
import com.docus.demo.mapper.sqlserver.PictureMapper;
2 years ago
import com.docus.demo.mapper.sqlserver2.TscanMapper;
import com.docus.demo.utils.ImageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service
public class SyncBasicFileImpl implements ISyncBasicFileService {
@Autowired
private BasicMapper basicMapper;
@Autowired
private PictureMapper pictureMapper;
@Autowired
private ScanAssortMapper scanAssortMapper;
2 years ago
@Autowired
private TscanMapper tscanMapper;
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
@Override
2 years ago
public CommonResult<?> syncChildren() {
//1.查询出101份的病案Pid 病案号 住院次数
List<BasicInfo> basicInfos = pictureMapper.getBasicInfoList();
//2.代入到联众数据库 查询图片信息
//3.根据id查询出文件信息
for (BasicInfo basicInfo: basicInfos) {
List<Tscan> oldScanList = tscanMapper.getOldScanListByPid(basicInfo.getPatientId());
//4.文件数据同步-> 路径 病案号 +病案id主键
List<Tscan> syncScanList = this.doSyncFile(basicInfo);
List<Tscan> insertList = this.getInsertList(oldScanList,syncScanList);
if (ObjectUtil.isNotEmpty(insertList)){
//5.数据入库tsacn
tscanMapper.insertScanList(insertList);
}
2 years ago
}
return CommonResult.success("同步成功");
}
2 years ago
private List<Tscan> getInsertList(List<Tscan> oldScanList, List<Tscan> syncScanList) {
return syncScanList.stream().filter(f->{
Tscan oldScan =oldScanList.stream()
.filter(old->ObjectUtil.equal(old.getPatientId(),f.getPatientId())&&ObjectUtil.equal(old.getScanPage(),f.getScanPage()))
.findFirst()
.orElse(null);
2 years ago
return oldScan==null;
}).collect(Collectors.toList());
}
2 years ago
private List<Tscan> doSyncFile(BasicInfo basicInfo) {
List<Tscan> tscanList = new ArrayList<>(1000);
//010 00 09590 19990405
String[] disDate = dateFormat.format(basicInfo.getDisDate()).split("-");
String cyYear = disDate[0];
String cyMonth = disDate[1];
String cyDay = disDate[2];
2 years ago
String inpatientNo = basicInfo.getInpatientNo();
String pid = basicInfo.getId();
//
String rootDir = "E:\\ServerE01"+File.separator
+cyYear+File.separator
+cyYear+cyMonth+ File.separator;
2 years ago
String outDir = "E:\\docus"+File.separator+inpatientNo+File.separator+pid ;
// 2.根据cid查询联众表t_picture 走索引大概零点几秒
2 years ago
List<TPicture> tPictureList = pictureMapper.getPictureInfoByCid(pid);
// 2.1根据病案信息拼接地址
2 years ago
for (TPicture tpicture : tPictureList) {
String picName = tpicture.getPicName().split(".jpg")[0];
String inPutFile = rootDir + picName + ".jp2";
String outFile = outDir + File.separator + picName + ".jpg";
boolean savePicFlag ;
boolean rotateFlag ;
// 2.2jp2转化jpg 图片通过文件流写到挂在的盘符
savePicFlag = ImageUtils.getInstance().savePic(inPutFile, outFile);
if (!savePicFlag){
//需要同步tif文件成jpg过来
savePicFlag = ImageUtils.getInstance().tifToJpg(rootDir + picName + ".tif",outFile);
}
//需要旋转一下文件
if (tpicture.getRotateDegree()!=0){
rotateFlag = ImageUtils.getInstance().rotateFile(outFile,outFile,tpicture.getRotateDegree());
}else {
rotateFlag = true;
}
// 2.4组合文件信息
2 years ago
Tscan tscan = new Tscan();
tscan.setPatientId(pid);
tscan.setAssortId(tpicture.getPicKind());
tscan.setScanPage(picName+".jpg");
if (savePicFlag&&rotateFlag){
2 years ago
tscan.setUpState(200);
}else if (savePicFlag){
2 years ago
tscan.setUpState(102);
//需要记录创建人为auto3表示同步失败的文件
}else {
2 years ago
tscan.setUpState(404);
}
2 years ago
tscanList.add(tscan);
}
2 years ago
return tscanList;
}
}