From 43e807c405e8cf5b725d1ced5490128da191eb98 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期五, 30 十月 2026 11:34:38 +0800
Subject: [PATCH] 【丽水】/smartor/patinhosp/addManualVisit 人工处理,接口完成删除未完成的任务,再次生成随访任务

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java |   83 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 78 insertions(+), 5 deletions(-)

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 b0f5b1f..a2be971 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -448,7 +448,7 @@
             if (StringUtils.isEmpty(serviceSubtask.getCurrentPreachform())) {
                 if (StringUtils.isNotEmpty(serviceSubtask.getPreachform())) {
                     //榛樿鍙栫涓�涓�
-                    serviceSubtaskRes.setCurrentPreachform(serviceSubtask.getPreachform().split(",")[0]);
+                    serviceSubtaskRes.setCurrentPreachform(serviceSubtask.getPreachform().split(",")[0].trim());
                 }
             }
             PatMedInhosp inhosp = patMedInhospMapper.selectPatMedInhospByInhospid(serviceSubtask.getInhospid());
@@ -1312,6 +1312,20 @@
     }
 
     /**
+     * 绉戝缂栫爜鍘婚噸锛屼繚鎸佸師椤哄簭锛岄伩鍏� service_task.deptcode 瓒呴暱鍜� service_taskdept 閲嶅缁戝畾
+     */
+    private String normalizeDeptCodes(String deptCodes) {
+        if (StringUtils.isEmpty(deptCodes)) {
+            return deptCodes;
+        }
+        return Arrays.stream(deptCodes.split(","))
+                .map(String::trim)
+                .filter(code -> StringUtils.isNotEmpty(code))
+                .distinct()
+                .collect(Collectors.joining(","));
+    }
+
+    /**
      * 鍗曚竴浠诲姟
      *
      * @return 缁撴灉
@@ -1323,6 +1337,8 @@
             log.info("浠诲姟鍏ュ弬涓虹┖锛岃妫�鏌ュ叆鍙�");
             throw new BaseException("浠诲姟鍏ュ弬涓虹┖锛岃妫�鏌ュ叆鍙�");
         }
+        // 绉戝缂栫爜鍘婚噸锛岄伩鍏� service_task.deptcode 瓒呴暱鍙� service_taskdept 閲嶅缁戝畾
+        serviceTaskVO.setDeptcode(normalizeDeptCodes(serviceTaskVO.getDeptcode()));
         ServiceTask serviceTask = DtoConversionUtils.sourceToTarget(serviceTaskVO, ServiceTask.class);
         if (CollectionUtils.isEmpty(serviceTaskVO.getPreachformList())) throw new BaseException("浠诲姟鐨勫彂閫佹柟寮忎负绌�");
         //灏唒reachfromList鏀惧埌serviceTask涓殑preachfrom涓�
@@ -1557,7 +1573,12 @@
                     serviceSubtask.setInhospid(patTaskRelevance.getHospid());
                     //鏂板缓瀹屾垚灏辨槸寰呭彂閫佺姸鎬�
                     serviceSubtask.setSendstate(2L);
-                    serviceSubtask.setDeptcode(StringUtils.isNotEmpty(patTaskRelevance.getDeptcode()) ? patTaskRelevance.getDeptcode() : serviceTaskVO.getDeptcode());
+                    String subtaskDeptCode = patTaskRelevance.getDeptcode();
+                    if (StringUtils.isEmpty(subtaskDeptCode) && StringUtils.isNotEmpty(serviceTaskVO.getDeptcode())) {
+                        // service_subtask.deptcode 涓哄崟鍊煎瓧娈碉紝涓嶈兘鍐欏叆浠诲姟鐨勫绉戝鎷兼帴涓诧紝鍙栫涓�涓瀹ゅ厹搴�
+                        subtaskDeptCode = serviceTaskVO.getDeptcode().split(",")[0].trim();
+                    }
+                    serviceSubtask.setDeptcode(subtaskDeptCode);
                     serviceSubtask.setDeptname(StringUtils.isNotEmpty(patTaskRelevance.getDeptName()) ? patTaskRelevance.getDeptName() : serviceTaskVO.getDeptname());
                     serviceSubtask.setLeavehospitaldistrictcode(patTaskRelevance.getLeavehospitaldistrictcode());
                     serviceSubtask.setLeavehospitaldistrictname(patTaskRelevance.getLeavehospitaldistrictname());
@@ -1697,6 +1718,11 @@
             if (StringUtils.isNotEmpty(serviceTaskVO.getAppltype())) {
                 if (serviceTaskVO.getAppltype().equals("1") || serviceTaskVO.getAppltype().equals("2")) {
                     if (StringUtils.isNotEmpty(serviceTaskVO.getDeptcode())) {
+                        // 淇敼浠诲姟鏃跺厛杞垹闄ゆ棫鐨勭瀹ょ粦瀹氾紝閬垮厤鏃х瀹ゆ畫鐣�
+                        ServiceTaskdept oldDept = new ServiceTaskdept();
+                        oldDept.setTaskId(serviceTask.getTaskid());
+                        oldDept.setDeptType("1");
+                        serviceTaskdeptService.deleteServiceTaskdeptByTaskId(oldDept);
                         String[] deptcodes = serviceTaskVO.getDeptcode().split(",");
                         for (String deptCode : deptcodes) {
                             ServiceTaskdept serviceTaskdept = new ServiceTaskdept();
@@ -3735,6 +3761,8 @@
             serviceSubtaskStatistic.setLeavehospitaldistrictcode(serviceSubtaskList.get(0).getLeavehospitaldistrictcode());
             serviceSubtaskStatistic.setDrcode(serviceSubtaskList.get(0).getDrcode());
             serviceSubtaskStatistic.setDrname(serviceSubtaskList.get(0).getDrname());
+            //闅忚涓績绉戝锛岀敤浜庣粺璁″啀娆¢殢璁挎帹閫佸埌闅忚涓績鐨勪汉鏁�
+            String centerDept = configService.selectConfigByKey("sys.smartor.center.dept", serviceSubtaskList.get(0).getOrgid());
             //鍑洪櫌浜烘
             serviceSubtaskStatistic.setDischargeCount(serviceSubtaskList.size());
             for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
@@ -3752,6 +3780,17 @@
                 //鍙婃椂闅忚浜烘锛氬凡瀹屾垚涓旀湭瓒呮椂
                 if (isTimelyFollowUp(serviceSubtask)) {
                     serviceSubtaskStatistic.setTimelyFollowUp(serviceSubtaskStatistic.getTimelyFollowUp() + 1L);
+                }
+
+                //棣栨鍑洪櫌浜烘锛歷isitCount = 1锛屼綔涓哄啀娆¢殢璁挎帹閫佺巼鐨勫垎姣�
+                if (serviceSubtask.getVisitCount() != null && serviceSubtask.getVisitCount() == 1) {
+                    serviceSubtaskStatistic.setFirstDischargeCount(serviceSubtaskStatistic.getFirstDischargeCount() + 1L);
+                }
+                //鍐嶆闅忚鎺ㄩ�佷汉鏁帮細棣栦釜鍐嶆闅忚锛坴isitCount = 2锛変笖鎵ц绉戝涓洪殢璁夸腑蹇冪瀹�
+                if (serviceSubtask.getVisitCount() != null && serviceSubtask.getVisitCount() == 2
+                        && StringUtils.isNotEmpty(centerDept)
+                        && StringUtils.equals(StringUtils.trim(centerDept), StringUtils.trim(serviceSubtask.getVisitDeptCode()))) {
+                    serviceSubtaskStatistic.setAgainFollowUpPushCount(serviceSubtaskStatistic.getAgainFollowUpPushCount() + 1L);
                 }
 
                 //浜哄伐宸叉嫧閫氭�婚噺
@@ -4768,6 +4807,8 @@
      * 鑾峰彇闅忚缁熻瓒呴摼鎺�
      * dischargeCountInfo
      * followUpNeededAllInfo - sendstate != 4 (1,2,3,5,6,7)
+     * firstDischargeCountInfo - visitCount = 1
+     * againFollowUpPushCountInfo - visitCount = 2 && visitDeptCode = sys.smartor.center.dept锛堥殢璁夸腑蹇冪瀹わ級
      * nonFollowUpInfo - sendstate = 4
      * needFollowUpInfo - visitCount = 1 && sendstate != 4
      * pendingFollowUpInfo - visitCount = 1 && sendstate = 2
@@ -4810,7 +4851,10 @@
     public List<ServiceSubtask> getSfStatisticsHyperlink(ServiceSubtaskCountReq serviceSubtaskCountReq) {
         String hyperLinkInfoType = serviceSubtaskCountReq.getHyperLinkInfoType();
         if (StringUtils.isNotEmpty(hyperLinkInfoType)) {
-            applyHyperLinkInfoType(serviceSubtaskCountReq, hyperLinkInfoType);
+            if (!applyHyperLinkInfoType(serviceSubtaskCountReq, hyperLinkInfoType)) {
+                // 涓嬮捇渚濊禆鐨勯厤缃己澶辨椂杩斿洖绌烘槑缁嗭紝閬垮厤閫�鍖栨垚鏃犺繃婊ゆ潯浠剁殑鏌ヨ
+                return new ArrayList<>();
+            }
         }
 
         String followUpCountStyle = serviceSubtaskCountReq.getFollowUpCountStyle();
@@ -4831,7 +4875,7 @@
         return serviceSubtasks;
     }
 
-    private void applyHyperLinkInfoType(ServiceSubtaskCountReq serviceSubtaskCountReq, String hyperLinkInfoType) {
+    private boolean applyHyperLinkInfoType(ServiceSubtaskCountReq serviceSubtaskCountReq, String hyperLinkInfoType) {
         //鍙婃椂闅忚鏄庣粏闇�瑕佹部鐢ㄨ姹傜殑棣栨/鍐嶆鍙e緞
         Integer originVisitCount = serviceSubtaskCountReq.getVisitCount();
         serviceSubtaskCountReq.setVisitCount(null);
@@ -4844,6 +4888,22 @@
         switch (hyperLinkInfoType) {
             case "dischargeCountInfo":
                 break;
+            case "firstDischargeCountInfo":
+                //棣栨鍑洪櫌浜烘锛歷isitCount = 1
+                serviceSubtaskCountReq.setVisitCount(1);
+                break;
+            case "againFollowUpPushCountInfo": {
+                //鍐嶆闅忚鎺ㄩ�佷汉鏁帮細visitCount = 2 涓旀墽琛岀瀹や负闅忚涓績绉戝
+                String centerDept = configService.selectConfigByKey("sys.smartor.center.dept", serviceSubtaskCountReq.getOrgid());
+                if (StringUtils.isBlank(centerDept)) {
+                    log.warn("鑾峰彇鍐嶆闅忚鎺ㄩ�佹槑缁嗗け璐ワ紝鏈厤缃殢璁夸腑蹇冪瀹ゅ弬鏁� sys.smartor.center.dept, orgid={}", serviceSubtaskCountReq.getOrgid());
+                    return false;
+                }
+                serviceSubtaskCountReq.setVisitCount(2);
+                serviceSubtaskCountReq.setVisitDeptCode(centerDept.trim());
+                serviceSubtaskCountReq.setVisitDeptName(null);
+                break;
+            }
             case "timelyFollowUpInfo":
                 serviceSubtaskCountReq.setVisitCount(originVisitCount);
                 serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L)));
@@ -4995,6 +5055,7 @@
             default:
                 break;
         }
+        return true;
     }
 
 
@@ -5336,6 +5397,8 @@
 
         // 鍒濆鍖栨暟鍊煎瓧娈�
         total.setDischargeCount(0);
+        total.setFirstDischargeCount(0L);
+        total.setAgainFollowUpPushCount(0L);
         total.setNonFollowUp(0L);
         total.setFilterCount(0L);
         total.setFollowUpNeeded(0L);
@@ -5368,6 +5431,8 @@
             if (stat.getDischargeCount() != null) {
                 total.setDischargeCount(total.getDischargeCount() + stat.getDischargeCount());
             }
+            total.setFirstDischargeCount(total.getFirstDischargeCount() + (stat.getFirstDischargeCount() != null ? stat.getFirstDischargeCount() : 0L));
+            total.setAgainFollowUpPushCount(total.getAgainFollowUpPushCount() + (stat.getAgainFollowUpPushCount() != null ? stat.getAgainFollowUpPushCount() : 0L));
             total.setNonFollowUp(total.getNonFollowUp() + (stat.getNonFollowUp() != null ? stat.getNonFollowUp() : 0L));
             total.setFilterCount(total.getFilterCount() + (stat.getFilterCount() != null ? stat.getFilterCount() : 0L));
             total.setFollowUpNeeded(total.getFollowUpNeeded() + (stat.getFollowUpNeeded() != null ? stat.getFollowUpNeeded() : 0L));
@@ -5762,7 +5827,15 @@
                 return resultMap;
             }
 
-            if (StringUtils.isEmpty(serviceSubtask.getPatidHis())) {
+            if (patArchive == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "鍙戦�佸紓甯革細" + "銆愬叕浼楀彿銆戞湭鏌ヨ鍒版偅鑰呮。妗堜俊鎭紝鏃犳硶閫氳繃鍏紬鍙峰彂閫�");
+                return resultMap;
+            }
+
+            // his绯荤粺鐨勬偅鑰卛d鍙栬嚜鎮h�呮。妗坧at_archive.patid_his锛�
+            // service_subtask鏌ヨ鏈叧鑱旇瀛楁锛坰erviceSubtask.getPatidHis()鎭掍负绌猴級锛屼笉鑳界敤浜庢牎楠�
+            if (StringUtils.isEmpty(patArchive.getPatidHis())) {
                 resultMap.put("code", -1);
                 resultMap.put("message", "鍙戦�佸紓甯革細" + "銆愬叕浼楀彿銆戝叕浼楀彿鍙戦�佸け璐�,his绯荤粺鐨勬偅鑰卛d涓虹┖");
                 return resultMap;

--
Gitblit v1.9.3