报告区分推送的和自己任务消费的

3.2.4.44
wyb 2 years ago
parent 141dd8dbbb
commit 8bb640f7df

@ -83,7 +83,7 @@ public class ReportDownController {
return CommonResult.failed("补偿任务id不能为空");
}
try {
reportService.makeupReportByTaskIds(taskIds);
reportService.makeupThreePartyPushReportByTaskIds(taskIds);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
return CommonResult.failed("补偿出现了一点小问题!");

@ -24,4 +24,11 @@ public class ReportDownPatientDto {
this.admisstimes = reportRecord.getAdmissTimes();
this.inpatientno = reportRecord.getInpatientNo();
}
public ReportDownPatientDto(ReportDto reportDto) {
this.patientid = reportDto.getPatientId();
this.jzh = reportDto.getJzh();
this.admisstimes = reportDto.getAdmisstimes();
this.inpatientno = reportDto.getInpatientNo();
}
}

@ -38,4 +38,13 @@ public class ReportDownScanFileDto {
this.downurl=reportRecord.getDownUrl();
this.serialnum=reportRecord.getSerialnum();
}
public ReportDownScanFileDto(ReportDto reportDto) {
this.taskid=reportDto.getTaskId();
this.filetitle=reportDto.getFileTitle();
this.filesource= 1;
this.filestoragetype=1;
this.filetype=reportDto.getDowntype();
this.downurl=reportDto.getDownUrl();
this.serialnum=reportDto.getSerialnum();
}
}

@ -0,0 +1,29 @@
package com.docus.server.report.event;
import com.docus.server.report.dto.ReportDto;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
/**
*
* @author wyb
*/
@Getter
public class TaskConsumptionReportDownEvent extends ApplicationEvent {
/**
* id ,
*/
private final ReportDto reportDto;
/**
*
* @param source
* @param reportDto
*/
public TaskConsumptionReportDownEvent(Object source,ReportDto reportDto) {
super(source);
this.reportDto=reportDto;
}
}

