From 55e93b41edeadeda8ba62a1d999491d75acb91e8 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期三, 18 十一月 2026 16:27:19 +0800
Subject: [PATCH] 【丽水】随访统计加上 首次累计语音、首次累计微信、首次累计短信、首次累计人工

---
 ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskStatistic.java         |   20 ++++
 ruoyi-task/src/main/java/com/ruoyi/task/controller/ServiceSubtaskController.java    |    4 
 ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java |  152 ++++++++++++++++++++++++++++++
 ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml                  |   56 +++++++++++
 ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskCountReq.java          |   10 ++
 5 files changed, 241 insertions(+), 1 deletions(-)

diff --git a/ruoyi-task/src/main/java/com/ruoyi/task/controller/ServiceSubtaskController.java b/ruoyi-task/src/main/java/com/ruoyi/task/controller/ServiceSubtaskController.java
index 33da528..3018f8f 100644
--- a/ruoyi-task/src/main/java/com/ruoyi/task/controller/ServiceSubtaskController.java
+++ b/ruoyi-task/src/main/java/com/ruoyi/task/controller/ServiceSubtaskController.java
@@ -852,6 +852,10 @@
      * smsSuccessInfo - visitCount = 1 && currentPreachForm = "4" && sendstate = 6
      * wechatSuccessInfo - visitCount = 1 && currentPreachForm = "5" && sendstate = 6
      * wechatInfo - visitCount = 1 && currentPreachForm = "5"
+     * voiceCumulativeInfo - visitCount = 1 && currentPreachForm 浣嶄簬 preachform 椤哄簭涓殑璇煶鍙婁箣鍚�
+     * weChatCumulativeInfo - visitCount = 1 && currentPreachForm 浣嶄簬 preachform 椤哄簭涓殑寰俊鍙婁箣鍚�
+     * smsCumulativeInfo - visitCount = 1 && currentPreachForm 浣嶄簬 preachform 椤哄簭涓殑鐭俊鍙婁箣鍚�
+     * manualCumulativeInfo - visitCount = 1 && currentPreachForm 浣嶄簬 preachform 椤哄簭涓殑浜哄伐鍙婁箣鍚�
      * abnormalInfo - visitCount = 1 && excep = "1"
      * needFollowUpAgainInfo - visitCount > 1 && sendstate != 4
      * pendingFollowUpAgainInfo -  visitCount > 1 && sendstate = 2
diff --git a/ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskCountReq.java b/ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskCountReq.java
index 9204983..7ec900e 100644
--- a/ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskCountReq.java
+++ b/ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskCountReq.java
@@ -286,6 +286,16 @@
     private String currentPreachform;
 
     /**
+     * 绱鍙戦�佹柟寮忕紪鐮� - 瓒呴摼鎺ョ粺璁°��
+     * <p>
+     * 1=浜哄伐銆�3=璇煶銆�4=鐭俊銆�5=寰俊銆備笌 currentPreachform 鐨勭瓑鍊艰繃婊や笉鍚岋紝
+     * 璇ユ潯浠舵寜 service_subtask.preachform 淇濆瓨鐨勬墽琛岄『搴忓垽鏂細
+     * 鍙 current_preachform 浣嶄簬璇ユ柟寮忓強鍏朵箣鍚庯紝灏辫涓鸿鏂瑰紡宸茶繘鍏ヨ繃銆�
+     */
+    @ApiModelProperty(value = "绱鍙戦�佹柟寮忕紪鐮侊細1浜哄伐 3璇煶 4鐭俊 5寰俊")
+    private String cumulativePreachform;
+
+    /**
      * 闅忚鎯呭喌 - 瓒呴摼鎺ョ粺璁�
      */
     @ApiModelProperty(value = "闅忚鎯呭喌:1姝e父璇煶,2鎮h�呮嫆鎺ユ垨鎷掕,3闈㈣鎴栬�呮帴璇�,4寰俊闅忚,5闅忚鐢佃瘽涓嶆纭�,6琚繃婊�,7鍏跺畠")
