代码优化

master
wyb 2 years ago
parent 5b78081616
commit ed68f155b1

@ -6,11 +6,13 @@ import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
@Slf4j
@SpringBootApplication(scanBasePackages ={"com.docus"})
@MapperScan("com.docus.server.**.mapper")
@EnableAsync
public class AppRunBootstrap {
public static void main(String[] args) {
System.setProperty("javax.xml.parsers.DocumentBuilderFactory","com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");

@ -1,5 +1,6 @@
package com.docus.server.report.dto;
import com.docus.server.report.entity.AfReportRecord;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -17,10 +18,10 @@ public class ReportDownPatientDto {
@ApiModelProperty(value = "物理存储位置,有则传")
private String storagelocation;
public ReportDownPatientDto(ReportDto reportDto) {
this.patientid = reportDto.getPatientId();
this.jzh = reportDto.getJzh();
this.admisstimes = reportDto.getAdmisstimes();
this.inpatientno = reportDto.getInpatientNo();
public ReportDownPatientDto(AfReportRecord reportRecord) {
this.patientid = reportRecord.getPatientId();
this.jzh = reportRecord.getJzh();
this.admisstimes = reportRecord.getAdmissTimes();
this.inpatientno = reportRecord.getInpatientNo();
}
}

@ -1,5 +1,6 @@
package com.docus.server.report.dto;
import com.docus.server.report.entity.AfReportRecord;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -28,13 +29,13 @@ public class ReportDownScanFileDto {
@ApiModelProperty(value = "是否作废 0否 不作废1是 作废")
private int cancel=0;
public ReportDownScanFileDto(ReportDto reportDto) {
this.taskid=reportDto.getTaskId();
this.filetitle=reportDto.getFileTitle();
this.filesource=Integer.parseInt(reportDto.getFileSource());
this.filestoragetype=Integer.parseInt(reportDto.getFilestoragetype());
this.filetype=reportDto.getDowntype();
this.downurl=reportDto.getDownUrl();
this.serialnum=reportDto.getSerialnum();
public ReportDownScanFileDto(AfReportRecord reportRecord) {
this.taskid=reportRecord.getTaskId();
this.filetitle=reportRecord.getFileName();
this.filesource= 1;
this.filestoragetype=1;
this.filetype=reportRecord.getDownType();
this.downurl=reportRecord.getDownUrl();
this.serialnum=reportRecord.getSerialnum();
}
}

@ -1,6 +1,5 @@
package com.docus.server.report.event;
import com.docus.server.report.dto.ReportDto;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@ -10,10 +9,20 @@ import org.springframework.context.ApplicationEvent;
*/
@Getter
public class ReportDownEvent extends ApplicationEvent {
private final ReportDto reportDto;
/**
* id ,
*/
private final Long taskId;
public ReportDownEvent(ReportDto reportDto) {
super(reportDto);
this.reportDto = reportDto;
/**
*
* @param source
* @param taskId
*/
public ReportDownEvent(Object source,Long taskId) {
super(source);
this.taskId=taskId;
}
}

@ -4,11 +4,13 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.docus.core.util.Func;
import com.docus.infrastructure.web.api.CommonResult;
import com.docus.infrastructure.web.api.ResultCode;
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.mapper.AfReportRecordMapper;
import lombok.extern.slf4j.Slf4j;
@ -22,6 +24,7 @@ import java.util.List;
/**
*
*
* @author wyb
*/
@Component
@ -35,20 +38,22 @@ public class ReportDownListener {
@EventListener
@Async("threadPoolExecutor")
public void reportDown(ReportDownEvent reportDownEvent){
ReportDto reportDto = reportDownEvent.getReportDto();
public void reportDown(ReportDownEvent reportDownEvent) {
// 根据任务id获取上报记录信息
AfReportRecord afReportRecord = afReportRecordMapper.getReportRecordInfoByTaskId(reportDownEvent.getTaskId());
// 组织基础信息数据
ReportDownPatientDto reportDownPatientDto = new ReportDownPatientDto(reportDto);
ReportDownPatientDto reportDownPatientDto = new ReportDownPatientDto(afReportRecord);
// 组织文件数据
List<ReportDownScanFileDto> reportDownScanFileDtos = new ArrayList<>(5);
ReportDownScanFileDto reportDownScanFileDto = new ReportDownScanFileDto(reportDto);
ReportDownScanFileDto reportDownScanFileDto = new ReportDownScanFileDto(afReportRecord);
reportDownScanFileDtos.add(reportDownScanFileDto);
// 组织下载数据,基础信息和文件数据
ReportDownDto reportDownDto = new ReportDownDto();
reportDownDto.setAssortid(reportDto.getAssortId());
reportDownDto.setCollectorid(reportDto.getSysFlag());
reportDownDto.setAssortid(afReportRecord.getZdAssortId());
reportDownDto.setCollectorid(afReportRecord.getSysflag());
reportDownDto.setScanusercode("admin");
reportDownDto.setScanusername("admin");
reportDownDto.setPatient(reportDownPatientDto);
@ -58,16 +63,21 @@ 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.timeout(5 * 1000);
post.header("Content-Type", "application/json; charset=utf-8");
post.body(requestParam);
HttpResponse response = post.execute();
String respBody = response.body();
log.info("调用下载服务成功,响应参数:{}",respBody);
afReportRecordMapper.updateStateByTaskId(reportDto.getTaskId());
}catch (Exception e){
log.error("调用下载服务失败:地址为:"+applicationBusinessConfig.getDownUrl()+" 参数为 "+requestParam,e);
log.info("调用下载服务成功,响应参数:{}", respBody);
CommonResult commonResult = Func.readJson(respBody, CommonResult.class);
if (ResultCode.SUCCESS.getCode().equals(commonResult.getCode())) {
// 下载返回了成功更新状态
afReportRecordMapper.updateStateByTaskId(reportDownEvent.getTaskId());
}
} catch (Exception e) {
log.error("调用下载服务失败", e);
}
}
}

@ -1,13 +1,8 @@
package com.docus.server.report.mapper;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.docus.server.report.entity.AfReportRecord;
import lombok.Data;
import org.apache.ibatis.annotations.Param;
import java.io.Serializable;
/**
*
* @author wyb
@ -43,4 +38,6 @@ public interface AfReportRecordMapper {
* @return
*/
int updateStateByTaskId(@Param("taskId") Long taskId);
AfReportRecord getReportRecordInfoByTaskId(@Param("taskId") Long taskId);
}

@ -82,8 +82,6 @@ public class ReportServiceImpl implements ReportService {
collectTaskMapper.saveTask(afCollectTask);
}
// 都成功后发布下载事件
reportDto.setTaskId(afReportRecord.getTaskId());
reportDto.setPatientId(patientId);
applicationContext.publishEvent(new ReportDownEvent(reportDto));
applicationContext.publishEvent(new ReportDownEvent(this,afReportRecord.getTaskId()));
}
}

@ -7,10 +7,11 @@
<insert id="saveRecord">
INSERT INTO `docus_archivefile`.`af_report_record`(`task_id`, `inpatient_no`, `jzh`, `admiss_times`, `down_url`,
`down_type`, `state`, `serialnum`, `sysflag`, `zd_assort_id`,
`create_time`, `update_time`, `file_name`,`patient_id`)
`create_time`, `update_time`, `file_name`, `patient_id`)
VALUES (#{reportRecord.taskId}, #{reportRecord.inpatientNo}, #{reportRecord.jzh}, #{reportRecord.admissTimes},
#{reportRecord.downUrl}, #{reportRecord.downType}, 0, #{reportRecord.serialnum},
#{reportRecord.sysflag}, #{reportRecord.zdAssortId}, now(), now(), #{reportRecord.fileName},#{reportRecord.patientId});
#{reportRecord.sysflag}, #{reportRecord.zdAssortId}, now(), now(), #{reportRecord.fileName},
#{reportRecord.patientId});
</insert>
<update id="updateRecordByTaskId">
update `docus_archivefile`.`af_report_record`
@ -37,4 +38,9 @@
and `sysflag` = #{sysFlag}
and admiss_times = #{admisstimes}
</select>
<select id="getReportRecordInfoByTaskId" resultType="com.docus.server.report.entity.AfReportRecord">
select *
from `docus_archivefile`.`af_report_record`
where `task_id` = #{taskId}
</select>
</mapper>

Loading…
Cancel
Save