根据任务id补偿开发

master
wyb 2 years ago
parent ed68f155b1
commit c884455ec2

@ -0,0 +1,44 @@
package com.docus.server.report.controller;
import com.docus.core.util.Func;
import com.docus.infrastructure.web.api.CommonResult;
import com.docus.server.report.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* @author wyb
*
*/
@Slf4j
@Api(tags = "文件上报,补偿控制")
@RestController
@RequestMapping("/report/makeup")
public class ReportDownController {
@Resource
private ReportService reportService;
@ApiOperation(value = "根据任务id补偿报告下载")
@PostMapping("/makeupReportByTaskIds")
public CommonResult<String> makeupReportByTaskIds(@RequestBody List<Long> taskIds){
if (Func.isEmpty(taskIds)) {
return CommonResult.failed("补偿任务id不能为空");
}
try {
reportService.makeupReportByTaskIds(taskIds);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
return CommonResult.failed("补偿出现了一点小问题!");
}
return CommonResult.success("补偿成功!");
}
}

@ -3,6 +3,8 @@ package com.docus.server.report.mapper;
import com.docus.server.report.entity.AfReportRecord;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
*
* @author wyb
@ -40,4 +42,11 @@ public interface AfReportRecordMapper {
int updateStateByTaskId(@Param("taskId") Long taskId);
AfReportRecord getReportRecordInfoByTaskId(@Param("taskId") Long taskId);
/**
* idpatientIdid
* @param taskIds id
* @return patientIdid
*/
List<Long> getHasPatientIdTaskIdsByTaskIds(@Param("taskIds") List<Long> taskIds);
}

@ -2,6 +2,8 @@ package com.docus.server.report.service;
import com.docus.server.report.dto.ReportDto;
import java.util.List;
/**
*
* @author wyb
@ -13,4 +15,10 @@ public interface ReportService {
* @param reportDto
*/
void report(ReportDto reportDto);
/**
* id
* @param taskIds id
*/
void makeupReportByTaskIds(List<Long> taskIds) throws Exception;
}

@ -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);
}
}

@ -43,4 +43,14 @@
from `docus_archivefile`.`af_report_record`
where `task_id` = #{taskId}
</select>
<select id="getHasPatientIdTaskIdsByTaskIds" resultType="java.lang.Long">
SELECT `task_id`
FROM `docus_archivefile`.`af_report_record`
WHERE `patient_id` IS NOT NULL
AND `patient_id` != ''
AND `task_id` IN
<foreach collection="taskIds" separator="," open="(" close=")" item="taskId">
#{taskId}
</foreach>
</select>
</mapper>

Loading…
Cancel
Save