diff --git a/ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskStatistic.java b/ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskStatistic.java
index a7eca77..79084b2 100644
--- a/ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskStatistic.java
+++ b/ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskStatistic.java
@@ -256,6 +256,26 @@
     @Excel(name = " 棣栨寰俊 ")
     private Long weChat = 0L;
 
+    /**
+     * 绱鍙e緞锛氭寜 {@code service_subtask.preachform} 淇濆瓨鐨勬墽琛岄『搴忔帹绠楋紝
+     * current_preachform 浣嶄簬璇煶鍙婁箣鍚庡嵆璁″叆銆備笌 {@link #voice} 鐨勨�滃綋鍓嶆柟寮�=璇煶鈥濆彛寰勪笉鍚屻��
+     */
+    @ApiModelProperty(value = "棣栨绱璇煶鍙戦�佹暟")
+    @Excel(name = " 棣栨绱璇煶 ")
+    private Long voiceCumulative = 0L;
+
+    @ApiModelProperty(value = "棣栨绱寰俊鍙戦�佹暟")
+    @Excel(name = " 棣栨绱寰俊 ")
+    private Long weChatCumulative = 0L;
+
+    @ApiModelProperty(value = "棣栨绱鐭俊鍙戦�佹暟")
+    @Excel(name = " 棣栨绱鐭俊 ")
+    private Long smsCumulative = 0L;
+
+    @ApiModelProperty(value = "棣栨绱浜哄伐鍙戦�佹暟")
+    @Excel(name = " 棣栨绱浜哄伐 ")
+    private Long manualCumulative = 0L;
+
     @ApiModelProperty(value = "棣栨浜哄伐鎴愬姛")
     @Excel(name = " 棣栨浜哄伐鎴愬姛 ")
     private Long manualSuccess = 0L;
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 897f1a9..d716385 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
@@ -2958,6 +2958,7 @@
                 //棣栨鍑洪櫌闅忚
                 if (serviceSubtask.getVisitCount() != null && serviceSubtask.getVisitCount() == 1) {
                     applyFirstFollowUpExtraStatistics(serviceSubtaskStatistic, serviceSubtask);
+                    applyFirstCumulativePreachformStatistics(serviceSubtaskStatistic, serviceSubtask, followUpCountStyle);
                     //棣栨搴旈殢璁�
                     if (serviceSubtask.getSendstate() != null && !serviceSubtask.getSendstate().equals(4L)) {
                         serviceSubtaskStatistic.setNeedFollowUp(serviceSubtaskStatistic.getNeedFollowUp() + 1L);
@@ -3291,6 +3292,126 @@
         return serviceSubtask.getIsManuallyCalled() != null && serviceSubtask.getIsManuallyCalled().equals(0L);
     }
 
+    /** 鍙戦�佹柟寮忕紪鐮侊細浜哄伐 */
+    private static final String PREACHFORM_MANUAL = "1";
+    /** 鍙戦�佹柟寮忕紪鐮侊細璇煶 */
+    private static final String PREACHFORM_VOICE = "3";
+    /** 鍙戦�佹柟寮忕紪鐮侊細鐭俊 */
+    private static final String PREACHFORM_SMS = "4";
+    /** 鍙戦�佹柟寮忕紪鐮侊細寰俊 */
+    private static final String PREACHFORM_WECHAT = "5";
+
+    /**
+     * 棣栨闅忚銆岀疮璁″彂閫佹柟寮忋�嶇粺璁°��
+     * <p>
+     * 鍘熷彛寰勫彧鐪� current_preachform 绛変簬鏌愪釜鏂瑰紡锛氫緥濡� current_preachform=5锛堝井淇★級鏃讹紝
+     * 鍓嶉潰宸茬粡鎵ц杩囩殑璇煶涓嶅啀璁″叆璇煶鏁般�傛湰鏂规硶鎸� service_subtask.preachform 淇濆瓨鐨�
+     * 椤哄簭鎺ㄧ畻锛歝urrent_preachform 鍦ㄩ『搴忎腑鐨勪綅缃箣鍓嶇殑鍙戦�佹柟寮忥紝閮界畻鈥滅疮璁″凡杩涘叆杩団�濄��
+     * <p>
+     * 渚嬶細preachform = 3,5,4,1锛堣闊斥啋寰俊鈫掔煭淇♀啋浜哄伐锛夛細
+     * <ul>
+     *   <li>current=3锛氱疮璁¤闊�=1锛涘井淇�/鐭俊/浜哄伐=0</li>
+     *   <li>current=5锛氱疮璁¤闊�=1銆佸井淇�=1锛涚煭淇�/浜哄伐=0</li>
+     *   <li>current=4锛氱疮璁¤闊�=1銆佸井淇�=1銆佺煭淇�=1锛涗汉宸�=0</li>
+     *   <li>current=1锛氬洓椤归兘=1</li>
+     * </ul>
+     * 绾﹀畾锛歝urrent_preachform 涓虹┖鏃跺彇 preachform 绗竴涓柟寮忥紱current_preachform=-1 鏃舵寜
+     * 鏈�鍚庝竴涓綅缃鐞嗭紱current_preachform 涓嶅湪椤哄簭涓椂鍙仛绮剧‘鍖归厤鍏滃簳锛岄伩鍏嶅巻鍙茶剰鏁版嵁璇畻銆�
+     * <p>
+     * sendstate 杩囨护涓庡師鏈� manual/voice/sms/weChat 淇濇寔涓�鑷达細
+     * followUpCountStyle=1 鎺掗櫎 sendstate=4锛�=3 鍙粺璁� sendstate=6锛涘叾瀹冪粺璁℃墍鏈夐潪绌� sendstate銆�
+     */
+    private void applyFirstCumulativePreachformStatistics(ServiceSubtaskStatistic statistic,
+                                                          ServiceSubtask serviceSubtask,
+                                                          String followUpCountStyle) {
+        if (serviceSubtask.getVisitCount() == null || serviceSubtask.getVisitCount() != 1) {
+            return;
+        }
+        if (!isCumulativePreachformCountable(serviceSubtask, followUpCountStyle)) {
+            return;
+        }
+        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;
+        }
+        int currentPosition;
+        if ("-1".equals(current)) {
+            // -1 琛ㄧず鎵�鏈夊彂閫佹柟寮忛兘宸查亶鍘嗗畬锛岀浉褰撲簬鍋滃湪鏈�鍚庝竴涓綅缃�
+            currentPosition = order.size();
+        } else {
+            int currentIndex = order.indexOf(current);
+            if (currentIndex < 0) {
+                // 鍘嗗彶寮傚父鍊间笉鍦ㄩ厤缃『搴忛噷锛氬彧鎸夌簿纭尮閰嶅厹搴曪紝閬垮厤鎶婂墠鍚庢柟寮忛兘绠楄繘鍘�
+                increaseExactCumulative(statistic, current);
+                return;
+            }
+            currentPosition = currentIndex + 1;
+        }
+        if (reachedPreachform(order, PREACHFORM_VOICE, currentPosition)) {
+            statistic.setVoiceCumulative(statistic.getVoiceCumulative() + 1L);
+        }
+        if (reachedPreachform(order, PREACHFORM_WECHAT, currentPosition)) {
+            statistic.setWeChatCumulative(statistic.getWeChatCumulative() + 1L);
+        }
+        if (reachedPreachform(order, PREACHFORM_SMS, currentPosition)) {
+            statistic.setSmsCumulative(statistic.getSmsCumulative() + 1L);
+        }
+        if (reachedPreachform(order, PREACHFORM_MANUAL, currentPosition)) {
+            statistic.setManualCumulative(statistic.getManualCumulative() + 1L);
+        }
+    }
+
+    private boolean isCumulativePreachformCountable(ServiceSubtask serviceSubtask, String followUpCountStyle) {
+        if (serviceSubtask.getSendstate() == null) {
+            return false;
+        }
+        if ("1".equals(followUpCountStyle)) {
+            return !Long.valueOf(4L).equals(serviceSubtask.getSendstate());
+        }
+        if ("3".equals(followUpCountStyle)) {
+            return Long.valueOf(6L).equals(serviceSubtask.getSendstate());
+        }
+        return true;
+    }
+
+    /**
+     * 鎷嗗垎 preachform 鎵ц椤哄簭銆傚吋瀹硅嫳鏂囬�楀彿銆佷腑鏂囬�楀彿鍜岀┖鏍硷紝鍘婚噸骞朵繚鎸佸師椤哄簭銆�
+     */
+    private List<String> splitPreachformOrder(String preachform) {
+        if (StringUtils.isEmpty(preachform)) {
+            return Collections.emptyList();
+        }
+        return Arrays.stream(preachform.split("[,锛宂"))
+                .map(String::trim)
+                .filter(StringUtils::isNotEmpty)
+                .distinct()
+                .collect(Collectors.toList());
+    }
+
+    private boolean reachedPreachform(List<String> order, String preachform, int currentPosition) {
+        int position = order.indexOf(preachform);
+        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);
+        }
+    }
+
     /**
      * 棣栨闅忚缁熻
      *
@@ -3331,6 +3452,7 @@
 
             //棣栨鍑洪櫌闅忚
             if (serviceSubtask.getVisitCount() != null && serviceSubtask.getVisitCount() == 1) {
+                applyFirstCumulativePreachformStatistics(serviceSubtaskStatistic, serviceSubtask, followUpCountStyle);
                 //棣栨搴旈殢璁�
                 if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() != 4) {
                     serviceSubtaskStatistic.setNeedFollowUp(serviceSubtaskStatistic.getNeedFollowUp() + 1L);
@@ -3883,6 +4005,10 @@
      * voiceSuccessInfo - visitCount = 1 && currentPreachForm = "3" && sendstate = 6
      * smsSuccessInfo - visitCount = 1 && currentPreachForm = "4" && sendstate = 6
      * wechatSuccessInfo - visitCount = 1 && currentPreachForm = "5" && sendstate = 6
+     * voiceCumulativeInfo - visitCount = 1 && currentPreachForm 浣嶄簬 preachform 椤哄簭涓殑璇煶鍙婁箣鍚�
+     * weChatCumulativeInfo - visitCount = 1 && currentPreachForm 浣嶄簬 preachform 椤哄簭涓殑寰俊鍙婁箣鍚�
+     * smsCumulativeInfo - visitCount = 1 && currentPreachForm 浣嶄簬 preachform 椤哄簭涓殑鐭俊鍙婁箣鍚�
+     * manualCumulativeInfo - visitCount = 1 && currentPreachForm 浣嶄簬 preachform 椤哄簭涓殑浜哄伐鍙婁箣鍚�
      * abnormalInfo - visitCount = 1 && excep = "1"
      * needFollowUpAgainInfo - visitCount > 1 && sendstate != 4
      * pendingFollowUpAgainInfo -  visitCount > 1 && sendstate = 2
@@ -3952,6 +4078,7 @@
         serviceSubtaskCountReq.setVisitCount(null);
         serviceSubtaskCountReq.setSendstates(null);
         serviceSubtaskCountReq.setCurrentPreachform(null);
+        serviceSubtaskCountReq.setCumulativePreachform(null);
         serviceSubtaskCountReq.setExcep(null);
         serviceSubtaskCountReq.setTaskSituation(null);
         serviceSubtaskCountReq.setFinishState(null);
@@ -4018,6 +4145,23 @@
             case "weChatInfo":
                 serviceSubtaskCountReq.setVisitCount(1);
                 serviceSubtaskCountReq.setCurrentPreachform("5");
+                break;
+            // 绱鍙e緞锛氭寜 preachform 鐨勬墽琛岄『搴忥紝current_preachform 浣嶄簬璇ユ柟寮忓強涔嬪悗鍗宠鍏�
+            case "voiceCumulativeInfo":
+                serviceSubtaskCountReq.setVisitCount(1);
+                serviceSubtaskCountReq.setCumulativePreachform("3");
+                break;
+            case "weChatCumulativeInfo":
+                serviceSubtaskCountReq.setVisitCount(1);
+                serviceSubtaskCountReq.setCumulativePreachform("5");
+                break;
+            case "smsCumulativeInfo":
+                serviceSubtaskCountReq.setVisitCount(1);
+                serviceSubtaskCountReq.setCumulativePreachform("4");
+                break;
+            case "manualCumulativeInfo":
+                serviceSubtaskCountReq.setVisitCount(1);
+                serviceSubtaskCountReq.setCumulativePreachform("1");
                 break;
             case "manualSuccessInfo":
                 serviceSubtaskCountReq.setVisitCount(1);
@@ -4646,6 +4790,10 @@
         total.setManual(0L);
         total.setSms(0L);
         total.setWeChat(0L);
+        total.setVoiceCumulative(0L);
+        total.setWeChatCumulative(0L);
+        total.setSmsCumulative(0L);
+        total.setManualCumulative(0L);
         total.setAbnormal(0L);
         total.setNeedFollowUpAgain(0L);
         total.setPendingFollowUpAgain(0L);
@@ -4691,6 +4839,10 @@
             total.setManual(total.getManual() + (stat.getManual() != null ? stat.getManual() : 0L));
             total.setSms(total.getSms() + (stat.getSms() != null ? stat.getSms() : 0L));
             total.setWeChat(total.getWeChat() + (stat.getWeChat() != null ? stat.getWeChat() : 0L));
+            total.setVoiceCumulative(total.getVoiceCumulative() + (stat.getVoiceCumulative() != null ? stat.getVoiceCumulative() : 0L));
+            total.setWeChatCumulative(total.getWeChatCumulative() + (stat.getWeChatCumulative() != null ? stat.getWeChatCumulative() : 0L));
+            total.setSmsCumulative(total.getSmsCumulative() + (stat.getSmsCumulative() != null ? stat.getSmsCumulative() : 0L));
+            total.setManualCumulative(total.getManualCumulative() + (stat.getManualCumulative() != null ? stat.getManualCumulative() : 0L));
             total.setAbnormal(total.getAbnormal() + (stat.getAbnormal() != null ? stat.getAbnormal() : 0L));
             total.setNeedFollowUpAgain(total.getNeedFollowUpAgain() + (stat.getNeedFollowUpAgain() != null ? stat.getNeedFollowUpAgain() : 0L));
             total.setPendingFollowUpAgain(total.getPendingFollowUpAgain() + (stat.getPendingFollowUpAgain() != null ? stat.getPendingFollowUpAgain() : 0L));
diff --git a/ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml b/ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml
index 93d3c3d..77253b8 100644
--- a/ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml
+++ b/ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml
@@ -358,6 +358,17 @@
         COALESCE(NULLIF(TRIM(current_preachform), ''), TRIM(SUBSTRING_INDEX(preachform, ',', 1)))
     </sql>
 
+    <!-- 绱鍙戦�佹柟寮忕粺璁$敤锛氬綊涓�鍖� preachform 椤哄簭锛堝幓绌烘牸銆佺粺涓�涓枃閫楀彿锛� -->
+    <sql id="normalizedPreachformExpr">
+        REPLACE(REPLACE(IFNULL(preachform, ''), ' ', ''), '锛�', ',')
+    </sql>
+
+    <!-- 绱鍙戦�佹柟寮忕粺璁$敤锛氬綊涓�鍖栧悗鐨勬湁鏁� current_preachform锛堜负绌烘椂鍙� preachform 绗竴涓級 -->
+    <sql id="normalizedEffectiveCurrentPreachformExpr">
+        COALESCE(NULLIF(TRIM(current_preachform), ''),
+                 TRIM(SUBSTRING_INDEX(<include refid="normalizedPreachformExpr"/>, ',', 1)))
+    </sql>
+
     <select id="selectServiceSubtaskBySendstate" parameterType="com.ruoyi.task.domain.entity.ServiceSubtaskEntity"
             resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
@@ -2873,9 +2884,52 @@
         </if>
         <if test="currentPreachform != null and currentPreachform != '' ">
             AND <include refid="effectiveCurrentPreachformExpr"/> = #{currentPreachform}
-            <if test="followUpCountStyle != null and followUpCountStyle = '1'">
+            <!-- 娉ㄦ剰锛歄GNL 閲屽崟寮曞彿 '1' 鏄� Character锛孲tring 涓庝箣鐢� = 姣旇緝浼氬緱鍒伴潪 0 鏁板瓧锛堟亽鐪燂級锛屽繀椤荤敤 =="1" -->
+            <if test='followUpCountStyle != null and followUpCountStyle == "1"'>
                 AND sendstate != 4
             </if>
+            <if test='followUpCountStyle != null and followUpCountStyle == "3"'>
+                AND sendstate = 6
+            </if>
+        </if>
+        <!--
+          绱鍙戦�佹柟寮忎笅閽伙細
+          preachform 鏄墽琛岄『搴忥紙濡� 3,5,4,1锛夛紝current_preachform 鏄綋鍓嶆墽琛屽埌鐨勪綅缃��
+          鑻ヨ鍦ㄢ�滆闊斥�濅笅閽伙紝鍒� current 浣嶄簬璇煶鍙婁箣鍚庣殑鎵�鏈夎閮借杩斿洖銆�
+          浠ヤ笅鏉′欢涓� ServiceSubtaskServiceImpl#applyFirstCumulativePreachformStatistics 鍙e緞涓�鑷达細
+            current 涓虹┖   -> 鎸� preachform 绗竴涓柟寮�
+            current = -1   -> 鎸夋渶鍚庝竴涓綅缃紙鍏ㄩ儴鏂瑰紡閮借繘鍏ヨ繃锛�
+            current 涓嶅湪椤哄簭涓� -> 鍙仛绮剧‘鍖归厤鍏滃簳
+        -->
+        <if test="cumulativePreachform != null and cumulativePreachform != ''">
+            AND (
+                CASE
+                    WHEN <include refid="normalizedPreachformExpr"/> = '' THEN
+                        <include refid="normalizedEffectiveCurrentPreachformExpr"/> = #{cumulativePreachform}
+
+                    WHEN <include refid="normalizedEffectiveCurrentPreachformExpr"/> = '-1' THEN
+                        FIND_IN_SET(#{cumulativePreachform},
+                            <include refid="normalizedPreachformExpr"/>) &gt; 0
+
+                    WHEN FIND_IN_SET(<include refid="normalizedEffectiveCurrentPreachformExpr"/>,
+                            <include refid="normalizedPreachformExpr"/>) = 0 THEN
+                        <include refid="normalizedEffectiveCurrentPreachformExpr"/> = #{cumulativePreachform}
+
+                    ELSE
+                        FIND_IN_SET(#{cumulativePreachform},
+                            <include refid="normalizedPreachformExpr"/>) &gt; 0
+                        AND FIND_IN_SET(#{cumulativePreachform},
+                            <include refid="normalizedPreachformExpr"/>)
+                            &lt;= FIND_IN_SET(<include refid="normalizedEffectiveCurrentPreachformExpr"/>,
+                            <include refid="normalizedPreachformExpr"/>)
+                END
+            )
+            <if test='followUpCountStyle != null and followUpCountStyle == "1"'>
+                AND sendstate != 4
+            </if>
+            <if test='followUpCountStyle != null and followUpCountStyle == "3"'>
+                AND sendstate = 6
+            </if>
         </if>
         <if test="excep != null and excep != ''">
             AND excep = #{excep}

--
Gitblit v1.9.3