From 5fef2f8eba701930b89fcebca593836f0c876a40 Mon Sep 17 00:00:00 2001 From: wyb <1977763549@qq.com> Date: Mon, 15 Jan 2024 14:24:30 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=94=B6=E5=88=B0=E5=B0=81?= =?UTF-8?q?=E5=AD=98=E7=94=B5=E5=AD=90=E7=97=85=E5=8E=86=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=B0=81=E5=AD=98id=E9=87=87=E9=9B=86=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E7=B3=BB=E7=BB=9F=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dataConfig/SystemCollectConfig | 27 +++++++ .../docus/bgts/config/ThreadPoolConfig.java | 31 +++++++ .../docus/bgts/dto/SystemCollectConfig.java | 65 +++++++++++++++ .../docus/bgts/handler/TBasicWebService.java | 81 ++++++++++++++++--- .../java/com/docus/bgts/utils/FileUtils.java | 13 +++ 5 files changed, 205 insertions(+), 12 deletions(-) create mode 100644 dataConfig/SystemCollectConfig create mode 100644 src/main/java/com/docus/bgts/config/ThreadPoolConfig.java create mode 100644 src/main/java/com/docus/bgts/dto/SystemCollectConfig.java diff --git a/dataConfig/SystemCollectConfig b/dataConfig/SystemCollectConfig new file mode 100644 index 0000000..8de2311 --- /dev/null +++ b/dataConfig/SystemCollectConfig @@ -0,0 +1,27 @@ +{ + "sealCollectClassify": "SEAL_COLLECT", + "sealCollectConfigs":[ + { + "desc":"封存病案-扫描视图报告采集", + "url":"http://127.0.0.1:9316/gdszy/patscan/collect/seal/collectBySealId" + },{ + "desc":"封存病案-Lis检验报告采集", + "url":"http://127.0.0.1:9315/collect/gdszy/lisBySealId" + },{ + "desc":"封存病案-pacs检查报告采集", + "url":"http://127.0.0.1:9303/seal/collect/pacs" + },{ + "desc":"封存病案-内镜报告采集", + "url":"http://127.0.0.1:9304/seal/collect/endoscopy" + },{ + "desc":"封存病案-心电报告采集", + "url":"http://127.0.0.1:9305/seal/collect/ecg" + },{ + "desc":"封存病案-重症报告采集", + "url":"http://127.0.0.1:9409/seal/collect/icu" + },{ + "desc":"封存病案-手麻报告采集", + "url":"http://127.0.0.1:9306/seal/collect/surgicalAnesthesia" + } + ] +} \ No newline at end of file diff --git a/src/main/java/com/docus/bgts/config/ThreadPoolConfig.java b/src/main/java/com/docus/bgts/config/ThreadPoolConfig.java new file mode 100644 index 0000000..085114b --- /dev/null +++ b/src/main/java/com/docus/bgts/config/ThreadPoolConfig.java @@ -0,0 +1,31 @@ +package com.docus.bgts.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @author YongBin Wen + * @date 2024/1/15 13:36 + */ + +@Configuration +public class ThreadPoolConfig { + + public ThreadPoolConfig() { + } + + @Bean + public ThreadPoolExecutor threadPoolExecutor() { + return new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), + (int)((double)Runtime.getRuntime().availableProcessors() / 0.1), + 60L, TimeUnit.SECONDS, + new LinkedBlockingQueue(Runtime.getRuntime().availableProcessors()), + Executors.defaultThreadFactory(), + new ThreadPoolExecutor.CallerRunsPolicy()); + } +} diff --git a/src/main/java/com/docus/bgts/dto/SystemCollectConfig.java b/src/main/java/com/docus/bgts/dto/SystemCollectConfig.java new file mode 100644 index 0000000..17e55c1 --- /dev/null +++ b/src/main/java/com/docus/bgts/dto/SystemCollectConfig.java @@ -0,0 +1,65 @@ +package com.docus.bgts.dto; + +import lombok.Data; + +import java.util.List; + +/** + * 系统采集配置 + * @author YongBin Wen + * @date 2024/1/15 11:33 + */ +@Data +public class SystemCollectConfig { + /** + * 分类用途-封存病案 + */ + private String sealCollectClassify; + + + /** + * 配置内容 + */ + private List sealCollectConfigs; + + @Data + public static class CollectConfig { + private String desc; + private String url; + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + } + + public enum Classify { + /** + * 系统采集配置分类-封存病案采集 + */ + SEAL_COLLECT("SEAL_COLLECT"); + /** + * 系统采集分类 + */ + final String classify; + + Classify(String classify) { + this.classify = classify; + } + public String getClassify() { + return classify; + } + + } +} diff --git a/src/main/java/com/docus/bgts/handler/TBasicWebService.java b/src/main/java/com/docus/bgts/handler/TBasicWebService.java index f2e3389..8f4b404 100644 --- a/src/main/java/com/docus/bgts/handler/TBasicWebService.java +++ b/src/main/java/com/docus/bgts/handler/TBasicWebService.java @@ -2,8 +2,7 @@ package com.docus.bgts.handler; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.docus.bgts.dto.SystemCollectConfig; import com.docus.bgts.entity.*; import com.docus.bgts.enums.Codes; import com.docus.bgts.facade.IAfCollectTaskService; @@ -15,30 +14,25 @@ import com.docus.bgts.utils.FileUtils; import com.docus.bgts.utils.HttpUtils; import com.docus.bgts.utils.ResultUtils; import com.docus.bgts.utils.XmlUtils; -//import com.sun.xml.internal.ws.util.xml.XmlUtil; -import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; - import org.apache.commons.lang3.exception.ExceptionUtils; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; -import org.dom4j.Namespace; import org.dom4j.io.SAXReader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import sun.misc.BASE64Decoder; +import javax.annotation.Resource; import javax.jws.WebService; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.text.SimpleDateFormat; import java.util.*; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -60,6 +54,9 @@ public class TBasicWebService implements ITBasicWebService { @Autowired TScanAssortMapper tScanAssortMapper; + @Resource + private ThreadPoolExecutor threadPoolExecutor; + // private Object lock = new Object(); private final Logger logger = LoggerFactory.getLogger(getClass()); @@ -165,6 +162,7 @@ public class TBasicWebService implements ITBasicWebService { reportDownPatientDto.setJzh(empIdText); reportDownPatientDto.setSealId(sealId); logger.info("封存患者jzh : " + empIdText); + sealCollect(sealId); reportDownDto.setPatient(reportDownPatientDto); List elementList = xmlUtils.getJsonByName(elementRoot); for (Element element : elementList) { @@ -385,6 +383,65 @@ public class TBasicWebService implements ITBasicWebService { } } + public static void main(String[] args) { + TBasicWebService service = new TBasicWebService(); + service.sealCollect(""); + } + private void sealCollect(String sealId) { + final String systemCollectConfigFileName = "dataConfig" + File.separator + "SystemCollectConfig"; + List sealCollectConfigs; + try { + String configJson = FileUtils.readJsonFromCurrentProject(systemCollectConfigFileName); + + SystemCollectConfig systemCollectConfig = JSON.parseObject(configJson, SystemCollectConfig.class); + String sealCollectClassify = systemCollectConfig.getSealCollectClassify(); + if (!SystemCollectConfig.Classify.SEAL_COLLECT.getClassify().equals(sealCollectClassify)) { + throw new RuntimeException("封存病案采集配置未配置!"); + } + sealCollectConfigs = systemCollectConfig.getSealCollectConfigs(); + for (SystemCollectConfig.CollectConfig config : sealCollectConfigs) { + if (StringUtils.isBlank(config.getDesc()) || StringUtils.isBlank(config.getUrl())) { + throw new RuntimeException("封存病案采集配置中描述和地址不能为空!"); + } + } + } catch (RuntimeException runtimeException) { + logger.error(runtimeException.getMessage(), runtimeException); + return; + } catch (Exception ex) { + logger.error("封存病案获取采集配置出现未知错误!", ex); + return; + } + // 添加封存采集任务的容器 + List> completableFutureList = new CopyOnWriteArrayList<>(); + for (SystemCollectConfig.CollectConfig config : sealCollectConfigs) { + CompletableFuture completableFuture = CompletableFuture.runAsync(() -> { + sealCollect(sealId, config); + }, threadPoolExecutor); + completableFutureList.add(completableFuture); + } + // 封存采集任务的容器不为空,阻塞到所有任务完成 + if (!completableFutureList.isEmpty()) { + CompletableFuture allFutures = CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[0])); + try { + allFutures.get(); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + } + } + + private void sealCollect(String sealId, SystemCollectConfig.CollectConfig config) { + String url = config.getUrl() + "?sealId=" + sealId; + String desc = config.getDesc(); + try { + logger.info("{},采集地址:{}", desc, url); + String result = HttpUtils.get(url); + logger.info("{},采集地址:{},采集结果:{}", desc, url, result); + } catch (Exception ex) { + logger.error(desc + ",采集地址:" + url + ",采集失败!", ex); + } + } + /** * 肇庆门急诊报告接收 @@ -751,9 +808,9 @@ public class TBasicWebService implements ITBasicWebService { } } - public static void main(String[] args) { - depdf(); - } +// public static void main(String[] args) { +// depdf(); +// } } diff --git a/src/main/java/com/docus/bgts/utils/FileUtils.java b/src/main/java/com/docus/bgts/utils/FileUtils.java index 7afb6b5..a718454 100644 --- a/src/main/java/com/docus/bgts/utils/FileUtils.java +++ b/src/main/java/com/docus/bgts/utils/FileUtils.java @@ -38,6 +38,19 @@ public class FileUtils { return jsonMap.get(name); } + /** + * 根据文件路径,从当前项目下获取静态文件中的内容 + * + * @param fileName 从当前项目下获取json配置文件内容 + * @return json内容 + */ + public static String readJsonFromCurrentProject(String fileName) { + //获取目录结构 + String path = FileUtils.currentPath(); + String filePath = path + File.separator + fileName; + //解析json映射文件 + return JsonUtils.readJsonFile(filePath); + } }