|
|
|
@ -1,22 +1,29 @@
|
|
|
|
|
package com.docus.bgts.service;
|
|
|
|
|
|
|
|
|
|
import com.docus.bgts.entity.MzSync;
|
|
|
|
|
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;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 梅州完整性检验
|
|
|
|
@ -35,7 +42,6 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
* 增量同步开始时间
|
|
|
|
|
*/
|
|
|
|
|
private String newSyncTime;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
tableName = String.valueOf(FileUtils.getJsonByName("syncTableName"));
|
|
|
|
|
tableNamespaces = String.valueOf(FileUtils.getJsonByName("syncTableNamespaces"));
|
|
|
|
@ -49,14 +55,45 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
@Autowired
|
|
|
|
|
MzSyncMapper mzSyncMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TScanAssortMapper tScanAssortMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
IAfCollectTaskService afCollectTaskService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
ZdAssortMapper zdAssortMapper;
|
|
|
|
|
|
|
|
|
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 截取url
|
|
|
|
|
* @param str
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String subStrUrl(String str) {
|
|
|
|
|
int beginIndex = str.indexOf("http");
|
|
|
|
|
int lastIndex = str.lastIndexOf(".pdf");
|
|
|
|
|
if (lastIndex == -1){
|
|
|
|
|
lastIndex = str.lastIndexOf(".jpg");
|
|
|
|
|
}
|
|
|
|
|
if(lastIndex == -1){
|
|
|
|
|
log.info("不存在pdf或jpg:"+ str);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String newStr = str.substring(beginIndex, lastIndex+4);
|
|
|
|
|
return newStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addSyncIntegrality() {
|
|
|
|
|
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;
|
|
|
|
@ -64,13 +101,17 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
for (int i = 0; ; i++) {
|
|
|
|
|
front = i * pageSize;
|
|
|
|
|
later = pageSize;
|
|
|
|
|
jzhs = afCollectAddMapper.listJzhAndAdd(front, later, newSyncTime);
|
|
|
|
|
jzhs = afCollectAddMapper.listJzhAndAdd(front, later, startDate,endDate);
|
|
|
|
|
count += jzhs.size();
|
|
|
|
|
if (jzhs.size() == 0) {
|
|
|
|
|
if(i == 0){
|
|
|
|
|
flag = false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
mzSyncs = mzSyncMapper.listMzSync(jzhs, front, later, tableName, tableNamespaces);
|
|
|
|
|
//完整性检验写入
|
|
|
|
|
integralityBySyncs(mzSyncs);
|
|
|
|
|
integralityBySyncs(mzSyncs,jzhs);
|
|
|
|
|
}
|
|
|
|
|
if (mzSyncs.size() != 0) {
|
|
|
|
|
log.info("本次成功同步数:" + mzSyncs.size());
|
|
|
|
@ -78,6 +119,7 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
}
|
|
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
|
|
log.info("增量完整性同步结束,程序执行时间为:" + (endTime - startTime) + "毫秒");
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -103,7 +145,7 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
} else {
|
|
|
|
|
mzSyncs = mzSyncMapper.listMzSync(jzhs, front, later, tableName, tableNamespaces);
|
|
|
|
|
//完整性检验写入
|
|
|
|
|
integralityBySyncs(mzSyncs);
|
|
|
|
|
integralityBySyncs(mzSyncs,jzhs);
|
|
|
|
|
}
|
|
|
|
|
if (mzSyncs.size() != 0) {
|
|
|
|
|
log.info("本次成功同步数:" + mzSyncs.size());
|
|
|
|
@ -119,10 +161,11 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
*
|
|
|
|
|
* @param mzSyncs
|
|
|
|
|
*/
|
|
|
|
|
private void integralityBySyncs(List<MzSync> mzSyncs ,List<String>) {
|
|
|
|
|
private void integralityBySyncs(List<MzSync> mzSyncs,List<String> jzhs) {
|
|
|
|
|
StringBuilder sql;
|
|
|
|
|
if (mzSyncs.size() != 0) {
|
|
|
|
|
List<Map> maps = afCollectAddMapper.integrality(mzSyncs);
|
|
|
|
|
//List<Map> maps = afCollectAddMapper.integrality(mzSyncs);
|
|
|
|
|
List<Map> maps = verifyIntegrity(mzSyncs,jzhs);
|
|
|
|
|
System.out.println(maps);
|
|
|
|
|
sql = new StringBuilder();
|
|
|
|
|
for (Map map : maps) {
|
|
|
|
@ -133,7 +176,6 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
sql.append(" where jzh=");
|
|
|
|
|
sql.append("'");
|
|
|
|
|
sql.append(map.get("jzh"));
|
|
|
|
|
sql.append("jzh");
|
|
|
|
|
sql.append("'");
|
|
|
|
|
sql.append(";");
|
|
|
|
|
}
|
|
|
|
@ -141,4 +183,177 @@ public class MzSyncService implements IMzSyncService {
|
|
|
|
|
afCollectAddMapper.dynamicSql(sql.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验完整性
|
|
|
|
|
* @param mzSyncs
|
|
|
|
|
* @param jzhs
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<Map> verifyIntegrity(List<MzSync> mzSyncs, List<String> jzhs) {
|
|
|
|
|
List<Map> maps = new ArrayList<>();
|
|
|
|
|
//根据记账号集合查询文件表有效的文件集合
|
|
|
|
|
List<MzSync> fileList = tScanAssortMapper.selectFilesByJzhs(jzhs);
|
|
|
|
|
//遍历按记账号分组的任务视图
|
|
|
|
|
for(MzSync mzSync : mzSyncs){
|
|
|
|
|
//定义返回map
|
|
|
|
|
Map map = new HashMap();
|
|
|
|
|
//获取jzh
|
|
|
|
|
String jzh = mzSync.getJzh();
|
|
|
|
|
//遍历任务试图文件集合
|
|
|
|
|
List<MzSyncDetails> mzSyncDetails = mzSync.getMzSyncDetails();
|
|
|
|
|
//定义缺失文件集合
|
|
|
|
|
StringBuilder faultFileTitles = new StringBuilder();
|
|
|
|
|
for(MzSyncDetails mzSyncDetail : mzSyncDetails){
|
|
|
|
|
//获取文件名称
|
|
|
|
|
String fileTitle = mzSyncDetail.getFileTitle();
|
|
|
|
|
//获取文件序列号
|
|
|
|
|
String serialnum = mzSyncDetail.getSerialnum();
|
|
|
|
|
//定义是否存在
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
if(!CollectionUtils.isEmpty(fileList)){
|
|
|
|
|
for(MzSync obj : fileList){
|
|
|
|
|
//获取jzh
|
|
|
|
|
String jzh1 = obj.getJzh();
|
|
|
|
|
if(jzh1.equals(jzh)){
|
|
|
|
|
List<MzSyncDetails> mzSyncDetails1 = obj.getMzSyncDetails();
|
|
|
|
|
for(MzSyncDetails vo : mzSyncDetails1){
|
|
|
|
|
|
|
|
|
|
//获取文件序列号
|
|
|
|
|
String serialnum1 = vo.getSerialnum();
|
|
|
|
|
if(vo.getFileTitle().equals(fileTitle) && serialnum1.equals(serialnum)){
|
|
|
|
|
flag = true;
|
|
|
|
|
mzSyncDetail.setCollectid(vo.getCollectid());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//遍历文件
|
|
|
|
|
if(!flag){
|
|
|
|
|
if(StringUtils.isNotBlank(faultFileTitles)){
|
|
|
|
|
faultFileTitles.append(",");
|
|
|
|
|
}
|
|
|
|
|
faultFileTitles.append(fileTitle + "缺失");
|
|
|
|
|
//调下载服务
|
|
|
|
|
updateFile(jzh,mzSyncDetail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isBlank(faultFileTitles)){
|
|
|
|
|
faultFileTitles = new StringBuilder("完整");
|
|
|
|
|
}
|
|
|
|
|
map.put("jzh",jzh);
|
|
|
|
|
map.put("file_title",faultFileTitles.toString());
|
|
|
|
|
maps.add(map);
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
//特殊处理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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|