From c462811cd33e81a80bc089e3677975c069d9cda5 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期六, 09 五月 2026 17:50:06 +0800
Subject: [PATCH] 代码提交

---
 smartor/src/main/java/com/smartor/domain/ServiceSubtask.java                               |    2 
 smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java |  102 ++++-
 smartor/src/main/java/com/smartor/service/impl/SvyLibTemplateServiceImpl.java              |   59 ++-
 smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java             |   80 ++--
 smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java                |   64 +++
 ruoyi-common/src/main/java/com/ruoyi/common/utils/AesUtils.java                            |   10 
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java              |   42 +
 smartor/src/main/java/com/smartor/service/impl/ServiceTaskServiceImpl.java                 |   45 +-
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceTaskController.java      |    4 
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java        |    9 
 smartor/src/main/resources/mapper/smartor/SysDeptMapper.xml                                |   30 +
 smartor/src/main/java/com/smartor/service/ISvyLibTemplateService.java                      |    6 
 smartor/src/main/java/com/smartor/mapper/SvyLibTemplateTargetoptionMapper.java             |   10 
 smartor/src/main/java/com/smartor/domain/SvyLibTemplateReq.java                            |    6 
 smartor/src/main/resources/mapper/smartor/ServiceTaskMapper.xml                            |  149 ++++----
 smartor/src/main/java/com/smartor/service/IServiceSubtaskService.java                      |    7 
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml                         |    1 
 smartor/src/main/resources/mapper/smartor/SvyLibTemplateMapper.xml                         |   68 +++
 ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java  |    2 
 smartor/src/main/java/com/smartor/mapper/SysDept2Mapper.java                               |    2 
 smartor/src/main/java/com/smartor/domain/ServiceTask.java                                  |    2 
 ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java                               |  115 +++---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceSubtaskController.java   |    8 
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/SvyLibTemplateController.java   |   19 
 smartor/src/main/java/com/smartor/domain/ServiceSubtaskTemplateVO.java                     |   42 ++
 smartor/src/main/java/com/smartor/mapper/SvyLibTemplateMapper.java                         |    4 
 smartor/src/main/resources/mapper/smartor/SvyLibTemplateTargetoptionMapper.xml             |   10 
 smartor/src/main/java/com/smartor/domain/ServiceTaskdiag.java                              |    4 
 smartor/src/main/java/com/smartor/service/IServiceTaskService.java                         |    2 
 29 files changed, 626 insertions(+), 278 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceSubtaskController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceSubtaskController.java
index f0f7e27..8660bda 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceSubtaskController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceSubtaskController.java
@@ -408,6 +408,14 @@
         return toAjax(serviceSubtaskService.updateServiceSubtask(serviceSubtask));
     }
 
+    @ApiOperation("淇敼瀛愪换鍔℃ā鏉�")
+    @AddOrgId(field = "orgid", paramIndex = 0, campusField = "campusid")
+    @PostMapping("/updateTemplate")
+    public AjaxResult updateTemplate(@RequestBody ServiceSubtaskTemplateVO serviceSubtaskTemplateVO) {
+        serviceSubtaskTemplateVO.setUpdateBy(getLoginUser().getUser().getNickName());
+        return toAjax(serviceSubtaskService.updateTemplate(serviceSubtaskTemplateVO));
+    }
+
     @ApiOperation("鏂板瀛愪换鍔�")
     @AddOrgId(field = "orgid", paramIndex = 0, campusField = "campusid")
     @PostMapping("/addSubTask")
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceTaskController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceTaskController.java
index 4bce0af..d33cc59 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceTaskController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceTaskController.java
@@ -228,7 +228,7 @@
 
         log.info("tid鍜宲id鐨勫�间负锛歿},{}", tid, pid);
         if (StringUtils.isEmpty(serviceTaskScriptQues.getPatfrom())) serviceTaskScriptQues.setPatfrom("0");
-        return success(serviceTaskService.getScriptInfoByCondition(tid, pid, true, serviceTaskScriptQues.getPatfrom()));
+        return success(serviceTaskService.getScriptInfoByCondition(tid, pid, true, serviceTaskScriptQues.getPatfrom(),null));
     }
 
 
@@ -252,7 +252,7 @@
 
         log.info("tid鍜宲id鐨勫�间负锛歿},{}", tid, pid);
         if (StringUtils.isEmpty(serviceTaskScriptQues.getPatfrom())) serviceTaskScriptQues.setPatfrom("0");
-        return success(serviceTaskService.getScriptInfoByCondition(tid, pid, true, serviceTaskScriptQues.getPatfrom()));
+        return success(serviceTaskService.getScriptInfoByCondition(tid, pid, true, serviceTaskScriptQues.getPatfrom(),null));
     }
 
 
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/SvyLibTemplateController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/SvyLibTemplateController.java
index 55b67de..45f6a4d 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/SvyLibTemplateController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/SvyLibTemplateController.java
@@ -13,10 +13,7 @@
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.PageUtils;
-import com.smartor.domain.SvyLibScriptTag;
-import com.smartor.domain.SvyLibTemplate;
-import com.smartor.domain.SvyLibTemplateReq;
-import com.smartor.domain.SvyLibTemplateVO;
+import com.smartor.domain.*;
 import com.smartor.service.ISvyLibTemplateService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -52,6 +49,20 @@
         return getDataTable(sviLibTemplate);
     }
 
+    @ApiOperation("鏌ヨ闂嵎鍒楄〃閫氳繃閮ㄩ棬鐥呭尯浠g爜")
+    @PostMapping("/getSviLibTemplateByDeptCode")
+    public Map<String, Object> getSviLibTemplateByDeptCode(@RequestBody TemplateDeptVO templateDeptVO) {
+        templateDeptVO.setPageNum(PageUtils.getOffset(templateDeptVO.getPageNum(), templateDeptVO.getPageSize()));
+        List<SvyLibTemplate> sviLibTemplate = svyLibTemplateService.getSviLibTemplateByDeptCode(templateDeptVO);
+
+        //鑾峰彇total
+        templateDeptVO.setPageNum(null);
+        templateDeptVO.setPageSize(null);
+        List<SvyLibTemplate> total = svyLibTemplateService.getSviLibTemplateByDeptCode(templateDeptVO);
+
+        return getDataTable3(CollectionUtils.isNotEmpty(total) ? total.size() : 0L, sviLibTemplate);
+    }
+
     /**
      * 鏌ヨ闂嵎鍒楄〃
      */
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/AesUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/AesUtils.java
index 902650d..43ba3a6 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/AesUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/AesUtils.java
@@ -16,7 +16,7 @@
     /** 绠楁硶/妯″紡/濉厖 */
     private static final String ALGORITHM = "AES/CBC/PKCS5Padding";
 
-    /** 榛樿 Key锛圚EX锛�32瀛楄妭鈫�256浣嶅瘑閽ワ級 */
+    /** 榛樿 Key锛圚EX锛�16瀛楄妭鈫�128浣嶅瘑閽ワ級 */
     private static final String DEFAULT_KEY = "0F471C56362408AF8DB929C38EDFD23C";
 
     /** 榛樿 IV锛圚EX锛�16瀛楄妭鈫�128浣嶅亸绉婚噺锛� */
@@ -101,7 +101,7 @@
     // -------------------------------------------------------------------------
 
     /**
-     * HEX 瀛楃涓茶浆瀛楄妭鏁扮粍锛堝ぇ灏忓啓鍧囧彲锛�
+     * HEX 瀛楃涓茶浆瀛楄妭鏁扮粍锛堝ぇ灏忓啓鍧囧彲锛夛紝涓嶈冻 16 瀛楄妭鑷姩琛� 0
      */
     private static byte[] hexToBytes(String hex) {
         if (hex == null || hex.length() % 2 != 0) {
@@ -113,6 +113,12 @@
             data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
                     + Character.digit(hex.charAt(i + 1), 16));
         }
+        // IV 涓嶈冻 16 瀛楄妭鏃惰ˉ 0锛堝吋瀹圭涓夋柟 8 瀛楄妭 IV锛�
+        if (data.length < 16) {
+            byte[] padded = new byte[16];
+            System.arraycopy(data, 0, padded, 0, data.length);
+            data = padded;
+        }
         return data;
     }
 
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java
index f95d141..b48d6ee 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java
@@ -49,8 +49,6 @@
             log.info("鐧诲綍鐢ㄦ埛锛歿} 涓嶆槸鏈尰闄㈠笎鍙凤細{}", username, split[1]);
             throw new ServiceException("瀵逛笉璧凤紝鎮ㄧ殑璐﹀彿锛�" + split[0] + " 涓嶆槸鏈尰闄㈢殑");
         }
-//-0/-85#4-                                                              
-
         passwordService.validate(user);
 
         return createLoginUser(user);
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
index 536017f..d82f317 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
@@ -230,11 +230,16 @@
     /**
      * HIS鏁版嵁閲囬泦
      * 瀹氭椂浠诲姟锛氶噰闆嗘偅鑰呬俊鎭�佸嚭闄€�侀棬璇婃暟鎹�
+     * todayZeroStr  褰撳墠鐨勬椂闂�   渚嬪锛�2026-05-06 00:00:00
      */
