陈昶聿
7 小时以前 38955eba4ef0e86bac6b1993b6b03abbbec2a929
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"/>
@@ -1013,7 +1024,9 @@
        ), '%y%m%d' ) )
        THEN 1 ELSE 0 END ) finished,1 AS tasknumber FROM service_subtask
        WHERE del_flag=0
        <if test="starttime == null and endtime==null">
        <!-- 只有未指定任何时间范围时才默认只统计已到期任务;
             只按出院时间查询时不能再排除未来 visit_time,否则及时率分母与主表不一致。 -->
        <if test="starttime == null and endtime == null and startOutHospTime == null and endOutHospTime == null">
            AND visit_time &lt; NOW()
        </if>
        <if test="starttime != null and endtime!=null">
@@ -1105,7 +1118,9 @@
        WHERE ss.del_flag = 0
        AND ss.visit_time IS NOT NULL
        AND ss.sendstate != 4
        <if test="starttime == null and endtime==null">
        <!-- 只有未指定任何时间范围时才默认只统计已到期任务;
             只按出院时间查询时不能再排除未来 visit_time,否则及时率分母与主表不一致。 -->
        <if test="starttime == null and endtime == null and startOutHospTime == null and endOutHospTime == null">
            AND DATE(ss.visit_time) &lt; DATE(NOW())
        </if>
        <if test="starttime != null and endtime!=null">
@@ -2891,9 +2906,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}