From 88d4cd31fa5b197a91ed081ba1df292420af2d05 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期四, 22 十月 2026 16:48:52 +0800
Subject: [PATCH] 【丽水】随访统计增加一列,及时随访,统计未超时且已完成的随访人次

---
 ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java |  261 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 171 insertions(+), 90 deletions(-)

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 34ada0f..cfe92f6 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
@@ -8,6 +8,7 @@
 import com.google.gson.Gson;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysDept;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.core.service.IDingTalkService;
 import com.ruoyi.common.dx.MessageSend;
@@ -16,13 +17,14 @@
 import com.ruoyi.common.enums.WxGZHEnum;
 import com.ruoyi.common.utils.*;
 import com.ruoyi.common.utils.http.HttpUtils;
-import com.ruoyi.common.utils.sms.smsUtils;
+import com.ruoyi.common.utils.sms.SmsUtils;
 import com.ruoyi.quartz.service.ICollectHISService;
 import com.ruoyi.quartz.util.CreateDataTable;
 import com.ruoyi.system.domain.SysConfig;
 import com.ruoyi.system.mapper.SysConfigMapper;
 import com.ruoyi.system.service.ISysConfigService;
 import com.ruoyi.system.service.ISysDeptService;
+import com.ruoyi.system.service.ISysUserService;
 import com.smartor.common.LSHospTokenUtil;
 import com.smartor.common.MtSubmitSmUtil;
 import com.smartor.common.QwenLLMUtil;
@@ -108,6 +110,9 @@
 
     @Autowired
     private IDingTalkService dingTalkService;
+
+    @Autowired
+    private ISysUserService userService;
 
 
     @Value("${localIP}")
@@ -283,31 +288,67 @@
         subtaskDetailTraceVO.setHandleFlag("0");
         List<ServiceSubtaskDetailTrace> serviceSubtaskDetailTraces =
                 serviceSubtaskDetailTraceService.selectServiceSubtaskDetailTtraceList(subtaskDetailTraceVO);
-        // 鎶� dutyDeptPersonCode 鏁寸悊鍒� list 涓紙濡傛灉澶氫釜浜虹敤閫楀彿鍒嗗壊锛屽垯灞曞紑骞跺幓閲嶏級
-        List<String> dutyDeptPersonCodeList = serviceSubtaskDetailTraces.stream()
-                .map(ServiceSubtaskDetailTrace::getDutyDeptPersonCode)
-                .filter(StringUtils::isNotBlank)
-                .flatMap(code -> Arrays.stream(code.split(",")))
-                .map(String::trim)
-                .filter(StringUtils::isNotBlank).distinct()  // 鍘婚噸
-                .collect(Collectors.toList());
         // 鑾峰彇鈥滃紓甯稿唴瀹规彁閱�"
         SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("send.except.content");
         String exceptContent = sysConfig.getConfigValue();
 
         // 鑾峰彇鈥滃唴瀹规彁閱掓祴璇曚汉宸ュ彿鈥�
