From 27df1079c1d230fab29f565f5209f2a02e0def8a Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期一, 20 七月 2026 16:56:51 +0800
Subject: [PATCH] 省立同德的功能

---
 smartor/src/main/java/com/smartor/service/impl/XHGatherPatArchiveServiceImpl.java |  184 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 173 insertions(+), 11 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 b55a0a5..150769f 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,20 @@
 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.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 +28,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 +49,26 @@
 
     @Value("${hosp_info_url}")
     private String hospInfoUrl;
-
-
     @Autowired
     IPatMedInhospService patMedInhospService;
-
     @Autowired
     IPatArchiveService patArchiveService;
+    @Autowired
+    IServiceAppointRecordService iServiceAppointRecordService;
+    @Autowired
+    private SysConfigMapper sysConfigMapper;
+    @Value("${xhsmsPath}")
+    private String xhsmsPath;
+    // 甯愬彿
+    @Value("${xhsmsAccount}")
+    private String xhsmsAccount;
+    //  鎺ュ彛瀵嗙爜
+    @Value("${xhsmsPwd}")
+    private String xhsmsPwd;
+    // 铏氭嫙鎺ュ叆鐮�
+    @Value("${xhsmsjrm}")
+    private String xhsmsjrm;
+
 
     /**
      * 鑾峰彇鎮h�呭嚭鍏ラ櫌淇℃伅
@@ -94,6 +109,72 @@
         }
     }
 
+    /**
+     * 鑾峰彇棰勭害鍋滆瘖璁板綍淇℃伅
+     *
+     * @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()));
+                    Map<String, String> map2 = new HashMap<String, String>();
+                    map2.put("action", "send");
+                    map2.put("account", xhsmsAccount);
+                    map2.put("password", xhsmsPwd);
+                    map2.put("mobile", serviceAppointRecord.getPatTel());
+                    map2.put("content", replace);
+                    map2.put("extno", xhsmsjrm);
+                    map2.put("rt", "json");
+                    StringBuilder encodedParams = new StringBuilder();
+
+                    for (Map.Entry<String, String> entry : map2.entrySet()) {
+                        if (encodedParams.length() > 0) {
+                            encodedParams.append("&");
+                        }
+                        // 瀵归敭鍜屽�艰繘琛孶RL缂栫爜
+                        String encodedKey = URLEncoder.encode(entry.getKey(), "UTF-8");
+                        String encodedValue = URLEncoder.encode(entry.getValue(), "UTF-8");
+                        encodedParams.append(encodedKey).append("=").append(encodedValue);
+                    }
+                    Boolean isSuccess = HttpUtils.sendPost(xhsmsPath, encodedParams.toString());
+                    if (isSuccess) {
+                        log.info("---澶勭悊鍋滆瘖璁板綍淇℃伅鍙戦�佹垚鍔�,鍏ュ弬涓�:{}", encodedParams.toString());
+                        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 +198,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,7 +284,8 @@
     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", "IS002347");
+        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");
         header.put("x-hcsb-token", "ArGE2JnHtxG/Zx5nrnGY4eOfMUJGGJokAJHigG1BrCY=");
@@ -201,11 +306,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 +329,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.warn("銆恜arseResponseData銆戝搷搴旀暟鎹腑data瀛楁涓虹┖鎴栭潪瀵硅薄绫诲瀷锛屽師濮嬫暟鎹細{}", result);
+                return new ArrayList<>();
+            }
+
+            JsonObject dataObject = dataElement.getAsJsonObject();
+            JsonElement resultElement = dataObject.get("result");
+            if (resultElement == null || !resultElement.isJsonArray()) {
+                log.warn("銆恜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 +442,7 @@
         PatMedInhosp queryInhosp = new PatMedInhosp();
         queryInhosp.setPatno(patArchive.getPatientno());
         queryInhosp.setSerialnum(patMedInhosp.getSerialnum());
+        queryInhosp.setCry(Integer.valueOf(cry));
         List<PatMedInhosp> existingInhosps = patMedInhospService.selectPatMedInhospList(queryInhosp);
 
         // 淇濆瓨鎴栨洿鏂颁綇闄俊鎭�
@@ -316,11 +475,14 @@
         // 浣忛櫌淇℃伅
         patMedInhosp.setSerialnum(thiedInhospInfo.getInpatientId());
         patMedInhosp.setFuflag("1");
+        if (StringUtils.isNotEmpty(patArchive.getNotrequiredFlag()) && patArchive.getNotrequiredFlag().equals("1"))
+            patMedInhosp.setFuflag("0");
         patMedInhosp.setInhospstate("0".equals(cry) ? "0" : "1");
 
         // 鍖婚櫌鍜屽簥浣嶄俊鎭�
         patMedInhosp.setHospitalcode(thiedInhospInfo.getAreaId());
         patMedInhosp.setBedNo(thiedInhospInfo.getAdmissBedNo());
+        patMedInhosp.setCry(Integer.valueOf(cry));
 
 
         // 鏃堕棿淇℃伅
@@ -390,7 +552,7 @@
         patArchive.setPatientno(thiedInhospInfo.getPatiMediaNo());
         patArchive.setIdcardno(thiedInhospInfo.getPatiIdCardNo().trim());
         patArchive.setName(thiedInhospInfo.getPatiRecordName());
-        patArchive.setSourcefrom(2);
+        patArchive.setSourcefrom(2L);
         patArchive.setPattype("2");
 
         // 鎬у埆

--
Gitblit v1.9.3