【丽水】随访统计加上 首次累计语音、首次累计微信、首次累计短信、首次累计人工
已修改5个文件
242 ■■■■■ 文件已修改
ruoyi-task/src/main/java/com/ruoyi/task/controller/ServiceSubtaskController.java 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskCountReq.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskStatistic.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java 152 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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
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正常语音,2患者拒接或拒访,3面访或者接诊,4微信随访,5随访电话不正确,6被过滤,7其它")
ruoyi-task/src/main/java/com/ruoyi/task/domain/ServiceSubtaskStatistic.java
@@ -256,6 +256,26 @@
    @Excel(name = " 首次微信 ")
    private Long weChat = 0L;
    /**
     * 累计口径:按 {@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;
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 保存的
     * 顺序推算:current_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>
     * 约定:current_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;
            // 累计口径:按 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));
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'">
            <!-- 注意:OGNL 里单引号 '1' 是 Character,String 与之用 = 比较会得到非 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 口径一致:
            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}