From eb6ec9c3c725c2271cb91f5211d4bc758c49bf31 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期三, 25 十一月 2026 15:46:14 +0800
Subject: [PATCH] 【丽水】随访统计枚举

---
 ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java |  111 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 96 insertions(+), 15 deletions(-)

diff --git a/ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java b/ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java
index 58b73f4..d51de99 100644
--- a/ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java
+++ b/ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java
@@ -280,6 +280,9 @@
     private static final String AGAIN_LOCK_KEY_PREFIX = "smartor:again:lock:";
     private static final long AGAIN_LOCK_SECONDS = 30L;
 
+    /** 缂欎簯鍘夸汉姘戝尰闄㈡満鏋勭紪鐮� */
+    private static final String JINYUN_PEOPLES_HOSPITAL_ORGID = "47246116333112211A1001";
+
     /**
      * 鏌ヨ鍗曚竴浠诲姟锛堥殢璁匡級
      *
@@ -885,6 +888,39 @@
     }
 
     /**
+     * 鍏煎銆岀瀹�/鐥呭尯銆嶅瓧娈甸噸鍛藉悕鍓嶇殑鏃у叆鍙傘��
+     *
+     * <p>2026-11 璧凤細{@code deptcode/deptname} = 鍦ㄩ櫌绉戝锛寋@code leaveldeptcode/leaveldeptname} = 绂婚櫌绉戝銆�
+     * 浣嗗墠绔�/鏃ц皟鐢ㄦ柟锛坽@code /serviceSubtask/addSubTask}锛変粛鍙兘鎶婄瀹ゆ斁鍦� {@code deptcode/deptname} 閲屻��
+     * 鑻ヤ笉褰掍綅锛屽瓙浠诲姟浼氳惤鍒般�屽湪闄㈢淮搴︺�嶏紝鍒楄〃鎸夌闄㈢瀹ょ瓫閫夋椂鏌ヤ笉鍒帮紙鏈绾夸笂 2654501/2663019 鍗虫闂锛夈��
+     *
+     * <p>瑙勫垯锛�
+     * <ul>
+     *   <li>鍙闈炲欢缁姢鐞嗭紙{@code service_type != '99'}锛夌敓鏁堬紱99 鍏佽浣跨敤鍦ㄩ櫌缁村害锛�</li>
+     *   <li>绂婚櫌绉戝涓虹┖涓� {@code deptcode} 鏈夊�兼椂锛屾妸 {@code deptcode/deptname} 杩佸埌绂婚櫌缁村害锛�</li>
+     *   <li>娓呯┖鍦ㄩ櫌缁村害锛岄伩鍏嶅悓涓�浠界瀹ゅ悓鏃跺懡涓袱缁勭瓫閫夛紙涓� {@code toSubtaskFromTaskVO} 鐨勫彛寰勪竴鑷达級銆�</li>
+     * </ul>
+     */
+    private void alignLeaveDeptFromLegacyDept(ServiceSubtask serviceSubtask) {
+        if (serviceSubtask == null || "99".equals(serviceSubtask.getServiceType())) {
+            return;
+        }
+        if (StringUtils.isEmpty(serviceSubtask.getLeaveldeptcode())
+                && StringUtils.isNotEmpty(serviceSubtask.getDeptcode())) {
+            serviceSubtask.setLeaveldeptcode(serviceSubtask.getDeptcode());
+        }
+        if (StringUtils.isEmpty(serviceSubtask.getLeaveldeptname())
+                && StringUtils.isNotEmpty(serviceSubtask.getDeptname())) {
+            serviceSubtask.setLeaveldeptname(serviceSubtask.getDeptname());
+        }
+        // 鎵嬪伐鏂板鍏ュ彛娌℃湁銆屽湪闄㈢淮搴︺�嶇殑鍙潬鏉ユ簮锛涗换鍔¢厤缃噷鐨勭瀹や笉鏄偅鑰呮湰浜虹殑鍦ㄩ櫌绉戝銆�
+        serviceSubtask.setDeptcode(null);
+        serviceSubtask.setDeptname(null);
+        serviceSubtask.setHospitaldistrictcode(null);
+        serviceSubtask.setHospitaldistrictname(null);
+    }
+
+    /**
      * 鏂板鍗曚竴浠诲姟锛堥殢璁匡級
      *
      * @param serviceSubtask 鍗曚竴浠诲姟锛堥殢璁匡級
@@ -892,6 +928,8 @@
      */
     @Override
     public Map<String, Object> insertServiceSubtask(ServiceSubtask serviceSubtask) {
+        // 鍏煎 2026-11 瀛楁閲嶅懡鍚嶅墠鐨勬棫鍏ュ弬锛�/addSubTask 浠嶅彲鑳芥妸绉戝鏀惧湪 deptcode/deptname 閲�
+        alignLeaveDeptFromLegacyDept(serviceSubtask);
         List<ServiceSubtask> serviceSubtasks = null;
         //鍏堟煡璇竴涓嬭鎮h�呮槸鍚﹀凡缁忓垱寤烘牴鎹畇erviceType,sendstate,inhospid,patid,orgid
         //杩欐牱鍒ゆ柇涓昏鏄负浜嗘兂璁╂柊鍗庡尰闄㈢殑澶栭儴瀵煎叆鎮h�呭垱寤轰换鍔★紝涔熻兘鐢ㄨ繖涓帴鍙�
@@ -2551,7 +2589,8 @@
         log.info("getSfStatistics鐨勫叆鍙備负锛歿}", serviceSubtaskCountReq);
         String drcode = "drcode";
         //缂欎簯浜烘皯 鏍规嵁缁忕鍖荤敓鍒嗙粍
-        if (serviceSubtaskCountReq.getOrgid().equals("47246116333112211A1001")) {
+        boolean jinyunHospital = JINYUN_PEOPLES_HOSPITAL_ORGID.equals(serviceSubtaskCountReq.getOrgid());
+        if (jinyunHospital) {
             drcode = "management_doctor_code";
         }
         String groupKey = drcode;
@@ -2565,7 +2604,10 @@
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                 groupKey = drcode;
             } else {
-                groupKey = "deptcode";
+                // 2026-11 瀛楁閲嶅懡鍚嶅悗锛歞eptcode 鏄湪闄㈢瀹わ紙鍘嗗彶鏁版嵁涓虹┖锛夛紝
+                // 鍑洪櫌绉戝宸叉敼鍚嶄负 leaveldeptcode锛屽垎缁勫繀椤荤敤鍚庤�咃紝
+                // 鍚﹀垯 getSfStatisticsGroupKey 浼氳繑鍥� NULL锛屾嫾鎴� IN (NULL) 瀵艰嚧鏁磋〃鏌ョ┖銆�
+                groupKey = "leaveldeptcode";
             }
         } else if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 3) {
             // 鐥呯缁熻锛氭寜浠诲姟ID鍒嗙粍锛屾瘡涓换鍔″嵆涓�涓梾绉嶉殢璁夸换鍔�
@@ -2576,6 +2618,17 @@
         Map<String, List<ServiceSubtask>> collect = new HashMap<>();
         serviceSubtaskCountReq.setGroupKey(groupKey);
         List<String> groupKeyList = serviceSubtaskMapper.getSfStatisticsGroupKey(serviceSubtaskCountReq);
+        /*
+         * 鍒嗙粍閿彲鑳戒负 NULL锛堝巻鍙叉暟鎹�佹垨閲嶅懡鍚嶅悗灏氭湭鍥炲~鐨勫湪闄㈢淮搴﹀垪锛夛紝
+         * 鐩存帴鎷艰繘 SQL 浼氬彉鎴� `AND IFNULL(鍒�,'Unknown') IN (NULL)`锛屾亽涓嶆垚绔嬶紝鏁村紶缁熻琛ㄤ负绌恒��
+         * 杩欓噷缁熶竴鎴� 'Unknown'锛屼笌鑱氬悎 SQL 鐨� IFNULL(鍒�,'Unknown') 鍙e緞瀵归綈銆�
+         */
+        if (groupKeyList != null) {
+            groupKeyList = groupKeyList.stream()
+                    .map(key -> key == null ? "Unknown" : key)
+                    .distinct()
+                    .collect(Collectors.toList());
+        }
         serviceSubtaskCountReq.setGroupKeyList(groupKeyList);
         List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
         switch (groupKey) {
@@ -2590,6 +2643,7 @@
                 collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getManagementDoctorCode()).orElse("Unknown")));
                 break;
             case "deptcode":
