|
|
package com.docus.demo.service;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.XmlUtil;
|
|
|
import cn.hutool.http.webservice.SoapClient;
|
|
|
import com.docus.demo.dto.SyncBasicDataDto;
|
|
|
import com.docus.demo.entity.*;
|
|
|
import com.docus.demo.facade.IWebService;
|
|
|
import com.docus.demo.mapper.mysql.BasicMapper;
|
|
|
import com.docus.demo.mapper.mysql.ScanAssortMapper;
|
|
|
import com.docus.demo.utils.PDFFileUtils;
|
|
|
import com.docus.demo.utils.SnowflakeIdWorker;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class WebServiceImpl implements IWebService {
|
|
|
|
|
|
@Resource
|
|
|
private BasicMapper basicMapper;
|
|
|
@Resource
|
|
|
private ScanAssortMapper scanAssortMapper;
|
|
|
|
|
|
private SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker(0, 0);
|
|
|
|
|
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
|
|
private final ExecutorService executor = Executors.newFixedThreadPool(8);
|
|
|
|
|
|
@Override
|
|
|
public CommonResult<?> syncInspection(SyncBasicDataDto syncBasicDataDto) {
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
//页码
|
|
|
int current;
|
|
|
//每页1000条数据
|
|
|
int limit = syncBasicDataDto.getLimit();
|
|
|
|
|
|
for (current = 1; ; current++) {
|
|
|
//查询基础数据
|
|
|
List<Tbasic> tbasicList = basicMapper.getOldBasicListLimit((current - 1) * limit, limit, syncBasicDataDto.getInpatientNoList(), syncBasicDataDto);
|
|
|
log.info("病案大小" + tbasicList.size());
|
|
|
if (tbasicList.size() == 0) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
|
|
|
for (int j = 0; j < tbasicList.size(); j++) {
|
|
|
|
|
|
Tbasic tbasic = tbasicList.get(j);
|
|
|
log.info("正在同步" + tbasic.getInpatientNo() + " " + tbasic.getAdmissTimes());
|
|
|
|
|
|
|
|
|
List<ScanAssort> oldScanAssortList = scanAssortMapper.getListByAssortId("A5A7AA6796D1715A2F1E35699C706C84", tbasic.getPatientId());
|
|
|
log.info("旧数据" + oldScanAssortList.size());
|
|
|
if (oldScanAssortList.size()>0){
|
|
|
log.info("跳过同步" + tbasic.getInpatientNo() + " " + tbasic.getAdmissTimes());
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
String pNo = tbasic.getInpatientNo();
|
|
|
String times = tbasic.getAdmissTimes().toString();
|
|
|
// String StartDate = sdf.format(tbasic.getAdmissDate());
|
|
|
// String EndDate = sdf.format(tbasic.getDisDate());
|
|
|
String StartDate = "2018-01-01 00:00:00";
|
|
|
String EndDate = "2025-01-01 00:00:00";
|
|
|
String patientId = tbasic.getPatientId();
|
|
|
|
|
|
//获取所有的报告列表
|
|
|
PatientListResult patientListResult = getCommonResult(pNo, times, StartDate, EndDate);
|
|
|
|
|
|
// log.info("返回结果"+patientListResult);
|
|
|
if (patientListResult == null) {
|
|
|
log.error(pNo + " " + times + "调用失败");
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
List<ScanAssort> scanAssortList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
for (int i = 0; i < patientListResult.getResult().getPidReportMain().size(); i++) {
|
|
|
//根据旧数据判断是否需要做同步
|
|
|
PatientListResult.Result.ReportInfo item = patientListResult.getResult().getPidReportMain().get(i);
|
|
|
// ScanAssort oldAssort = oldScanAssortList.stream()
|
|
|
// .filter(f -> f.getFileTitle().equals(item.getPidComName())).findAny().orElse(null);
|
|
|
|
|
|
|
|
|
String root = "F:\\jianyan" + File.separator
|
|
|
+ tbasic.getInpatientNo() + File.separator
|
|
|
+ tbasic.getAdmissTimes();
|
|
|
|
|
|
// log.info("开始转换"+root);
|
|
|
//时间段内如果查询到住院次数相同的数据 则数据入库
|
|
|
if (item.getPidAddmissTimes().equals(times) && item.getPidInNo().equals(pNo)) {
|
|
|
log.info("正在同步" + item.getPidComName() + i);
|
|
|
// log.info("进入条件");
|
|
|
PatientReportResult patientReportResult = this.getReportResult(item.getRepId());
|
|
|
String base64Result = patientReportResult.getResult().getPatient().getPatientReport();
|
|
|
List<ScanAssort> addScanList = new ArrayList<>();
|
|
|
try {
|
|
|
log.info("开始转换");
|
|
|
addScanList = PDFFileUtils.base64StringToPDF(base64Result, root, item.getRepId(), item.getPidComName(), i);
|
|
|
log.info("转换结束");
|
|
|
} catch (IOException e) {
|
|
|
log.error("检验pdf转化出错" + e.getMessage(),e);
|
|
|
}
|
|
|
addScanList.forEach(scanAssort -> {
|
|
|
ScanAssort oldAssort = oldScanAssortList.stream()
|
|
|
.filter(f -> f.getScanPage().equals(scanAssort.getScanPage())).findAny().orElse(null);
|
|
|
if (oldAssort != null) {
|
|
|
scanAssort.setId(oldAssort.getId());
|
|
|
} else {
|
|
|
scanAssort.setId(snowflakeIdWorker.nextId());
|
|
|
}
|
|
|
scanAssort.setPatientId(patientId);
|
|
|
scanAssortList.add(scanAssort);
|
|
|
log.info("结果" + scanAssort);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//数据写入到3.0
|
|
|
if (ObjectUtil.isNotEmpty(scanAssortList)) {
|
|
|
log.info("开始写入" + scanAssortList.size());
|
|
|
scanAssortMapper.insertOrUpdateBatch(scanAssortList);
|
|
|
log.info("写入结束" + scanAssortList.size());
|
|
|
}
|
|
|
}
|
|
|
log.info("业务结束");
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage(), e);
|
|
|
}
|
|
|
|
|
|
|
|
|
}, executor);
|
|
|
|
|
|
|
|
|
return CommonResult.success("同步检验数据成功");
|
|
|
}
|
|
|
|
|
|
private PatientReportResult getReportResult(String repID) {
|
|
|
String paramMap =
|
|
|
"<![CDATA[<Request>" +
|
|
|
"<RepID>" + repID + "</RepID>" +
|
|
|
"<CustomReportSuffix></CustomReportSuffix>"
|
|
|
+ "</Request>]]>";
|
|
|
//拼接外层入参
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
|
params.put("MethodName", "GetPatientReport");
|
|
|
params.put("XMLData", paramMap);
|
|
|
Map<String, Object> result = this.request(params);
|
|
|
|
|
|
//转对象List stream获取报告id
|
|
|
return BeanUtil.fillBeanWithMap(result, new PatientReportResult(), false);
|
|
|
}
|
|
|
|
|
|
|
|
|
private PatientListResult getCommonResult(String pNo, String times, String StartDate, String EndDate) {
|
|
|
String paramMap =
|
|
|
"<![CDATA[<Request>" +
|
|
|
"<PidInNo>" + pNo + "</PidInNo>"
|
|
|
+ "<PidAddmissTimes>" + times + "</PidAddmissTimes>"
|
|
|
+ "<StartDate>" + StartDate + "</StartDate>"
|
|
|
+ "<EndDate>" + EndDate + "</EndDate>"
|
|
|
+ "</Request>]]>";
|
|
|
|
|
|
//拼接外层入参
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
|
params.put("MethodName", "GetPatientList");
|
|
|
params.put("XMLData", paramMap);
|
|
|
Map<String, Object> result = this.request(params);
|
|
|
// log.info(result.toString());
|
|
|
if (ObjectUtil.isEmpty(result.get("Result"))) {
|
|
|
// log.info(paramMap);
|
|
|
// log.info(result.toString());
|
|
|
return null;
|
|
|
}
|
|
|
//转对象List stream获取报告id
|
|
|
return BeanUtil.fillBeanWithMap(result, new PatientListResult(), false);
|
|
|
}
|
|
|
|
|
|
|
|
|
private Map<String, Object> request(Map<String, Object> params) {
|
|
|
String result = "";
|
|
|
try {
|
|
|
String url = "http://192.168.8.127:8040/DCLService.asmx";
|
|
|
SoapClient client = SoapClient.create(url);
|
|
|
client.header("SOAPAction", "http://dcl.org/DCLInterface");
|
|
|
// 设置要请求的方法,此接口方法前缀为web,传入对应的命名空间
|
|
|
client.setMethod("dcl:DCLInterface", "http://dcl.org/");
|
|
|
client.setParams(params, true);
|
|
|
|
|
|
// log.info("[请求ID:{}]测试方法字符串接口:{},入参:{}",requestId,url,client.getMsgStr(true));
|
|
|
// 发送请求,参数true表示返回一个格式化后的XML内容
|
|
|
// 返回内容为XML字符串,可以配合XmlUtil解析这个响应
|
|
|
result = client.send(false);
|
|
|
result = result.replaceAll(">", ">").replaceAll("<", "<");
|
|
|
|
|
|
// log.info("[请求ID:{}]测试方法字符串出参:{}",requestId,result);
|
|
|
if (result.contains("<DCLInterfaceResult>")) {
|
|
|
result = result.substring(result.indexOf("<DCLInterfaceResult>") + 20, result.indexOf("</DCLInterfaceResult>"));
|
|
|
} else {
|
|
|
result = result.substring(result.indexOf("Result>") + 7, result.indexOf("}</") + 1);
|
|
|
}
|
|
|
|
|
|
// log.info(result);
|
|
|
return XmlUtil.xmlToMap(result);
|
|
|
} catch (Exception ex) {
|
|
|
log.error("测试方法字符串出现异常,入参:{},出参:{},{}", params, result, ex);
|
|
|
throw ex;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|