From 44f9b71dc492f1e60f33d18bc8d3c619da44618e Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期二, 24 十一月 2026 17:19:26 +0800
Subject: [PATCH] Merge branch 'smartor_ls_merge' into 20261118市一随访

---
 ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java |  166 ++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 128 insertions(+), 38 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 d716385..6ed84a4 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
@@ -2660,6 +2660,8 @@
                 continue;
             }
             ServiceSubtaskStatistic statistic = getStatistic(serviceSubtaskList, serviceSubtaskCountReq.getFollowUpCountStyle(), serviceSubtaskCountReq.getVisitCount());
+            // hzszlyy锛氬墠绔笉鏀瑰瓧娈碉紝鐩存帴鎶婄疮璁″�煎洖濉埌鍘� manual/voice/sms/weChat 鍙� Again 瀛楁
+            applySiteCumulativeOverride(statistic);
             if ("taskid".equals(groupKey)) {
                 applyTaskGroupInfo(statistic, serviceSubtaskList);
             }
@@ -3081,6 +3083,7 @@
                 }//浜屾鍑洪櫌闅忚
                 else if (serviceSubtask.getVisitCount() != null && serviceSubtask.getVisitCount() > 1) {
                     applyAgainFollowUpExtraStatistics(serviceSubtaskStatistic, serviceSubtask);
+                    applyAgainCumulativePreachformStatistics(serviceSubtaskStatistic, serviceSubtask, followUpCountStyle);
                     //鍐嶆搴旈殢璁�
                     if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() != 4) {
                         serviceSubtaskStatistic.setNeedFollowUpAgain(serviceSubtaskStatistic.getNeedFollowUpAgain() + 1L);
@@ -3301,6 +3304,17 @@
     /** 鍙戦�佹柟寮忕紪鐮侊細寰俊 */
     private static final String PREACHFORM_WECHAT = "5";
 
+    /** 绱浣嶅浘锛氳闊� */
+    private static final int CUMULATIVE_MASK_VOICE = 1;
+    /** 绱浣嶅浘锛氬井淇� */
+    private static final int CUMULATIVE_MASK_WECHAT = 1 << 1;
+    /** 绱浣嶅浘锛氱煭淇� */
+    private static final int CUMULATIVE_MASK_SMS = 1 << 2;
+    /** 绱浣嶅浘锛氫汉宸� */
+    private static final int CUMULATIVE_MASK_MANUAL = 1 << 3;
+    /** 闇�瑕佹妸绱鍊煎洖濉埌鍘熷瓧娈电殑绔欑偣 */
+    private static final String SITE_HZSZLYY = "hzszlyy";
+
     /**
      * 棣栨闅忚銆岀疮璁″彂閫佹柟寮忋�嶇粺璁°��
      * <p>
@@ -3330,42 +3344,101 @@
         if (!isCumulativePreachformCountable(serviceSubtask, followUpCountStyle)) {
             return;
         }
+        int mask = resolveCumulativePreachformMask(serviceSubtask);
+        if ((mask & CUMULATIVE_MASK_VOICE) != 0) {
+            statistic.setVoiceCumulative(statistic.getVoiceCumulative() + 1L);
+        }
+        if ((mask & CUMULATIVE_MASK_WECHAT) != 0) {
+            statistic.setWeChatCumulative(statistic.getWeChatCumulative() + 1L);
+        }
+        if ((mask & CUMULATIVE_MASK_SMS) != 0) {
+            statistic.setSmsCumulative(statistic.getSmsCumulative() + 1L);
+        }
+        if ((mask & CUMULATIVE_MASK_MANUAL) != 0) {
+            statistic.setManualCumulative(statistic.getManualCumulative() + 1L);
+        }
+    }
+
+    /**
+     * 鍐嶆闅忚銆岀疮璁″彂閫佹柟寮忋�嶇粺璁★紝鍙e緞涓� {@link #applyFirstCumulativePreachformStatistics} 涓�鑷淬��
+     */
+    private void applyAgainCumulativePreachformStatistics(ServiceSubtaskStatistic statistic,
+                                                          ServiceSubtask serviceSubtask,
+                                                          String followUpCountStyle) {
+        if (serviceSubtask.getVisitCount() == null || serviceSubtask.getVisitCount() <= 1) {
+            return;
+        }
+        if (!isCumulativePreachformCountable(serviceSubtask, followUpCountStyle)) {
+            return;
+        }
+        int mask = resolveCumulativePreachformMask(serviceSubtask);
+        if ((mask & CUMULATIVE_MASK_VOICE) != 0) {
+            statistic.setVoiceAgainCumulative(statistic.getVoiceAgainCumulative() + 1L);
+        }
+        if ((mask & CUMULATIVE_MASK_WECHAT) != 0) {
+            statistic.setWeChatAgainCumulative(statistic.getWeChatAgainCumulative() + 1L);
+        }
+        if ((mask & CUMULATIVE_MASK_SMS) != 0) {
+            statistic.setSmsAgainCumulative(statistic.getSmsAgainCumulative() + 1L);
+        }
+        if ((mask & CUMULATIVE_MASK_MANUAL) != 0) {
+            statistic.setManualAgainCumulative(statistic.getManualAgainCumulative() + 1L);
+        }
+    }
+
+    /**
+     * 璁$畻鏌愭潯瀛愪换鍔♀�滃凡杩涘叆杩団�濈殑鍙戦�佹柟寮忎綅鍥俱��
+     * <p>
+     * current_preachform 涓虹┖鍙栫涓�涓紱= -1 瑙嗕负鍏ㄩ儴閬嶅巻瀹岋紱涓嶅湪椤哄簭閲屾椂閫�鍖栦负绮剧‘鍖归厤銆�
+     */
+    private int resolveCumulativePreachformMask(ServiceSubtask serviceSubtask) {
         List<String> order = splitPreachformOrder(serviceSubtask.getPreachform());
         String current = StringUtils.isNotBlank(serviceSubtask.getCurrentPreachform())
                 ? serviceSubtask.getCurrentPreachform().trim()
                 : (order.isEmpty() ? null : order.get(0));
         if (order.isEmpty()) {
-            // 娌℃湁椤哄簭鏃堕��鍖栦负鈥滃綋鍓嶆柟寮忕簿纭尮閰嶁�濓紝涓� SQL 鐨� normalizedPreachformExpr = '' 鍒嗘敮涓�鑷�
-            if (current != null) {
-                increaseExactCumulative(statistic, current);
-            }
-            return;
+            return exactCumulativeMask(current);
         }
         int currentPosition;
         if ("-1".equals(current)) {
-            // -1 琛ㄧず鎵�鏈夊彂閫佹柟寮忛兘宸查亶鍘嗗畬锛岀浉褰撲簬鍋滃湪鏈�鍚庝竴涓綅缃�
             currentPosition = order.size();
         } else {
             int currentIndex = order.indexOf(current);
             if (currentIndex < 0) {
-                // 鍘嗗彶寮傚父鍊间笉鍦ㄩ厤缃『搴忛噷锛氬彧鎸夌簿纭尮閰嶅厹搴曪紝閬垮厤鎶婂墠鍚庢柟寮忛兘绠楄繘鍘�
-                increaseExactCumulative(statistic, current);
-                return;
+                return exactCumulativeMask(current);
             }
             currentPosition = currentIndex + 1;
         }
+        int mask = 0;
         if (reachedPreachform(order, PREACHFORM_VOICE, currentPosition)) {
-            statistic.setVoiceCumulative(statistic.getVoiceCumulative() + 1L);
+            mask |= CUMULATIVE_MASK_VOICE;
         }
         if (reachedPreachform(order, PREACHFORM_WECHAT, currentPosition)) {
-            statistic.setWeChatCumulative(statistic.getWeChatCumulative() + 1L);
+            mask |= CUMULATIVE_MASK_WECHAT;
         }
         if (reachedPreachform(order, PREACHFORM_SMS, currentPosition)) {
-            statistic.setSmsCumulative(statistic.getSmsCumulative() + 1L);
+            mask |= CUMULATIVE_MASK_SMS;
         }
         if (reachedPreachform(order, PREACHFORM_MANUAL, currentPosition)) {
-            statistic.setManualCumulative(statistic.getManualCumulative() + 1L);
+            mask |= CUMULATIVE_MASK_MANUAL;
         }
+        return mask;
+    }
+
+    private int exactCumulativeMask(String current) {
+        if (PREACHFORM_MANUAL.equals(current)) {
+            return CUMULATIVE_MASK_MANUAL;
+        }
+        if (PREACHFORM_VOICE.equals(current)) {
+            return CUMULATIVE_MASK_VOICE;
+        }
+        if (PREACHFORM_SMS.equals(current)) {
+            return CUMULATIVE_MASK_SMS;
+        }
+        if (PREACHFORM_WECHAT.equals(current)) {
+            return CUMULATIVE_MASK_WECHAT;
+        }
+        return 0;
     }
 
     private boolean isCumulativePreachformCountable(ServiceSubtask serviceSubtask, String followUpCountStyle) {
@@ -3400,15 +3473,39 @@
         return position >= 0 && currentPosition >= position + 1;
     }
 
-    private void increaseExactCumulative(ServiceSubtaskStatistic statistic, String current) {
-        if (PREACHFORM_MANUAL.equals(current)) {
-            statistic.setManualCumulative(statistic.getManualCumulative() + 1L);
-        } else if (PREACHFORM_VOICE.equals(current)) {
-            statistic.setVoiceCumulative(statistic.getVoiceCumulative() + 1L);
-        } else if (PREACHFORM_SMS.equals(current)) {
-            statistic.setSmsCumulative(statistic.getSmsCumulative() + 1L);
-        } else if (PREACHFORM_WECHAT.equals(current)) {
-            statistic.setWeChatCumulative(statistic.getWeChatCumulative() + 1L);
+    /**
+     * hzszlyy 绔欑偣淇濇寔鍓嶇瀛楁涓嶅彉锛氭妸绱鍊煎洖濉埌鍘� manual/voice/sms/weChat 鍙� Again 瀛楁銆�
+     * <p>
+     * 鍏跺畠绔欑偣涓嶈鐩栵紝缁х画浣跨敤鍘熸潵鐨勨�滃綋鍓嶆柟寮忕簿纭尮閰嶁�濆彛寰勩��
+     */
+    private void applySiteCumulativeOverride(ServiceSubtaskStatistic statistic) {
+        if (!SITE_HZSZLYY.equals(active)) {
+            return;
+        }
+        statistic.setManual(nvlLong(statistic.getManualCumulative()));
+        statistic.setVoice(nvlLong(statistic.getVoiceCumulative()));
+        statistic.setSms(nvlLong(statistic.getSmsCumulative()));
+        statistic.setWeChat(nvlLong(statistic.getWeChatCumulative()));
+        statistic.setManualAgain(nvlLong(statistic.getManualAgainCumulative()));
+        statistic.setVoiceAgain(nvlLong(statistic.getVoiceAgainCumulative()));
+        statistic.setSmsAgain(nvlLong(statistic.getSmsAgainCumulative()));
+        statistic.setWeChatAgain(nvlLong(statistic.getWeChatAgainCumulative()));
+    }
+
+    /**
+     * 瓒呴摼鎺ヤ笅閽荤殑鍙戦�佹柟寮忔潯浠躲��
+     * <p>
+     * hzszlyy 绔欑偣鐨勫墠绔笉鏀瑰瓧娈碉紝浠嶇偣鍘熸潵鐨� manualInfo/voiceInfo/...锛�
+     * 鍚庣鏀圭敤绱鍙e緞锛涘叾瀹冪珯鐐逛繚鎸� current_preachform 绮剧‘鍖归厤銆�
+     */
+    private void applyPreachformInfoCondition(ServiceSubtaskCountReq serviceSubtaskCountReq,
+                                              int visitCount,
+                                              String preachform) {
+        serviceSubtaskCountReq.setVisitCount(visitCount);
+        if (SITE_HZSZLYY.equals(active)) {
+            serviceSubtaskCountReq.setCumulativePreachform(preachform);
+        } else {
+            serviceSubtaskCountReq.setCurrentPreachform(preachform);
         }
     }
 
@@ -3627,6 +3724,7 @@
 
             //鍐嶆鍑洪櫌闅忚
             if (serviceSubtask.getVisitCount() != null && serviceSubtask.getVisitCount() > 1) {
+                applyAgainCumulativePreachformStatistics(serviceSubtaskStatistic, serviceSubtask, followUpCountStyle);
                 //鍐嶆搴旈殢璁�
                 if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() != 4) {
                     serviceSubtaskStatistic.setNeedFollowUpAgain(serviceSubtaskStatistic.getNeedFollowUpAgain() + 1L);
@@ -4131,20 +4229,16 @@
                 serviceSubtaskCountReq.setSendstates(new ArrayList<>(Arrays.asList(5L, 7L)));
                 break;
             case "manualInfo":
-                serviceSubtaskCountReq.setVisitCount(1);
-                serviceSubtaskCountReq.setCurrentPreachform("1");
+                applyPreachformInfoCondition(serviceSubtaskCountReq, 1, PREACHFORM_MANUAL);
                 break;
             case "voiceInfo":
-                serviceSubtaskCountReq.setVisitCount(1);
-                serviceSubtaskCountReq.setCurrentPreachform("3");
+                applyPreachformInfoCondition(serviceSubtaskCountReq, 1, PREACHFORM_VOICE);
                 break;
             case "smsInfo":
-                serviceSubtaskCountReq.setVisitCount(1);
-                serviceSubtaskCountReq.setCurrentPreachform("4");
+                applyPreachformInfoCondition(serviceSubtaskCountReq, 1, PREACHFORM_SMS);
                 break;
             case "weChatInfo":
-                serviceSubtaskCountReq.setVisitCount(1);
-                serviceSubtaskCountReq.setCurrentPreachform("5");
+                applyPreachformInfoCondition(serviceSubtaskCountReq, 1, PREACHFORM_WECHAT);
                 break;
             // 绱鍙e緞锛氭寜 preachform 鐨勬墽琛岄『搴忥紝current_preachform 浣嶄簬璇ユ柟寮忓強涔嬪悗鍗宠鍏�
             case "voiceCumulativeInfo":
@@ -4204,20 +4298,16 @@
                 serviceSubtaskCountReq.setSendstates(new ArrayList<>(Arrays.asList(5L, 7L)));
                 break;
             case "manualAgainInfo":
-                serviceSubtaskCountReq.setVisitCount(2);
-                serviceSubtaskCountReq.setCurrentPreachform("1");
+                applyPreachformInfoCondition(serviceSubtaskCountReq, 2, PREACHFORM_MANUAL);
                 break;
             case "voiceAgainInfo":
-                serviceSubtaskCountReq.setVisitCount(2);
-                serviceSubtaskCountReq.setCurrentPreachform("3");
+                applyPreachformInfoCondition(serviceSubtaskCountReq, 2, PREACHFORM_VOICE);
                 break;
             case "smsAgainInfo":
-                serviceSubtaskCountReq.setVisitCount(2);
-                serviceSubtaskCountReq.setCurrentPreachform("4");
+                applyPreachformInfoCondition(serviceSubtaskCountReq, 2, PREACHFORM_SMS);
                 break;
             case "weChatAgainInfo":
-                serviceSubtaskCountReq.setVisitCount(2);
-                serviceSubtaskCountReq.setCurrentPreachform("5");
+                applyPreachformInfoCondition(serviceSubtaskCountReq, 2, PREACHFORM_WECHAT);
                 break;
             case "manualAgainSuccessInfo":
                 serviceSubtaskCountReq.setVisitCount(1);

--
Gitblit v1.9.3