|
|
|
@ -15,9 +15,12 @@ import org.springframework.context.ApplicationContext;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 报告服务实现类
|
|
|
|
|
*
|
|
|
|
|
* @author wyb
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
@ -37,22 +40,22 @@ public class ReportServiceImpl implements ReportService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void report(ReportDto reportDto) {
|
|
|
|
|
String patientId=null;
|
|
|
|
|
String patientId = null;
|
|
|
|
|
try {
|
|
|
|
|
// 如果出现多条出错的情况,还是得保存收到的信息,人工干预处理
|
|
|
|
|
patientId=tBasicMapper.getPatientIdByInpatientNoAndAdminssTimes(reportDto.getInpatientNo(),reportDto.getAdmisstimes());
|
|
|
|
|
}catch (Exception ex){
|
|
|
|
|
log.error("查询病案主键出错了",ex);
|
|
|
|
|
patientId = tBasicMapper.getPatientIdByInpatientNoAndAdminssTimes(reportDto.getInpatientNo(), reportDto.getAdmisstimes());
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
log.error("查询病案主键出错了", ex);
|
|
|
|
|
}
|
|
|
|
|
// 不验证数据,始终保存收到的信息
|
|
|
|
|
AfReportRecord afReportRecord = afReportRecordMapper.getRecordBySerialnumAndInpatientNoAndSysFlag(reportDto.getSerialnum(),reportDto.getInpatientNo(),reportDto.getAdmisstimes(),reportDto.getSysFlag());
|
|
|
|
|
if(afReportRecord==null){
|
|
|
|
|
AfReportRecord afReportRecord = afReportRecordMapper.getRecordBySerialnumAndInpatientNoAndSysFlag(reportDto.getSerialnum(), reportDto.getInpatientNo(), reportDto.getAdmisstimes(), reportDto.getSysFlag());
|
|
|
|
|
if (afReportRecord == null) {
|
|
|
|
|
long id = idService.getDateSeq();
|
|
|
|
|
afReportRecord = new AfReportRecord(reportDto);
|
|
|
|
|
afReportRecord.setTaskId(id);
|
|
|
|
|
afReportRecord.setPatientId(patientId);
|
|
|
|
|
afReportRecordMapper.saveRecord(afReportRecord);
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
// 更新 主要更新 url
|
|
|
|
|
afReportRecord.setDownUrl(reportDto.getDownUrl());
|
|
|
|
|
afReportRecord.setDownType(reportDto.getDowntype());
|
|
|
|
@ -63,14 +66,14 @@ public class ReportServiceImpl implements ReportService {
|
|
|
|
|
// 不使用事务,不需要回滚上面的保存
|
|
|
|
|
|
|
|
|
|
// 根据记录中的任务id,查询是否需要新增任务
|
|
|
|
|
if(Func.isBlank(patientId)){
|
|
|
|
|
log.warn("病案号:{},住院次数:{} 未找到病案基础数据,暂不进行下载任务!",reportDto.getInpatientNo(),reportDto.getAdmisstimes());
|
|
|
|
|
if (Func.isBlank(patientId)) {
|
|
|
|
|
log.warn("病案号:{},住院次数:{} 未找到病案基础数据,暂不进行下载任务!", reportDto.getInpatientNo(), reportDto.getAdmisstimes());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 判断是否需要保存任务
|
|
|
|
|
AfCollectTask afCollectTask=collectTaskMapper.getTaskById(afReportRecord.getTaskId());
|
|
|
|
|
if(afCollectTask==null){
|
|
|
|
|
afCollectTask=new AfCollectTask();
|
|
|
|
|
AfCollectTask afCollectTask = collectTaskMapper.getTaskById(afReportRecord.getTaskId());
|
|
|
|
|
if (afCollectTask == null) {
|
|
|
|
|
afCollectTask = new AfCollectTask();
|
|
|
|
|
afCollectTask.setId(afReportRecord.getTaskId());
|
|
|
|
|
afCollectTask.setC1(reportDto.getSerialnum());
|
|
|
|
|
afCollectTask.setC2(reportDto.getFileTitle());
|
|
|
|
@ -82,6 +85,35 @@ public class ReportServiceImpl implements ReportService {
|
|
|
|
|
collectTaskMapper.saveTask(afCollectTask);
|
|
|
|
|
}
|
|
|
|
|
// 都成功后发布下载事件
|
|
|
|
|
applicationContext.publishEvent(new ReportDownEvent(this,afReportRecord.getTaskId()));
|
|
|
|
|
applicationContext.publishEvent(new ReportDownEvent(this, afReportRecord.getTaskId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void makeupReportByTaskIds(List<Long> taskIds) throws Exception {
|
|
|
|
|
int taskIdLength = taskIds.size();
|
|
|
|
|
// 定义一批200查询,分批次
|
|
|
|
|
final int oneBatchCount = 200;
|
|
|
|
|
int startIndex;
|
|
|
|
|
int toIndex = 0;
|
|
|
|
|
do {
|
|
|
|
|
startIndex = toIndex;
|
|
|
|
|
toIndex = startIndex + oneBatchCount;
|
|
|
|
|
// 如果大于原来集合长度,最大截取就是集合长度
|
|
|
|
|
if (toIndex >= taskIdLength) {
|
|
|
|
|
toIndex = taskIdLength;
|
|
|
|
|
}
|
|
|
|
|
// 截取每一批
|
|
|
|
|
List<Long> makeupTaskIds = taskIds.subList(startIndex, toIndex);
|
|
|
|
|
makeupTaskIds = afReportRecordMapper.getHasPatientIdTaskIdsByTaskIds(makeupTaskIds);
|
|
|
|
|
if (Func.isNotEmpty(makeupTaskIds)) {
|
|
|
|
|
for (Long taskId : makeupTaskIds) {
|
|
|
|
|
// 发布下载事件
|
|
|
|
|
applicationContext.publishEvent(new ReportDownEvent(this, taskId));
|
|
|
|
|
// 等待防止过快
|
|
|
|
|
TimeUnit.MILLISECONDS.sleep(50);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 当截取长度小于集合长度,可以进行下次循环截取
|
|
|
|
|
} while (toIndex < taskIdLength);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|