-        String testPerson = sysConfigMapper.checkConfigKeyUnique("send.test.person").getConfigValue();
-        if (StringUtils.isNotBlank(testPerson)) {
-            String[] split = testPerson.split(",");
-            if (CollectionUtils.isEmpty(dutyDeptPersonCodeList)) dutyDeptPersonCodeList = Arrays.asList(split);
-            else dutyDeptPersonCodeList.addAll(Arrays.asList(split));
-        }
+        SysConfig testPersonConfig = sysConfigMapper.checkConfigKeyUnique("send.test.person");
+        String testPerson = ObjectUtils.isNotEmpty(testPersonConfig) ? testPersonConfig.getConfigValue() : "";
+        if(CollectionUtils.isNotEmpty(serviceSubtaskDetailTraces)){
+            for (ServiceSubtaskDetailTrace serviceSubtaskDetailTrace : serviceSubtaskDetailTraces) {
+                List<String> dutyDeptPersonCodeList = new ArrayList<>();
+                        // 鎶� dutyDeptPersonCode 鏁寸悊鍒� list 涓紙濡傛灉澶氫釜浜虹敤閫楀彿鍒嗗壊锛屽垯灞曞紑骞跺幓閲嶏級
+                String dutyDeptPersonCodeStr = serviceSubtaskDetailTrace.getDutyDeptPersonCode();
+                if(StringUtils.isNotEmpty(dutyDeptPersonCodeStr)){
+                    String[] dutyDeptPersonCodeSplit = dutyDeptPersonCodeStr.split(",");
+                    if (CollectionUtils.isEmpty(dutyDeptPersonCodeList)) {
+                        dutyDeptPersonCodeList = new ArrayList<>(Arrays.asList(dutyDeptPersonCodeSplit));
+                    } else {
+                        dutyDeptPersonCodeList.addAll(Arrays.asList(dutyDeptPersonCodeSplit));
+                    }
 
-        if (CollectionUtils.isNotEmpty(dutyDeptPersonCodeList)) {
-            for (String dutyDeptPersonCode : dutyDeptPersonCodeList) {
-                log.info("銆恠endExceptInfo銆戝彂閫佷汉宸ュ彿锛歿}", dutyDeptPersonCode);
-                String dutyDeptPerson = dingTalkService.getDingTalkUserByMobile(dutyDeptPersonCode);
-                dingTalkService.sendDingTalkText(exceptContent, dutyDeptPerson);
+                }
+
+                if (StringUtils.isNotBlank(testPerson)) {
+                    String[] split = testPerson.split(",");
+                    if (CollectionUtils.isEmpty(dutyDeptPersonCodeList)) {
+                        dutyDeptPersonCodeList = new ArrayList<>(Arrays.asList(split));
+                    } else {
+                        dutyDeptPersonCodeList.addAll(Arrays.asList(split));
+                    }
+                }
+
+                if (CollectionUtils.isNotEmpty(dutyDeptPersonCodeList)) {
+                    for (String dutyDeptPersonCode : dutyDeptPersonCodeList) {
+                        log.info("銆恠endExceptInfo銆戝彂閫佷汉宸ュ彿锛歿}", dutyDeptPersonCode);
+                        SysUser sysUser = new SysUser();
+                        SysUser sysUserVo = new SysUser();
+                        sysUserVo.setUserName(dutyDeptPersonCode);
+                        sysUserVo.setOrgid(serviceSubtaskDetailTrace.getOrgid());
+                        List<SysUser> users = userService.getUserList(sysUserVo);
+                        String phoneNumber = "";
+                        if(ObjectUtils.isNotEmpty(users)){
+                            sysUser = users.get(0);
+                            phoneNumber = sysUser.getPhonenumber();
+                        }else {
+                            continue;
+                        }
+
+                        if(StringUtils.isEmpty(phoneNumber)){
+                            continue;
+                        }
+                        String dutyDeptPerson = dingTalkService.getDingTalkUserByMobile(phoneNumber);
+                        if(StringUtils.isNotBlank(dutyDeptPerson)){
+                            String context = TemplateUtils.render(exceptContent, serviceSubtaskDetailTrace);
+                            dingTalkService.sendDingTalkText(context, dutyDeptPerson);
+                            //鏇存柊鐘舵��
+                            serviceSubtaskDetailTrace.setHandleFlag("1");
+                            serviceSubtaskDetailTrace.setUpdateTime(new Date());
+                            serviceSubtaskDetailTraceService.updateServiceSubtaskDetailTtrace(serviceSubtaskDetailTrace);
+                        }
+                    }
+                }
             }
         }
     }
@@ -882,6 +923,13 @@
             serviceSubtaskList.addAll(compensateServiceSubtaskList);
         }
         for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
+            //currentPreachform涓虹┖锛岃鏄庤瀛愪换鍔¤繕娌℃湁鎵ц杩囦换浣曚竴绉嶅彂閫佹柟寮�(sendstate=1锛屽睘浜庨娆¤ˉ鍋�)锛�
+            //杩欓噷鐩存帴浜ょ粰sfHandlle澶勭悊锛屽畠浼氭寜sort=1鐨勭涓�绉嶅彂閫佹柟寮忓彂閫侊紝涓巊etSendPreachform涓殑澶勭悊淇濇寔涓�鑷�
+            if (StringUtils.isEmpty(serviceSubtask.getCurrentPreachform())) {
+                log.warn("銆恈ompensateTask銆憇ubid锛歿}锛宑urrentPreachform涓虹┖锛屾寜绗竴绉嶅彂閫佹柟寮忚ˉ鍋垮鐞�", serviceSubtask.getId());
+                sfHandlle(serviceSubtask);
+                continue;
+            }
             //鏍规嵁褰撳墠鐨勬墽琛屾柟寮忥紝鑾峰彇涓嬩竴绉嶆墽琛屾柟寮�
             ServiceSubtaskPreachform serviceSubtaskPreachform = new ServiceSubtaskPreachform();
             serviceSubtaskPreachform.setTaskid(serviceSubtask.getTaskid());