-    public void dealHisData() {
+    public void dealHisData(String todayZeroStr) {
         log.info("銆恉ealHisData銆戝紑濮嬫墽琛孒IS鏁版嵁閲囬泦浠诲姟");
         // 鑾峰彇鏄ㄥぉ0鐐瑰埌浠婂ぉ0鐐圭殑鏃堕棿鑼冨洿
         LocalDateTime todayZero = LocalDateTime.now().with(LocalTime.MIN);
+        if (StringUtils.isNotBlank(todayZeroStr)) {
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            todayZero = LocalDateTime.parse(todayZeroStr, formatter);
+        }
         LocalDateTime yesterdayZero = todayZero.minusDays(1);
         log.info("銆恉ealHisData銆戦噰闆嗘椂闂磋寖鍥达細{} ~ {}", yesterdayZero, todayZero);
 
@@ -253,8 +258,7 @@
             } catch (Exception e) {
                 log.error("銆恉ealHisData銆戞柊鍗庢暟鎹噰闆嗗紓甯�", e);
             }
-        }
-        else if (active.trim().equals("hn")) {
+        } else if (active.trim().equals("hn")) {
             try {
                 // 娌冲崡鏁版嵁閲囬泦
                 HnDataGatherVO hnDataGatherVO = new HnDataGatherVO();
@@ -269,8 +273,7 @@
             } catch (Exception e) {
                 log.error("銆恉ealHisData銆戞渤鍗楁暟鎹噰闆嗗紓甯�", e);
             }
-        }
-        else if (active.trim().equals("sltd") || active.trim().equals("nhfy")) {
+        } else if (active.trim().equals("sltd") || active.trim().equals("nhfy")) {
             //鐪佺珛鍚屽痉涓庡崕鍗楅檮涓�鐢ㄥ悓涓�濂楅噰闆嗘柟娉曪紙閮芥槸鏉ユ湭鏉ユ彁渚涳級
 
             try {
@@ -322,14 +325,14 @@
 
                 // 鐪佺珛鍚屽痉鏁版嵁閲囬泦
                 for (Long cid : campusidList) {
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈鍏ラ櫌鈥濆紑濮嬮噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
+                    log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈鍏ラ櫌鈥濆紑濮嬮噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
                     String nowTime = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                     ServiceSLTDInhospReqVO serviceSLTDInhospReqVO = new ServiceSLTDInhospReqVO();
                     serviceSLTDInhospReqVO.setOrgId("20001001");
                     serviceSLTDInhospReqVO.setCampusId(cid);
                     serviceSLTDInhospReqVO.setEncounterTimeStart(nowTime);
                     serviceSLTDInhospReqVO.setEncounterTimeEnd(nowTime);
-                    if(active.trim().equals("nhfy")) {
+                    if (active.trim().equals("nhfy")) {
                         serviceSLTDInhospReqVO.setEncounterTimeStart(yesterdayZero.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                         serviceSLTDInhospReqVO.setEncounterTimeEnd(todayZero.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                     }
@@ -338,73 +341,75 @@
                     list.add("FH0109.23");
                     list.add("FH0109.53");
                     serviceSLTDInhospReqVO.setStatusList(list);
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈鍏ラ櫌鈥濋噰闆嗘暟鎹叆鍙傦細{}", serviceSLTDInhospReqVO);
+                    log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈鍏ラ櫌鈥濋噰闆嗘暟鎹叆鍙傦細{}", serviceSLTDInhospReqVO);
                     serviceSLTDHealthcareRecordService.queryHealthcareRecordList(serviceSLTDInhospReqVO);
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈鍏ラ櫌鈥濈祼鏉熼噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
+                    log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈鍏ラ櫌鈥濈祼鏉熼噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
 
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滃叆闄⑩�濆紑濮嬮噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
+                    log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滃叆闄⑩�濆紑濮嬮噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
                     serviceSLTDInhospReqVO.setOrgId("20001001");
                     serviceSLTDInhospReqVO.setCampusId(cid);
                     serviceSLTDInhospReqVO.setEncounterTimeStart(null);
                     serviceSLTDInhospReqVO.setEncounterTimeEnd(null);
                     serviceSLTDInhospReqVO.setStartHeadTime(nowTime);
                     serviceSLTDInhospReqVO.setStartTailTime(nowTime);
-                    if(active.trim().equals("nhfy")) {
+                    if (active.trim().equals("nhfy")) {
                         serviceSLTDInhospReqVO.setStartHeadTime(yesterdayZero.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                         serviceSLTDInhospReqVO.setStartTailTime(todayZero.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                     }
                     List<String> listStr = new ArrayList<>();
                     listStr.add("FH0109.26");
                     serviceSLTDInhospReqVO.setStatusList(listStr);
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滃叆闄⑩�濋噰闆嗘暟鎹叆鍙傦細{}", serviceSLTDInhospReqVO);
+                    log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滃叆闄⑩�濋噰闆嗘暟鎹叆鍙傦細{}", serviceSLTDInhospReqVO);
                     serviceSLTDHealthcareRecordService.queryHealthcareRecordList(serviceSLTDInhospReqVO);
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滃叆闄⑩�濈祼鏉熼噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
+                    log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滃叆闄⑩�濈祼鏉熼噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
 
-                    // 闂ㄦ�ヨ瘖鍒嗛〉閲囬泦锛氭瘡椤�1000鏉★紝鐩村埌鏃犳暟鎹负姝�
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濆紑濮嬪垎椤甸噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
-                    serviceSLTDInhospReqVO.setStartHeadTime(null);
-                    serviceSLTDInhospReqVO.setStartTailTime(null);
-                    serviceSLTDInhospReqVO.setEncounterTimeStart(nowTime);
-                    serviceSLTDInhospReqVO.setEncounterTimeEnd(nowTime);
-                    if(active.trim().equals("nhfy")) {
-                        serviceSLTDInhospReqVO.setEncounterTimeStart(yesterdayZero.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
-                        serviceSLTDInhospReqVO.setEncounterTimeEnd(todayZero.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
-                    }
-                    serviceSLTDInhospReqVO.setStatusList(null);
-                    List<String> list1 = new ArrayList<>();
-                    list1.add("FH0108.01");
-                    list1.add("FH0108.03");
-                    serviceSLTDInhospReqVO.setHealthcareRecordTypeList(list1);
-                    long outpPage = 1L;
-                    final long OUTP_PAGE_SIZE = 1000L;
-                    while (true) {
-                        serviceSLTDInhospReqVO.setCurrent(outpPage);
-                        serviceSLTDInhospReqVO.setSize(OUTP_PAGE_SIZE);
-                        log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濋噰闆嗙{}椤垫暟鎹紝闄㈠尯锛歿}", outpPage, cid);
-                        List<ServiceSLTDInhospResDTO> outpResult = serviceSLTDHealthcareRecordService.queryHealthcareRecordList(serviceSLTDInhospReqVO);
-                        if (CollectionUtils.isEmpty(outpResult)) {
-                            log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濈{}椤垫棤鏁版嵁锛岄噰闆嗙粨鏉燂紝闄㈠尯锛歿}", outpPage, cid);
-                            break;
+                    // 闂ㄦ�ヨ瘖鍒嗛〉閲囬泦锛氭瘡椤�1000鏉★紝鐩村埌鏃犳暟鎹负姝�(鍗楀崕闄勪竴鐨勫厛涓嶉噰闂ㄦ�ヨ瘖鏁版嵁)
+                    if (active.trim().equals("sltd")) {
+                        log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濆紑濮嬪垎椤甸噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
+                        serviceSLTDInhospReqVO.setStartHeadTime(null);
+                        serviceSLTDInhospReqVO.setStartTailTime(null);
+                        serviceSLTDInhospReqVO.setEncounterTimeStart(nowTime);
+                        serviceSLTDInhospReqVO.setEncounterTimeEnd(nowTime);
+                        if (active.trim().equals("nhfy")) {
+                            serviceSLTDInhospReqVO.setEncounterTimeStart(yesterdayZero.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+                            serviceSLTDInhospReqVO.setEncounterTimeEnd(todayZero.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                         }
-                        log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濈{}椤甸噰闆唟}鏉★紝闄㈠尯锛歿}", outpPage, outpResult.size(), cid);
-                        if (outpResult.size() < OUTP_PAGE_SIZE) {
-                            break;
+                        serviceSLTDInhospReqVO.setStatusList(null);
+                        List<String> list1 = new ArrayList<>();
+                        list1.add("FH0108.01");
+                        list1.add("FH0108.03");
+                        serviceSLTDInhospReqVO.setHealthcareRecordTypeList(list1);
+                        long outpPage = 1L;
+                        final long OUTP_PAGE_SIZE = 1000L;
+                        while (true) {
+                            serviceSLTDInhospReqVO.setCurrent(outpPage);
+                            serviceSLTDInhospReqVO.setSize(OUTP_PAGE_SIZE);
+                            log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濋噰闆嗙{}椤垫暟鎹紝闄㈠尯锛歿}", outpPage, cid);
+                            List<ServiceSLTDInhospResDTO> outpResult = serviceSLTDHealthcareRecordService.queryHealthcareRecordList(serviceSLTDInhospReqVO);
+                            if (CollectionUtils.isEmpty(outpResult)) {
+                                log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濈{}椤垫棤鏁版嵁锛岄噰闆嗙粨鏉燂紝闄㈠尯锛歿}", outpPage, cid);
+                                break;
+                            }
+                            log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濈{}椤甸噰闆唟}鏉★紝闄㈠尯锛歿}", outpPage, outpResult.size(), cid);
+                            if (outpResult.size() < OUTP_PAGE_SIZE) {
+                                break;
+                            }
+                            outpPage++;
                         }
-                        outpPage++;
+                        // 娓呴櫎鍒嗛〉鍙傛暟锛岄伩鍏嶅奖鍝嶅悗缁嚭鍏ラ櫌鏌ヨ
+                        serviceSLTDInhospReqVO.setCurrent(null);
+                        serviceSLTDInhospReqVO.setSize(null);
+                        log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濆垎椤甸噰闆嗗畬鎴愶紝闄㈠尯锛歿}", cid);
                     }
-                    // 娓呴櫎鍒嗛〉鍙傛暟锛岄伩鍏嶅奖鍝嶅悗缁嚭鍏ラ櫌鏌ヨ
-                    serviceSLTDInhospReqVO.setCurrent(null);
-                    serviceSLTDInhospReqVO.setSize(null);
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濆垎椤甸噰闆嗗畬鎴愶紝闄㈠尯锛歿}", cid);
 
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滃嚭闄⑩�濆紑濮嬮噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
+                    log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滃嚭闄⑩�濆紑濮嬮噰闆嗘暟鎹紝闄㈠尯锛歿}", cid);
                     serviceSLTDInhospReqVO.setStartHeadTime(null);
                     serviceSLTDInhospReqVO.setStartTailTime(null);
                     serviceSLTDInhospReqVO.setEncounterTimeStart(null);
                     serviceSLTDInhospReqVO.setEncounterTimeEnd(null);
                     serviceSLTDInhospReqVO.setPreOutHospitalHeadDate(nowTime);
                     serviceSLTDInhospReqVO.setPreOutHospitalTailDate(nowTime);
-                    if(active.trim().equals("nhfy")) {
+                    if (active.trim().equals("nhfy")) {
                         serviceSLTDInhospReqVO.setPreOutHospitalHeadDate(yesterdayZero.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                         serviceSLTDInhospReqVO.setPreOutHospitalTailDate(todayZero.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                     }
@@ -413,9 +418,9 @@
 //                    list2.add("FH0108.02");
                     list2.add("FH0109.27");
                     serviceSLTDInhospReqVO.setStatusList(list2);
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滃嚭闄⑩�濋噰闆嗘暟鎹叆鍙傦細{}", serviceSLTDInhospReqVO);
+                    log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滃嚭闄⑩�濋噰闆嗘暟鎹叆鍙傦細{}", serviceSLTDInhospReqVO);
                     serviceSLTDHealthcareRecordService.queryHealthcareRecordList(serviceSLTDInhospReqVO);
-                    log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滃嚭闄⑩�濇潫閲囬泦鏁版嵁锛岄櫌鍖猴細{}", cid);
+                    log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滃嚭闄⑩�濇潫閲囬泦鏁版嵁锛岄櫌鍖猴細{}", cid);
                 }
 
             } catch (Exception e) {
@@ -438,7 +443,7 @@
                 ServiceSLTDInhospReqVO serviceSLTDInhospReqVO = new ServiceSLTDInhospReqVO();
                 serviceSLTDInhospReqVO.setOrgId("20001001");
                 serviceSLTDInhospReqVO.setCampusId(30001002L);
-                log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濆紑濮嬮噰闆嗘暟鎹紝闄㈠尯锛歿}", "30001002");
+                log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濆紑濮嬮噰闆嗘暟鎹紝闄㈠尯锛歿}", "30001002");
                 serviceSLTDInhospReqVO.setStartHeadTime(null);
                 serviceSLTDInhospReqVO.setStartTailTime(null);
                 serviceSLTDInhospReqVO.setEncounterTimeStart(nowTime);
@@ -448,15 +453,17 @@
                 list1.add("FH0108.01");
                 list1.add("FH0108.03");
                 serviceSLTDInhospReqVO.setHealthcareRecordTypeList(list1);
-                log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濋噰闆嗘暟鎹叆鍙傦細{}", serviceSLTDInhospReqVO);
+                log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濋噰闆嗘暟鎹叆鍙傦細{}", serviceSLTDInhospReqVO);
                 serviceSLTDHealthcareRecordService.queryHealthcareRecordList(serviceSLTDInhospReqVO);
-                log.debug("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濇潫閲囬泦鏁版嵁锛岄櫌鍖猴細{}", "30001002");
+                log.info("銆恉ealHisData銆戠渷绔嬪悓寰封�滈棬鎬ヨ瘖鈥濇潫閲囬泦鏁版嵁锛岄櫌鍖猴細{}", "30001002");
             }
         } catch (Exception e) {
             log.error("銆恉ealHisData銆戠渷绔嬪悓寰锋暟鎹噰闆嗗紓甯�", e);
         }
 
-    }    /**
+    }
+
+    /**
      * 杩欎釜鍙槸鏂板崕涓存椂浣跨敤锛屽钩鏃剁敤涓嶅埌
      */
     public void dealHisData2() {
diff --git a/smartor/src/main/java/com/smartor/domain/ServiceSubtask.java b/smartor/src/main/java/com/smartor/domain/ServiceSubtask.java
index 03c9436..a32a571 100644
--- a/smartor/src/main/java/com/smartor/domain/ServiceSubtask.java
+++ b/smartor/src/main/java/com/smartor/domain/ServiceSubtask.java
@@ -176,7 +176,7 @@
      * 妯℃澘鍚�
      */
     @Excel(name = " 妯℃澘鍚� ")
-    @ApiModelProperty(value = "鎷夊彇鏃堕棿")
+    @ApiModelProperty(value = "妯℃澘鍚�")
     private String templatename;
 
     /**
diff --git a/smartor/src/main/java/com/smartor/domain/ServiceSubtaskTemplateVO.java b/smartor/src/main/java/com/smartor/domain/ServiceSubtaskTemplateVO.java
new file mode 100644
index 0000000..16270c1
--- /dev/null
+++ b/smartor/src/main/java/com/smartor/domain/ServiceSubtaskTemplateVO.java
@@ -0,0 +1,42 @@
+package com.smartor.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.common.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 瀛愪换鍔¢棶鍗锋ā鏉�
+ *
+ * @author ruoyi
+ * @date 2024-02-02
+ */
+@ApiModel(value = "ServiceSubtaskTemplateVO", description = "瀛愪换鍔¢棶鍗锋ā鏉�")
+@Data
+public class ServiceSubtaskTemplateVO {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 涓婚敭
+     */
+    @ApiModelProperty(value = "涓婚敭")
+    private Long subId;
+
+    /**
+     * 淇敼浜�
+     */
+    @ApiModelProperty(value = "淇敼浜�")
+    private String updateBy;
+
+
+    @ApiModelProperty(value = "闂嵎妯℃澘")
+    private SvyTaskTemplateVO svyTaskTemplateVO;
+
+}
+
+
diff --git a/smartor/src/main/java/com/smartor/domain/ServiceTask.java b/smartor/src/main/java/com/smartor/domain/ServiceTask.java
index f1435c8..da0606e 100644
--- a/smartor/src/main/java/com/smartor/domain/ServiceTask.java
+++ b/smartor/src/main/java/com/smartor/domain/ServiceTask.java
@@ -377,7 +377,7 @@
     private List<String> leavehospitaldistrictcodes;
 
     /**
-     * 鍑洪櫌鐥呭尯缂栧彿
+     * 鍑洪櫌绉戝缂栧彿
      */
     @ApiModelProperty(value = "鍑洪櫌閮ㄩ棬缂栧彿闆嗗悎")
     private List<String> leaveldeptcodes;
diff --git a/smartor/src/main/java/com/smartor/domain/ServiceTaskdiag.java b/smartor/src/main/java/com/smartor/domain/ServiceTaskdiag.java
index d5f572c..1ba466a 100644
--- a/smartor/src/main/java/com/smartor/domain/ServiceTaskdiag.java
+++ b/smartor/src/main/java/com/smartor/domain/ServiceTaskdiag.java
@@ -69,8 +69,8 @@
     /**
      * 閮ㄩ棬鍚嶇О
      */
-    @ApiModelProperty("閮ㄩ棬鍚嶇О")
-    @Excel(name = "閮ㄩ棬鍚嶇О")
+    @ApiModelProperty("鐤剧梾鍚嶇О")
+    @Excel(name = "鐤剧梾鍚嶇О")
     private String icd10name;
 
     /**
diff --git a/smartor/src/main/java/com/smartor/domain/SvyLibTemplateReq.java b/smartor/src/main/java/com/smartor/domain/SvyLibTemplateReq.java
index cae3177..c41a2ec 100644
--- a/smartor/src/main/java/com/smartor/domain/SvyLibTemplateReq.java
+++ b/smartor/src/main/java/com/smartor/domain/SvyLibTemplateReq.java
@@ -45,6 +45,12 @@
     private String svyname;
 
     /**
+     * 绉戝鍚嶇О闆嗗悎锛堜互鈥�,鈥濆垎鍓诧級
+     */
+    @ApiModelProperty(value = "绉戝鍚嶇О闆嗗悎锛堜互鈥�,鈥濆垎鍓诧級")
+    private String deptNames;
+
+    /**
      * 閫傜敤鐤剧梾
      */
     @ApiModelProperty(value = "閫傜敤鐤剧梾")
diff --git a/smartor/src/main/java/com/smartor/mapper/SvyLibTemplateMapper.java b/smartor/src/main/java/com/smartor/mapper/SvyLibTemplateMapper.java
index c8ba70f..5cfbff6 100644
--- a/smartor/src/main/java/com/smartor/mapper/SvyLibTemplateMapper.java
+++ b/smartor/src/main/java/com/smartor/mapper/SvyLibTemplateMapper.java
@@ -4,6 +4,8 @@
 
 import com.smartor.domain.SvyLibTemplate;
 import com.smartor.domain.SvyLibTemplateReq;
+import com.smartor.domain.TemplateDept;
+import com.smartor.domain.TemplateDeptVO;
 import org.apache.ibatis.annotations.Mapper;
 
 /**
@@ -30,6 +32,8 @@
      */
     public List<SvyLibTemplate> selectSvyLibTemplateList(SvyLibTemplateReq svyLibTemplateReq);
 
+    public List<SvyLibTemplate> selectSvyLibTemplateListByDeptCode(TemplateDeptVO templateDeptVO);
+
     /**
      * 鏂板闂嵎
      *
diff --git a/smartor/src/main/java/com/smartor/mapper/SvyLibTemplateTargetoptionMapper.java b/smartor/src/main/java/com/smartor/mapper/SvyLibTemplateTargetoptionMapper.java
index 375870f..1f14200 100644
--- a/smartor/src/main/java/com/smartor/mapper/SvyLibTemplateTargetoptionMapper.java
+++ b/smartor/src/main/java/com/smartor/mapper/SvyLibTemplateTargetoptionMapper.java
@@ -2,6 +2,7 @@
 
 import com.smartor.domain.SvyLibTemplateTargetoption;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -60,4 +61,13 @@
      * @return 缁撴灉
      */
     public int deleteSvyLibTemplateTargetoptionByIds(Long[] ids);
+
+    /**
+     * 鏍规嵁璇濇湳ID鍒楄〃鍜屾満鏋処D鎵归噺鏌ヨ閫夐」
+     *
+     * @param scriptIds 璇濇湳ID鍒楄〃
+     * @param orgid     鏈烘瀯ID
+     * @return 閫夐」闆嗗悎
+     */
+    public List<SvyLibTemplateTargetoption> selectByScriptIds(@Param("scriptIds") List<Long> scriptIds, @Param("orgid") String orgid);
 }
diff --git a/smartor/src/main/java/com/smartor/mapper/SysDept2Mapper.java b/smartor/src/main/java/com/smartor/mapper/SysDept2Mapper.java
index 5a4b6a7..ae80c8e 100644
--- a/smartor/src/main/java/com/smartor/mapper/SysDept2Mapper.java
+++ b/smartor/src/main/java/com/smartor/mapper/SysDept2Mapper.java
@@ -40,6 +40,8 @@
 
     public SysDept selectDeptByCode(@Param("deptCode")String deptCode,@Param("orgid")String orgid);
 
+    public SysDept selectDeptByCodeAndCampus(@Param("deptCode")String deptCode,@Param("orgid")String orgid,@Param("campusid")String campusid);
+
     /**
      * 鏍规嵁ID鏌ヨ鎵�鏈夊瓙閮ㄩ棬
      *
diff --git a/smartor/src/main/java/com/smartor/service/IServiceSubtaskService.java b/smartor/src/main/java/com/smartor/service/IServiceSubtaskService.java
index fafffb0..e2a02ff 100644
--- a/smartor/src/main/java/com/smartor/service/IServiceSubtaskService.java
+++ b/smartor/src/main/java/com/smartor/service/IServiceSubtaskService.java
@@ -80,6 +80,13 @@
     public Boolean updateServiceSubtask(ServiceSubtask ServiceSubtask);
 
     /**
+     * 瀛愪换鍔℃ā鏉夸慨鏀�
+     * @param serviceSubtaskTemplateVO
+     * @return
+     */
+    public Boolean updateTemplate(ServiceSubtaskTemplateVO serviceSubtaskTemplateVO);
+
+    /**
      * 鎵归噺鍒犻櫎鍗曚竴浠诲姟锛堥殢璁匡級
      *
      * @param ids 闇�瑕佸垹闄ょ殑鍗曚竴浠诲姟锛堥殢璁匡級涓婚敭闆嗗悎
diff --git a/smartor/src/main/java/com/smartor/service/IServiceTaskService.java b/smartor/src/main/java/com/smartor/service/IServiceTaskService.java
index dcc24fe..3565ef4 100644
--- a/smartor/src/main/java/com/smartor/service/IServiceTaskService.java
+++ b/smartor/src/main/java/com/smartor/service/IServiceTaskService.java
@@ -75,7 +75,7 @@
      * @param patid
      * @return
      */
-    public Map<String, Object> getScriptInfoByCondition(Long taskid, Long patid, Boolean isFinish, String patfrom);
+    public Map<String, Object> getScriptInfoByCondition(Long taskid, Long patid, Boolean isFinish, String patfrom,Long subId);
 
     public Map<String, Object> getScriptByCondition(Long taskid, String zyserialnum, String mzserialnum, String tsserialnum);
 
diff --git a/smartor/src/main/java/com/smartor/service/ISvyLibTemplateService.java b/smartor/src/main/java/com/smartor/service/ISvyLibTemplateService.java
index a9924be..e1015ec 100644
--- a/smartor/src/main/java/com/smartor/service/ISvyLibTemplateService.java
+++ b/smartor/src/main/java/com/smartor/service/ISvyLibTemplateService.java
@@ -3,9 +3,7 @@
 import java.util.List;
 
 import com.ruoyi.common.core.domain.AjaxResult;
-import com.smartor.domain.SvyLibTemplate;
-import com.smartor.domain.SvyLibTemplateReq;
-import com.smartor.domain.SvyLibTemplateVO;
+import com.smartor.domain.*;
 import org.springframework.web.bind.annotation.RequestBody;
 
 /**
@@ -25,6 +23,8 @@
 
     public List<SvyLibTemplate> getSviLibTemplate(SvyLibTemplate svyLibTemplate);
 
+    public List<SvyLibTemplate> getSviLibTemplateByDeptCode(TemplateDeptVO templateDeptVO);
+
     /**
      * 鏌ヨ闂嵎鍒楄〃
      *
diff --git a/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
index 5db97f8..93186db 100644
--- a/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
@@ -479,7 +479,7 @@
                         pmiJB.setLongTaskReason(StringUtils.isNotEmpty(patMedInhosp.getLongTaskReason()) ? patMedInhosp.getLongTaskReason() + errorIcd : errorIcd);
                         patMedInhospMapper.updatePatMedInhosp(pmiJB);
                     } else if (CollectionUtils.isEmpty(serviceTaskdiags)) {
-                        errorIcd = "璇ユ偅鑰呮墍鍦ㄧ梾鍖烘湭閰嶇疆闀挎湡浠诲姟;";
+                        errorIcd = "璇ユ偅鑰呮墍鎮g柧鐥呮湭閰嶇疆闀挎湡浠诲姟;";
                         PatMedInhosp patMedInhosp = patMedInhospMapper.selectPatMedInhospByInhospid(pmiJB.getInhospid());
                         pmiJB.setDiagcheckFlag("2");
                         pmiJB.setLongTaskReason(StringUtils.isNotEmpty(patMedInhosp.getLongTaskReason()) ? patMedInhosp.getLongTaskReason() + errorIcd : errorIcd);
@@ -856,7 +856,7 @@
      * @param check         鏄惁闇�瑕佹牎楠�
      * @param patMedInhosp1 鐥呬汉鍑哄叆闄俊鎭�
      * @param patArchive    鐥呬汉淇℃伅
-     * @param type          闅忚绫诲瀷(1-绉戝锛�2-鐥呭尯锛�3-鐤剧梾锛�
+     * @param type          闅忚绫诲瀷(1-绉戝锛�2-鐥呭尯锛�3-鐤剧梾 4-鍏ラ櫌绉戝 5-鍏ラ櫌鐥呭尯)
      * @param config        閰嶇疆淇℃伅 visit.early.day
      */
     //灏嗘偅鑰呮斁鍒皊ubtask涓�
@@ -886,22 +886,41 @@
                 patMedInhosp1.setLongTaskReason(longTaskReason + " & 璇ユ偅鑰呯柧鐥呴暱鏈熶换鍔′笉瀛樺湪,浠诲姟ID涓�:" + taskid);
                 patMedInhospMapper.updatePatMedInhosp(patMedInhosp1);
                 return;
+            } else if (type == 4) {
+                patMedInhosp1.setInDeptcheckFlag("2");
+                patMedInhosp1.setLongTaskReason(longTaskReason + " & 璇ユ偅鑰呭叆闄㈢瀹ら暱鏈熶换鍔′笉瀛樺湪,浠诲姟ID涓�:" + taskid);
+                patMedInhospMapper.updatePatMedInhosp(patMedInhosp1);
+                return;
+            } else if (type == 5) {
+                patMedInhosp1.setInWardcheckFlag("2");
+                patMedInhosp1.setLongTaskReason(longTaskReason + " & 璇ユ偅鑰呭叆闄㈢梾鍖洪暱鏈熶换鍔′笉瀛樺湪,浠诲姟ID涓�:" + taskid);
+                patMedInhospMapper.updatePatMedInhosp(patMedInhosp1);
+                return;
             }
         } else {
             serviceTask = serviceTasks.get(0);
         }
