|
|
|
@ -1,24 +1,16 @@
|
|
|
|
|
package com.docus.bgts.service;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.docus.bgts.entity.*;
|
|
|
|
|
import com.docus.bgts.enums.Codes;
|
|
|
|
|
import com.docus.bgts.facade.IAfCollectTaskService;
|
|
|
|
|
import com.docus.bgts.facade.IMzSyncService;
|
|
|
|
|
import com.docus.bgts.mapper.dbmysql.ZdAssortMapper;
|
|
|
|
|
import com.docus.bgts.mapper.dbmysql.AfCollectAddMapper;
|
|
|
|
|
import com.docus.bgts.mapper.dbmysql.TScanAssortMapper;
|
|
|
|
|
import com.docus.bgts.mapper.dboracle.MzSyncMapper;
|
|
|
|
|
import com.docus.bgts.utils.FileUtils;
|
|
|
|
|
import com.docus.bgts.utils.HttpUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.LocalTime;
|
|
|
|
@ -59,138 +51,24 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
TScanAssortMapper tScanAssortMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
IAfCollectTaskService afCollectTaskService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
ZdAssortMapper zdAssortMapper;
|
|
|
|
|
|
|
|
|
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
|
|
|
|
UpdateFileService updateFileService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 截取url
|
|
|
|
|
* @param str
|
|
|
|
|
* 梅州完整性校验规则
|
|
|
|
|
* @param jzhs
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String subStrUrl(String str) {
|
|
|
|
|
List<String> replaceUrls = (List<String>) FileUtils.getJsonByName("replaceUrl");
|
|
|
|
|
if(null != replaceUrls){
|
|
|
|
|
for(String replaceUrl : replaceUrls){
|
|
|
|
|
str = str.replaceAll(replaceUrl,"");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean addSyncIntegrality(String startDate,String endDate) {
|
|
|
|
|
//定义是否更新采集时间
|
|
|
|
|
boolean flag = true;
|
|
|
|
|
log.info("增量完整性同步开始");
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
//获取分页数
|
|
|
|
|
Integer pageSize = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("pageSize")));
|
|
|
|
|
int count = 0;
|
|
|
|
|
List<String> jzhs;
|
|
|
|
|
int front;
|
|
|
|
|
int later;
|
|
|
|
|
for (int i = 0; ; i++) {
|
|
|
|
|
front = i * pageSize;
|
|
|
|
|
later = pageSize;
|
|
|
|
|
jzhs = afCollectAddMapper.listJzhAndAdd(front, later, startDate,endDate);
|
|
|
|
|
count += jzhs.size();
|
|
|
|
|
if (jzhs.size() == 0) {
|
|
|
|
|
if(i == 0){
|
|
|
|
|
flag = false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
addSyncIntegralityByJzhsMethod(jzhs,front,later);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
|
|
log.info("增量完整性同步结束,程序执行时间为:" + (endTime - startTime) + "毫秒");
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addSyncIntegralityByJzhs(String jzhs,int front,int later) {
|
|
|
|
|
List<String> jzhList = Arrays.asList(jzhs.split(","));
|
|
|
|
|
addSyncIntegralityByJzhsMethod(jzhList,front,later);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addSyncIntegralityByJzhsMethod(List<String> jzhs,int front,int later) {
|
|
|
|
|
List<MzSync> mzSyncs;
|
|
|
|
|
mzSyncs = mzSyncMapper.listMzSync(jzhs, front, later, tableName, tableNamespaces);
|
|
|
|
|
//完整性检验写入
|
|
|
|
|
integralityBySyncs(mzSyncs,jzhs);
|
|
|
|
|
if (mzSyncs.size() != 0) {
|
|
|
|
|
log.info("本次成功同步数:" + mzSyncs.size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 完整性同步方法
|
|
|
|
|
*/
|
|
|
|
|
// @Transactional
|
|
|
|
|
@Override
|
|
|
|
|
public void syncIntegrality() {
|
|
|
|
|
log.info("完整性同步开始");
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
//获取分页数
|
|
|
|
|
Integer pageSize = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("pageSize")));
|
|
|
|
|
List<String> jzhs;
|
|
|
|
|
int front;
|
|
|
|
|
int later;
|
|
|
|
|
List<MzSync> mzSyncs;
|
|
|
|
|
for (int i = 0; ; i++) {
|
|
|
|
|
front = i * pageSize;
|
|
|
|
|
later = pageSize;
|
|
|
|
|
jzhs = afCollectAddMapper.listJzh(front, later);
|
|
|
|
|
if (jzhs.size() == 0) {
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
mzSyncs = mzSyncMapper.listMzSync(jzhs, front, later, tableName, tableNamespaces);
|
|
|
|
|
//完整性检验写入
|
|
|
|
|
integralityBySyncs(mzSyncs,jzhs);
|
|
|
|
|
}
|
|
|
|
|
if (mzSyncs.size() != 0) {
|
|
|
|
|
log.info("本次成功同步数:" + mzSyncs.size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
|
|
log.info("完整性同步结束,程序执行时间为:" + (endTime - startTime) + "毫秒");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 完整性检验写入
|
|
|
|
|
*
|
|
|
|
|
* @param mzSyncs
|
|
|
|
|
*/
|
|
|
|
|
private void integralityBySyncs(List<MzSync> mzSyncs,List<String> jzhs) {
|
|
|
|
|
StringBuilder sql;
|
|
|
|
|
if (mzSyncs.size() != 0) {
|
|
|
|
|
//List<Map> maps = afCollectAddMapper.integrality(mzSyncs);
|
|
|
|
|
List<Map> maps = verifyIntegrity(mzSyncs,jzhs);
|
|
|
|
|
sql = new StringBuilder();
|
|
|
|
|
for (Map map : maps) {
|
|
|
|
|
sql.append("update docus_medicalrecord.t_basic set integrity_desc=");
|
|
|
|
|
sql.append("'");
|
|
|
|
|
sql.append(map.get("file_title"));
|
|
|
|
|
sql.append("',update_time=now()");
|
|
|
|
|
sql.append(" where jzh=");
|
|
|
|
|
sql.append("'");
|
|
|
|
|
sql.append(map.get("jzh"));
|
|
|
|
|
sql.append("'");
|
|
|
|
|
sql.append(";");
|
|
|
|
|
}
|
|
|
|
|
System.out.println(sql);
|
|
|
|
|
afCollectAddMapper.dynamicSql(sql.toString());
|
|
|
|
|
}
|
|
|
|
|
public List<Map> getCompleteIntegrity(List<String> jzhs){
|
|
|
|
|
//根据记帐号查询任务视图
|
|
|
|
|
List<MzSync> mzSyncs = mzSyncMapper.listMzSync(jzhs,tableName, tableNamespaces);
|
|
|
|
|
//校验完整性
|
|
|
|
|
List<Map> maps = verifyIntegrity(mzSyncs,jzhs);
|
|
|
|
|
return maps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验完整性
|
|
|
|
|
* 梅州校验完整性
|
|
|
|
|
* @param mzSyncs
|
|
|
|
|
* @param jzhs
|
|
|
|
|
* @return
|
|
|
|
@ -250,7 +128,7 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
}
|
|
|
|
|
faultFileTitles.append(fileTitle + "缺失");
|
|
|
|
|
//调下载服务
|
|
|
|
|
updateFile(jzh,mzSyncDetail);
|
|
|
|
|
updateFileService.updateFile(jzh,mzSyncDetail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//添加急诊病历缺失
|
|
|
|
@ -269,114 +147,4 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
}
|
|
|
|
|
return maps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*{
|
|
|
|
|
* "assortid": "string",
|
|
|
|
|
* "collectorid": "string",
|
|
|
|
|
* "ip": "string",
|
|
|
|
|
* "patient": {
|
|
|
|
|
* "jzh": "string"
|
|
|
|
|
* },
|
|
|
|
|
* "scanfiles": [
|
|
|
|
|
* {
|
|
|
|
|
* "downurl": "string",
|
|
|
|
|
* "filesource": 0,
|
|
|
|
|
* "filestoragetype": 0,
|
|
|
|
|
* "filetitle": "string",
|
|
|
|
|
* "filetype": 0,
|
|
|
|
|
* "serialnum": "string",
|
|
|
|
|
* "taskid": 0
|
|
|
|
|
* }
|
|
|
|
|
* ],
|
|
|
|
|
* "scanusercode": "string",
|
|
|
|
|
* "scanusername": "string"
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
private void updateFile(String jzh,MzSyncDetails mzSyncDetail) {
|
|
|
|
|
ReportDownDto reportDownDto;
|
|
|
|
|
ReportDownScanFileDto reportDownScanFileDto;
|
|
|
|
|
ReportDownPatientDto reportDownPatientDto;
|
|
|
|
|
//临时资料存储
|
|
|
|
|
String serialnum;
|
|
|
|
|
String filetitle;
|
|
|
|
|
String downurl;
|
|
|
|
|
String collectorid = "";
|
|
|
|
|
String assortid = getAssortid(mzSyncDetail.getAssortName());
|
|
|
|
|
reportDownDto = new ReportDownDto();
|
|
|
|
|
reportDownDto.setAssortid(assortid);
|
|
|
|
|
//获取基本数据信息
|
|
|
|
|
List<ReportDownScanFileDto> reportDownDtoArr = new ArrayList<>();
|
|
|
|
|
reportDownPatientDto = new ReportDownPatientDto();
|
|
|
|
|
reportDownPatientDto.setJzh(jzh);
|
|
|
|
|
log.info("患者主索引号:" + jzh);
|
|
|
|
|
reportDownDto.setPatient(reportDownPatientDto);
|
|
|
|
|
filetitle = mzSyncDetail.getFileTitle();
|
|
|
|
|
downurl = mzSyncDetail.getFileUrl();
|
|
|
|
|
if(StringUtils.isBlank(downurl)){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//特殊处理url
|
|
|
|
|
downurl = subStrUrl(downurl);
|
|
|
|
|
if(StringUtils.isBlank(downurl)){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//获取采集流水号
|
|
|
|
|
serialnum = mzSyncDetail.getSerialnum();
|
|
|
|
|
collectorid = mzSyncDetail.getCollectid();
|
|
|
|
|
reportDownScanFileDto = new ReportDownScanFileDto();
|
|
|
|
|
reportDownScanFileDto.setDownurl(downurl);
|
|
|
|
|
reportDownScanFileDto.setFiletitle(filetitle);
|
|
|
|
|
reportDownScanFileDto.setSerialnum(serialnum);
|
|
|
|
|
reportDownScanFileDto.setFilesource(1);
|
|
|
|
|
reportDownScanFileDto.setFilestoragetype(1);
|
|
|
|
|
reportDownDtoArr.add(reportDownScanFileDto);
|
|
|
|
|
reportDownDto.setCollectorid(collectorid);
|
|
|
|
|
reportDownDto.setScanfiles(reportDownDtoArr);
|
|
|
|
|
afCollectTaskService.insert(reportDownDto);
|
|
|
|
|
String post = "";
|
|
|
|
|
log.info("--------执行上传功能----------");
|
|
|
|
|
Map params = JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class);
|
|
|
|
|
Map<String, Object> headMap = new HashMap<>();
|
|
|
|
|
headMap.put("Content-Type", "application/json");
|
|
|
|
|
try {
|
|
|
|
|
post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, params);
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
// String post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), map, headMap);
|
|
|
|
|
if (StringUtils.isBlank(post)) {
|
|
|
|
|
log.info("--------上传时出现错误,可能是文件服务没有启动----------");
|
|
|
|
|
throw new RuntimeException("上传时出现错误,可能是文件服务没有启动");
|
|
|
|
|
}
|
|
|
|
|
Map resMap = JSON.parseObject(post, Map.class);
|
|
|
|
|
if (String.valueOf(resMap.get("code")).equals("500")) {
|
|
|
|
|
throw new RuntimeException(String.valueOf(resMap.get("msg")));
|
|
|
|
|
} else {
|
|
|
|
|
log.info("----------执行成功-----------");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取分类id
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String getAssortid(String assortName) {
|
|
|
|
|
String assortId = String.valueOf(FileUtils.getJsonByName("assortid"));
|
|
|
|
|
if (StringUtils.isBlank(assortId)) {
|
|
|
|
|
List<ZdAssort> zdAssorts = zdAssortMapper.selectAll(assortName);
|
|
|
|
|
if (CollectionUtils.isEmpty(zdAssorts)) {
|
|
|
|
|
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
|
ZdAssort zdAssort = new ZdAssort();
|
|
|
|
|
zdAssort.setAssortName(assortName);
|
|
|
|
|
zdAssort.setAssortId(uuid);
|
|
|
|
|
zdAssort.setEffective(1);
|
|
|
|
|
zdAssortMapper.insertZdAssort(zdAssort);
|
|
|
|
|
assortId = uuid;
|
|
|
|
|
} else {
|
|
|
|
|
assortId = zdAssorts.get(0).getAssortId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return assortId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|