陈昶聿
2 天以前 44f9b71dc492f1e60f33d18bc8d3c619da44618e
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"/>
@@ -2130,10 +2141,28 @@
        where 1=1
        and a.del_flag = '0'
        and b.del_flag = '0'
        and a.appltype = '3'
        <!-- 专病统计:单病种任务(appltype=3) + 专病任务组(appltype=5) -->
        and (
            a.appltype = '3'
            or (
                a.appltype = '5'
                and (
                    a.hosp_type = '3'
                    or (a.diag_type is not null and a.diag_type &lt;&gt; '')
                    or exists (
                        select 1
                        from service_task_schedule s
                        where s.taskid = a.taskid
                          and s.del_flag = '0'
                          and s.icd10_codes is not null
                          and s.icd10_codes &lt;&gt; ''
                    )
                )
            )
        )
        <if test="orgid != null and orgid != ''">and a.orgid = #{orgid}</if>
        <if test="campusid != null and campusid != ''">and b.campusid = #{campusid}</if>
        <if test="taskId != null">and a.task_id = #{taskId}</if>
        <if test="taskId != null">and a.taskid = #{taskId}</if>
        <if test="taskName != null and taskName != ''">
            and a.task_name like concat('%', #{taskName}, '%')
        </if>
@@ -2141,7 +2170,7 @@
            and a.diag_type = #{diagType}
        </if>
        <if test="taskIds != null and taskIds.size() > 0">
            AND a.task_id IN
            AND a.taskid IN
            <foreach collection="taskIds" item="taskIdItem" open="(" separator=","
                     close=")">
                #{taskIdItem}
@@ -2873,9 +2902,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}