From a88166cf58c321b22c88641a50ce201f5df839aa Mon Sep 17 00:00:00 2001 From: wyb <1977763549@qq.com> Date: Thu, 31 Aug 2023 17:12:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E6=8A=A5=E9=80=9A?= =?UTF-8?q?=E7=94=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/docus/server/CollectApplication.java | 49 ++++++- .../converter/FileReportConverter.java | 106 ++++++++++++++ .../server/collect/entity/DownloadTask.java | 130 ++++++++++++++++++ .../docus/server/collect/entity/TBasic.java | 35 +++++ .../server/collect/enums/DownWayEnum.java | 43 ++++++ .../collect/enums/DownloadStateEnum.java | 36 +++++ .../client/DownloadPlatformService.java | 21 +++ .../client/dto/ReportDownDto.java | 29 ++++ .../client/dto/ReportDownPatientDto.java | 19 +++ .../client/dto/ReportDownScanFileDto.java | 44 ++++++ .../infrastructure/dao/DownloadTaskDao.java | 47 +++++++ .../dao/impl/DownloadTaskDaoImpl.java | 51 +++++++ .../mapper/DownloadTaskMapper.java | 37 +++++ .../collect/service/FileReportService.java | 25 ++++ .../service/dto/ReportFileInfoDTO.java | 104 ++++++++++++++ .../service/impl/FileReportServiceImpl.java | 97 +++++++++++++ src/main/resources/bootstrap.yml | 5 +- src/main/resources/mapper/TBasicMapper.xml | 58 ++++++++ 18 files changed, 933 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/docus/server/collect/converter/FileReportConverter.java create mode 100644 src/main/java/com/docus/server/collect/entity/DownloadTask.java create mode 100644 src/main/java/com/docus/server/collect/entity/TBasic.java create mode 100644 src/main/java/com/docus/server/collect/enums/DownWayEnum.java create mode 100644 src/main/java/com/docus/server/collect/enums/DownloadStateEnum.java create mode 100644 src/main/java/com/docus/server/collect/infrastructure/client/DownloadPlatformService.java create mode 100644 src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownDto.java create mode 100644 src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownPatientDto.java create mode 100644 src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownScanFileDto.java create mode 100644 src/main/java/com/docus/server/collect/infrastructure/dao/DownloadTaskDao.java create mode 100644 src/main/java/com/docus/server/collect/infrastructure/dao/impl/DownloadTaskDaoImpl.java create mode 100644 src/main/java/com/docus/server/collect/infrastructure/mapper/DownloadTaskMapper.java create mode 100644 src/main/java/com/docus/server/collect/service/FileReportService.java create mode 100644 src/main/java/com/docus/server/collect/service/dto/ReportFileInfoDTO.java create mode 100644 src/main/java/com/docus/server/collect/service/impl/FileReportServiceImpl.java create mode 100644 src/main/resources/mapper/TBasicMapper.xml diff --git a/src/main/java/com/docus/server/CollectApplication.java b/src/main/java/com/docus/server/CollectApplication.java index ac203f3..82c5ac7 100644 --- a/src/main/java/com/docus/server/CollectApplication.java +++ b/src/main/java/com/docus/server/CollectApplication.java @@ -1,9 +1,17 @@ package com.docus.server; +import com.docus.core.util.SpringUtils; +import com.docus.server.collect.enums.DownWayEnum; +import com.docus.server.collect.service.FileReportService; +import com.docus.server.collect.service.dto.ReportFileInfoDTO; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.scheduling.annotation.EnableAsync; +import java.io.BufferedReader; +import java.io.FileReader; import java.util.Properties; /** @@ -11,14 +19,51 @@ import java.util.Properties; * * @author wyb */ -@SpringBootApplication(scanBasePackages = {"com.docus"}) +@EnableFeignClients +@EnableAsync @MapperScan("com.docus.server.**.mapper") +@SpringBootApplication(scanBasePackages = {"com.docus"}) public class CollectApplication { - public static void main(String[] args) { + public static void main(String[] args) throws Exception { Properties props = System.getProperties(); props.setProperty("org.apache.cxf.stax.allowInsecureParser", "1"); props.setProperty("UseSunHttpHandler", "true"); props.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); SpringApplication.run(CollectApplication.class, args); + +// testBase64Report(); + + + } + + private static void testBase64Report() { + try { + String url=getBase64(); + ReportFileInfoDTO dto = new ReportFileInfoDTO(); + dto.setPatientId("20001099999"); + dto.setSysFlag("icu"); + dto.setSerialNum("0002353348_1229183645"); + dto.setFileTitle("szy服务"); + dto.setTaskId(2023060815440200002L); + dto.setDownUrl(url); + dto.setDownWayEnum(DownWayEnum.BASE64); + dto.setIp("szy-lis"); + dto.setUserName("lis"); + dto.setReportUserFullName("lis"); + dto.setAssortId("list-assort"); + FileReportService reportService = SpringUtils.getBean(FileReportService.class); + reportService.saveDownloadTaskAndReport(dto); + }catch (Exception ex){ + ex.printStackTrace(); + } + } + + private static String getBase64() throws Exception { + FileReader reader = new FileReader("C:\\Users\\WYBDEV\\Desktop\\sb.txt"); + BufferedReader bufferedReader = new BufferedReader(reader); + String base64 = bufferedReader.readLine(); + bufferedReader.close(); + reader.close(); + return base64; } } diff --git a/src/main/java/com/docus/server/collect/converter/FileReportConverter.java b/src/main/java/com/docus/server/collect/converter/FileReportConverter.java new file mode 100644 index 0000000..0642bf7 --- /dev/null +++ b/src/main/java/com/docus/server/collect/converter/FileReportConverter.java @@ -0,0 +1,106 @@ +package com.docus.server.collect.converter; + +import com.docus.server.collect.entity.DownloadTask; +import com.docus.server.collect.enums.DownloadStateEnum; +import com.docus.server.collect.infrastructure.client.dto.ReportDownDto; +import com.docus.server.collect.infrastructure.client.dto.ReportDownPatientDto; +import com.docus.server.collect.infrastructure.client.dto.ReportDownScanFileDto; +import com.docus.server.collect.service.dto.ReportFileInfoDTO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.Collections; +import java.util.Date; +import java.util.List; + +/** + * @author 文件上报转换 + */ +@Component +@Slf4j +public class FileReportConverter { + + + /** + * 转换病案文件上报信息,得到下载任务对象 + * + * @param fileInfoDTO 病案文件上报信息 + * @param basicDataType 基础数据类型 0:普通病案 1:门急诊病案 2:省中医封存病案 + * @return 下载任务对象 + */ + public DownloadTask convertDownloadTask(ReportFileInfoDTO fileInfoDTO, Integer basicDataType) { + Date currentTime = new Date(); + DownloadTask downloadTask = new DownloadTask(); + downloadTask.setPatientId(fileInfoDTO.getPatientId()); + downloadTask.setInpatientNo(fileInfoDTO.getInpatientNo()); + downloadTask.setAdmissions(fileInfoDTO.getAdmisstimes()); + downloadTask.setJzh(fileInfoDTO.getJzh()); + downloadTask.setLatestIp(fileInfoDTO.getIp()); + downloadTask.setLatestFileUrl(fileInfoDTO.getDownUrl()); + downloadTask.setLatestFileUrlType(fileInfoDTO.getDownWayEnum().value()); + downloadTask.setLatestFileTitle(fileInfoDTO.getFileTitle()); + downloadTask.setLatestZdAssortId(fileInfoDTO.getAssortId()); + downloadTask.setLatestReportTime(currentTime); + downloadTask.setLatestDownloadStatus(DownloadStateEnum.WAIT.code()); + downloadTask.setCollectTaskId(fileInfoDTO.getTaskId()); + downloadTask.setSource(fileInfoDTO.getSysFlag()); + downloadTask.setFileSerialNum(fileInfoDTO.getSerialNum()); + downloadTask.setLatestReportUserName(fileInfoDTO.getUserName()); + downloadTask.setLatestReportUserFullName(fileInfoDTO.getReportUserFullName()); + downloadTask.setFileStorageFormat(1); + downloadTask.setBasicDataType(basicDataType); + return downloadTask; + } + /** + * 下载任务转下载平台上报参数 + * @param downloadTask 下载任务 + * @return 下载平台上报参数 + */ + public ReportDownDto convertDownloadPlatformParam(DownloadTask downloadTask) { + ReportDownPatientDto patient = convertDownloadPlatformPatientParam(downloadTask); + List scanFiles = Collections.singletonList(convertDownloadPlatformFileParam(downloadTask)); + ReportDownDto reportDownDto = new ReportDownDto(); + reportDownDto.setCollectorid(downloadTask.getSource()); + reportDownDto.setIp(downloadTask.getLatestIp()); + reportDownDto.setAssortid(downloadTask.getLatestZdAssortId()); + reportDownDto.setScanusercode(downloadTask.getLatestReportUserName()); + reportDownDto.setScanusername(downloadTask.getLatestReportUserFullName()); + reportDownDto.setPatient(patient); + reportDownDto.setScanfiles(scanFiles); + return reportDownDto; + } + /** + * 下载任务转下载平台上报参数患者参数 + * @param downloadTask 下载任务 + * @return 下载平台上报参数患者参数 + */ + public ReportDownPatientDto convertDownloadPlatformPatientParam(DownloadTask downloadTask) { + ReportDownPatientDto patientDto = new ReportDownPatientDto(); + patientDto.setPatientid(downloadTask.getPatientId()); + patientDto.setInpatientno(downloadTask.getInpatientNo()); + patientDto.setAdmisstimes(downloadTask.getAdmissions()); + patientDto.setJzh(downloadTask.getJzh()); + return patientDto; + } + + /** + * 下载任务转下载平台上报参数文件参数 + * @param downloadTask 下载任务 + * @return 下载平台上报参数文件参数 + */ + public ReportDownScanFileDto convertDownloadPlatformFileParam(DownloadTask downloadTask) { + ReportDownScanFileDto scanFileDto = new ReportDownScanFileDto(); + scanFileDto.setTaskid(downloadTask.getCollectTaskId()); + scanFileDto.setFiletitle(downloadTask.getLatestFileTitle()); + scanFileDto.setFilesource(1); + scanFileDto.setFilestoragetype(1); + scanFileDto.setFiletype(downloadTask.getLatestFileUrlType()); + scanFileDto.setDownurl(downloadTask.getLatestFileUrl()); + scanFileDto.setSerialnum(downloadTask.getFileSerialNum()); + scanFileDto.setSortdate(null); + scanFileDto.setCancel(0); + scanFileDto.setAssortid(downloadTask.getLatestZdAssortId()); + scanFileDto.setFileStorageFormat(1); + return scanFileDto; + } +} diff --git a/src/main/java/com/docus/server/collect/entity/DownloadTask.java b/src/main/java/com/docus/server/collect/entity/DownloadTask.java new file mode 100644 index 0000000..067a3f0 --- /dev/null +++ b/src/main/java/com/docus/server/collect/entity/DownloadTask.java @@ -0,0 +1,130 @@ +package com.docus.server.collect.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + + +import java.io.Serializable; +import java.util.Date; + +/** + * 文件下载任务 + * + * @author wyb + **/ +@ApiModel(value = "DownloadTask对象", description = "文件生成下载任务") +@Data +@TableName("af_download_task") +public class DownloadTask implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "文件id(主键)") + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + @TableField("patient_id") + @ApiModelProperty(value = "档案id(患者主键)") + private String patientId; + + + @TableField("inpatient_no") + @ApiModelProperty(value = "病案号") + private String inpatientNo; + + @TableField("admissions") + @ApiModelProperty(value = "住院次数") + private Integer admissions; + + @TableField("jzh") + @ApiModelProperty(value = "记账号") + private String jzh; + + @TableField("latest_ip") + @ApiModelProperty(value = "最新的上报ip") + private String latestIp; + + + @TableField("latest_file_url") + @ApiModelProperty(value = "最新的上报文件地址") + private String latestFileUrl; + + @TableField("latest_file_url_type") + @ApiModelProperty(value = "最新的获取文件方式(文件地址类型,http(1),base64(2),base64url(3),smb(4),localbase64(5))") + private Integer latestFileUrlType; + + @TableField("latest_file_title") + @ApiModelProperty(value = "最新的上报文件标题") + private String latestFileTitle; + + + @TableField("latest_zd_assort_id") + @ApiModelProperty(value = "最新的上报文件分类id") + private String latestZdAssortId; + + + @TableField("latest_report_time") + @ApiModelProperty(value = "最新的上报时间") + private Date latestReportTime; + + + @TableField("latest_download_status") + @ApiModelProperty(value = "最新的下载状态(0:未开始,1:成功,2:失败)") + private Integer latestDownloadStatus; + + + @TableField("latest_download_time") + @ApiModelProperty(value = "最新的下载时间") + private Date latestDownloadTime; + + + @TableField("collect_task_id") + @ApiModelProperty(value = "采集任务id") + private Long collectTaskId; + + @TableField("source") + @ApiModelProperty(value = "来源或者采集器id") + private String source; + + @TableField("file_serial_num") + @ApiModelProperty(value = "来源或者采集器id") + private String fileSerialNum; + + @TableField("latest_report_user_name") + @ApiModelProperty(value = "最后一次上报人工号") + private String latestReportUserName; + + @TableField("latest_report_user_full_name") + @ApiModelProperty(value = "最后一次上报人姓名") + private String latestReportUserFullName; + + @TableField("latest_retry_user_name") + @ApiModelProperty(value = "最后一次重试操作人工号") + private String latestRetryUserName; + + @TableField("latest_retry_user_full_name") + @ApiModelProperty(value = "最后一次重试操作人姓名") + private String latestRetryUserFullName; + + @TableField("basic_data_type") + @ApiModelProperty(value = "基础数据类型 0:普通病案 1:门急诊病案 2:省中医封存病案") + private Integer basicDataType; + + + @TableField("download_file_path") + @ApiModelProperty(value = "文件下载存放路径(程序生成)") + private String downloadFilePath; + + + @TableField("file_storage_format") + @ApiModelProperty(value = "下载存储文件的方式 0 传过来的格式,1转为 pdf 默认 ,2 转为图片jpg存储") + public Integer fileStorageFormat; + + public DownloadTask() { + } + +} \ No newline at end of file diff --git a/src/main/java/com/docus/server/collect/entity/TBasic.java b/src/main/java/com/docus/server/collect/entity/TBasic.java new file mode 100644 index 0000000..4052f19 --- /dev/null +++ b/src/main/java/com/docus/server/collect/entity/TBasic.java @@ -0,0 +1,35 @@ +package com.docus.server.collect.entity; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 患者基础信息 + * + * @author WYBDEV + */ +@Data +@ApiModel(value = "患者基础信息") +public class TBasic { + @ApiModelProperty(value = "病案主键") + private String patientId; + @ApiModelProperty(value = "住院号") + private String inpatientNo; + @ApiModelProperty(value = "住院次数") + private Integer admissTimes; + @ApiModelProperty(value = "入院日期 yyyy-MM-dd HH:mm:ss") + private String admissDate; + @ApiModelProperty(value = "入院科室名称") + private String admissDeptName; + @ApiModelProperty(value = "出院日期 yyyy-MM-dd HH:mm:ss") + private String disDate; + @ApiModelProperty(value = "出院科室名称") + private String disDeptName; + @ApiModelProperty(value = "记账号") + private String jzh; + @ApiModelProperty(value = "姓名") + private String name; + @ApiModelProperty(value = "住院id") + private String admissId; +} diff --git a/src/main/java/com/docus/server/collect/enums/DownWayEnum.java b/src/main/java/com/docus/server/collect/enums/DownWayEnum.java new file mode 100644 index 0000000..2c02198 --- /dev/null +++ b/src/main/java/com/docus/server/collect/enums/DownWayEnum.java @@ -0,0 +1,43 @@ +package com.docus.server.collect.enums; + +/** + * 下载方式 + */ +public enum DownWayEnum { + /** + * http https ftp + */ + HTTP(1,"网络地址URL"), + /** + * base64 + */ + BASE64(2,"BASE64内容文本"), + /** + * url返回base64内容 + */ + BASE64URL(3,"BASE64内容地址"), + /** + * 共享文件夹 + */ + SMB(4,"共享文件夹"), + /** + * 本地文件base64 + */ + LocalBase64(5,"本地BAE64内容文件"), + ; + + private final Integer code; + private final String desc; + + private DownWayEnum(Integer code, String desc) { + this.code = code; + this.desc=desc; + } + public Integer value() { + return this.code; + } + public String desc(){ + return this.desc; + } + +} diff --git a/src/main/java/com/docus/server/collect/enums/DownloadStateEnum.java b/src/main/java/com/docus/server/collect/enums/DownloadStateEnum.java new file mode 100644 index 0000000..bf9c886 --- /dev/null +++ b/src/main/java/com/docus/server/collect/enums/DownloadStateEnum.java @@ -0,0 +1,36 @@ +package com.docus.server.collect.enums; + +/** + * 下载状态 + * + * @author wyb + */ +public enum DownloadStateEnum { + /** + * 等待下载,未开始下载 + */ + WAIT(0, "未开始"), + /** + * 下载成功 + */ + success(1, "成功"), + /** + * 下载失败 + */ + fail(2, "失败"); + final Integer code; + final String desc; + + DownloadStateEnum(Integer code, String desc) { + this.code = code; + this.desc = desc; + } + + public Integer code() { + return this.code; + } + + public String desc() { + return this.desc; + } +} diff --git a/src/main/java/com/docus/server/collect/infrastructure/client/DownloadPlatformService.java b/src/main/java/com/docus/server/collect/infrastructure/client/DownloadPlatformService.java new file mode 100644 index 0000000..a42fc4c --- /dev/null +++ b/src/main/java/com/docus/server/collect/infrastructure/client/DownloadPlatformService.java @@ -0,0 +1,21 @@ +package com.docus.server.collect.infrastructure.client; + +import com.docus.infrastructure.web.api.CommonResult; +import com.docus.server.collect.infrastructure.client.dto.ReportDownDto; +import io.swagger.annotations.ApiOperation; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * 下载平台服务 + * @author wyb + */ +@FeignClient(url = "${docus.url.downloadPlatform}",name = "download-platform") +public interface DownloadPlatformService { + + @ApiOperation("病案上报文件(通用)") + @RequestMapping(value = "/api/downplatform/report",method = RequestMethod.POST) + public CommonResult report(@RequestBody ReportDownDto resources); +} diff --git a/src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownDto.java b/src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownDto.java new file mode 100644 index 0000000..64d1afe --- /dev/null +++ b/src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownDto.java @@ -0,0 +1,29 @@ +package com.docus.server.collect.infrastructure.client.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class ReportDownDto { + @ApiModelProperty(value = "采集器id") + private String collectorid; + + @ApiModelProperty(value = "采集器ip") + private String ip; + + @ApiModelProperty(value = "分类id") + private String assortid; + + @ApiModelProperty(value = "患者信息") + private ReportDownPatientDto patient; + + @ApiModelProperty(value = "文件信息") + private List scanfiles; + + @ApiModelProperty(value = "扫描用户代码") + private String scanusercode; + @ApiModelProperty(value = "扫描用户名称") + private String scanusername; +} \ No newline at end of file diff --git a/src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownPatientDto.java b/src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownPatientDto.java new file mode 100644 index 0000000..4eb441c --- /dev/null +++ b/src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownPatientDto.java @@ -0,0 +1,19 @@ +package com.docus.server.collect.infrastructure.client.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class ReportDownPatientDto { + @ApiModelProperty(value = "记帐号") + private String jzh; + @ApiModelProperty(value = "住院次数,记帐号重复则加这个参数,无则Null") + private Integer admisstimes; + @ApiModelProperty(value = "病案主键,如有传则使用,无则使用jzh") + private String patientid; + @ApiModelProperty(value = "病案号") + private String inpatientno; + + @ApiModelProperty(value = "物理存储位置,有则传") + private String storagelocation; +} diff --git a/src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownScanFileDto.java b/src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownScanFileDto.java new file mode 100644 index 0000000..29a129a --- /dev/null +++ b/src/main/java/com/docus/server/collect/infrastructure/client/dto/ReportDownScanFileDto.java @@ -0,0 +1,44 @@ +package com.docus.server.collect.infrastructure.client.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class ReportDownScanFileDto { + @ApiModelProperty(value = "任务id(如无效任务id,则不更新任务表数据)") + private Long taskid; + @ApiModelProperty(value = "文件标题") + private String filetitle; + @ApiModelProperty(value = "采集类型(文件来源 1:采集器;2:扫描生产软件)") + private int filesource; + @ApiModelProperty(value = "下载类型(1:服务器本地;2:ftp服务器;3:共享文件夹)") + private int filestoragetype; + @ApiModelProperty(value = "文件类型(1:url,2:base64,3:url base64,4:共享文件,5:本地文件base64)") + private int filetype=1; + @ApiModelProperty(value = "下载地址") + private String downurl; +// @ApiModelProperty(value = "档案信息") +// private String recordid; + @ApiModelProperty(value = "采集流水号") + private String serialnum; + + @ApiModelProperty(value = "排序日期") + private String sortdate; + + @ApiModelProperty(value = "是否作废 : 0:否 不作废,1:是 作废") + private int cancel=0; + + + @ApiModelProperty(value = "分类id",hidden = true) + private String assortid; + + + @ApiModelProperty(value = "归档系统文件id",hidden = true) + private Long tScanAssortId; + + /** + * 下载存储文件的方式 0 传过来的格式,1转为 pdf 默认 ,2 转为图片jpg存储 + */ + public int fileStorageFormat=1; + +} diff --git a/src/main/java/com/docus/server/collect/infrastructure/dao/DownloadTaskDao.java b/src/main/java/com/docus/server/collect/infrastructure/dao/DownloadTaskDao.java new file mode 100644 index 0000000..964d35f --- /dev/null +++ b/src/main/java/com/docus/server/collect/infrastructure/dao/DownloadTaskDao.java @@ -0,0 +1,47 @@ +package com.docus.server.collect.infrastructure.dao; + +import com.docus.infrastructure.core.db.dao.IBaseDao; +import com.docus.server.collect.entity.DownloadTask; +import com.docus.server.collect.entity.TBasic; +import com.docus.server.collect.service.dto.ReportFileInfoDTO; + +import java.util.List; + +/** + * 下载任务表-数据访问接口 + * @author wyb + */ +public interface DownloadTaskDao extends IBaseDao { + /** + * 根据上报文件信息中的患者信息,查询患者基础数据 + * @param fileInfoDTO 上报文件信息 + * @return 患者基础数据 + */ + List getBasicInfo(ReportFileInfoDTO fileInfoDTO); + + + /** + * 从下载任务表中获取下载任务id,来源,采文件唯一标识,和患者信息 + * @param downloadTask 下载任务 + * @return 下载任务id(也是文件id) + */ + Long getDownloadTaskIdFromDownloadTask(DownloadTask downloadTask); + + /** + * 根据病案的来源,病案文件的唯一标识,从文件表得到文件下载任务id(也是文件id) + * @param patientId 病案主键 + * @param source 来源 + * @param serialNum 文件唯一标识 + * @return 下载任务id(也是文件id) + */ + Long getDownloadTaskIdFromSanAssort(String patientId, String source, String serialNum); + + /** + * 根据病案的来源,病案文件的唯一标识,从下载记录表得到文件下载任务id(也是文件id) + * @param patientId 病案主键 + * @param source 来源 + * @param serialNum 文件唯一标识 + * @return 下载任务id(也是文件id) + */ + Long getDownloadTaskIdFromDownFile(String patientId, String source, String serialNum); +} diff --git a/src/main/java/com/docus/server/collect/infrastructure/dao/impl/DownloadTaskDaoImpl.java b/src/main/java/com/docus/server/collect/infrastructure/dao/impl/DownloadTaskDaoImpl.java new file mode 100644 index 0000000..a825b0e --- /dev/null +++ b/src/main/java/com/docus/server/collect/infrastructure/dao/impl/DownloadTaskDaoImpl.java @@ -0,0 +1,51 @@ +package com.docus.server.collect.infrastructure.dao.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.docus.core.util.Func; +import com.docus.infrastructure.core.db.dao.impl.BaseDaoImpl; +import com.docus.server.collect.entity.DownloadTask; +import com.docus.server.collect.entity.TBasic; +import com.docus.server.collect.infrastructure.dao.DownloadTaskDao; +import com.docus.server.collect.infrastructure.mapper.DownloadTaskMapper; +import com.docus.server.collect.service.dto.ReportFileInfoDTO; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 下载任务表-数据访问实现类 + * + * @author wyb + */ +@Repository +public class DownloadTaskDaoImpl extends BaseDaoImpl implements DownloadTaskDao { + @Override + public List getBasicInfo(ReportFileInfoDTO fileInfoDTO) { + return baseMapper.getBasicInfo(fileInfoDTO); + } + + @Override + public Long getDownloadTaskIdFromDownloadTask(DownloadTask downloadTask) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.select(DownloadTask::getId); + wrapper.eq(Func.isNotBlank(downloadTask.getPatientId()), DownloadTask::getPatientId, downloadTask.getPatientId()); + wrapper.eq(Func.isNotBlank(downloadTask.getJzh()), DownloadTask::getJzh, downloadTask.getJzh()); + wrapper.eq(Func.isNotBlank(downloadTask.getInpatientNo()), DownloadTask::getInpatientNo, downloadTask.getInpatientNo()); + wrapper.eq(Func.isNotEmpty(downloadTask.getAdmissions()), DownloadTask::getAdmissions, downloadTask.getAdmissions()); + List downloadTasks = baseMapper.selectList(wrapper); + if (Func.isNotEmpty(downloadTasks) && downloadTasks.size() == 1) { + return downloadTasks.get(0).getId(); + } + return null; + } + + @Override + public Long getDownloadTaskIdFromSanAssort(String patientId, String source, String serialNum) { + return baseMapper.getDownloadTaskIdFromSanAssort(patientId, source, serialNum); + } + + @Override + public Long getDownloadTaskIdFromDownFile(String patientId, String source, String serialNum) { + return baseMapper.getDownloadTaskIdFromDownFile(patientId, source, serialNum); + } +} diff --git a/src/main/java/com/docus/server/collect/infrastructure/mapper/DownloadTaskMapper.java b/src/main/java/com/docus/server/collect/infrastructure/mapper/DownloadTaskMapper.java new file mode 100644 index 0000000..497bd8e --- /dev/null +++ b/src/main/java/com/docus/server/collect/infrastructure/mapper/DownloadTaskMapper.java @@ -0,0 +1,37 @@ +package com.docus.server.collect.infrastructure.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.docus.server.collect.entity.DownloadTask; +import com.docus.server.collect.entity.TBasic; +import com.docus.server.collect.service.dto.ReportFileInfoDTO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface DownloadTaskMapper extends BaseMapper { + /** + * 根据上报文件的患者信息获取基础病案信息 from `docus_medicalrecord`.`t_basic` + * + * @param fileInfoDTO 上报文件信息 + * @return 病案基础信息 + */ + List getBasicInfo(@Param("dto") ReportFileInfoDTO fileInfoDTO); + /** + * 根据病案的来源,病案文件的唯一标识,从文件表得到文件下载任务id(也是文件id) + * @param patientId 病案主键 + * @param source 来源 + * @param serialNum 文件唯一标识 + * @return 下载任务id(也是文件id) + */ + Long getDownloadTaskIdFromSanAssort(@Param("patientId") String patientId, @Param("source") String source, @Param("serialNum") String serialNum); + /** + * 根据病案的来源,病案文件的唯一标识,从下载记录表得到文件下载任务id(也是文件id) + * @param patientId 病案主键 + * @param source 来源 + * @param serialNum 文件唯一标识 + * @return 下载任务id(也是文件id) + */ + Long getDownloadTaskIdFromDownFile(@Param("patientId") String patientId, @Param("source") String source, @Param("serialNum") String serialNum); +} diff --git a/src/main/java/com/docus/server/collect/service/FileReportService.java b/src/main/java/com/docus/server/collect/service/FileReportService.java new file mode 100644 index 0000000..698e4c4 --- /dev/null +++ b/src/main/java/com/docus/server/collect/service/FileReportService.java @@ -0,0 +1,25 @@ +package com.docus.server.collect.service; + +import com.docus.server.collect.entity.DownloadTask; +import com.docus.server.collect.service.dto.ReportFileInfoDTO; + +/** + * 文件上报-接口 + * @author wyb + */ +public interface FileReportService { + /** + * + * 上报文件信息,生成|更新下载任务,并下发下载平台,此方法用于基础病案 t_basic + * @param fileInfoDTO 上报文件信息 + */ + void saveDownloadTaskAndReport(ReportFileInfoDTO fileInfoDTO); + + /** + * 根据下载文件任务信息,查询下载任务id(用作文件id) + * 查询有三个地方,文件表(需要有patientId),文件下载记录表(需要有patientId),文件下载任务表 + * @param downloadTask 下载文件任务信息 + * @return 下载任务id + */ + Long getDownloadTaskId(DownloadTask downloadTask); +} diff --git a/src/main/java/com/docus/server/collect/service/dto/ReportFileInfoDTO.java b/src/main/java/com/docus/server/collect/service/dto/ReportFileInfoDTO.java new file mode 100644 index 0000000..cbe31ae --- /dev/null +++ b/src/main/java/com/docus/server/collect/service/dto/ReportFileInfoDTO.java @@ -0,0 +1,104 @@ +package com.docus.server.collect.service.dto; + +import com.docus.server.collect.enums.DownWayEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 上报的文件信息 + * 住院号,记账号,住院次数,患者病案主键 必须有一组组合能查出患者基础信息且唯一,不能多传参数,防止查不出来 + * + * @author wyb + */ +@ApiModel("上报的文件信息对象") +@Data +public class ReportFileInfoDTO { + + /** + * 住院号 + */ + @ApiModelProperty("住院号") + private String inpatientNo; + /** + * 记账号/住院流水号 + */ + @ApiModelProperty("记账号/住院流水号") + private String jzh; + /** + * 住院次数 + */ + @ApiModelProperty("住院次数") + private Integer admisstimes; + /** + * 患者病案主键 + */ + @ApiModelProperty("患者病案主键") + private String patientId; + /** + * 采集来源系统 + */ + @ApiModelProperty("采集来源系统") + @NotBlank + private String sysFlag; + /** + * 下载地址 + */ + @ApiModelProperty("下载地址") + @NotBlank + private String downUrl; + + /** + * 下载地址 + */ + @ApiModelProperty("下载地址类型") + @NotNull + private DownWayEnum downWayEnum; + + /** + * 文件名 + */ + @ApiModelProperty("文件名") + @NotBlank + private String fileTitle; + /** + * 采集流水号/文件唯一id + */ + @ApiModelProperty("采集流水号/文件唯一id") + @NotBlank + private String serialNum; + /** + * 文件分类id + */ + @ApiModelProperty("文件分类id") + @NotBlank + private String assortId; + + + /** + * 下载对应任务id ,接收处理 + */ + @ApiModelProperty("下载对应任务id ,接收处理") + private Long taskId; + + /** + * ip地址 + */ + @ApiModelProperty("ip地址") + private String ip; + + /** + * 用户工号 + */ + @ApiModelProperty("用户工号") + private String userName; + + /** + * 用户名 + */ + @ApiModelProperty("用户名") + private String reportUserFullName; +} diff --git a/src/main/java/com/docus/server/collect/service/impl/FileReportServiceImpl.java b/src/main/java/com/docus/server/collect/service/impl/FileReportServiceImpl.java new file mode 100644 index 0000000..a7d6209 --- /dev/null +++ b/src/main/java/com/docus/server/collect/service/impl/FileReportServiceImpl.java @@ -0,0 +1,97 @@ +package com.docus.server.collect.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.docus.core.util.Func; +import com.docus.infrastructure.redis.service.IdService; +import com.docus.server.collect.converter.FileReportConverter; +import com.docus.server.collect.entity.DownloadTask; +import com.docus.server.collect.entity.TBasic; +import com.docus.server.collect.infrastructure.client.DownloadPlatformService; +import com.docus.server.collect.infrastructure.dao.DownloadTaskDao; +import com.docus.server.collect.service.FileReportService; +import com.docus.server.collect.service.dto.ReportFileInfoDTO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * 文件上报-实现 + * + * @author wyb + */ +@Slf4j +@Service +public class FileReportServiceImpl implements FileReportService { + @Autowired + private DownloadPlatformService downloadPlatformService; + @Autowired + private DownloadTaskDao downloadTaskDao; + @Autowired + private FileReportConverter fileReportConverter; + + @Autowired + private IdService idService; + + @Autowired + private ThreadPoolExecutor threadPoolExecutor; + + @Override + public void saveDownloadTaskAndReport(ReportFileInfoDTO fileInfoDTO) { + // 查询基础数据,更新新的病案信息 + List tBasics = downloadTaskDao.getBasicInfo(fileInfoDTO); + // 如果找到患者基础数据,并且刚好为1条 + if (CollUtil.isNotEmpty(tBasics) && tBasics.size() == 1) { + TBasic tBasic = tBasics.get(0); + fileInfoDTO.setPatientId(tBasic.getPatientId()); + fileInfoDTO.setInpatientNo(tBasic.getInpatientNo()); + fileInfoDTO.setAdmisstimes(tBasic.getAdmissTimes()); + fileInfoDTO.setJzh(tBasic.getJzh()); + } + // 转换下载任务对象 + DownloadTask downloadTask = fileReportConverter.convertDownloadTask(fileInfoDTO, 0); + // 查询旧的下载任务id,更新/保存任务信息 + Long downloadTaskId = Optional.ofNullable(getDownloadTaskId(downloadTask)).orElse(idService.getDateSeq()); + downloadTask.setId(downloadTaskId); + downloadTaskDao.saveOrUpdate(downloadTask); + report(downloadTask); + } + + @Override + public Long getDownloadTaskId(DownloadTask downloadTask) { + String patientId = downloadTask.getPatientId(); + if(StrUtil.isNotBlank(patientId)){ + String serialNum = downloadTask.getFileSerialNum(); + String source = downloadTask.getSource(); + // 从文件表获取 + Long downloadTaskId = downloadTaskDao.getDownloadTaskIdFromSanAssort(patientId,source,serialNum); + if (Func.isNotEmpty(downloadTaskId)) { + return downloadTaskId; + } + // 从下载记录表获取 + downloadTaskId = downloadTaskDao.getDownloadTaskIdFromDownFile(patientId,source,serialNum); + if (Func.isNotEmpty(downloadTaskId)) { + return downloadTaskId; + } + } + // 从下载任务表获取,不考虑重复,重复那就是调研不清楚或者代码调用错误 + return downloadTaskDao.getDownloadTaskIdFromDownloadTask(downloadTask); + } + + /** + * 根据下载任务,上报到下载平台服务 + * + * @param downloadTask 下载任务 + */ + private void report(DownloadTask downloadTask) { + threadPoolExecutor.execute(() -> { + if (downloadTask.getBasicDataType().equals(0)) { + downloadPlatformService.report(fileReportConverter.convertDownloadPlatformParam(downloadTask)); + } + }); + } +} diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml index 4f0d21e..01ceeb0 100644 --- a/src/main/resources/bootstrap.yml +++ b/src/main/resources/bootstrap.yml @@ -4,7 +4,7 @@ spring: application: name: @artifactId@ datasource: - url: jdbc:log4jdbc:mysql://db.docus.cn:3306/docus_medicalrecord?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + url: jdbc:log4jdbc:mysql://db.docus.cn:3306/docus_archivefile?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: docus password: docus702 driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy @@ -46,6 +46,9 @@ spring: docus: dbtype: mysql + url: + # 下载平台服务地址 + downloadPlatform: http://192.168.16.85:9291 mybatis-plus: configuration: diff --git a/src/main/resources/mapper/TBasicMapper.xml b/src/main/resources/mapper/TBasicMapper.xml new file mode 100644 index 0000000..fdb263d --- /dev/null +++ b/src/main/resources/mapper/TBasicMapper.xml @@ -0,0 +1,58 @@ + + + + + + + +