From 0afac42fb2e9d6e5291304dd0044ce3042b45d2b Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期六, 10 十月 2026 15:09:14 +0800
Subject: [PATCH] 短信模块提交

---
 smartor/src/main/java/com/smartor/service/impl/XHGatherPatArchiveServiceImpl.java |  159 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 150 insertions(+), 9 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/XHGatherPatArchiveServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/XHGatherPatArchiveServiceImpl.java
index 22df1bf..d434c92 100644
--- a/smartor/src/main/java/com/smartor/service/impl/XHGatherPatArchiveServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/XHGatherPatArchiveServiceImpl.java
@@ -3,19 +3,23 @@
 import com.google.common.reflect.TypeToken;
 import com.google.gson.Gson;
 import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.domain.entity.SysUserDept;
 import com.ruoyi.common.core.domain.entity.SysUserRole;
+import com.ruoyi.common.utils.HttpUtil;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.http.HttpUtils;
+import com.ruoyi.message.SendResult;
+import com.ruoyi.message.sms.SmsSendRequest;
+import com.ruoyi.message.sms.SmsSenderFactory;
+import com.ruoyi.system.domain.SysConfig;
+import com.ruoyi.system.mapper.SysConfigMapper;
 import com.smartor.domain.*;
 import com.smartor.mapper.*;
-import com.smartor.service.IHNGatherPatArchiveService;
-import com.smartor.service.IPatArchiveService;
-import com.smartor.service.IPatMedInhospService;
-import com.smartor.service.IXHGatherPatArchiveService;
+import com.smartor.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +31,7 @@
 import java.io.File;
 import java.io.FileWriter;
 import java.lang.reflect.Type;
+import java.net.URLEncoder;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
@@ -47,13 +52,21 @@
 
     @Value("${hosp_info_url}")
     private String hospInfoUrl;
-
-
     @Autowired
     IPatMedInhospService patMedInhospService;
-
     @Autowired
     IPatArchiveService patArchiveService;
