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.
162 lines
5.7 KiB
Java
162 lines
5.7 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;
|
|
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;
|
|
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.Date;
|
|
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;
|
|
@Autowired
|
|
private TscanMapper tscanMapper;
|
|
|
|
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
@Override
|
|
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)){
|
|
//判断数据量 如果文件数据大于五百条 需要做拆分分批次插入
|
|
int batchSize = 100;
|
|
// 拆分列表
|
|
for (int i = 0; i < insertList.size(); i += batchSize) {
|
|
int endIndex = Math.min(i + batchSize, insertList.size());
|
|
List<Tscan> sublist = insertList.subList(i, endIndex);
|
|
//5.数据入库tsacn
|
|
tscanMapper.insertScanList(sublist);
|
|
}
|
|
}
|
|
}
|
|
return CommonResult.success("同步成功");
|
|
}
|
|
|
|
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);
|
|
return oldScan==null;
|
|
}).collect(Collectors.toList());
|
|
}
|
|
|
|
|
|
private List<Tscan> doSyncFile(BasicInfo basicInfo) {
|
|
List<Tscan> tscanList = new ArrayList<>(1000);
|
|
|
|
String[] disDate = dateFormat.format(basicInfo.getDisDate()).split("-");
|
|
String cyYear = disDate[0];
|
|
String cyMonth = disDate[1];
|
|
String cyDay = disDate[2];
|
|
String patPath = basicInfo.getPatPath();
|
|
String inpatientNo = basicInfo.getInpatientNo().trim();
|
|
|
|
String patientId = basicInfo.getPatientId();
|
|
String pid = basicInfo.getId();
|
|
|
|
|
|
String rootDir = "E:\\ServerE01"+File.separator
|
|
+cyYear+File.separator
|
|
+cyYear+cyMonth+ File.separator
|
|
+cyYear+cyMonth+cyDay+ File.separator
|
|
+patPath+File.separator;
|
|
|
|
String outDir = "E:\\docus"+File.separator+inpatientNo+File.separator+patientId ;
|
|
|
|
File file = new File(rootDir);
|
|
if (!file.exists()){
|
|
rootDir= basicInfo.getHostReason();
|
|
}
|
|
|
|
|
|
// 2.根据cid查询联众表t_picture 走索引大概零点几秒
|
|
List<TPicture> tPictureList = pictureMapper.getPictureInfoByCid(pid);
|
|
// 2.1根据病案信息拼接地址
|
|
|
|
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组合文件信息
|
|
Tscan tscan = new Tscan();
|
|
tscan.setPatientId(patientId);
|
|
tscan.setAssortId(tpicture.getPicKind());
|
|
tscan.setScanPage(picName+".jpg");
|
|
tscan.setUpDate(new Date());
|
|
|
|
if (savePicFlag&&rotateFlag){
|
|
tscan.setUpState(200);
|
|
}else if (savePicFlag){
|
|
tscan.setUpState(102);
|
|
//需要记录创建人为auto3表示同步失败的文件
|
|
}else {
|
|
tscan.setUpState(404);
|
|
}
|
|
|
|
tscanList.add(tscan);
|
|
|
|
if (!savePicFlag){
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
return tscanList;
|
|
}
|
|
|
|
}
|