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.
docus-active-query-service/src/main/java/com/docus/bgts/service/AfCollectTaskServiceImpl.java

313 lines
12 KiB
Java

package com.docus.bgts.service;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.docus.bgts.entity.*;
import com.docus.bgts.facade.IAfCollectTaskService;
import com.docus.bgts.mapper.dbmysql.AfCollectTaskMapper;
import com.docus.bgts.mapper.dbmysql.AfInterfaceCollectMapper;
import com.docus.bgts.mapper.dbmysql.AfInterfaceCollectSubMapper;
import com.docus.bgts.mapper.dboracle.TestMapper;
import com.docus.bgts.rpc.dto.ReportDownDto;
import com.docus.bgts.rpc.dto.ReportDownScanFileDto;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
/**
* <p>
* 病案采集任务 服务实现类
* </p>
*
* @author 曾文和
* @since 2021-05-07
*/
@Service
public class AfCollectTaskServiceImpl extends ServiceImpl<AfCollectTaskMapper, AfCollectTask> implements IAfCollectTaskService {
public static int MAX_SIZE_PER_TIME = 10;
@Autowired
TestMapper testMapper;
@Autowired
AfCollectTaskMapper afCollectTaskMapper;
@Autowired
AfInterfaceCollectMapper afInterfaceCollectMapper;
@Autowired
AfInterfaceCollectSubMapper afInterfaceCollectSubMapper;
@Override
public String getpatientIdByEmpId(String empId) {
String patientId = afCollectTaskMapper.getpatientIdByEmpId(empId);
return patientId;
}
@Override
public void insert(ReportDownDto reportDownDto) {
synchronized (this) {
try {
AfCollectTask afCollectTask;
String patientid = reportDownDto.getPatient().getPatientid();
String patientId = StrUtil.isEmpty(patientid) ? getpatientIdByEmpId(reportDownDto.getPatient().getJzh()) : patientid;
if (StringUtils.isBlank(patientId)) {
throw new RuntimeException("操作的病案信息不存在");
}
Date date = new Date();
Integer save = null;
List<ReportDownScanFileDto> scanfiles = reportDownDto.getScanfiles();
for (ReportDownScanFileDto scanfile : scanfiles) {
// 判断任务是否已存在
afCollectTask = afCollectTaskMapper.selectOne(new QueryWrapper<AfCollectTask>().eq("C1", scanfile.getSerialnum()).eq("sysflag", reportDownDto.getCollectorid()));
if (afCollectTask == null) {
//不存在 新增
afCollectTask = new AfCollectTask();
afCollectTask.setPatientId(patientId);
afCollectTask.setSysflag(reportDownDto.getCollectorid());
afCollectTask.setState("0");
afCollectTask.setSyncTime(date);
afCollectTask.setC1(scanfile.getSerialnum());
afCollectTask.setC2(scanfile.getFiletitle());
afCollectTask.setC3(reportDownDto.getPatient().getJzh());
save = afCollectTaskMapper.insert(afCollectTask);
if (save <= 0) {
throw new RuntimeException("插入病案任务表数据出错");
} else {
log.warn("插入病案成功");
}
} else {
//存在就修改
afCollectTask.setPatientId(patientId);
afCollectTask.setSysflag(reportDownDto.getCollectorid());
afCollectTask.setState("0");
afCollectTask.setSyncTime(date);
afCollectTask.setC1(scanfile.getSerialnum());
afCollectTask.setC2(scanfile.getFiletitle());
save = afCollectTaskMapper.updateById(afCollectTask);
log.warn("修改病案成功");
}
scanfile.setTaskid(afCollectTask.getId());
}
reportDownDto.setScanfiles(scanfiles);
} catch (Exception e) {
log.error(reportDownDto.getPatient().getJzh() + "插入任务表出错! " + e.getMessage());
}
}
}
@Override
public String getJzhByInpatientNo(String inPatientNo, String visitId) {
return afCollectTaskMapper.getJzhByInpatientNo(inPatientNo,visitId);
}
@Override
public String getJzhByJzh(String jzh) {
return afCollectTaskMapper.getJzhByJzh(jzh);
}
@Override
public void insertServer(ReportDownDto reportDownDto) {
synchronized (this) {
String patientId;
AfCollectTask afCollectTask;
if (StringUtils.isNotBlank(reportDownDto.getPatient().getPatientid())) {
patientId = reportDownDto.getPatient().getPatientid();
} else if (StringUtils.isBlank(reportDownDto.getPatient().getJzh())) {
patientId = getPatientIdByInpatientNo(reportDownDto.getPatient().getInpatientno(), reportDownDto.getPatient().getAdmisstimes());
} else {
patientId = getpatientIdByEmpId(reportDownDto.getPatient().getJzh());
}
if (StringUtils.isBlank(patientId)) {
throw new RuntimeException("操作的病案信息不存在");
}
Date date = new Date();
Integer save = null;
List<ReportDownScanFileDto> scanfiles = reportDownDto.getScanfiles();
for (ReportDownScanFileDto scanfile : scanfiles) {
// 判断任务是否已存在
afCollectTask = afCollectTaskMapper.selectOne(new QueryWrapper<AfCollectTask>().eq("C1", scanfile.getSerialnum()).eq("sysflag", reportDownDto.getCollectorid()));
if (afCollectTask == null) {
//不存在 新增
afCollectTask = new AfCollectTask();
afCollectTask.setPatientId(patientId);
afCollectTask.setSysflag(reportDownDto.getCollectorid());
afCollectTask.setState("0");
afCollectTask.setSyncTime(date);
afCollectTask.setC1(scanfile.getSerialnum());
afCollectTask.setC2(scanfile.getFiletitle());
afCollectTask.setC3(reportDownDto.getPatient().getJzh());
save = afCollectTaskMapper.insert(afCollectTask);
if (save <= 0) {
throw new RuntimeException("插入病案任务表数据出错");
} else {
log.warn("插入病案成功");
}
} else {
//存在就修改
afCollectTask.setPatientId(patientId);
afCollectTask.setSysflag(reportDownDto.getCollectorid());
afCollectTask.setState("0");
afCollectTask.setSyncTime(date);
afCollectTask.setC1(scanfile.getSerialnum());
afCollectTask.setC2(scanfile.getFiletitle());
save = afCollectTaskMapper.updateById(afCollectTask);
log.warn("修改病案成功");
}
scanfile.setTaskid(afCollectTask.getId());
}
reportDownDto.setScanfiles(scanfiles);
}
}
@Override
public void updateInterfaceCollect(String collectSubId, int state) {
log.warn("开始记录采集");
AfInterfaceCollectSub afInterfaceCollectSub = afInterfaceCollectSubMapper.selectById(collectSubId);
log.warn("操作记录:"+afInterfaceCollectSub);
if (afInterfaceCollectSub == null) {
throw new RuntimeException("afInterfaceCollectSub表数据为空");
}
int i;
afInterfaceCollectSub.setState(state);
i = afInterfaceCollectSubMapper.updateById(afInterfaceCollectSub);
if (i <= 0) {
throw new RuntimeException("记录任务数时出错");
}
if (state == 1) {
AfInterfaceCollect afInterfaceCollect = afInterfaceCollectMapper.selectById(afInterfaceCollectSub.getAfInterfaceCollectId());
afInterfaceCollect.setCompleteCount(afInterfaceCollect.getCompleteCount() + 1);
i = afInterfaceCollectMapper.updateById(afInterfaceCollect);
if (i <= 0) {
throw new RuntimeException("记录任务数时出错");
}
}
}
@Override
public List<Map> getjzhByDate(String startDate, String endDate,int size,int current) {
List<Map> patientIds = afCollectTaskMapper.getjzhByDate(startDate, endDate,size,current);
return patientIds;
}
@Override
public List<String> getC1ByPatientId(List<String> patientIds, String collectorId) {
List<List<String>> batchPatientIds = Lists.partition(patientIds, MAX_SIZE_PER_TIME);
List<String> c1s = new ArrayList<>();
for (List<String> batchPatientId : batchPatientIds) {
List<String> c1 = afCollectTaskMapper.getC1ByPatientId(batchPatientId, collectorId);
if (c1 != null && c1.size() != 0 ) {
for (String s : c1) {
c1s.add(s);
}
}
}
return c1s;
}
@Override
public List<String> getPatientIdByC1(List<String> C1s) {
List<List<String>> batchPatientIds = Lists.partition(C1s, MAX_SIZE_PER_TIME);
List<String> patientIds = new ArrayList<>();
for (List<String> batchC1s : batchPatientIds) {
List<String> patientId = afCollectTaskMapper.getPatientIdByC1(batchC1s);
if (patientId != null && patientId.size() != 0 ) {
for (String s : patientId) {
patientIds.add(s);
}
}
}
return patientIds;
}
@Override
public List<String> getJzhByPatientId(List<String> patientIds) {
List<String> jzhs = new ArrayList<>();
List<List<String>> batchPatientIds = Lists.partition(patientIds, MAX_SIZE_PER_TIME);
for (List<String> batchPatientId : batchPatientIds) {
List<String> jzh = afCollectTaskMapper.getJzhByPatientId(batchPatientId);
if (jzh != null && jzh.size() !=0 ) {
for (String s : jzh) {
jzhs.add(s);
}
}
}
return jzhs;
}
@Override
public String getPatientIdByInpatientNo(String inPatientNo, String visitId) {
return afCollectTaskMapper.getPatientIdByInpatientNo(inPatientNo, visitId);
}
/**
* 根据jzh查询文件采集任务情况
* @param jzhs
* @return
*/
@Override
public List<Map> getCompleteIntegrity(List<String> jzhs) {
//根据记帐号查询任务完成情况
List<JzhListSync> taskList = afCollectTaskMapper.selectListByJzhs(jzhs);
List<Map> maps = new ArrayList<>();
if(!CollectionUtils.isEmpty(taskList)){
//遍历判断完整性
for(String jzh : jzhs){
//定义不完整描述
StringBuilder integrity = new StringBuilder();
for(JzhListSync jzhListSync : taskList){
if(jzhListSync.getJzh().equals(jzh)){
//获取jzh对应任务明细集合
List<TaskDetail> taskDetails = jzhListSync.getTaskDetails();
for(TaskDetail taskDetail : taskDetails) {
//获取完成状态
String state = taskDetail.getState();
if (StringUtils.isBlank(state) || !"3".equals(state)){
//未完成状态
if(StringUtils.isNotBlank(integrity)){
integrity.append(",");
}
integrity.append(taskDetail.getFileTitle()).append("缺失");
}
}
break;
}
}
//定义完整性map
Map<String,String> map = new HashMap<>();
if(StringUtils.isBlank(integrity)){
integrity = new StringBuilder("完整");
}
map.put("jzh",jzh);
map.put("file_title",integrity.toString());
maps.add(map);
}
}
return maps;
}
@Override
public TSeal findSealByCondition(TSeal seal) {
return afCollectTaskMapper.findSealByCondition(seal);
}
@Override
public List<TBasic> getBasicInfo(TBasic tBasic) {
return afCollectTaskMapper.getBasicInfo(tBasic);
}
}