@@ -952,6 +1000,24 @@
         LocalDate today = LocalDate.now();
         // 濡傛灉鏃ユ湡鏃╀簬鎴栫瓑浜庝粖澶╋紝杩斿洖 true
         return !localDate.isAfter(today);
+    }
+
+    /**
+     * 鎸夋満鏋勬煡璇㈤厤缃�硷紙鍚屼竴 key 鍦ㄤ笉鍚屾満鏋勪笅鍙厤缃笉鍚屽�硷級
+     *
+     * @param configKey 閰嶇疆key
+     * @param orgid     鏈烘瀯ID
+     * @return 閰嶇疆鍊硷紝鏈厤缃繑鍥� null
+     */
+    private String getConfigValue(String configKey, String orgid) {
+        SysConfig query = new SysConfig();
+        query.setConfigKey(configKey);
+        query.setOrgid(orgid);
+        List<SysConfig> sysConfigs = configService.selectConfigList(query);
+        if (CollectionUtils.isNotEmpty(sysConfigs)) {
+            return sysConfigs.get(0).getConfigValue();
+        }
+        return null;
     }
 
     /**
@@ -1090,7 +1156,7 @@
                         } else {
                             sysConfig = sysConfigMapper.checkConfigKeyUnique("wj.sms.template");
                         }
-                        if (!Objects.isNull(sysConfig)) {
+                        if (!Objects.isNull(sysConfig) && StringUtils.isNotEmpty(sysConfig.getConfigValue())) {
                             String smsContemt = sysConfig.getConfigValue();
 //                            sendMagParam.setContent("鎮ㄥソ锛岄個璇锋偍濉啓鍑洪櫌璋冩煡琛紝璇风偣鍑�" + sendMagParam.getUrl() + "濉啓銆傛劅璋㈡偍閰嶅悎锛�");
                             sendMagParam.setContent(smsContemt.replace("${wjurl}", sendMagParam.getUrl()));
@@ -1104,7 +1170,7 @@
                             sendMagParam.setUrl(url);
 
                             SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("xj.sms.template");
-                            if (!Objects.isNull(sysConfig)) {
+                            if (!Objects.isNull(sysConfig) && StringUtils.isNotEmpty(sysConfig.getConfigValue())) {
                                 String smsContemt = sysConfig.getConfigValue();
 //                              sendMagParam.setContent("鎮ㄥソ锛岄個璇锋偍濉啓鍑洪櫌瀹f暀璋冩煡琛紝璇风偣鍑�" + sendMagParam.getUrl() + "鏌ョ湅銆傛劅璋㈡偍閰嶅悎锛�");
                                 sendMagParam.setContent(smsContemt.replace("${xjurl}", sendMagParam.getUrl()));
@@ -1118,6 +1184,13 @@
                             sendMagParam.setContent(content);
                         }
 
+                    }
+
+                    //鍐呭涓虹┖璇存槑鐭俊妯℃澘鏈厤缃垨瀹f暀/閫氱煡鍐呭涓虹┖锛岀洿鎺ユ寜鍙戦�佸け璐ュ鐞嗭紝閬垮厤鍚庣画鍙戦�佹椂鍑虹幇绌烘寚閽�
+                    if (StringUtils.isEmpty(sendMagParam.getContent())) {
+                        log.error("銆恠fHandlle銆戦暱鏈熶换鍔$煭淇″唴瀹逛负绌猴紝鏃犳硶鍙戦�侊紝subid锛歿}锛宼askid锛歿}锛宼ype锛歿}锛屾満鏋処D锛歿}", serviceSubtask.getId(), serviceSubtask.getTaskid(), serviceSubtask.getType(), serviceSubtask.getOrgid());
+                        setSuccessPreachForm(serviceSubtask, sendPreachform, "闀挎湡浠诲姟鐭俊鍙戦�佸け璐�:鐭俊鍐呭涓虹┖(鐭俊妯℃澘鏈厤缃垨鍐呭涓虹┖), 鏃堕棿: " + now, "5");
+                        return;
                     }
 
                     serviceOutPath.setRadix(format);
@@ -1155,33 +1228,48 @@
 //                        String url = configService.selectConfigByKey("token.360", serviceSubtask.getOrgid());
 //                        //涓芥按鐨勭煭淇″彂閫佹柟寮�
 //                        Map<String, String> map = MsgLSEnum.getAddressByCode(serviceSubtask.getOrgid());
-                        SysConfig config = new SysConfig();
-                        config.setConfigKey("ls.msg.info");
-                        config.setOrgid(serviceSubtask.getOrgid());
-                        List<SysConfig> sysConfigs = configService.selectConfigList(config);
-                        Map<String, String> msgInfo = new HashMap<>();
-                        if (CollectionUtils.isNotEmpty(sysConfigs)) {
-                            String configValue = sysConfigs.get(0).getConfigValue();
+                        if ("47226079133110211G1001".equals(serviceSubtask.getOrgid())) {
+                            // 濡囧辜涓浗绉诲姩浜慚AS锛屼笉渚濊禆 ls.msg.info 涓� token
+                            SmsUtils.YunMasConfig yunMasConfig = SmsUtils.YunMasConfig.of(getConfigValue("ls.msg.yunmas", serviceSubtask.getOrgid()));
+                            SmsUtils.SmsResult smsResult = SmsUtils.sendYunMasSms(yunMasConfig, sendMagParam.getPhone(), sendMagParam.getContent());
+                            log.info("銆恠fHandlle銆戜簯MAS鐭俊鍙戦�佺粨鏋滐細ok={}锛宺spcod={}锛宮sgGroup={}锛宮essage={}",
+                                    smsResult.isOk(), smsResult.getRspcod(), smsResult.getMsgGroup(), smsResult.getMessage());
+                            if (smsResult.isOk()) {
+                                isSuccess = "true";
+                            } else {
+                                log.error("銆恠fHandlle銆戜簯MAS鐭俊鍙戦�佸け璐ワ紝subid锛歿}锛屾墜鏈哄彿锛歿}锛屽師鍥狅細{}",
+                                        serviceSubtask.getId(), sendMagParam.getPhone(), smsResult.getMessage());
+                            }
+                        } else {
+                            SysConfig config = new SysConfig();
+                            config.setConfigKey("ls.msg.info");
+                            config.setOrgid(serviceSubtask.getOrgid());
+                            List<SysConfig> sysConfigs = configService.selectConfigList(config);
+                            Map<String, String> msgInfo = new HashMap<>();
+                            if (CollectionUtils.isNotEmpty(sysConfigs)) {
+                                String configValue = sysConfigs.get(0).getConfigValue();
+                                ObjectMapper objectMapper = new ObjectMapper();
+                                if (StringUtils.isNotEmpty(configValue)) {
+                                    msgInfo = objectMapper.readValue(configValue, Map.class);
+                                }
+                            }
+                            log.info("-----------map鐨勫�间负锛歿}", msgInfo);
+                            if (ObjectUtils.isEmpty(msgInfo) || StringUtils.isEmpty(msgInfo.get("address"))) {
+                                setSuccessPreachForm(serviceSubtask, sendPreachform, "鐭俊鍙戦�佸け璐�,璇ユ満鏋勬病鏈夐厤缃煭淇″湴鍧�, 鏃堕棿:" + now, "5");
+                                return;
+                            }
+                            String token = LSHospTokenUtil.getToken(serviceSubtask.getOrgid(), msgInfo.get("tokenUrl"));
+                            log.info("銆恠fHandlle銆戜附姘寸煭淇″彂閫侊紝鍦板潃锛歿}锛屽弬鏁帮細{}锛屾満鏋処D锛歿}", msgInfo.get("address"), sendMagParam, serviceSubtask.getOrgid());
+                            String dxCode = getDXCode(msgInfo.get("address"), sendMagParam.getPhone(), sendMagParam.getContent(), msgInfo.get("sendPersonId"), msgInfo.get("sendPersonName"), MsgLSEnum.getHeaderByCode(msgInfo), token);
+                            log.info("銆恠fHandlle銆戜附姘寸煭淇″彂閫佺粨鏋滐細{}", dxCode);
                             ObjectMapper objectMapper = new ObjectMapper();
-                            if (StringUtils.isNotEmpty(configValue)) {
-                                msgInfo = objectMapper.readValue(configValue, Map.class);
+                            Map<String, Object> textParam = objectMapper.readValue(dxCode, Map.class);
+                            String code = textParam.get("Code").toString();
+                            if (code.equals("0")) {
+                                isSuccess = "true";
                             }
                         }
-                        log.info("-----------map鐨勫�间负锛歿}", msgInfo);
-                        String token = LSHospTokenUtil.getToken(serviceSubtask.getOrgid(), msgInfo.get("tokenUrl"));
-                        if (ObjectUtils.isNotEmpty(msgInfo) && StringUtils.isEmpty(msgInfo.get("address"))) {
-                            setSuccessPreachForm(serviceSubtask, sendPreachform, "鐭俊鍙戦�佸け璐�,璇ユ満鏋勬病鏈夐厤缃煭淇″湴鍧�, 鏃堕棿:" + now, "5");
-                            return;
-                        }
-                        log.info("銆恠fHandlle銆戜附姘寸煭淇″彂閫侊紝鍦板潃锛歿}锛屽弬鏁帮細{}锛屾満鏋処D锛歿}", msgInfo.get("address"), sendMagParam, serviceSubtask.getOrgid());
-                        String dxCode = getDXCode(msgInfo.get("address"), sendMagParam.getPhone(), sendMagParam.getContent(), msgInfo.get("sendPersonId"), msgInfo.get("sendPersonName"), MsgLSEnum.getHeaderByCode(msgInfo), token);
-                        log.info("銆恠fHandlle銆戜附姘寸煭淇″彂閫佺粨鏋滐細{}", dxCode);
-                        ObjectMapper objectMapper = new ObjectMapper();
-                        Map<String, Object> textParam = objectMapper.readValue(dxCode, Map.class);
-                        String code = textParam.get("Code").toString();
-                        if (code.equals("0")) {
-                            isSuccess = "true";
-                        }
+
                     } else if (active.equals("sltd") || active.equals("nhfy")) {
                         log.info("sltd杩涙潵浜嗗悧锛焮}   ,---sendMagParam.getContent()鐨勫弬鏁颁负锛歿}", active, sendMagParam.getContent());
                         if (active.equals("sltd")) {
@@ -1229,13 +1317,13 @@
                         String campusid = ObjectUtils.isNotEmpty(sysDept) ? sysDept.getCampusid() : "2";
                         //婀栨花鍗曠嫭鍙戦�佹柟寮�
                         if ("1".equals(campusid)) {
-                            String result = smsUtils.sendSms1(xhsmsPath, xhsmsAccount, xhsmsPwd, sendMagParam.getPhone(), content);
+                            String result = SmsUtils.sendSms1(xhsmsPath, xhsmsAccount, xhsmsPwd, sendMagParam.getPhone(), content);
                             //杩欓噷闇�瑕佹牴鎹畆esult杩斿洖鐨勫�煎幓鍒ゆ柇锛屾槸鍚︽垚鍔燂紝鐒跺悗灏嗗�艰祴鍊肩粰isSuccess
                             if (StringUtils.isNotEmpty(result) && result.contains("澶勭悊鎴愬姛")) {
                                 isSuccess = "true";
                             }
                         } else {
-                            String result = smsUtils.sendSms(xhsmsPath, xhsmsAccount, xhsmsPwd, sendMagParam.getPhone(), content);
+                            String result = SmsUtils.sendSms(xhsmsPath, xhsmsAccount, xhsmsPwd, sendMagParam.getPhone(), content);
                             //杩欓噷闇�瑕佹牴鎹畆esult杩斿洖鐨勫�煎幓鍒ゆ柇锛屾槸鍚︽垚鍔燂紝鐒跺悗灏嗗�艰祴鍊肩粰isSuccess
                             if (StringUtils.isNotEmpty(result) && result.contains("澶勭悊鎴愬姛")) {
                                 isSuccess = "true";
@@ -1317,7 +1405,7 @@
                     //甯備竴鍖婚櫌
                     if (active.equals("hzszlyy")) {
                         //澶勭悊涓枃涔辩爜闂
-                        wxCode = smsUtils.sendChat(url, patArchive.getTelcode(), serviceSubtask.getSfzh());
+                        wxCode = SmsUtils.sendChat(url, patArchive.getTelcode(), serviceSubtask.getSfzh());
                     } else {
                         wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), patArchive.getTelcode(), serviceSubtask.getSendname(), patArchive.getPatidHis(), wxqqxx);
                     }
@@ -1707,14 +1795,15 @@
      * @return
      */
     private String getObject(ServiceSubtask serviceSubtask, String scriptContent) {
+        //鍐呭涓虹┖鏃剁洿鎺ヨ繑鍥烇紝閬垮厤涓嬮潰鐨剅eplace鍑虹幇绌烘寚閽�
+        if (StringUtils.isEmpty(scriptContent)) {
+            return scriptContent;
+        }
         Map<String, Map<String, String>> param = getParam(serviceSubtask.getTaskid());
         for (Map<String, String> map : param.values()) {
             for (String key : map.keySet()) {
                 scriptContent = scriptContent.replace(key, StringUtils.isNotEmpty(map.get(key)) ? map.get(key) : "");
             }
-        }
-        if (StringUtils.isEmpty(scriptContent)) {
-            return scriptContent;
         }
         scriptContent = scriptContent.replace("${name}", StringUtils.isNotEmpty(serviceSubtask.getSendname()) ? serviceSubtask.getSendname() : "");
         scriptContent = scriptContent.replace("${dzz}", StringUtils.isNotEmpty(serviceSubtask.getAddr()) ? serviceSubtask.getAddr() : "");
@@ -1818,7 +1907,16 @@
 
     /**
      * 澶勭悊瓒呮椂闅忚浠诲姟
-     * @return
+     * <p>
+     * 鎵弿銆屽嚭闄㈡弧 deadlineDay 澶╀粛鏈畬鎴愩�嶇殑棣栨闅忚浠诲姟锛坰endstate=7 + visit_count=1锛夛紝
+     * 鎸夊綋鍓嶄换鍔$殑 nexttaskid 鐢熸垚鍐嶆闅忚浠诲姟骞惰浆鍒伴殢璁夸腑蹇冦��
+     * <p>
+     * 娉ㄦ剰锛氭埅姝㈡椂闂村繀椤诲湪寰幆澶栬绠椾竴娆°�傚巻鍙插疄鐜版妸 {@code deadlineDay = -deadlineDay}
+     * 鍐欏湪寰幆浣撳唴锛屾瘡杞彇鍙嶄竴娆★紝瀵艰嚧鍋舵暟杞敤銆屼粖澶� + deadlineDay銆嶅仛鎴鏃堕棿锛�
+     * 鎶婂嚭闄笉婊� 28 澶╃殑瓒呮椂浠诲姟涔熸壂浜嗚繘鏉ャ��
+     *
+     * @param orgid       鏈烘瀯ID
+     * @param deadlineDay 鍑洪櫌婊″灏戝ぉ绠楄秴鏃讹紙姝f暟锛屽 28锛�
      */
     public void dealSubtaskDeadline(String orgid, Integer deadlineDay){
         //鑾峰彇浠诲姟淇℃伅
@@ -1828,9 +1926,17 @@
         st.setNexttaskflag("1");
         st.setOrgid(orgid);
         List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(st);
+
+        // 鎴鏃堕棿鍙畻涓�娆★細鍑洪櫌鏃堕棿 <= 浠婂ぉ - deadlineDay
+        int days = Math.abs(ObjectUtils.isEmpty(deadlineDay) ? 28 : deadlineDay);
+        Date deadline = DateUtils.addDays(new Date(), -days);
+        log.info("銆恉ealSubtaskDeadline銆戝紑濮嬫壂鎻�, orgid={}, day={}, deadline={}, 浠诲姟鏁�={}",
+                orgid, days, deadline, serviceTasks.size());
+
         for (ServiceTask serviceTask : serviceTasks) {
-            deadlineDay = -deadlineDay;
-            Date deadline = DateUtils.addDays(new Date(), deadlineDay);
+            if (ObjectUtils.isEmpty(serviceTask.getNexttaskid())) {
+                continue;
+            }
             //閫氳繃浠诲姟ID鎷垮埌鎮h�呬俊鎭�,骞朵笖闅忚鏃堕棿寰楁槸浠婂ぉ涔嬪墠鐨�
             ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity();
             serviceSubtaskVO.setOrgid(orgid);
@@ -1839,45 +1945,20 @@
             serviceSubtaskVO.setVisitCount(1);
             serviceSubtaskVO.setTaskid(serviceTask.getTaskid());
             serviceSubtaskVO.setEndOutHospTime(deadline);
+
             List<ServiceSubtask> serviceSubtaskList
                     = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
             log.info("銆恉ealSubtaskDeadline銆戣幏鍙栧埌{}涓秴鏃朵换鍔�, taskid={}", serviceSubtaskList.size(), serviceTask.getTaskid());
             for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
-                PatMedInhosp patMedInhospVo = new PatMedInhosp();
-                patMedInhospVo.setOrgid(serviceSubtask.getOrgid());
-                patMedInhospVo.setInhospid(serviceSubtask.getInhospid());
-                List<PatMedInhosp> patMedInhospList = iPatMedInhospService.selectPatMedInhospList(patMedInhospVo);
-                PatMedInhosp patMedInhosp = new PatMedInhosp();
-                if (!patMedInhospList.isEmpty()) {
-                    patMedInhosp = patMedInhospList.get(0);
-                }else {
-                    continue;
-                }
-                if(ObjectUtils.isEmpty(serviceTask.getNexttaskid())){
-                    continue;
-                }
-                ServiceTask nextServiceTask = serviceTaskMapper.selectServiceTaskByTaskid(serviceTask.getNexttaskid());
-                PatArchive patArchive = patArchiveService.selectPatArchiveByPatid(serviceSubtask.getPatid());
-                String config = configService.selectConfigByKey("visit.early.day");
-                Integer type = 1;
-
-                //鏂板鍐嶆闅忚浠诲姟
-                ServiceSubtask serviceSubtaskAgain = iPatMedInhospService.boxedServiceSubtask(nextServiceTask,
-                        patMedInhosp, patArchive, config, type);
-                serviceSubtaskAgain.setId(null);
-                serviceSubtaskAgain.setUpid(serviceSubtask.getId().intValue());
-                serviceSubtaskAgain.setVisitCount(serviceSubtask.getVisitCount() + 1);
-                serviceSubtaskAgain.setSendstate(2L);
-                serviceSubtaskAgain.setCreateTime(new Date());
-                serviceSubtaskAgain.setUpdateTime(new Date());
-                serviceSubtaskAgain.setVisitType(serviceSubtask.getVisitType());
-                serviceSubtaskAgain.setVisitDeptCode(serviceSubtask.getVisitDeptCode());
-                serviceSubtaskAgain.setVisitDeptName(serviceSubtask.getVisitDeptName());
-                int i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtaskAgain);
-                if (i == 1) {
-                    //鍐嶆闅忚浠诲姟鍒涘缓鎴愬姛鍚庯紝鍘熶换鍔℃敼涓哄け璐ョ姸鎬�
-                    serviceSubtask.setSendstate(5L);
-                    serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
+                try {
+                    // 鐢熸垚閫昏緫缁熶竴鏀跺彛鍒� service锛氶攣 + 骞傜瓑 + 浜嬪姟 + 鍙戦�佹柟寮忔槑缁嗗垵濮嬪寲
+                    String result = iServiceSubtaskService.addSubTaskAgainByDeadline(serviceSubtask);
+                    log.info("銆恉ealSubtaskDeadline銆戠敓鎴愬啀娆¢殢璁�, subId={}, taskid={}, 缁撴灉={}",
+                            serviceSubtask.getId(), serviceTask.getTaskid(), result);
+                } catch (Exception e) {
+                    // 鍗曟潯澶辫触涓嶅奖鍝嶅叾浠栨偅鑰�
+                    log.error("銆恉ealSubtaskDeadline銆戠敓鎴愬啀娆¢殢璁垮け璐�, subId=" + serviceSubtask.getId()
+                            + ", taskid=" + serviceTask.getTaskid(), e);
                 }
             }
         }

--
Gitblit v1.9.3