@ -4,11 +4,11 @@ import lombok.Getter;
import org.springframework.context.ApplicationEvent;
/**
*
*
* @author wyb
*/
@Getter
public class ReportDownEvent extends ApplicationEvent {
public class ThreePartyPushReportDownEvent extends ApplicationEvent {
/**
* id ,
*/
@ -19,7 +19,7 @@ public class ReportDownEvent extends ApplicationEvent {
* @param source
* @param taskId
*/
public ReportDownEvent(Object source,Long taskId) {
public ThreePartyPushReportDownEvent(Object source, Long taskId) {
super(source);
this.taskId=taskId;
}

@ -643,7 +643,7 @@ public class ReportJob {
if (reportRecords != null) {
updateReportRecordPatientId(reportRecords);
List<Long> taskIds = reportRecords.stream().map(AfReportRecord::getTaskId).collect(Collectors.toList());
reportService.makeupReportByTaskIds(taskIds);
reportService.makeupThreePartyPushReportByTaskIds(taskIds);
}
page++;
} while (loopCondition);

@ -10,8 +10,10 @@ import com.docus.server.report.config.ApplicationBusinessConfig;
import com.docus.server.report.dto.ReportDownDto;
import com.docus.server.report.dto.ReportDownPatientDto;
import com.docus.server.report.dto.ReportDownScanFileDto;
import com.docus.server.report.dto.ReportDto;
import com.docus.server.report.entity.AfReportRecord;
import com.docus.server.report.event.ReportDownEvent;
import com.docus.server.report.event.TaskConsumptionReportDownEvent;
import com.docus.server.report.event.ThreePartyPushReportDownEvent;
import com.docus.server.report.mapper.AfReportRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
@ -21,6 +23,8 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
*
@ -38,9 +42,9 @@ public class ReportDownListener {
@EventListener
@Async("threadPoolExecutor")
public void reportDown(ReportDownEvent reportDownEvent) {
public void threePartyPushReportDown(ThreePartyPushReportDownEvent threePartyPushReportDownEvent) {
// 根据任务id获取上报记录信息
AfReportRecord afReportRecord = afReportRecordMapper.getReportRecordInfoByTaskId(reportDownEvent.getTaskId());
AfReportRecord afReportRecord = afReportRecordMapper.getReportRecordInfoByTaskId(threePartyPushReportDownEvent.getTaskId());
// 组织基础信息数据
ReportDownPatientDto reportDownPatientDto = new ReportDownPatientDto(afReportRecord);
@ -64,20 +68,64 @@ public class ReportDownListener {
String requestParam = Func.toJson(reportDownDto);
try {
log.info("调用下载服务,地址:{} ,参数:{}",applicationBusinessConfig.getDownUrl(),requestParam);
HttpRequest post = HttpUtil.createPost(applicationBusinessConfig.getDownUrl());
post.timeout(5 * 1000);
post.header("Content-Type", "application/json; charset=utf-8");
post.body(requestParam);
HttpResponse response = post.execute();
String respBody = response.body();
String respBody = post(applicationBusinessConfig.getDownUrl(),requestParam);
log.info("调用下载服务成功,响应参数:{}", respBody);
CommonResult commonResult = Func.readJson(respBody, CommonResult.class);
if (ResultCode.SUCCESS.getCode().equals(commonResult.getCode())) {
// 下载返回了成功更新状态
afReportRecordMapper.updateStateByTaskId(reportDownEvent.getTaskId());
afReportRecordMapper.updateStateByTaskId(threePartyPushReportDownEvent.getTaskId());
}
} catch (Exception e) {
log.error("调用下载服务失败", e);
}
}
@EventListener
@Async("threadPoolExecutor")
public void taskConsumptionReporDown(TaskConsumptionReportDownEvent taskConsumptionReportDownEvent) {
ReportDto reportDto = taskConsumptionReportDownEvent.getReportDto();
// 组织基础信息数据
ReportDownPatientDto reportDownPatientDto = new ReportDownPatientDto(reportDto);
// 组织文件数据
List<ReportDownScanFileDto> reportDownScanFileDtos = new ArrayList<>(5);
ReportDownScanFileDto reportDownScanFileDto = new ReportDownScanFileDto(reportDto);
reportDownScanFileDtos.add(reportDownScanFileDto);
// 组织下载数据,基础信息和文件数据
ReportDownDto reportDownDto = new ReportDownDto();
reportDownDto.setAssortid(reportDto.getAssortId());
reportDownDto.setCollectorid(reportDto.getSysFlag());
reportDownDto.setScanusercode("admin");
reportDownDto.setScanusername("admin");
reportDownDto.setPatient(reportDownPatientDto);
reportDownDto.setScanfiles(reportDownScanFileDtos);
// 下面是调用下载服务
String requestParam = Func.toJson(reportDownDto);
try {
log.info("调用下载服务,地址:{} ,参数:{}",applicationBusinessConfig.getDownUrl(),requestParam);
String respBody = post(applicationBusinessConfig.getDownUrl(),requestParam);
log.info("调用下载服务成功,响应参数:{}", respBody);
} catch (Exception e) {
log.error("调用下载服务失败", e);
}
}
private final static Lock HTTP_POST_LOCK=new ReentrantLock();
public String post(String url,String body){
HTTP_POST_LOCK.lock();
try {
HttpRequest post = HttpUtil.createPost(url);
post.timeout(5 * 1000);
post.header("Content-Type", "application/json; charset=utf-8");
post.body(body);
HttpResponse response = post.execute();
return response.body();
}finally {
HTTP_POST_LOCK.unlock();
}
}
}

@ -20,5 +20,5 @@ public interface ReportService {
* id
* @param taskIds id
*/
void makeupReportByTaskIds(List<Long> taskIds) throws Exception;
void makeupThreePartyPushReportByTaskIds(List<Long> taskIds) throws Exception;
}

@ -6,7 +6,8 @@ import com.docus.server.collection.mapper.TBasicMapper;
import com.docus.server.report.dto.ReportDto;
import com.docus.server.report.entity.AfCollectTask;
import com.docus.server.report.entity.AfReportRecord;
import com.docus.server.report.event.ReportDownEvent;
import com.docus.server.report.event.TaskConsumptionReportDownEvent;
import com.docus.server.report.event.ThreePartyPushReportDownEvent;
import com.docus.server.report.mapper.AfCollectTaskMapper;
import com.docus.server.report.mapper.AfReportRecordMapper;
@ -41,6 +42,24 @@ public class ReportServiceImpl implements ReportService {
@Override
public void report(ReportDto reportDto) {
// 系统无视图生成的任务,消费查询的报告
if (reportDto.getTaskId() != null) {
taskConsumptionReport(reportDto);
}
// 第三方推送的报告,任务后生成的
threePartyPushReports(reportDto);
}
private void taskConsumptionReport(ReportDto reportDto) {
applicationContext.publishEvent(new TaskConsumptionReportDownEvent(this, reportDto));
try {
TimeUnit.MILLISECONDS.sleep(50);
} catch (InterruptedException ex) {
log.error(ex.getMessage(), ex);
}
}
private void threePartyPushReports(ReportDto reportDto) {
String patientId = null;
try {
// 如果出现多条出错的情况,还是得保存收到的信息,人工干预处理
@ -86,7 +105,7 @@ public class ReportServiceImpl implements ReportService {
collectTaskMapper.saveTask(afCollectTask);
}
// 都成功后发布下载事件
applicationContext.publishEvent(new ReportDownEvent(this, afReportRecord.getTaskId()));
applicationContext.publishEvent(new ThreePartyPushReportDownEvent(this, afReportRecord.getTaskId()));
try {
TimeUnit.MILLISECONDS.sleep(50);
} catch (InterruptedException ex) {
@ -95,7 +114,7 @@ public class ReportServiceImpl implements ReportService {
}
@Override
public void makeupReportByTaskIds(List<Long> taskIds) throws Exception {
public void makeupThreePartyPushReportByTaskIds(List<Long> taskIds) throws Exception {
if (taskIds == null || taskIds.isEmpty()) {
return;
}
@ -117,7 +136,7 @@ public class ReportServiceImpl implements ReportService {
if (Func.isNotEmpty(makeupTaskIds)) {
for (Long taskId : makeupTaskIds) {
// 发布下载事件
applicationContext.publishEvent(new ReportDownEvent(this, taskId));
applicationContext.publishEvent(new ThreePartyPushReportDownEvent(this, taskId));
// 等待防止过快
TimeUnit.MILLISECONDS.sleep(50);
}

Loading…
Cancel
Save