+            case "leaveldeptcode":
                 collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeaveldeptcode()).orElse("Unknown")));
                 break;
             case "leavehospitaldistrictcode":
@@ -2602,8 +2656,16 @@
                 collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
                 break;
         }
-        //鑾峰彇鍙婃椂鐜囩粺璁″悎闆�
-        Map<String, Map<String, Object>> jsRates = getSsRateForSfStatistics(serviceSubtaskCountReq, collect);
+        /*
+         * 缂欎簯鍘夸汉姘戝尰闄㈢殑鈥滃強鏃剁巼鈥濆彛寰勬槸鈥滃強鏃堕殢璁夸汉娆� / 搴旈殢璁夸汉娆♀�濓紝
+         * 蹇呴』鍜屽悓涓�鎵圭粺璁¤閲岀殑 timelyFollowUp / followUpNeeded 淇濇寔涓�鑷淬��
+         * 涓嶈兘鍐嶈蛋 selectTimelyRateBatch锛氳 SQL 鍦ㄦ湭浼犲簲闅忚鏃堕棿鑼冨洿鏃惰繕浼氳拷鍔�
+         * visit_time < NOW()锛屽彧鎸夊嚭闄㈡椂闂寸粺璁℃椂浼氭妸鏈埌鏈熶换鍔℃帓闄ゅ湪鍒嗘瘝澶栵紝
+         * 瀵艰嚧椤甸潰涓婄殑鍙婃椂鐜囧拰鈥滃強鏃堕殢璁夸汉娆�/搴旈殢璁夸汉娆♀�濆涓嶄笂銆�
+         */
+        Map<String, Map<String, Object>> jsRates = jinyunHospital
+                ? Collections.emptyMap()
+                : getSsRateForSfStatistics(serviceSubtaskCountReq, collect);
         for (String collectKey : collect.keySet()) {
             List<ServiceSubtask> serviceSubtaskList = collect.get(collectKey);
             if (CollectionUtils.isEmpty(serviceSubtaskList)) {
@@ -2613,7 +2675,9 @@
             if ("taskid".equals(groupKey)) {
                 applyTaskGroupInfo(statistic, serviceSubtaskList);
             }
-            if (ObjectUtils.isNotEmpty(jsRates)) {
+            if (jinyunHospital) {
+                statistic.setRate(calculateJinyunTimelyRate(statistic));
+            } else if (ObjectUtils.isNotEmpty(jsRates)) {
                 Map<String, Object> jsRateMap = jsRates.get(collectKey);
                 BigDecimal jsRate = new BigDecimal("0");
                 if (ObjectUtils.isNotEmpty(jsRateMap) && ObjectUtils.isNotEmpty(jsRateMap.get("rate"))) {
@@ -2718,6 +2782,23 @@
      */
     private long nvlLong(Long value) {
         return value == null ? 0L : value;
+    }
+
+    /**
+     * 缂欎簯鍘夸汉姘戝尰闄㈠強鏃剁巼锛氬強鏃堕殢璁夸汉娆� / 搴旈殢璁夸汉娆°��
+     * <p>
+     * 涓よ�呴兘鍙栬嚜鍚屼竴鏉$粺璁$粨鏋滐紝淇濊瘉椤甸潰涓婄殑鍙婃椂鐜囦笌杩欎袱鍒楀彲浠ヤ簰鐩搁獙绠椼��
+     * 搴旈殢璁夸汉娆′负 0 鏃惰繑鍥� 0锛屽墠绔寜 0.00% 灞曠ず銆�
+     */
+    private double calculateJinyunTimelyRate(ServiceSubtaskStatistic statistic) {
+        long followUpNeeded = nvlLong(statistic.getFollowUpNeeded());
+        if (followUpNeeded <= 0) {
+            return 0D;
+        }
+        long timelyFollowUp = nvlLong(statistic.getTimelyFollowUp());
+        return BigDecimal.valueOf(timelyFollowUp)
+                .divide(BigDecimal.valueOf(followUpNeeded), 4, RoundingMode.HALF_UP)
+                .doubleValue();
     }
 
     /**
@@ -3206,7 +3287,7 @@
     }
 
     /**
-     * 鍐嶆闅忚闄勫姞缁熻锛氬緟闅忚銆佸凡鍙戦�併�佷汉宸ョ數璇濊秴鏃跺強鍥為櫌澶嶈瘖澶嶆煡锛坰uggest=6锛夈��
+     * 鍐嶆闅忚闄勫姞缁熻锛氬緟闅忚銆佸凡鍙戦�併�佷汉宸ョ數璇濊秴鏃跺強鍥為櫌澶嶈瘖澶嶆煡锛坰uggest=7锛夈��
      */
     private void applyAgainFollowUpExtraStatistics(ServiceSubtaskStatistic statistic, ServiceSubtask serviceSubtask) {
         if (serviceSubtask.getVisitCount() == null || serviceSubtask.getVisitCount() <= 1) {
@@ -3216,9 +3297,9 @@
             return;
         }
         Long sendstate = serviceSubtask.getSendstate();
-        // 鍥為櫌澶嶈瘖澶嶆煡锛氬啀娆¢殢璁夸腑鎸夊鐞嗘剰瑙� suggest=6 缁熻
-        if (StringUtils.equals("6", StringUtils.trim(serviceSubtask.getSuggest()))) {
-            statistic.setSuggest6CountAgain(statistic.getSuggest6CountAgain() + 1L);
+        // 鍥為櫌澶嶈瘖澶嶆煡锛氬啀娆¢殢璁夸腑鎸夊鐞嗘剰瑙� suggest=7 缁熻
+        if (StringUtils.equals("7", StringUtils.trim(serviceSubtask.getSuggest()))) {
+            statistic.setSuggest7CountAgain(statistic.getSuggest7CountAgain() + 1L);
         }
         if (sendstate.equals(3L)) {
             statistic.setSentAgain(statistic.getSentAgain() + 1L);
@@ -3864,7 +3945,7 @@
      * pendingFollowUpSentAgainInfo - visitCount > 1 && sendstate in (3,7)
      * sentInfo - visitCount = 1 && sendstate = 3
      * sentAgainInfo - visitCount > 1 && sendstate = 3
-     * suggest6CountAgainInfo - visitCount > 1 && suggest = 6
+     * suggest7CountAgainInfo - visitCount > 1 && suggest = 7
      * filterCountList - taskSituation = 6 && sendstate = 4
      *
      */
@@ -4049,10 +4130,10 @@
                 serviceSubtaskCountReq.setVisitCount(2);
                 serviceSubtaskCountReq.setExcep("1");
                 break;
-            case "suggest6CountAgainInfo":
-                // 鍐嶆闅忚鍥為櫌澶嶈瘖澶嶆煡锛歷isitCount > 1 涓� suggest = 6
+            case "suggest7CountAgainInfo":
+                // 鍐嶆闅忚鍥為櫌澶嶈瘖澶嶆煡锛歷isitCount > 1 涓� suggest = 7
                 serviceSubtaskCountReq.setVisitCount(2);
-                serviceSubtaskCountReq.setSuggest("6");
+                serviceSubtaskCountReq.setSuggest("7");
                 break;
             case "taskSituation1Info":
                 serviceSubtaskCountReq.setTaskSituation(1);
@@ -4611,7 +4692,7 @@
         total.setSentAgain(0L);
         total.setFollowUpSuccessAgain(0L);
         total.setFollowUpFailAgain(0L);
-        total.setSuggest6CountAgain(0L);
+        total.setSuggest7CountAgain(0L);
         total.setManualAgain(0L);
         total.setSmsAgain(0L);
         total.setWeChatAgain(0L);
@@ -4656,7 +4737,7 @@
             total.setSentAgain(total.getSentAgain() + (stat.getSentAgain() != null ? stat.getSentAgain() : 0L));
             total.setFollowUpSuccessAgain(total.getFollowUpSuccessAgain() + (stat.getFollowUpSuccessAgain() != null ? stat.getFollowUpSuccessAgain() : 0L));
             total.setFollowUpFailAgain(total.getFollowUpFailAgain() + (stat.getFollowUpFailAgain() != null ? stat.getFollowUpFailAgain() : 0L));
-            total.setSuggest6CountAgain(total.getSuggest6CountAgain() + (stat.getSuggest6CountAgain() != null ? stat.getSuggest6CountAgain() : 0L));
+            total.setSuggest7CountAgain(total.getSuggest7CountAgain() + (stat.getSuggest7CountAgain() != null ? stat.getSuggest7CountAgain() : 0L));
             total.setManualAgain(total.getManualAgain() + (stat.getManualAgain() != null ? stat.getManualAgain() : 0L));
             total.setSmsAgain(total.getSmsAgain() + (stat.getSmsAgain() != null ? stat.getSmsAgain() : 0L));
             total.setWeChatAgain(total.getWeChatAgain() + (stat.getWeChatAgain() != null ? stat.getWeChatAgain() : 0L));

--
Gitblit v1.9.3