+    @Autowired
+    IServiceAppointRecordService iServiceAppointRecordService;
+    @Autowired
+    private SysConfigMapper sysConfigMapper;
+
+    /**
+     * 娑堟伅鍙戦�佹柟宸ュ巶锛堢煭淇�/寰俊鍏紬鍙凤級锛屾浛浠e師鏉ョ洿鎺ユ敞鍏� xhsms* 閰嶇疆 + HttpUtils 鐨勫啓娉�
+     */
+    @Autowired
+    private SmsSenderFactory smsSenderFactory;
+
 
     /**
      * 鑾峰彇鎮h�呭嚭鍏ラ櫌淇℃伅
@@ -94,6 +107,55 @@
         }
     }
 
+    /**
+     * 鑾峰彇棰勭害鍋滆瘖璁板綍淇℃伅
+     *
+     * @param cry       鍑哄叆闄㈢被鍨嬶細0-鍏ラ櫌锛�1-鍑洪櫌 2,棰勭害璁板綍
+     * @param startTime 寮�濮嬫椂闂�
+     * @param endTime   缁撴潫鏃堕棿
+     */
+    public void getAppointRecordInfo(String cry, LocalDateTime startTime, LocalDateTime endTime) {
+        log.info("銆恎etAppointRecordInfo銆戝紑濮嬭幏鍙栧彇棰勭害鍋滆瘖璁板綍淇℃伅锛屾椂闂磋寖鍥达細{} ~ {}", startTime, endTime);
+        long startTimeMillis = System.currentTimeMillis();
+
+        try {
+            // 绗竴姝ワ細鏋勫缓璇锋眰鍙傛暟骞惰皟鐢℉IS鎺ュ彛
+            List<ServiceAppointRecord> appointRecordFromHIS = getAppointRecordFromHIS(cry, startTime, endTime);
+
+            if (CollectionUtils.isEmpty(appointRecordFromHIS)) {
+                log.info("銆恎etAppointRecordInfo銆戣幏鍙栭绾﹀仠璇婅褰曚俊鎭负绌猴紝璺宠繃澶勭悊");
+                return;
+            }
+            log.info("銆恎etAppointRecordInfo銆戣幏鍙栭绾﹀仠璇婅褰曚俊鎭瘂}鏉�", appointRecordFromHIS.size());
+            SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("yytz.sms.template");
+            if (sysConfig != null) {
+                String smsContemt = sysConfig.getConfigValue();
+                // 绗簩姝ワ細澶勭悊鍋滆瘖璁板綍淇℃伅
+                for (ServiceAppointRecord serviceAppointRecord : appointRecordFromHIS) {
+                    String replace = smsContemt.replace("${patFileName}", StringUtils.defaultString(serviceAppointRecord.getPatFileName())).replace("${registTimeRange}", StringUtils.defaultString(serviceAppointRecord.getRegistTimeRange())).replace("${registDeptName}", StringUtils.defaultString(serviceAppointRecord.getRegistDeptName())).replace("${treatDoctName}", StringUtils.defaultString(serviceAppointRecord.getTreatDoctName()));
+                    //鐭俊鍙戦�佸凡鏀跺彛鍒� ruoyi-message 妯″潡锛堟柊鍗庨�氶亾璧拌〃鍗曟ā寮忥紝涓庡師瀹炵幇涓�鑷达級
+                    SendResult sendResult = smsSenderFactory.send("xh",
+                            SmsSendRequest.of(serviceAppointRecord.getPatTel(), replace));
+                    if (sendResult.isOk()) {
+                        log.info("---澶勭悊鍋滆瘖璁板綍淇℃伅鍙戦�佹垚鍔�,鍏ュ弬涓�:{}", sendResult.getRawResponse());
+                        serviceAppointRecord.setSendTime(new Date());
+                        serviceAppointRecord.setSenderName("绯荤粺绠$悊鍛�");
+                        iServiceAppointRecordService.insertServiceAppointRecord(serviceAppointRecord);
+                    } else {
+                        log.info("澶勭悊鍋滆瘖璁板綍淇℃伅鍙戦�佸け璐�");
+                        iServiceAppointRecordService.insertServiceAppointRecord(serviceAppointRecord);
+                    }
+                }
+            }
+            long endTimeMillis = System.currentTimeMillis();
+            log.info("銆恎etAppointRecordInfo銆憑},棰勭害鍋滆瘖璁板綍淇℃伅澶勭悊瀹屾垚锛岃�楁椂锛歿}ms", endTimeMillis - startTimeMillis);
+
+        } catch (Exception e) {
+            log.error("銆恎etAppointRecordInfo銆戣幏鍙栭绾﹀仠璇婅褰曚俊鎭鐞嗗紓甯�", e);
+            throw new RuntimeException("鑾峰彇棰勭害鍋滆瘖璁板綍淇℃伅澶勭悊寮傚父", e);
+        }
+    }
+
 
     /**
      * 绗竴姝ワ細璋冪敤HIS鎺ュ彛鑾峰彇鏁版嵁
@@ -117,6 +179,29 @@
             throw e;
         }
     }
+
+
+    private List<ServiceAppointRecord> getAppointRecordFromHIS(String cry, LocalDateTime startTime, LocalDateTime endTime) {
+        try {
+            // 鏋勫缓璇锋眰鍙傛暟
+            Map<String, String> requestParams = buildRequestParams(cry, startTime, endTime);
+
+            // 鏋勫缓璇锋眰澶�
+            Map<String, String> headers = buildRequestHeaders(startTime);
+
+            // 鍙戦�丠TTP璇锋眰
+            log.info("銆恎etAppointRecordFromHIS銆戝彂閫丠TTP璇锋眰锛岃姹傚弬鏁帮細{},璇锋眰鍦板潃锛歿}", new Gson().toJson(requestParams), hospInfoUrl);
+            String result = HttpUtils.sendPostByHeader(hospInfoUrl, new Gson().toJson(requestParams), headers);
+
+            // 瑙f瀽鍝嶅簲鏁版嵁
+            return parseResponseData2(result);
+
+        } catch (Exception e) {
+            log.error("銆恌etchHisData銆戣皟鐢℉IS鎺ュ彛寮傚父", e);
+            throw e;
+        }
+    }
+
 
     /**
      * 绗簩姝ワ細淇濆瓨鍘熷鏁版嵁鍒版枃浠�
@@ -180,6 +265,7 @@
     private Map<String, String> buildRequestHeaders(LocalDateTime startTime) {
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S");
         Map<String, String> header = new HashMap<>();
+//        header.put("x-hcsb-serviceno", "IS044056");
         header.put("x-hcsb-serviceno", "IS002347");
         header.put("x-hcsb-version", "2.0");
         header.put("x-hcsb-sourcesyscode", "14");
@@ -201,11 +287,17 @@
             req.put("cashStartDate", startTime.format(formatter));
             req.put("cashEndDate", endTime.format(formatter));
             req.put("currStatus", "4");
-        } else {
+        } else if ("0".equals(cry)) {
             // 鍏ラ櫌鍙傛暟
             req.put("admissStartDate", startTime.format(formatter));
             req.put("admissEndDate", endTime.format(formatter));
             req.put("currStatus", "2");
+        } else if ("2".equals(cry)) {
+            // 棰勭害璁板綍鏌ヨ
+            req.put("appointRegistDateBegin", startTime.format(formatter));
+            req.put("appointRegistDateEnd", endTime.format(formatter));
+            // 鎺掔彮鍋滆瘖 锛堥绾︾姸鎬佹爣蹇�(0:宸查绾�  1:宸叉寕鍙�  2:宸查��鍙�  3:宸插氨璇�  -1:鐥呬汉鍙栨秷  -2:鍖婚櫌鍙栨秷  -3:鎺掔彮鍋滆瘖)锛�
+            req.put("scheduleStatusFlag", "-3");
         }
 
         return req;
@@ -218,12 +310,59 @@
         try {
             Gson gson = new Gson();
             JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
-            JsonArray resultArray = jsonObject.getAsJsonObject("data").getAsJsonArray("result");
+
+            // 鏍¢獙data瀛楁鏄惁涓篔sonObject
+            JsonElement dataElement = jsonObject.get("data");
+            if (dataElement == null || !dataElement.isJsonObject()) {
+                log.info("銆恜arseResponseData銆戝搷搴旀暟鎹腑data瀛楁涓虹┖鎴栭潪瀵硅薄绫诲瀷锛屽師濮嬫暟鎹細{}", result);
+                return new ArrayList<>();
+            }
+
+            JsonObject dataObject = dataElement.getAsJsonObject();
+            JsonElement resultElement = dataObject.get("result");
+            if (resultElement == null || !resultElement.isJsonArray()) {
+                log.info("銆恜arseResponseData銆戝搷搴旀暟鎹腑result瀛楁涓虹┖鎴栭潪鏁扮粍绫诲瀷锛屽師濮嬫暟鎹細{}", result);
+                return new ArrayList<>();
+            }
+
+            JsonArray resultArray = resultElement.getAsJsonArray();
             Type resultType = new TypeToken<List<ThiedInhospInfo>>() {
             }.getType();
             return gson.fromJson(resultArray, resultType);
         } catch (Exception e) {
             log.error("銆恜arseResponseData銆戣В鏋愬搷搴旀暟鎹紓甯革紝鍘熷鏁版嵁锛歿}", result, e);
+            throw e;
+        }
+    }
+
+    /**
+     * 瑙f瀽鍝嶅簲鏁版嵁
+     */
+    private List<ServiceAppointRecord> parseResponseData2(String result) {
+        try {
+            Gson gson = new Gson();
+            JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
+
+            // 鏍¢獙data瀛楁鏄惁涓篔sonObject
+            JsonElement dataElement = jsonObject.get("data");
+            if (dataElement == null || !dataElement.isJsonObject()) {
+                log.warn("銆恜arseResponseData2銆戝搷搴旀暟鎹腑data瀛楁涓虹┖鎴栭潪瀵硅薄绫诲瀷锛屽師濮嬫暟鎹細{}", result);
+                return new ArrayList<>();
+            }
+
+            JsonObject dataObject = dataElement.getAsJsonObject();
+            JsonElement resultElement = dataObject.get("result");
+            if (resultElement == null || !resultElement.isJsonArray()) {
+                log.warn("銆恜arseResponseData2銆戝搷搴旀暟鎹腑result瀛楁涓虹┖鎴栭潪鏁扮粍绫诲瀷锛屽師濮嬫暟鎹細{}", result);
+                return new ArrayList<>();
+            }
+
+            JsonArray resultArray = resultElement.getAsJsonArray();
+            Type resultType = new TypeToken<List<ServiceAppointRecord>>() {
+            }.getType();
+            return gson.fromJson(resultArray, resultType);
+        } catch (Exception e) {
+            log.error("銆恜arseResponseData2銆戣В鏋愬搷搴旀暟鎹紓甯革紝鍘熷鏁版嵁锛歿}", result, e);
             throw e;
         }
     }
@@ -284,6 +423,7 @@
         PatMedInhosp queryInhosp = new PatMedInhosp();
         queryInhosp.setPatno(patArchive.getPatientno());
         queryInhosp.setSerialnum(patMedInhosp.getSerialnum());
+        queryInhosp.setCry(Integer.valueOf(cry));
         List<PatMedInhosp> existingInhosps = patMedInhospService.selectPatMedInhospList(queryInhosp);
 
         // 淇濆瓨鎴栨洿鏂颁綇闄俊鎭�
@@ -323,6 +463,7 @@
         // 鍖婚櫌鍜屽簥浣嶄俊鎭�
         patMedInhosp.setHospitalcode(thiedInhospInfo.getAreaId());
         patMedInhosp.setBedNo(thiedInhospInfo.getAdmissBedNo());
+        patMedInhosp.setCry(Integer.valueOf(cry));
 
 
         // 鏃堕棿淇℃伅

--
Gitblit v1.9.3