-        if (Objects.isNull(patMedInhosp1.getEndtime())) {
+        if (patMedInhosp1.getInhospstate().equals("1") && Objects.isNull(patMedInhosp1.getEndtime())) {
             return;
         }
         //灏佽serviceSubtask
-        ServiceSubtask serviceSubtask = boxedServiceSubtask(serviceTask, patMedInhosp1, patArchive, config);
+        ServiceSubtask serviceSubtask = boxedServiceSubtask(serviceTask, patMedInhosp1, patArchive, config, type);
         if (ObjectUtils.isEmpty(serviceSubtask)) {
             return;
         }
         if (type != 2) {
             //绉戝鍜岀柧鐥� 閮界敤 绉戝濉厖
-            serviceSubtask.setVisitDeptCode(patMedInhosp1.getLeaveldeptcode());
-            serviceSubtask.setVisitDeptName(patMedInhosp1.getLeaveldeptname());
+            if (patMedInhosp1.getInhospstate().equals("1")) {
+                serviceSubtask.setVisitDeptCode(patMedInhosp1.getLeaveldeptcode());
+                serviceSubtask.setVisitDeptName(patMedInhosp1.getLeaveldeptname());
+            } else if (patMedInhosp1.getInhospstate().equals("0")) {
+                serviceSubtask.setVisitDeptCode(patMedInhosp1.getDeptcode());
+                serviceSubtask.setVisitDeptName(patMedInhosp1.getDeptname());
+                if(type==5){
+                    serviceSubtask.setVisitDeptCode(patMedInhosp1.getHospitaldistrictcode());
+                    serviceSubtask.setVisitDeptName(patMedInhosp1.getHospitaldistrictname());
+                }
+            }
         } else if (type == 2) {
             serviceSubtask.setVisitDeptCode(patMedInhosp1.getLeavehospitaldistrictcode());
             serviceSubtask.setVisitDeptName(patMedInhosp1.getLeavehospitaldistrictname());
@@ -1035,6 +1054,8 @@
                 if (type == 1) patMedInhosp2.setDeptcheckFlag("1");
                 if (type == 2) patMedInhosp2.setWardcheckFlag("1");
                 if (type == 3) patMedInhosp2.setDiagcheckFlag("1");
+                if (type == 4) patMedInhosp2.setInDeptcheckFlag("1");
+                if (type == 5) patMedInhosp2.setInWardcheckFlag("1");
                 patMedInhospMapper.updatePatMedInhosp(patMedInhosp2);
             } else {
                 //鐢熸垚瀛愪换鍔″け璐ワ紝
@@ -1044,6 +1065,8 @@
                 if (type == 1) patMedInhosp2.setDeptcheckFlag("2");
                 if (type == 2) patMedInhosp2.setWardcheckFlag("2");
                 if (type == 3) patMedInhosp2.setDiagcheckFlag("2");
+                if (type == 4) patMedInhosp2.setInDeptcheckFlag("2");
+                if (type == 5) patMedInhosp2.setInWardcheckFlag("2");
                 patMedInhosp2.setRemark("鐢熸垚瀛愪换鍔″け璐� " + type);
                 patMedInhospMapper.updatePatMedInhosp(patMedInhosp2);
             }
@@ -1235,7 +1258,7 @@
 
 
     //灏佽serviceSubtask
-    private ServiceSubtask boxedServiceSubtask(ServiceTask serviceTask, PatMedInhosp patMedInhosp1, PatArchive patArchive, String config) {
+    private ServiceSubtask boxedServiceSubtask(ServiceTask serviceTask, PatMedInhosp patMedInhosp1, PatArchive patArchive, String config, Integer type) {
         //澧炲姞serviceTask鍒ょ┖
 //        if(Objects.isNull(serviceTask)){
 //            return null;
@@ -1251,6 +1274,15 @@
         serviceSubtask.setDrname(patMedInhosp1.getDrname());
         serviceSubtask.setDeptcode(patMedInhosp1.getLeaveldeptcode());
         serviceSubtask.setDeptname(patMedInhosp1.getLeaveldeptname());
+        serviceSubtask.setLeavehospitaldistrictcode(patMedInhosp1.getLeavehospitaldistrictcode());
+        serviceSubtask.setLeavehospitaldistrictname(patMedInhosp1.getLeavehospitaldistrictname());
+        if (type == 4 || type == 5) {
+            //璁剧疆鍏ラ櫌鐨�
+            serviceSubtask.setDeptcode(patMedInhosp1.getDeptcode());
+            serviceSubtask.setDeptname(patMedInhosp1.getDeptname());
+            serviceSubtask.setLeavehospitaldistrictcode(patMedInhosp1.getHospitaldistrictcode());
+            serviceSubtask.setLeavehospitaldistrictname(patMedInhosp1.getHospitaldistrictname());
+        }
         serviceSubtask.setLeaveicd10code(patMedInhosp1.getLeaveicd10code());
         serviceSubtask.setLeavediagname(patMedInhosp1.getDiagname());
         serviceSubtask.setTemplateid(serviceTask.getTemplateid());
@@ -1270,6 +1302,7 @@
         serviceSubtask.setServiceType(serviceTask.getServiceType());
         serviceSubtask.setPreachform(serviceTask.getPreachform());
         serviceSubtask.setHospType("2");
+        if (type == 4 || type == 5) serviceSubtask.setHospType("6");
         serviceSubtask.setCreateTime(new Date());
         serviceSubtask.setUpdateTime(new Date());
         serviceSubtask.setCreateBy(patMedInhosp1.getNurseName());
@@ -1277,17 +1310,24 @@
         serviceSubtask.setLeavehospitaldistrictname(patMedInhosp1.getLeavehospitaldistrictname());
         serviceSubtask.setUpdateBy(serviceTask.getUpdateBy());
         serviceSubtask.setUpdateTime(new Date());
+        //濡傛灉鏄鏁欏氨璁剧疆涓�7
+        if (serviceTask.getServiceType().equals("17")) serviceSubtask.setTaskSituation(7);
         //璁剧疆鍙戦�佹椂闂�
         if (serviceTask.getSendDay() == null) serviceTask.setSendDay(1L);
         Date newDate = null;
         if (!Objects.isNull(patMedInhosp1.getEndtime())) {
             newDate = addDays(patMedInhosp1.getEndtime(), serviceTask.getSendDay().intValue());
         } else {
-            patMedInhosp1.setDeptcheckFlag("2");
-            patMedInhosp1.setRemark(patMedInhosp1.getRemark() + "& 璇ユ偅鑰呯柧鐥呭嚭闄㈡椂闂翠负绌�,鍑洪櫌璁板綍ID涓�:" + patMedInhosp1.getInhospid());
-            patMedInhospMapper.updatePatMedInhosp(patMedInhosp1);
-            //濡傛灉鍑洪櫌鏃堕棿涓虹┖锛屽垯杩斿洖涓�涓柊瀵硅薄
-            return new ServiceSubtask();
+            //濡傛灉绛変簬4,璇存槑鏄叆闄㈠鏁欙紝鍏ラ櫌涓嶅彲鑳芥湁endTime
+            if (type != 4 && type != 5) {
+                patMedInhosp1.setDeptcheckFlag("2");
+                patMedInhosp1.setRemark(patMedInhosp1.getRemark() + "& 璇ユ偅鑰呯柧鐥呭嚭闄㈡椂闂翠负绌�,鍑洪櫌璁板綍ID涓�:" + patMedInhosp1.getInhospid());
+                patMedInhospMapper.updatePatMedInhosp(patMedInhosp1);
+                //濡傛灉鍑洪櫌鏃堕棿涓虹┖锛屽垯杩斿洖涓�涓柊瀵硅薄
+                return new ServiceSubtask();
+            }
+            //鍏ラ櫌瀹f暀锛屽熀鏈綋澶╂垨闅斿ぉ灏辫鍙戝嚭
+            newDate = addDays(new Date(), serviceTask.getSendDay().intValue());
         }
         serviceSubtask.setLongSendTime(newDate);
         serviceSubtask.setVisitTime(newDate);
diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java
index f58bb00..09add5e 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java
@@ -1,7 +1,10 @@
 package com.smartor.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.json.JSON;
+import cn.hutool.json.JSONUtil;
 import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.domain.entity.SysUserDept;
@@ -11,12 +14,14 @@
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.DtoConversionUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.http.HttpUtils;
 import com.smartor.domain.*;
 import com.smartor.domain.entity.ServiceSubtaskEntity;
 import com.smartor.mapper.*;
 import com.smartor.service.IPatMedOuthospService;
 import com.smartor.service.IServiceExternalService;
 import lombok.extern.slf4j.Slf4j;
+import netscape.javascript.JSObject;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -1860,40 +1865,18 @@
 
     @Override
     public Map<String, Object> query360PatInfolwl(Long patid, SysUser sysUser) {
-        Map<String, Object> result = new HashMap<>();
-        PatArchive pa = patArchiveMapper.selectPatArchiveByPatid(patid);
-        if (pa.getPatientno() == null) {
-            result.put("url", null);
-            result.put("error", "鎮h�呯紪鍙蜂负绌�");
-            return result;
+        PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patid);
+        Map<String, String> headers = buildRequestHeaders();
+        Map<String, Object> requestParams = buildRequestParams(sysUser,patArchive);
+        String result = HttpUtils.sendPostByHeader("http://cfdata.nhyfy.cn/kapi/hbos-h360/open/getNoLoginUrl", new Gson().toJson(requestParams), headers);
+        log.info("============result鐨勫�间负锛歿}",result);
+        Gson gson = new Gson();
+        Map<String, Object> map = null;
+        if (result != null) {
+            map = gson.fromJson(result, new TypeToken<Map<String, Object>>() {
+            }.getType());
         }
-
-        StringBuffer sbf = new StringBuffer("http://cfdata.nhyfy.cn/cfdata/h360/patient-summary?");
-        sbf.append("referer=thirdparty");
-        sbf.append("&encode=1");
-        sbf.append("&patientMainIndexNum=" + AesUtils.encrypt(pa.getPatientno()));
-        sbf.append("&workId=" + AesUtils.encrypt(sysUser.getUserName()));
-        sbf.append("&workName=" + AesUtils.encrypt(sysUser.getNickName()));
-        sbf.append("&hisOrgCode=" + AesUtils.encrypt("20001001"));
-        sbf.append("&hisOrgName=" + AesUtils.encrypt("鍗楀崕澶у闄勫睘绗竴鍖婚櫌"));
-        sbf.append("&hisHosCode=" + AesUtils.encrypt("30001002"));
-        sbf.append("&hisHosName=" + AesUtils.encrypt("鍗楀崕澶у闄勫睘绗竴鍖婚櫌"));
-        String url360 = null;
-        try {
-            url360 = URLEncoder.encode(sbf.toString(), "UTF-8");
-        } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException(e);
-        }
-
-        StringBuffer stringBuffer = new StringBuffer("http://cfdata.nhyfy.cn/cfdata/login/nologin?");
-        //accountNo瀵规帴浜轰笉缁欙紝鍏堢┖鐫�---------------------------------------------------------------
-        stringBuffer.append("accountNo=");
-        stringBuffer.append("&source=third");
-        stringBuffer.append("&redirectUrl=" + url360);
-
-        result.put("url", stringBuffer.toString());
-        result.put("error", null);
-        return result;
+        return map;
     }
 
     private Boolean getType(String type, Map dataMap) {
@@ -2072,4 +2055,35 @@
         return ageMap;
     }
 
+
+    private Map<String, String> buildRequestHeaders() {
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("app-key", "ak-0p5Qi0J1I4AL67ztEYQL1j9v");
+        return headers;
+    }
+
+    private Map<String, Object> buildRequestParams(SysUser sysUser,PatArchive patArchive) {
+        Map<String, Object> requestParams = new HashMap<>();
+        requestParams.put("key",  sysUser.getUserName());
+        requestParams.put("windowOpen", false);
+        requestParams.put("isShowHeader", false);
+        requestParams.put("encode", 1);
+
+        Map<String, Object> params = new HashMap<>();
+        //鐥呭巻鍙�
+        params.put("patientMainIndexNum", patArchive.getPatientno());
+        params.put("sourceSystem", "pacs");
+        params.put("workId", sysUser.getUserName());
+        params.put("workName", sysUser.getNickName());
+        params.put("hisDepName", sysUser.getDeptName());
+        params.put("hisDepCode", sysUser.getDeptCode());
+        params.put("hisOrgName", "鍗楀崕澶у闄勫睘绗竴鍖婚櫌");
+        params.put("hisOrgCode", "20001001");
+        params.put("hisHosName", "鍗楀崕澶у闄勫睘绗竴鍖婚櫌");
+        params.put("hisHosCode", "30001002");
+        requestParams.put("params", params);
+        return requestParams;
+    }
+
 }
diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
index 9644504..fe2ceb1 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
@@ -167,10 +167,15 @@
                 sysDept.setUpdateTime(new Date());
                 sysDept.setUpdateBy(null);
 
-                SysDept sysDept1 = sysDeptMapper.selectDeptByCode(sysDept.getDeptCode(), sysDept.getOrgid());
+                // 鎸� deptCode + orgid + campusid 鏌ラ噸锛岄伩鍏嶈法闄㈠尯绉戝閲嶅
+                SysDept sysDept1 = sysDeptMapper.selectDeptByCodeAndCampus(sysDept.getDeptCode(), sysDept.getOrgid(), sysDept.getCampusid());
                 if (Objects.isNull(sysDept1)) {
-                    int i = sysDeptMapper.insertDept(sysDept);
-                    log.info("ServiceExternalServiceImpl---addDeptInfo鏄惁鏂板鎴愬姛锛歿}", i);
+                    try {
+                        int i = sysDeptMapper.insertDept(sysDept);
+                        log.info("ServiceExternalServiceImpl---addDeptInfo鏄惁鏂板鎴愬姛锛歿}", i);
+                    } catch (org.springframework.dao.DuplicateKeyException e) {
+                        log.warn("銆恞ueryDeptWardAreaInfoList銆戠瀹ゅ凡瀛樺湪(骞跺彂鎻掑叆)锛岃烦杩囷細deptCode={}, orgid={}, campusid={}", sysDept.getDeptCode(), sysDept.getOrgid(), sysDept.getCampusid());
+                    }
                 } else {
                     sysDept.setDeptId(sysDept1.getDeptId());
                     int i = sysDeptMapper.updateDept(sysDept);
@@ -248,19 +253,29 @@
             sysUser.setUpdateTime(new Date());
             sysUser.setUpdateBy("admin");
             sysUser.setCreateBy("admin");
-            sysUser.setCreateBy("admin");
             sysUser.setOrgid("" + getLongValue(dataItem, "orgId"));
             BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
             sysUser.setPassword(passwordEncoder.encode(userPwd));
             SysUser sysUser1 = sysUser2Mapper.selectUserByUserName(sysUser.getUserName());
             if (ObjectUtils.isNotEmpty(sysUser1)) {
-                //鐢变汉宸ョ淮鎶ょ殑瀛楁鏄笉闇�瑕佹洿鏂扮殑
+                //宸插瓨鍦細鐢变汉宸ョ淮鎶ょ殑瀛楁鏄笉闇�瑕佹洿鏂扮殑锛宱rgid/campusid淇濈暀鍘熷�间笉瑕嗙洊
                 sysUser.setSearchscope(null);
                 sysUser.setPassword(null);
                 sysUser.setUserId(sysUser1.getUserId());
+                sysUser.setOrgid(null);
+                sysUser.setCampusid(null);
                 sysUser2Mapper.updateUser(sysUser);
             } else {
-                sysUser2Mapper.insertUser(sysUser);
+                try {
+                    sysUser2Mapper.insertUser(sysUser);
+                } catch (org.springframework.dao.DuplicateKeyException e) {
+                    //骞跺彂鎻掑叆鍦烘櫙锛氶噸鏂版煡璇㈣幏鍙栧凡瀛樺湪璁板綍锛岄伩鍏嶉噸澶�
+                    log.warn("銆恞ueryHospUserInfoList銆戠敤鎴峰凡瀛樺湪(骞跺彂鎻掑叆)锛岃烦杩囷細userName={}", sysUser.getUserName());
+                    SysUser existingUser = sysUser2Mapper.selectUserByUserName(sysUser.getUserName());
+                    if (ObjectUtils.isNotEmpty(existingUser)) {
+                        sysUser.setUserId(existingUser.getUserId());
+                    }
+                }
             }
 
             // 澶勭悊鐢ㄦ埛涓庨儴闂ㄧ殑鍏崇郴
@@ -275,8 +290,8 @@
                         log.info("------businessDeptMap鏄惁鏈夊�硷細{}", businessDeptMap);
                         String hisDeptId = getStringValue(businessDeptMap, "deptId");
                         log.info("------hisDeptId鏄惁鏈夊�硷細{}, reqVO.getOrgId()鐨勫�间负:{}", hisDeptId, reqVO.getCampusId());
-                        //鍦ㄨ繖閲岋紝hisDeptId灏辨槸deptCode
-                        SysDept sysDept = sysDeptMapper.selectDeptByCode(hisDeptId, reqVO.getOrgId());
+                        //鍦ㄨ繖閲岋紝hisDeptId灏辨槸deptCode锛屾寜闄㈠尯+鏈烘瀯鏌ョ瀹わ紝閬垮厤璺ㄩ櫌鍖烘煡閿�
+                        SysDept sysDept = sysDeptMapper.selectDeptByCodeAndCampus(hisDeptId, reqVO.getOrgId(), reqVO.getCampusId() != null ? reqVO.getCampusId().toString() : null);
                         log.info("------hisDeptId鏄惁鏈夊�硷細{}, reqVO.getCampusId()鐨勫�间负:{}", hisDeptId, reqVO.getCampusId());
                         if (Objects.isNull(sysDept)) continue;
                         SysUserDept sysUserDept = new SysUserDept();
@@ -585,7 +600,6 @@
         queryInhosp.setSerialnum(StringUtils.trim(patMedInhosp.getSerialnum()));
         queryInhosp.setOrgid(StringUtils.trim(dto.getOrgId()));
         queryInhosp.setInhospstate(cry);
-        queryInhosp.setSchemestatus(0L);
         log.info("----------------杩欓噷鐨勫叆鍙備负锛歿},{}", queryInhosp.getPatno(), queryInhosp.getSerialnum());
         List<PatMedInhosp> existingInhosps = patMedInhospService.selectPatMedInhosp(queryInhosp);
 
@@ -596,8 +610,10 @@
                 queryInhosp.setInhospstate("3");
                 List<PatMedInhosp> patMedInhospList = patMedInhospService.selectPatMedInhosp(queryInhosp);
                 if (CollectionUtils.isNotEmpty(patMedInhospList)) {
-                    //濡傛灉棰勫叆闄笉涓虹┖锛屽垯杩涜淇敼
+                    //濡傛灉棰勫叆闄笉涓虹┖锛屽垯杩涜淇敼锛堥鍏ラ櫌鈫掑叆闄級
+                    patMedInhosp.setInhospid(patMedInhospList.get(0).getInhospid());
                     patMedInhospService.updatePatMedInhosp(patMedInhosp);
+                    log.info("鐢遍鍏ラ櫌鏇存柊涓哄叆闄細serialnum={}", patMedInhosp.getSerialnum());
                 } else {
                     //濡傛灉鍑洪櫌涓嶄负绌猴紝鍒欎笉杩涜澶勭悊
                     queryInhosp.setInhospstate("1");
@@ -674,6 +690,8 @@
             if (locked == null || Boolean.TRUE.equals(locked)) {
                 try {
                     queryInhosp.setInhospstate(null);
+                    queryInhosp.setSchemestatus(null);
+                    queryInhosp.setPatno(null);
                     List<PatMedInhosp> patMedInhospList3 = patMedInhospService.selectPatMedInhosp(queryInhosp);
                     if (CollectionUtils.isEmpty(patMedInhospList3)) {
                         try {
@@ -726,12 +744,12 @@
         }
         if ("1".equals(cry)) {
             patMedInhosp.setInhospstate("1");
-            if (CollectionUtils.isNotEmpty(dto.getDiagnosisList()) && dto.getDiagnosisList().size() > 0) {
-                for (ServiceSLTDDiagnosisResDTO diagnosis : dto.getDiagnosisList()) {
-                    if (diagnosis.getIsMainDiagnosis() == 1) {
-                        patMedInhosp.setLeavediagname(diagnosis.getDiagnosisDictName() == null ? "" : diagnosis.getDiagnosisDictName());
-                        patMedInhosp.setLeaveicd10code(diagnosis.getDiagnosisDictCode() == null ? "" : diagnosis.getDiagnosisDictCode());
-                    }
+            ServiceSLTDDiagnosisResDTO mainDischargeDiagnosis = dto.getMainDischargeDiagnosis();
+            log.info("-----------mainDischargeDiagnosis鐨勫�兼湁浜嗗悧?{}", mainDischargeDiagnosis);
+            if (!Objects.isNull(mainDischargeDiagnosis)) {
+                if (mainDischargeDiagnosis.getIsMainDiagnosis() == 1) {
+                    patMedInhosp.setLeavediagname(StringUtils.defaultString(mainDischargeDiagnosis.getDiagnosisDictName(), ""));
+                    patMedInhosp.setLeaveicd10code(StringUtils.defaultString(mainDischargeDiagnosis.getDiagnosisDictCode(), ""));
                 }
             }
         }
@@ -792,18 +810,46 @@
     private PatArchive processPatientArchive(ServiceSLTDInhospResDTO dto) {
         List<PatArchive> existingArchives = null;
 
-        // 浼樺厛鎸� patientno 绮剧‘鏌ラ噸锛屾煡涓嶅埌鍐嶆寜 idcardno 鏌ラ噸锛圓ND鏉′欢浼氭紡鏌ュ悓涓�浜轰笉鍚宲atientno鐨勬儏鍐碉級
-        if (dto.getPatientId() != null) {
+        // 绗竴姝ワ細鎸� patientno 绮剧‘鏌ラ噸锛堜笌鎻掑叆鏃朵娇鐢ㄧ殑 medicalRecordNo 涓�鑷达級
+        String patientno = dto.getMedicalRecordNo() == null ? null : String.valueOf(dto.getMedicalRecordNo());
+        if (StringUtils.isNotEmpty(patientno)) {
             PatArchive queryByPatientNo = new PatArchive();
-            queryByPatientNo.setPatientno(String.valueOf(dto.getPatientId()));
-            queryByPatientNo.setIdcardno(StringUtils.isNotEmpty(dto.getIdCardNo()) ? dto.getIdCardNo().trim() : null);
+            queryByPatientNo.setPatientno(patientno);
             existingArchives = patArchiveService.selectPatArchiveList(queryByPatientNo);
         }
+
+        // 绗簩姝ワ細鎸� patientno 鏌ヤ笉鍒版椂锛屾寜 idcardno 鏌ラ噸锛堝垎姝R锛岄伩鍏岮ND鏉′欢婕忔煡锛�
+        if (CollectionUtils.isEmpty(existingArchives) && StringUtils.isNotEmpty(dto.getIdCardNo())) {
+            PatArchive queryByIdCard = new PatArchive();
+            queryByIdCard.setIdcardno(dto.getIdCardNo().trim());
+            existingArchives = patArchiveService.selectPatArchiveList(queryByIdCard);
+        }
+
+        // 绗笁姝ワ細鎸� patidHis 鏌ラ噸锛堝吋瀹规棫鏁版嵁锛屾棫鏁版嵁鍙兘浠� patientId 瀛樹负 patientno锛�
+        if (CollectionUtils.isEmpty(existingArchives) && dto.getPatientId() != null) {
+            PatArchive queryByPatidHis = new PatArchive();
+            queryByPatidHis.setPatientno(String.valueOf(dto.getPatientId()));
+            existingArchives = patArchiveService.selectPatArchiveList(queryByPatidHis);
+        }
+
         PatArchive patArchive = buildPatientArchive(dto);
 
         if (CollectionUtils.isEmpty(existingArchives)) {
-            patArchiveService.insertPatArchive(patArchive);
-            log.debug("銆恜rocessPatientArchive銆戞柊澧炴偅鑰呮。妗堬紝鎮h�呯紪鍙凤細{}", patArchive.getPatientno());
+            try {
+                patArchiveService.insertPatArchive(patArchive);
+                log.debug("銆恜rocessPatientArchive銆戞柊澧炴偅鑰呮。妗堬紝鎮h�呯紪鍙凤細{}", patArchive.getPatientno());
+            } catch (org.springframework.dao.DuplicateKeyException e) {
+                log.warn("銆恜rocessPatientArchive銆戞偅鑰呮。妗堝凡瀛樺湪(骞跺彂鎻掑叆)锛岃烦杩囷細patientno={}, idcardno={}", patArchive.getPatientno(), patArchive.getIdcardno());
+                // 骞跺彂鎻掑叆鍦烘櫙锛岄噸鏂版煡璇㈣幏鍙栧凡瀛樺湪鐨勮褰�
+                PatArchive queryRetry = new PatArchive();
+                queryRetry.setPatientno(patArchive.getPatientno());
+                existingArchives = patArchiveService.selectPatArchiveList(queryRetry);
+                if (CollectionUtils.isNotEmpty(existingArchives)) {
+                    patArchive.setId(existingArchives.get(0).getId());
+                    patArchive.setNotrequiredFlag(existingArchives.get(0).getNotrequiredFlag());
+                    patArchive.setNotrequiredreason(existingArchives.get(0).getNotrequiredreason());
+                }
+            }
         } else {
             patArchive.setId(existingArchives.get(0).getId());
             patArchive.setNotrequiredFlag(existingArchives.get(0).getNotrequiredFlag());
@@ -897,7 +943,17 @@
         dto.setCostNatureName(getStringValue(dataItem, "costNatureName"));
         dto.setCostNatureCode(getStringValue(dataItem, "costNatureCode"));
         dto.setFurtherConsultationStatus(getIntegerValue(dataItem, "furtherConsultationStatus"));
-
+        Object mainDiagObj = dataItem.get("mainDischargeDiagnosis");
+        if (mainDiagObj instanceof Map) {
+            Map<String, Object> mainDiagMap = (Map<String, Object>) mainDiagObj;
+            ServiceSLTDDiagnosisResDTO mainDiag = new ServiceSLTDDiagnosisResDTO();
+            mainDiag.setDiagnosisDictCode(getStringValue(mainDiagMap, "diagnosisDictCode"));
+            mainDiag.setDiagnosisDictName(getStringValue(mainDiagMap, "diagnosisDictName"));
+            mainDiag.setDiagnosisCategory(getStringValue(mainDiagMap, "diagnosisCategory"));
+            mainDiag.setRecordType(getIntegerValue(mainDiagMap, "recordType"));
+            mainDiag.setIsMainDiagnosis(getIntegerValue(mainDiagMap, "isMainDiagnosis"));
+            dto.setMainDischargeDiagnosis(mainDiag);
+        }
         Object contactsObj = dataItem.get("residentContactInfos");
         if (contactsObj instanceof List) {
             dto.setResidentContactInfos(parseContacts((List<?>) contactsObj));
diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java
index 6dedd3a..5d1f90a 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java
@@ -734,19 +734,20 @@
 
     @Override
     public Map<String, Object> selectPatQuestionResult(ServiceSubTaskQueryReq serviceSubTaskQueryReq) {
-        log.error("selectPatQuesTionResult鐨勫叆鍙備负锛歿}", serviceSubTaskQueryReq);
+        log.info("selectPatQuesTionResult鐨勫叆鍙備负锛歿}", serviceSubTaskQueryReq);
         Map<String, Object> map = new HashMap<>();
 
         //鑾峰彇鏈鐨勯棶绛旂粨鏋�
-        Map<String, Object> scriptInfoByCondition = serviceTaskService.getScriptInfoByCondition(serviceSubTaskQueryReq.getTaskid(), serviceSubTaskQueryReq.getPatid(), serviceSubTaskQueryReq.getIsFinish(), serviceSubTaskQueryReq.getPatfrom());
+        Map<String, Object> scriptInfoByCondition = serviceTaskService.getScriptInfoByCondition(serviceSubTaskQueryReq.getTaskid(), serviceSubTaskQueryReq.getPatid(), serviceSubTaskQueryReq.getIsFinish(), serviceSubTaskQueryReq.getPatfrom(), serviceSubTaskQueryReq.getSubId());
         map = getMap(scriptInfoByCondition, serviceSubTaskQueryReq.getSubId(), serviceSubTaskQueryReq.getPatid());
 
         //鑾峰彇涓婃鐨勯棶绛旂粨鏋�
         ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(serviceSubTaskQueryReq.getSubId());
         map.put("upScriptResult", null);
+        map.put("templateName", serviceSubtask.getTemplatename());
         map.put("upTaskName", null);
         if (ObjectUtils.isNotEmpty(serviceSubtask) && serviceSubtask.getUpid() != null) {
-            Map<String, Object> scriptInfoByCondition2 = serviceTaskService.getScriptInfoByCondition(serviceSubTaskQueryReq.getTaskid(), serviceSubTaskQueryReq.getPatid(), serviceSubTaskQueryReq.getIsFinish(), serviceSubTaskQueryReq.getPatfrom());
+            Map<String, Object> scriptInfoByCondition2 = serviceTaskService.getScriptInfoByCondition(serviceSubTaskQueryReq.getTaskid(), serviceSubTaskQueryReq.getPatid(), serviceSubTaskQueryReq.getIsFinish(), serviceSubTaskQueryReq.getPatfrom(),serviceSubTaskQueryReq.getSubId());
             Map<String, Object> map1 = getMap(scriptInfoByCondition2, Long.valueOf(serviceSubtask.getUpid()), serviceSubTaskQueryReq.getPatid());
             if (!map1.isEmpty()) {
                 map.put("upScriptResult", map1.get("scriptResult"));
@@ -761,10 +762,8 @@
     private Map<String, Object> getMap(Map<String, Object> scriptInfoByCondition, Long subid, Long patid) {
         Map<String, Object> map = new HashMap<>();
         if (ObjectUtils.isNotEmpty(scriptInfoByCondition) && ObjectUtils.isNotEmpty(scriptInfoByCondition.get("script"))) {
-//            log.error("-----------scriptInfoByCondition鐨勫�间负锛歿}", scriptInfoByCondition);
             if (scriptInfoByCondition.get("type").equals("1")) {
                 List<IvrTaskTemplateScriptVO> ivrTaskTemplateScriptVOS = (List<IvrTaskTemplateScriptVO>) scriptInfoByCondition.get("script");
-//                List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOList = DtoConversionUtils.sourceToTarget(ivrTaskTemplateScriptVOS, IvrLibaTemplateScriptVO.class);
                 for (IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO : ivrTaskTemplateScriptVOS) {
                     Map<String, String> scriptResult = getScriptResult(subid, patid, ivrTaskTemplateScriptVO.getId());
                     if (ObjectUtils.isNotEmpty(scriptResult)) {
diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
index 61d3e86..fc9cdfb 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -521,6 +521,23 @@
         return serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
     }
 
+    @Override
+    public Boolean updateTemplate(ServiceSubtaskTemplateVO serviceSubtaskTemplateVO) {
+        ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(serviceSubtaskTemplateVO.getSubId());
+        if (serviceSubtask == null || serviceSubtask.getSendstate() != 2L)
+            throw new BaseException("璇ヤ换鍔″凡鍙戦�佺粰鎮h�咃紝涓嶈兘鍐嶈繘琛屼慨鏀规ā鏉�");
+
+        Integer taskTempid = svyTaskTemplateService.saveOrUpdateTemplate(serviceSubtaskTemplateVO.getSvyTaskTemplateVO());
+        if (taskTempid == null) return false;
+
+        String tempName = svyTaskTemplateService.selectSvyTaskTemplateBySvyid(Long.valueOf(taskTempid)).getSvyname();
+        serviceSubtask.setTemplateid(taskTempid.longValue());
+        serviceSubtask.setTemplatename(tempName);
+        serviceSubtask.setUpdateBy(serviceSubtaskTemplateVO.getUpdateBy());
+        serviceSubtask.setLibtemplateid(serviceSubtaskTemplateVO.getSvyTaskTemplateVO().getTemplateid());
+        return updateServiceSubtask(serviceSubtask);
+    }
+
     /**
      * 鎵归噺鍒犻櫎鍗曚竴浠诲姟锛堥殢璁匡級
      *
@@ -657,12 +674,6 @@
                     serviceTaskoper.setOrgid(serviceTask.getOrgid());
                     serviceTaskoper.setCreateTime(new Date());
                     if (StringUtils.isNotEmpty(serviceTaskVO.getOplevelcode())) {
-//                        String[] opcodes = serviceTaskVO.getOpcode().split(",");
-//                        for (String opcode : opcodes) {
-//                            serviceTaskoper.setOpcode(opcode);
-//                            log.info("----serviceTaskoper鐨勫�间负锛歿}", serviceTaskoper);
-//                            serviceTaskoperService.insertServiceTaskoper(serviceTaskoper);
-//                        }
                         log.info("----serviceTaskoper鐨勫�间负锛歿}", serviceTaskoper);
                         serviceTaskoperService.insertServiceTaskoper(serviceTaskoper);
                     }
@@ -771,8 +782,7 @@
                 }
             }
 
-        }
-        else if (serviceTaskVO.getIsoperation() != null && serviceTaskVO.getIsoperation() == 2) {
+        } else if (serviceTaskVO.getIsoperation() != null && serviceTaskVO.getIsoperation() == 2) {
             //浠诲姟淇敼
             if (ObjectUtils.isNotEmpty(serviceTaskVO.getSendTimeslot()))
                 serviceTask.setSendTimeSlot(JSON.toJSONString(serviceTaskVO.getSendTimeslot()));
@@ -870,13 +880,19 @@
                     serviceTaskdiag.setUpdateTime(new Date());
                     if (StringUtils.isNotEmpty(serviceTaskVO.getIcd10code())) {
                         String[] icd10codes = serviceTaskVO.getIcd10code().split(",");
-                        for (String icdcode : icd10codes) {
+                        String[] icd10names = serviceTaskVO.getIcd10name().split(",");
+                        if (icd10codes.length != icd10names.length) {
+                            throw new BaseException("鐤剧梾缂栫爜鍜岀柧鐥呭悕绉版暟閲忎笉涓�鑷�");
+                        }
+                        for (int i = 0; i < icd10codes.length; i++) {
                             //鍏堟煡璇竴涓嬫槸鍚﹀瓨鍦�
                             ServiceTaskdiag serviceTaskdiag2 = new ServiceTaskdiag();
                             serviceTaskdiag2.setTaskId(serviceTaskVO.getTaskid());
-                            serviceTaskdiag2.setIcd10code(icdcode);
+                            serviceTaskdiag2.setIcd10code(icd10codes[i]);
+                            serviceTaskdiag2.setIcd10name(icd10names[i]);
                             List<ServiceTaskdiag> serviceTaskdiags = serviceTaskdiagService.selectServiceTaskdiagList(serviceTaskdiag2);
-                            serviceTaskdiag.setIcd10code(icdcode);
+                            serviceTaskdiag.setIcd10code(icd10codes[i]);
+                            serviceTaskdiag.setIcd10name(icd10names[i]);
                             log.info("----serviceTaskdiag鏇存柊鐨勫�间负锛歿}", serviceTaskdiag);
                             if (CollectionUtils.isNotEmpty(serviceTaskdiags)) {
                                 serviceTaskdiag.setId(serviceTaskdiags.get(0).getId());
@@ -2508,7 +2524,7 @@
     }
 
     @Override
-    public List<ServiceSubtaskIsAbnormalStatistic> getSfStatisticsIsAbnormalExport(ServiceSubtaskCountReq serviceSubtaskCountReq){
+    public List<ServiceSubtaskIsAbnormalStatistic> getSfStatisticsIsAbnormalExport(ServiceSubtaskCountReq serviceSubtaskCountReq) {
 
         return null;
     }
@@ -3956,7 +3972,7 @@
                 serviceSubtask.setRemark(remark + ";鎵�鏈夊彂閫佹柟寮忓潎鏈幏鍙栫粨鏋滐紝浠诲姟澶辫触");
                 serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
                 return true;
-            }else {
+            } else {
                 //鍔犲叆鐩墠琛ュ伩閲岀殑 remark
                 serviceSubtask.setRemark(StringUtils.isNotEmpty(serviceSubtask.getRemark()) ? serviceSubtask.getRemark() + "," + remark : remark);
                 serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceTaskServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceTaskServiceImpl.java
index 4ac0673..531474a 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceTaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceTaskServiceImpl.java
@@ -173,7 +173,7 @@
         ServiceSubtaskEntity serviceSubtaskVO = DtoConversionUtils.sourceToTarget(serviceSubtask, ServiceSubtaskEntity.class);
         List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
         for (ServiceSubtask ss : serviceSubtaskList) {
-            log.error("sfSend闇�瑕佺Щ闄ょ殑subId涓猴細{}", ss.getId().toString());
+            log.info("sfSend闇�瑕佺Щ闄ょ殑subId涓猴細{}", ss.getId().toString());
             redisCache.removeElementFromList("cache-exist", ss.getId().toString());
             redisCache.removeElementFromList("cache-0", ss.getId().toString());
             redisCache.removeElementFromList("cache-1", ss.getId().toString());
@@ -230,21 +230,18 @@
     }
 
     @Override
-    public Map<String, Object> getScriptInfoByCondition(Long taskid, Long patid, Boolean isFinish, String patfrom) {
+    public Map<String, Object> getScriptInfoByCondition(Long taskid, Long patid, Boolean isFinish, String patfrom, Long subId) {
         Map<String, Object> map = new HashMap<>();
         ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity();
-        serviceSubtaskVO.setPatid(patid);
-        serviceSubtaskVO.setTaskid(taskid);
-        serviceSubtaskVO.setSendstate(3L);
+        if (subId != null) {
+            serviceSubtaskVO.setSubId(subId);
+        } else {
+            serviceSubtaskVO.setPatid(patid);
+            serviceSubtaskVO.setTaskid(taskid);
+            serviceSubtaskVO.setSendstate(3L);
+        }
         List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
-//        //鏌ヨ鎮h�呮槸鍚﹂噸瑕嗗仛棰�
-//        if (CollectionUtils.isEmpty(selectServiceSubtaskList)) {
-//            Long submit = selectServiceSubtaskList.get(0).getSubmit();
-//            if (submit == 1L) {
-//                map.put("submit", "1");
-//                return map;
-//            }
-//        }
+
         //閫氳繃浠诲姟ID鑾峰彇妯℃澘ID
         ServiceTask serviceTask = selectServiceTaskByTaskid(taskid);
         if (serviceTask == null) {
@@ -253,12 +250,12 @@
         List info = new ArrayList();
         if (serviceTask.getType().equals("1")) {
             //闅忚
-            log.error("鏂囨湰闅忚闂");
+            log.info("鏂囨湰闅忚闂");
             info = sfInfo(serviceTask, patid, patfrom);
         } else if (serviceTask.getType().equals("2")) {
             //闂嵎
-            log.error("鏂囨湰闂嵎闂");
-            info = wjInfo(serviceTask, patid, isFinish, patfrom);
+            log.info("鏂囨湰闂嵎闂");
+            info = wjInfo(serviceTask, patid, isFinish, patfrom, subId);
         } else {
             //瀹f暀
             info = xjInfo(Long.valueOf(serviceTask.getLibtemplateid()), taskid, patid, isFinish);
@@ -373,7 +370,7 @@
                     }
                 }
                 //鏇挎崲鎮h�呬釜浜轰俊鎭暟鎹�
-                log.error("闂id锛歿},   闂鍐呭锛歿}", svyTaskTemplateScriptVO.getId(), svyTaskTemplateScriptVO.getScriptContent());
+                log.info("闂id锛歿},   闂鍐呭锛歿}", svyTaskTemplateScriptVO.getId(), svyTaskTemplateScriptVO.getScriptContent());
                 if (StringUtils.isNotEmpty(svyTaskTemplateScriptVO.getScriptContent()) && ObjectUtils.isNotEmpty(patArchive)) {
                     svyTaskTemplateScriptVO.setScriptContent(svyTaskTemplateScriptVO.getScriptContent().replace("${name}", StringUtils.isNotEmpty(patArchive.getName()) ? patArchive.getName() : ""));
                     svyTaskTemplateScriptVO.setScriptContent(svyTaskTemplateScriptVO.getScriptContent().replace("${dzz}", StringUtils.isNotEmpty(patArchive.getPlaceOfResidence()) ? patArchive.getPlaceOfResidence() : ""));
@@ -466,12 +463,16 @@
      * @param patid
      * @return
      */
-    private List wjInfo(ServiceTask serviceTask, Long patid, Boolean isFinish, String patfrom) {
+    private List wjInfo(ServiceTask serviceTask, Long patid, Boolean isFinish, String patfrom, Long subId) {
         //鐢ㄦ埛鐐瑰嚮浜嗗閾撅紝灏辩畻浠栭鍙栦簡
         //杩欐牱鍋氫細鏈変竴涓棶棰橈紝濡傛灉鍥哄畾浠诲姟锛屼細鍑虹幇涓�涓换鍔¢噷锛屾湁澶氫釜璇ユ偅鑰�
         ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity();
-        serviceSubtaskVO.setTaskid(serviceTask.getTaskid());
-        serviceSubtaskVO.setPatid(patid);
+        if (subId != null) {
+            serviceSubtaskVO.setSubId(subId);
+        } else {
+            serviceSubtaskVO.setTaskid(serviceTask.getTaskid());
+            serviceSubtaskVO.setPatid(patid);
+        }
         List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
         if (CollectionUtils.isNotEmpty(serviceSubtaskList) && serviceSubtaskList.size() == 1) {
             if (serviceSubtaskList.get(0).getSendstate() == 3 && isFinish == true) {
@@ -485,6 +486,8 @@
         //閫氳繃妯℃澘ID鑾峰彇闂淇℃伅
         SvyTaskTemplateScript svyTaskTemplateScript = new SvyTaskTemplateScript();
         svyTaskTemplateScript.setTemplateID(Long.valueOf(serviceTask.getTemplateid()));
+        if (CollectionUtils.isNotEmpty(serviceSubtaskList) && serviceSubtaskList.get(0).getTemplateid() != null)
+            svyTaskTemplateScript.setTemplateID(serviceSubtaskList.get(0).getTemplateid());
         svyTaskTemplateScript.setDelFlag("0");
         List<SvyTaskTemplateScript> svyTaskTemplateScripts = svyTaskTemplateScriptMapper.selectSvyTaskTemplateScriptList(svyTaskTemplateScript);
         if (CollectionUtils.isEmpty(svyTaskTemplateScripts) || svyTaskTemplateScripts.size() == 0) {
@@ -529,7 +532,7 @@
                     }
                 }
                 //鏇挎崲鎮h�呬釜浜轰俊鎭暟鎹�
-                log.error("闂id锛歿},   闂鍐呭锛歿}", svyTaskTemplateScriptVO.getId(), svyTaskTemplateScriptVO.getScriptContent());
+                log.info("闂id锛歿},   闂鍐呭锛歿}", svyTaskTemplateScriptVO.getId(), svyTaskTemplateScriptVO.getScriptContent());
                 if (StringUtils.isNotEmpty(svyTaskTemplateScriptVO.getScriptContent()) && ObjectUtils.isNotEmpty(patArchive)) {
                     svyTaskTemplateScriptVO.setScriptContent(svyTaskTemplateScriptVO.getScriptContent().replace("${name}", StringUtils.isNotEmpty(patArchive.getName()) ? patArchive.getName() : ""));
                     svyTaskTemplateScriptVO.setScriptContent(svyTaskTemplateScriptVO.getScriptContent().replace("${dzz}", StringUtils.isNotEmpty(patArchive.getPlaceOfResidence()) ? patArchive.getPlaceOfResidence() : ""));
diff --git a/smartor/src/main/java/com/smartor/service/impl/SvyLibTemplateServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/SvyLibTemplateServiceImpl.java
index 4dee0f7..d5944ea 100644
--- a/smartor/src/main/java/com/smartor/service/impl/SvyLibTemplateServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/SvyLibTemplateServiceImpl.java
@@ -59,23 +59,16 @@
         svyLibTemplateReq.setSvyname(svyLibTemplate.getSvyname());
         svyLibTemplateReq.setOrgid(svyLibTemplate.getOrgid());
         List<SvyLibTemplate> svyLibTemplates = svyLibTemplateMapper.selectSvyLibTemplateList(svyLibTemplateReq);
-        for (SvyLibTemplate svyLibTemplate1 : svyLibTemplates) {
-            SvyLibTemplateScript svyLibTemplateScript = new SvyLibTemplateScript();
-            svyLibTemplateScript.setSvyid(svyLibTemplate1.getSvyid());
-            svyLibTemplateScript.setOrgid(svyLibTemplate1.getOrgid());
-            List<SvyLibTemplateScript> svyLibTemplateScripts = svyLibTemplateScriptMapper.selectSvyLibTemplateScriptList(svyLibTemplateScript);
-            for (SvyLibTemplateScript svyLibTemplateScript1 : svyLibTemplateScripts) {
-                if (svyLibTemplateScript1.getScriptType().equals("1") || svyLibTemplateScript1.getScriptType().equals("2")) {
-                    SvyLibTemplateTargetoption svyLibTemplateTargetoption = new SvyLibTemplateTargetoption();
-                    svyLibTemplateTargetoption.setScriptid(svyLibTemplateScript1.getId());
-                    svyLibTemplateTargetoption.setOrgid(svyLibTemplateScript1.getOrgid());
-                    List<SvyLibTemplateTargetoption> svyLibTemplateTargetoptions = svyLibTemplateTargetoptionMapper.selectSvyLibTemplateTargetoptionList(svyLibTemplateTargetoption);
-                    svyLibTemplateScript1.setSvyLibTemplateTargetoptions(svyLibTemplateTargetoptions);
-                }
-            }
-            svyLibTemplate1.setSvyTemplateLibScripts(svyLibTemplateScripts);
-        }
+        svyLibTemplatesCycle(svyLibTemplates);
+        return svyLibTemplates;
+    }
 
+    @Override
+    public List<SvyLibTemplate> getSviLibTemplateByDeptCode(TemplateDeptVO templateDeptVO) {
+        if (templateDeptVO.getType() == null) templateDeptVO.setType(1L);
+        if (templateDeptVO.getDeptType() == null) templateDeptVO.setDeptType("1");
+        List<SvyLibTemplate> svyLibTemplates = svyLibTemplateMapper.selectSvyLibTemplateListByDeptCode(templateDeptVO);
+        svyLibTemplatesCycle(svyLibTemplates);
         return svyLibTemplates;
     }
 
@@ -185,9 +178,9 @@
                 svyLibScript.setGuid(svyLibTemplateVO.getGuid());
                 svyLibScript.setOrgid(svyLibTemplateVO.getOrgid());
                 //鑾峰彇涓�涓嬪垎绫诲悕绉�
-                if(StringUtils.isEmpty(svyLibScript.getCategoryName())){
+                if (StringUtils.isEmpty(svyLibScript.getCategoryName())) {
                     SvyLibScriptCategory svyLibScriptCategory = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryById(svyLibScript.getCategoryid());
-                    if(svyLibScriptCategory != null) svyLibScript.setCategoryName(svyLibScriptCategory.getName());
+                    if (svyLibScriptCategory != null) svyLibScript.setCategoryName(svyLibScriptCategory.getName());
                 }
 
 
@@ -317,4 +310,34 @@
             svyLibTemplateTargetoptionMapper.deleteSvyLibTemplateTargetoptionById(svyLibTemplateTargetoption.getId());
         }
     }
+
+    private void svyLibTemplatesCycle(List<SvyLibTemplate> svyLibTemplates) {
+        for (SvyLibTemplate svyLibTemplate1 : svyLibTemplates) {
+            SvyLibTemplateScript svyLibTemplateScript = new SvyLibTemplateScript();
+            svyLibTemplateScript.setSvyid(svyLibTemplate1.getSvyid());
+            svyLibTemplateScript.setOrgid(svyLibTemplate1.getOrgid());
+            List<SvyLibTemplateScript> svyLibTemplateScripts = svyLibTemplateScriptMapper.selectSvyLibTemplateScriptList(svyLibTemplateScript);
+
+            // 鏀堕泦鎵�鏈夐渶瑕佹煡璇㈤�夐」鐨剆criptId锛坰criptType涓�1鎴�2鐨勯鐩墠闇�瑕侀�夐」锛�
+            List<Long> scriptIds = svyLibTemplateScripts.stream().filter(s -> "1".equals(s.getScriptType()) || "2".equals(s.getScriptType())).map(SvyLibTemplateScript::getId).filter(Objects::nonNull).collect(Collectors.toList());
+
+            // 鎵归噺鏌ヨ鎵�鏈夐�夐」锛屾寜scriptId鍒嗙粍
+            Map<Long, List<SvyLibTemplateTargetoption>> optionMap;
+            if (CollectionUtils.isNotEmpty(scriptIds)) {
+                List<SvyLibTemplateTargetoption> allOptions = svyLibTemplateTargetoptionMapper.selectByScriptIds(scriptIds, svyLibTemplate1.getOrgid());
+                optionMap = allOptions.stream().collect(Collectors.groupingBy(SvyLibTemplateTargetoption::getScriptid));
+            } else {
+                optionMap = new HashMap<>();
+            }
+
+            // 灏嗛�夐」鍒嗛厤鍒板搴旈鐩�
+            for (SvyLibTemplateScript svyLibTemplateScript1 : svyLibTemplateScripts) {
+                if ("1".equals(svyLibTemplateScript1.getScriptType()) || "2".equals(svyLibTemplateScript1.getScriptType())) {
+                    svyLibTemplateScript1.setSvyLibTemplateTargetoptions(optionMap.getOrDefault(svyLibTemplateScript1.getId(), new ArrayList<>()));
+                }
+            }
+
+            svyLibTemplate1.setSvyTemplateLibScripts(svyLibTemplateScripts);
+        }
+    }
 }
diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index d4b064b..c96c11e 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -266,6 +266,7 @@
             resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
         where del_flag = 0
+        <if test="subId != null ">and id = #{subId}</if>
         <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
         <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
         <if test="continueCount != null ">and continue_count = #{continueCount}</if>
diff --git a/smartor/src/main/resources/mapper/smartor/ServiceTaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceTaskMapper.xml
index 8c3bdf7..e961099 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceTaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceTaskMapper.xml
@@ -254,81 +254,84 @@
         service_task.nexttaskname,
         service_task.orgid from service_task
         where 1=1
-            and service_task.del_flag = 0
-            <!--            and taskid in (-->
-            <!--            select task_id from service_taskdept-->
-            <!--            where 1=1-->
-            <!--                <if test="leaveldeptcodes != null and leaveldeptcodes.size()>0">-->
-            <!--                    and dept_code in-->
-            <!--                    <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","-->
-            <!--                             close=")">-->
-            <!--                        #{leaveldeptcode}-->
-            <!--                    </foreach>-->
-            <!--                </if>-->
-            <!--            )-->
-            <if test="taskName != null  and taskName != ''">and service_task.task_name like concat('%', #{taskName},
-                '%')
-            </if>
-            <if test="sendTimeSlot != null  and sendTimeSlot != ''">and service_task.send_time_slot like concat('%',
-                #{sendTimeSlot},
-                '%')
-            </if>
-            <if test="templateid != null  and templateid != ''">and service_task.templateid = #{templateid}</if>
-            <if test="longTask != null  and longTask != ''">and service_task.long_task = #{longTask}</if>
-            <if test="serviceType != null  and serviceType != ''">and service_task.service_type = #{serviceType}</if>
-            <if test="templatename != null  and templatename != ''">and service_task.templatename like concat('%',
-                #{templatename},
-                '%')
-            </if>
-            <if test="labelinfo != null  and labelinfo != ''">and service_task.labelinfo = #{labelinfo}</if>
-            <if test="count != null ">and service_task.count = #{count}</if>
-            <if test="executed != null ">and service_task.executed = #{executed}</if>
-            <if test="unexecuted != null ">and service_task.unexecuted = #{unexecuted}</if>
-            <if test="fail != null ">and service_task.fail = #{fail}</if>
-            <if test="checkuserid != null  and checkuserid != ''">and service_task.checkuserid = #{checkuserid}</if>
-            <if test="checkusername != null  and checkusername != ''">and service_task.checkusername like concat('%',
-                #{checkusername}, '%')
-            </if>
-            <if test="checktime != null ">and service_task.checktime = #{checktime}</if>
-            <if test="sendDay != null ">and service_task.send_day = #{sendDay}</if>
-            <if test="type != null  and type != ''">and service_task.type = #{type}</if>
-            <if test="typename != null  and typename != ''">and service_task.typename like concat('%', #{typename},
-                '%')
-            </if>
-            <if test="beginTime != null ">and date_format( service_task.update_time,'%y%m%d') &gt;=
-                date_format(#{beginTime},'%y%m%d')
-            </if>
-            <if test="endTime != null ">and date_format( service_task.update_time,'%y%m%d') &lt;=
-                date_format(#{endTime},'%y%m%d')
-            </if>
+        and service_task.del_flag = 0
+        <if test="taskName != null  and taskName != ''">and service_task.task_name like concat('%', #{taskName},
+            '%')
+        </if>
+        <if test="sendTimeSlot != null  and sendTimeSlot != ''">and service_task.send_time_slot like concat('%',
+            #{sendTimeSlot},
+            '%')
+        </if>
+        <if test="templateid != null  and templateid != ''">and service_task.templateid = #{templateid}</if>
+        <if test="longTask != null  and longTask != ''">and service_task.long_task = #{longTask}</if>
+        <if test="serviceType != null  and serviceType != ''">and service_task.service_type = #{serviceType}</if>
+        <if test="templatename != null  and templatename != ''">and service_task.templatename like concat('%',
+            #{templatename},
+            '%')
+        </if>
+        <if test="labelinfo != null  and labelinfo != ''">and service_task.labelinfo = #{labelinfo}</if>
+        <if test="count != null ">and service_task.count = #{count}</if>
+        <if test="executed != null ">and service_task.executed = #{executed}</if>
+        <if test="unexecuted != null ">and service_task.unexecuted = #{unexecuted}</if>
+        <if test="fail != null ">and service_task.fail = #{fail}</if>
+        <if test="checkuserid != null  and checkuserid != ''">and service_task.checkuserid = #{checkuserid}</if>
+        <if test="checkusername != null  and checkusername != ''">and service_task.checkusername like concat('%',
+            #{checkusername}, '%')
+        </if>
+        <if test="checktime != null ">and service_task.checktime = #{checktime}</if>
+        <if test="sendDay != null ">and service_task.send_day = #{sendDay}</if>
+        <if test="type != null  and type != ''">and service_task.type = #{type}</if>
+        <if test="typename != null  and typename != ''">and service_task.typename like concat('%', #{typename},
+            '%')
+        </if>
+        <if test="beginTime != null ">and date_format( service_task.update_time,'%y%m%d') &gt;=
+            date_format(#{beginTime},'%y%m%d')
+        </if>
+        <if test="endTime != null ">and date_format( service_task.update_time,'%y%m%d') &lt;=
+            date_format(#{endTime},'%y%m%d')
+        </if>
 
-            <if test="deptcode != null  and deptcode != ''">and service_task.deptcode = #{deptcode}</if>
-            <if test="deptname != null  and deptname != ''">and service_task.deptname = #{deptname}</if>
-            <if test="isupload != null ">and service_task.isupload = #{isupload}</if>
-            <if test="uploadTime != null ">and service_task.upload_time = #{uploadTime}</if>
-            <if test="orgid != null  and orgid != ''">and service_task.orgid = #{orgid}</if>
-            <if test="compensateDate != null  and compensateDate != ''">and service_task.compensate_date =
-                #{compensateDate}
-            </if>
-            <if test="hospType != null  and hospType != ''">and service_task.hosp_type = #{hospType}</if>
-            <if test="libtemplateid != null ">and service_task.libtemplateid = #{libtemplateid}</if>
-            <if test="libtemplatename != null  and libtemplatename != ''">and service_task.libtemplatename =
-                #{libtemplatename}
-            </if>
-            <if test="createBy != null  and createBy != ''">and service_task.create_by = #{createBy}</if>
-            <if test="sendState != null  ">and service_task.send_state = #{sendState}</if>
-            <if test="compensateDate != null  ">and service_task.compensate_date = #{compensateDate}</if>
-            <if test="patCycle != null  ">and service_task.pat_cycle = #{patCycle}</if>
-            <if test="nexttaskflag != null  ">and nexttaskflag = #{nexttaskflag}</if>
-            <if test="nexttaskid != null  ">and nexttaskid = #{nexttaskid}</if>
-            <if test="nexttaskname != null  ">and nexttaskname = #{nexttaskname}</if>
-            <if test="appltype != null  ">and appltype = #{appltype}</if>
-            <if test="leavehospitaldistrictname != null  ">and service_task.leavehospitaldistrictname =
-                #{leavehospitaldistrictname}
-            </if>
-            <if test="leavehospitaldistrictcode != null  ">and service_task.leavehospitaldistrictcode =
+        <if test="deptcode != null  and deptcode != ''">and service_task.deptcode = #{deptcode}</if>
+        <if test="deptname != null  and deptname != ''">and service_task.deptname = #{deptname}</if>
+        <if test="isupload != null ">and service_task.isupload = #{isupload}</if>
+        <if test="uploadTime != null ">and service_task.upload_time = #{uploadTime}</if>
+        <if test="orgid != null  and orgid != ''">and service_task.orgid = #{orgid}</if>
+        <if test="compensateDate != null  and compensateDate != ''">and service_task.compensate_date =
+            #{compensateDate}
+        </if>
+        <if test="hospType != null  and hospType != ''">and service_task.hosp_type = #{hospType}</if>
+        <if test="libtemplateid != null ">and service_task.libtemplateid = #{libtemplateid}</if>
+        <if test="libtemplatename != null  and libtemplatename != ''">and service_task.libtemplatename =
+            #{libtemplatename}
+        </if>
+        <if test="createBy != null  and createBy != ''">and service_task.create_by = #{createBy}</if>
+        <if test="sendState != null  ">and service_task.send_state = #{sendState}</if>
+        <if test="compensateDate != null  ">and service_task.compensate_date = #{compensateDate}</if>
+        <if test="patCycle != null  ">and service_task.pat_cycle = #{patCycle}</if>
+        <if test="nexttaskflag != null  ">and nexttaskflag = #{nexttaskflag}</if>
+        <if test="nexttaskid != null  ">and nexttaskid = #{nexttaskid}</if>
+        <if test="nexttaskname != null  ">and nexttaskname = #{nexttaskname}</if>
+        <if test="appltype != null  ">and appltype = #{appltype}</if>
+        <if test="leavehospitaldistrictname != null  ">and service_task.leavehospitaldistrictname =
+            #{leavehospitaldistrictname}
+        </if>
+        <if test="leavehospitaldistrictcodes!=null and leavehospitaldistrictcodes.size()>0">
+            AND service_task.leavehospitaldistrictcode IN
+            <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
+                     close=")">
                 #{leavehospitaldistrictcode}
-            </if>
+            </foreach>
+        </if>
+        <if test="leaveldeptcodes!=null and leaveldeptcodes.size()>0">
+            AND service_task.deptcode IN
+            <foreach collection="leaveldeptcodes" item="deptcode" open="(" separator=","
+                     close=")">
+                #{deptcode}
+            </foreach>
+        </if>
+        <if test="leavehospitaldistrictcode != null  ">and service_task.leavehospitaldistrictcode =
+            #{leavehospitaldistrictcode}
+        </if>
         order by update_time desc,taskid desc
     </select>
 
diff --git a/smartor/src/main/resources/mapper/smartor/SvyLibTemplateMapper.xml b/smartor/src/main/resources/mapper/smartor/SvyLibTemplateMapper.xml
index 9058c05..a70011d 100644
--- a/smartor/src/main/resources/mapper/smartor/SvyLibTemplateMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/SvyLibTemplateMapper.xml
@@ -124,17 +124,69 @@
         icd10_association group by outid) b ON a.del_flag = 0
         AND a.svyid = b.outid
         where 1=1
-            and a.del_flag=0
-            <if test="categoryid != null ">and a.categoryid = #{categoryid}</if>
-            <if test="svyid != null ">and a.svyid = #{svyid}</if>
-            <if test="longTemp != null ">and a.long_temp = #{longTemp}</if>
-            <if test="orgid != null ">and a.orgid = #{orgid}</if>
-            <if test="svyname != null  and svyname != ''">and a.svyname like concat('%', #{svyname}, '%')</if>
-            <if test="description != null  and description != ''">and b.icd10name like concat('%', #{description}, '%')
-            </if>
+        and a.del_flag=0
+        <if test="categoryid != null ">and a.categoryid = #{categoryid}</if>
+        <if test="svyid != null ">and a.svyid = #{svyid}</if>
+        <if test="longTemp != null ">and a.long_temp = #{longTemp}</if>
+        <if test="orgid != null ">and a.orgid = #{orgid}</if>
+        <if test="svyname != null  and svyname != ''">and a.svyname like concat('%', #{svyname}, '%')</if>
+        <if test="description != null  and description != ''">and b.icd10name like concat('%', #{description}, '%')
+        </if>
         order by a.create_time desc
     </select>
 
+
+    <select id="selectSvyLibTemplateListByDeptCode" parameterType="com.smartor.domain.TemplateDeptVO"
+            resultMap="SvyLibTemplateResult">
+        SELECT
+        a.svyid,
+        a.long_temp,
+        a.conclusion,
+        a.instruction,
+        a.prologue,
+        a.categoryid,
+        a.svycode,
+        a.svyname,
+        a.description,
+        a.introduce,
+        a.submitprompt,
+        a.templateid,
+        a.version,
+        a.centerlibrarycode,
+        a.centerlibraryid,
+        a.islocal,
+        a.isenable,
+        a.orgid,
+        a.del_flag,
+        a.create_by,
+        a.create_time,
+        a.update_by,
+        a.update_time,
+        a.isupload,
+        a.upload_time,
+        a.dept_names,
+        a.value_type,
+        a.reply,
+        a.campus,
+        a.suitway,
+        a.script_score,
+        a.score_type,
+        a.otherdata,
+        a.guid
+        FROM
+        svy_lib_template a
+        LEFT JOIN template_dept b ON a.del_flag = 0
+        AND a.svyid = b.tempid
+        where a.del_flag=0
+          and b.del_flag=0
+        <if test="deptCode != null ">and b.dept_code = #{deptCode}</if>
+        <if test="deptType != null ">and b.dept_type = #{deptType}</if>
+        <if test="type != null">and b.type=#{type}</if>
+        <if test="tempid != null">and a.svyid=#{tempid}</if>
+        order by a.create_time desc
+        <if test="pageSize != null  and pageNum != null">limit ${pageSize} OFFSET ${pageNum}</if>
+    </select>
+
     <select id="selectSvyLibTemplateBySvyid" parameterType="Long" resultMap="SvyLibTemplateResult">
         <include refid="selectSvyLibTemplateVo"/>
         where svyid = #{svyid} and del_flag=0
diff --git a/smartor/src/main/resources/mapper/smartor/SvyLibTemplateTargetoptionMapper.xml b/smartor/src/main/resources/mapper/smartor/SvyLibTemplateTargetoptionMapper.xml
index 8de34f9..dba6882 100644
--- a/smartor/src/main/resources/mapper/smartor/SvyLibTemplateTargetoptionMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/SvyLibTemplateTargetoptionMapper.xml
@@ -268,4 +268,14 @@
             #{id}
         </foreach>
     </delete>
+
+    <select id="selectByScriptIds" resultMap="SvyLibTemplateTargetoptionResult">
+        <include refid="selectSvyLibTemplateTargetoptionVo"/>
+        where del_flag = 0
+        and scriptid in
+        <foreach item="scriptId" collection="scriptIds" open="(" separator="," close=")">
+            #{scriptId}
+        </foreach>
+        <if test="orgid != null and orgid != ''">and orgid = #{orgid}</if>
+    </select>
 </mapper>
diff --git a/smartor/src/main/resources/mapper/smartor/SysDeptMapper.xml b/smartor/src/main/resources/mapper/smartor/SysDeptMapper.xml
index cfdfba5..66be32b 100644
--- a/smartor/src/main/resources/mapper/smartor/SysDeptMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/SysDeptMapper.xml
@@ -154,6 +154,36 @@
         </if>
     </select>
 
+    <select id="selectDeptByCodeAndCampus" parameterType="string" resultMap="SysDeptResult">
+        select d.dept_id,
+        d.parent_id,
+        d.type,
+        d.campusid,
+        d.dept_code,
+        d.dept_type,
+        d.ancestors,
+        d.dept_name,
+        d.order_num,
+        d.leader,
+        d.phone,
+        d.email,
+        d.orgid,
+        d.his_dept_id,
+        d.his_parent_id,
+        d.status
+        from sys_dept d
+        where del_flag = 0
+        <if test="deptCode != null and deptCode != ''">
+            AND dept_code = #{deptCode}
+        </if>
+        <if test="orgid != null and orgid != ''">
+            AND orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            AND campusid = #{campusid}
+        </if>
+    </select>
+
     <select id="checkDeptExistUser" parameterType="Long" resultType="int">
         select count(1)
         from sys_user

--
Gitblit v1.9.3