陈昶聿
9 天以前 4262e7819cb911f8109b4df82b8f80dfab1e72fe
smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -291,6 +291,36 @@
        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext}</if>
    </select>
    <!-- 即将超时过滤:是否即将超时(soonTimeout=1) + 即将超时时间(soonTimeoutHours,单位小时)。
         截止时间口径与 RyTask/RedisMqReceiver 的 isSubtaskDeadline 保持一致:
         service_subtask.endtime + service_task.send_day(缺省1) + (Σ service_subtask_preachform.compensate_time + 1) 天;
         仅当存在有效补偿记录时才计算截止时间(无补偿记录不参与即将超时);
         仅统计“尚未超时、且在 N 小时内将要超时”的数据。 -->
    <sql id="soonTimeoutDeadlineExpr">
        (
        SELECT DATE_ADD(
        DATE_ADD(ss.endtime, INTERVAL COALESCE(st.send_day, 1) DAY),
        INTERVAL (COALESCE(pf.compensate_days, 0) + 1) DAY
        )
        FROM service_subtask ss
        LEFT JOIN service_task st ON st.taskid = ss.taskid AND st.del_flag = '0'
        INNER JOIN (
        SELECT subid,
        SUM(CAST(COALESCE(NULLIF(TRIM(compensate_time), ''), '0') AS SIGNED)) AS compensate_days
        FROM service_subtask_preachform
        WHERE del_flag = 0
        GROUP BY subid
        ) pf ON pf.subid = ss.id
        WHERE ss.id = service_subtask.id
        )
    </sql>
    <sql id="soonTimeoutFilter">
        <if test="soonTimeout != null and soonTimeout == 1">
            AND <include refid="soonTimeoutDeadlineExpr"/> &gt; NOW()
            AND <include refid="soonTimeoutDeadlineExpr"/> &lt;= DATE_ADD(NOW(), INTERVAL COALESCE(#{soonTimeoutHours}, 0) HOUR)
        </if>
    </sql>
    <select id="selectServiceSubtaskList" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
            resultMap="ServiceSubtaskResult">
@@ -406,17 +436,21 @@
            </if>
        </if>
        <if test="deptOrDistrict==2">
            AND (1=1
            <if test="leavehospitaldistrictcodes != null">
                AND leavehospitaldistrictcode IN
            AND (
            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
                leavehospitaldistrictcode IN
                <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="("
                         separator=","
                         close=")">
                    #{leavehospitaldistrictcode}
                </foreach>
            </if>
            <if test=" leaveldeptcodes != null">
                OR deptcode IN
            <if test="(leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0)
                and (leaveldeptcodes != null and leaveldeptcodes.size() > 0)">
                OR
            </if>
            <if test=" leaveldeptcodes != null and leaveldeptcodes.size() > 0">
                deptcode IN
                <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
                         close=")">
                    #{leaveldeptcode}
@@ -525,6 +559,7 @@
                #{visitDeptCode}
            </foreach>
        </if>
        <include refid="soonTimeoutFilter"/>
        <if test="sort != null  and sort==0">order by endtime asc</if>
        <if test="sort != null  and sort==1">order by endtime desc</if>
        <if test="sort != null  and sort==2">order by visit_time asc</if>
@@ -534,7 +569,9 @@
        <if test="sort != null  and sort==7">order by visit_time asc</if>
        <if test="sort != null  and sort==8">order by visit_time desc</if>
        <if test="sort != null  and sort==9">order by sendname asc</if>
        <if test="pageSize != null  and pageNum != null">limit ${pageSize} OFFSET ${pageNum}</if>
        <if test="pageSize != null  and pageNum != null">
            LIMIT ${pageSize} OFFSET ${pageNum}
        </if>
    </select>
    <select id="selectSatisfactionSubtaskList" parameterType="com.smartor.domain.VO.PatSatisfactionReqVO"
@@ -692,6 +729,7 @@
        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
        <if test="continueCount != null ">and continue_count = #{continueCount}</if>
        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext}</if>
        <include refid="soonTimeoutFilter"/>
    </select>
    <select id="selectSendstateByCondition" parameterType="com.smartor.domain.ServiceSubtask" resultType="Integer">
@@ -738,6 +776,12 @@
        </if>
        <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
        <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if>
        <if test="startOutHospTime != null">
            AND date_format(endtime,'%y%m%d') &gt;= date_format(#{startOutHospTime},'%y%m%d')
        </if>
        <if test="endOutHospTime != null">
            AND date_format(endtime,'%y%m%d') &lt;= date_format(#{endOutHospTime},'%y%m%d')
        </if>
        ) a
    </select>
@@ -803,6 +847,12 @@
                     close=")">
                #{serviceType}
            </foreach>
        </if>
        <if test="startOutHospTime != null">
            AND date_format(ss.endtime,'%y%m%d') &gt;= date_format(#{startOutHospTime},'%y%m%d')
        </if>
        <if test="endOutHospTime != null">
            AND date_format(ss.endtime,'%y%m%d') &lt;= date_format(#{endOutHospTime},'%y%m%d')
        </if>
        <if test="groupKey != null and groupKey != ''">
            AND ss.${groupKey} IN
@@ -1557,7 +1607,8 @@
        continue_content,
        continue_count,
        continue_time_next,
        task_situation
        task_situation,
        is_manually_called
        from service_subtask
        where 1=1
        and del_flag = 0
@@ -1844,7 +1895,8 @@
        continue_count,
        continue_time_next,
        task_situation,
        remark
        remark,
        is_manually_called
        from service_subtask
        where 1=1
        and del_flag = 0
@@ -1930,6 +1982,9 @@
        </if>
        <if test="deptcode != null and deptcode != ''">
            AND deptcode = #{deptcode}
        </if>
        <if test="isManuallyCalled != null">
            AND is_manually_called = #{isManuallyCalled}
        </if>
        order by endtime desc
        <if test="pageSize != null  and pageNum != null">
@@ -2588,6 +2643,7 @@
        SUM(CASE WHEN sendstate != 2 THEN 1 ELSE 0 END) AS yfs,
        SUM(CASE WHEN sendstate = 2 THEN 1 ELSE 0 END) AS wfs,
        SUM(CASE WHEN sendstate = 6 THEN 1 ELSE 0 END) AS ywc,
        SUM(CASE WHEN sendstate = 7 THEN 1 ELSE 0 END) AS cs,
        SUM(CASE WHEN excep IS NOT NULL AND excep = '1' THEN 1 ELSE 0 END) AS yc,
        SUM(CASE WHEN excep IS NOT NULL AND excep = '2' THEN 1 ELSE 0 END) AS jg,
        COUNT(1) as total
@@ -2624,17 +2680,21 @@
            </if>
        </if>
        <if test="deptOrDistrict==2">
            AND (1=1
            AND (
            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
                AND leavehospitaldistrictcode IN
                leavehospitaldistrictcode IN
                <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="("
                         separator=","
                         close=")">
                    #{leavehospitaldistrictcode}
                </foreach>
            </if>
            <if test="(leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0)
                and (leaveldeptcodes != null and leaveldeptcodes.size() > 0)">
                OR
            </if>
            <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0">
                OR deptcode IN
                deptcode IN
                <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
                         close=")">
                    #{leaveldeptcode}
@@ -2820,32 +2880,73 @@
        COUNT(CASE WHEN sendstate = 5 THEN 1 END) AS failedVisitCount,
        SUM(CASE WHEN excep IS NOT NULL AND excep = '1' THEN 1 ELSE 0 END) AS abnormalVisitCount,
        SUM(CASE WHEN excep IS NOT NULL AND excep = '2' THEN 1 ELSE 0 END) AS warnningVisitCount,
        COUNT(*) AS allVisitCount
        FROM service_subtask
        WHERE del_flag = '0'
        AND service_type = '2'
        AND visit_count = 1
        COUNT(*) AS allVisitCount,
        <choose>
            <when test="soonTimeoutHours != null and soonTimeoutHours > 0">
                COUNT(CASE WHEN t.soon_deadline &gt; NOW()
                AND t.soon_deadline &lt;= DATE_ADD(NOW(), INTERVAL #{soonTimeoutHours} HOUR)
                THEN 1 END) AS soonTimeoutCount
            </when>
            <otherwise>
                0 AS soonTimeoutCount
            </otherwise>
        </choose>
        FROM (
        SELECT ss.*,
        <!-- 即将超时截止时间 = 出院时间(endtime) + 发送日(send_day, 缺省1) + 补偿天数(compensate_time 求和后再 +1 天),
             与 RyTask/RedisMqReceiver 的 isSubtaskDeadline 口径保持一致;
             无有效补偿记录(cp.subid 为空)时截止时间为 NULL,不参与即将超时统计 -->
        CASE
        WHEN cp.subid IS NULL THEN NULL
        ELSE DATE_ADD(
        DATE_ADD(ss.endtime, INTERVAL COALESCE(st.send_day, 1) DAY),
        INTERVAL (COALESCE(cp.compensate_days, 0) + 1) DAY
        )
        END AS soon_deadline
        FROM service_subtask ss
        LEFT JOIN service_task st ON st.taskid = ss.taskid AND st.del_flag = '0'
        <!-- 补偿时间:先按子任务聚合成一行再关联,避免一对多放大计数;
             compensate_time 是 varchar 且可能存成空串,需先置空再转数字 -->
        LEFT JOIN (
        SELECT subid,
        SUM(CAST(COALESCE(NULLIF(TRIM(compensate_time), ''), '0') AS SIGNED)) AS compensate_days
        FROM service_subtask_preachform
        WHERE del_flag = 0
        GROUP BY subid
        ) cp ON cp.subid = ss.id
        WHERE ss.del_flag = '0'
        AND ss.service_type = '2'
        AND ss.visit_count = 1
        <if test="orgid != null and orgid != ''">
            AND orgid = #{orgid}
            AND ss.orgid = #{orgid}
        </if>
        <if test="campusid != null and campusid != ''">
            and campusid = #{campusid}
            and ss.campusid = #{campusid}
        </if>
        <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
            AND leavehospitaldistrictcode IN
            <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="("
                     separator=","
                     close=")">
                #{leavehospitaldistrictcode}
            </foreach>
        <if test="(leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0)
                or (leaveldeptcodes != null and leaveldeptcodes.size() > 0)">
            AND (
            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
                ss.leavehospitaldistrictcode IN
                <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="("
                         separator=","
                         close=")">
                    #{leavehospitaldistrictcode}
                </foreach>
            </if>
            <if test="(leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0)
                and (leaveldeptcodes != null and leaveldeptcodes.size() > 0)">
                OR
            </if>
            <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0">
                ss.deptcode IN
                <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
                         close=")">
                    #{leaveldeptcode}
                </foreach>
            </if>)
        </if>
        <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0">
            AND deptcode IN
            <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
                     close=")">
                #{leaveldeptcode}
            </foreach>
        </if>
        ) t
    </select>
    <select id="querySendCount" parameterType="com.smartor.domain.entity.ServiceSubtaskSatisfactionEntity"