代码优化

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.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
@Slf4j @Slf4j
@SpringBootApplication(scanBasePackages ={"com.docus"}) @SpringBootApplication(scanBasePackages ={"com.docus"})
@MapperScan("com.docus.server.**.mapper") @MapperScan("com.docus.server.**.mapper")
@EnableAsync
public class AppRunBootstrap { public class AppRunBootstrap {
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("javax.xml.parsers.DocumentBuilderFactory","com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); System.setProperty("javax.xml.parsers.DocumentBuilderFactory","com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");

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

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

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

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

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

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

Loading…
Cancel
Save