根据任务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
@ -84,4 +87,33 @@ public class ReportServiceImpl implements ReportService {
// 都成功后发布下载事件
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