From c4dc6a5d66524d08b768046d9d2d5974bf96f45c Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期三, 11 十一月 2026 14:06:23 +0800
Subject: [PATCH] Merge branch 'smartor_ls_261103' into smartor_ls_merge

---
 ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml |  388 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 335 insertions(+), 53 deletions(-)

diff --git a/ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml b/ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml
index c9b4b74..5a56e4d 100644
--- a/ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml
+++ b/ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml
@@ -108,6 +108,9 @@
         <result property="loopCount" column="loop_count"/>
         <result property="isManuallyCalled" column="is_manually_called"/>
         <result property="campusid" column="campusid"/>
+        <result property="diagType" column="diag_type"/>
+        <!-- 2026-11锛氶噸瑕佹�ф爣璁扮紪鐮侊紙鏃ラ棿鎵嬫湳/鏃ラ棿璇婄枟/鏃犫�︼級锛屽缓浠诲姟鏃跺彇鑷� pat_med_inhosp -->
+        <result property="importanceFlagCode" column="importance_flag_code"/>
     </resultMap>
 
     <resultMap type="com.ruoyi.task.domain.ServiceSubtaskCount" id="ServiceSubtaskResult2">
@@ -243,6 +246,7 @@
                hospitaldistrictname,
                deptcode,
                deptname,
+               importance_flag_code,
                stop_state,
                leavehospitaldistrictcode,
                leavehospitaldistrictname,
@@ -266,50 +270,61 @@
     </sql>
 
     <!-- 瓒呮椂瀹屾垚銆佸欢鏈熷畬鎴愰�昏緫 瀹屾垚鏃剁姸鎬�(finish_state)璁$畻锛氫粎褰撴湰娆℃洿鏂版妸 sendstate 缃负 6锛堥殢璁垮畬鎴愶級鏃朵娇鐢ㄣ��
-         鍩哄噯鎴鏃堕棿 base = endtime + send_day(缂虹渷1) + (危 service_subtask_preachform.compensate_time + 1) 澶╋紝
-         涓� RyTask/RedisMqReceiver 鐨� isSubtaskDeadline 鍙e緞淇濇寔涓�鑷达紱
+         鍩哄噯鎴鏃堕棿 base锛�
+           闈炰换鍔$粍(appltype != 5)锛歟ndtime + send_day(缂虹渷1) + (危 service_subtask_preachform.compensate_time + 1) 澶╋紱
+           浠诲姟缁�(appltype = 5)锛氭寜 schedule_benchmark 瑙f瀽鍩哄噯鏃堕棿
+                                   (1-鍏ラ櫌 2-鍑洪櫌 3-灏辫瘖 4-鍏ョ粍 0/鍏跺畠-鑷畾涔夋椂闂�)
+                                   + day_offset + (危 compensate_time + 1) 澶╋紙涓嶅彔鍔� send_day锛夛紱
+         涓� RyTask/RedisMqReceiver 鐨� isSubtaskDeadline銆乻electTimelyRateBatch 鍙e緞淇濇寔涓�鑷达紱
          delay = COALESCE(service_task.delay_finish_days, 0)锛�
          finish_time = COALESCE(鍏ュ弬 finishtime, 搴撲腑 finishtime, NOW())锛�
            finish_time <= base                                    -> 1 姝e父瀹屾垚
            delay > 0 涓� finish_time <= base + delay               -> 2 寤舵湡瀹屾垚
            鍏朵綑锛堝惈 delay 涓� 0 鎴� NULL銆佹垨宸茶秴鍑哄欢鏈熺獥鍙o級          -> 3 瓒呮椂瀹屾垚
          finishtime 涓虹┖鏃剁敤 NOW() 鍏滃簳锛屼繚璇佸畬鎴愭椂涓�瀹氬啓鍏ョ姸鎬侊紱
-         浠呭綋 endtime 涓虹┖瀵艰嚧鏃犳硶璁$畻鏃舵墠淇濇寔鍘熷�间笉瑕嗙洊銆� -->
-    <sql id="finishStateExpr">
+         base 涓虹┖锛坋ndtime / schedule / day_offset 缂哄け锛夋椂淇濇寔鍘熷�间笉瑕嗙洊銆� -->
+    <sql id="finishDeadlineExpr">
+        DATE_ADD(
         CASE
-        WHEN service_subtask.endtime IS NULL THEN finish_state
+            WHEN COALESCE(st.appltype, '') = '5' THEN
+                DATE_ADD(
+                CASE sts.schedule_benchmark
+                    WHEN 1 THEN service_subtask.starttime
+                    WHEN 2 THEN service_subtask.endtime
+                    WHEN 3 THEN service_subtask.admindate
+                    WHEN 4 THEN service_subtask.create_time
+                    ELSE sts.schedule_benchmark_custom_time
+                END,
+                INTERVAL std.day_offset DAY)
+            ELSE
+                DATE_ADD(service_subtask.endtime, INTERVAL COALESCE(st.send_day, 1) DAY)
+        END,
+        INTERVAL (COALESCE((SELECT SUM(CAST(COALESCE(NULLIF(TRIM(pf.compensate_time), ''), '0') AS SIGNED))
+        FROM service_subtask_preachform pf
+        WHERE pf.subid = service_subtask.id AND pf.del_flag = 0), 0) + 1) DAY)
+    </sql>
+
+    <sql id="finishStateExpr">
+        COALESCE((
+        SELECT
+        CASE
+        WHEN <include refid="finishDeadlineExpr"/> IS NULL THEN NULL
         WHEN COALESCE(#{finishtime,jdbcType=TIMESTAMP}, service_subtask.finishtime, NOW())
-        &lt;= DATE_ADD(
-        DATE_ADD(
-        service_subtask.endtime,
-        INTERVAL COALESCE((SELECT st.send_day FROM service_task st
-        WHERE st.taskid = service_subtask.taskid AND st.del_flag = '0' LIMIT 1), 1) DAY
-        ),
-        INTERVAL (COALESCE((SELECT SUM(CAST(COALESCE(NULLIF(TRIM(pf.compensate_time), ''), '0') AS SIGNED))
-        FROM service_subtask_preachform pf
-        WHERE pf.subid = service_subtask.id AND pf.del_flag = 0), 0) + 1) DAY
-        )
+        &lt;= <include refid="finishDeadlineExpr"/>
         THEN 1
-        WHEN COALESCE((SELECT st.delay_finish_days FROM service_task st
-        WHERE st.taskid = service_subtask.taskid AND st.del_flag = '0' LIMIT 1), 0) &gt; 0
+        WHEN COALESCE(st.delay_finish_days, 0) &gt; 0
         AND COALESCE(#{finishtime,jdbcType=TIMESTAMP}, service_subtask.finishtime, NOW())
-        &lt;= DATE_ADD(
-        DATE_ADD(
-        DATE_ADD(
-        service_subtask.endtime,
-        INTERVAL COALESCE((SELECT st.send_day FROM service_task st
-        WHERE st.taskid = service_subtask.taskid AND st.del_flag = '0' LIMIT 1), 1) DAY
-        ),
-        INTERVAL (COALESCE((SELECT SUM(CAST(COALESCE(NULLIF(TRIM(pf.compensate_time), ''), '0') AS SIGNED))
-        FROM service_subtask_preachform pf
-        WHERE pf.subid = service_subtask.id AND pf.del_flag = 0), 0) + 1) DAY
-        ),
-        INTERVAL COALESCE((SELECT st.delay_finish_days FROM service_task st
-        WHERE st.taskid = service_subtask.taskid AND st.del_flag = '0' LIMIT 1), 0) DAY
-        )
+        &lt;= DATE_ADD(<include refid="finishDeadlineExpr"/>,
+        INTERVAL COALESCE(st.delay_finish_days, 0) DAY)
         THEN 2
         ELSE 3
         END
+        FROM (SELECT 1) dummy
+        LEFT JOIN service_task st ON st.taskid = service_subtask.taskid
+        LEFT JOIN service_task_schedule sts ON sts.id = service_subtask.schedule_id
+        LEFT JOIN service_task_schedule_detail std ON std.id = service_subtask.schedule_detail_id
+        LIMIT 1
+        ), finish_state)
     </sql>
 
     <!-- 褰撳墠鎵ц鏂瑰紡锛氶娆¢殢璁� current_preachform 涓虹┖鏃讹紝鍙� preachform 鐨勭涓�涓墽琛屾柟寮忓厹搴� -->
@@ -372,16 +387,34 @@
     <sql id="filterLeaveDimAnd">
         /* f-v3 */
         <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
-            AND leavehospitaldistrictcode IN
+            AND (
+            leavehospitaldistrictcode IN
             <foreach collection="leavehospitaldistrictcodes" item="lvWardCodeItem" open="(" separator="," close=")">
                 #{lvWardCodeItem}
             </foreach>
+            <!-- 寤剁画鎶ょ悊浠诲姟锛坰ervice_type='99'锛夊彲浠ュ湪鎮h�呰繕娌″嚭闄㈡椂鐢熸垚锛�
+                 杩欑被璁板綍鍙湁銆屽湪闄㈢淮搴︺�嶏紙hospitaldistrictcode / deptcode锛夛紝鍑洪櫌缁村害鏄� NULL銆�
+                 NULL 涓嶅尮閰嶄换浣� IN锛屼换鍔′細銆屾彁绀虹敓鎴愭垚鍔熴�佸垪琛ㄩ噷鍗存煡涓嶅埌銆嶏紝
+                 鎵�浠ュ嚭闄㈢淮搴︿负绌烘椂鐢ㄥ悓涓�濂楃紪鐮佷綋绯荤殑鍦ㄩ櫌缁村害鍏滃簳銆� -->
+            OR (service_type = '99' AND (leavehospitaldistrictcode IS NULL OR leavehospitaldistrictcode = '')
+                AND hospitaldistrictcode IN
+                <foreach collection="leavehospitaldistrictcodes" item="lvWardCodeItem" open="(" separator="," close=")">
+                    #{lvWardCodeItem}
+                </foreach>)
+            )
         </if>
         <if test="leaveldeptcodes != null and leaveldeptcodes.size() > 0">
-            AND leaveldeptcode IN
+            AND (
+            leaveldeptcode IN
             <foreach collection="leaveldeptcodes" item="lvDeptCodeItem" open="(" separator="," close=")">
                 #{lvDeptCodeItem}
             </foreach>
+            OR (service_type = '99' AND (leaveldeptcode IS NULL OR leaveldeptcode = '')
+                AND deptcode IN
+                <foreach collection="leaveldeptcodes" item="lvDeptCodeItem" open="(" separator="," close=")">
+                    #{lvDeptCodeItem}
+                </foreach>)
+            )
         </if>
     </sql>
 
@@ -422,20 +455,38 @@
                   or (leaveldeptcodes != null and leaveldeptcodes.size() > 0)">
             AND (
             <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
+                (
                 leavehospitaldistrictcode IN
                 <foreach collection="leavehospitaldistrictcodes" item="lvWardCodeItem" open="(" separator="," close=")">
                     #{lvWardCodeItem}
                 </foreach>
+                <!-- 寤剁画鎶ょ悊浠诲姟锛坰ervice_type='99'锛夊彲浠ュ湪鎮h�呰繕娌″嚭闄㈡椂鐢熸垚锛�
+                     杩欑被璁板綍鍙湁銆屽湪闄㈢淮搴︺�嶏紙hospitaldistrictcode / deptcode锛夛紝鍑洪櫌缁村害鏄� NULL銆�
+                     NULL 涓嶅尮閰嶄换浣� IN锛屼换鍔′細銆屾彁绀虹敓鎴愭垚鍔熴�佸垪琛ㄩ噷鍗存煡涓嶅埌銆嶏紝
+                     鎵�浠ュ嚭闄㈢淮搴︿负绌烘椂鐢ㄥ悓涓�濂楃紪鐮佷綋绯荤殑鍦ㄩ櫌缁村害鍏滃簳銆� -->
+                OR (service_type = '99' AND (leavehospitaldistrictcode IS NULL OR leavehospitaldistrictcode = '')
+                    AND hospitaldistrictcode IN
+                    <foreach collection="leavehospitaldistrictcodes" item="lvWardCodeItem" open="(" separator="," close=")">
+                        #{lvWardCodeItem}
+                    </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">
+                (
                 leaveldeptcode IN
                 <foreach collection="leaveldeptcodes" item="lvDeptCodeItem" open="(" separator="," close=")">
                     #{lvDeptCodeItem}
                 </foreach>
+                OR (service_type = '99' AND (leaveldeptcode IS NULL OR leaveldeptcode = '')
+                    AND deptcode IN
+                    <foreach collection="leaveldeptcodes" item="lvDeptCodeItem" open="(" separator="," close=")">
+                        #{lvDeptCodeItem}
+                    </foreach>)
+                )
             </if>
             )
         </if>
@@ -672,6 +723,26 @@
         <if test="operatorNo != null  and operatorNo != ''">and operator_no = #{operatorNo}</if>
         <if test="wechat != null  and wechat != ''">and wechat = #{wechat}</if>
         <if test="hospType != null  and hospType != ''">and hosp_type = #{hospType}</if>
+        <!--
+          2026-11锛氶噸瑕佹�ф爣璁扮瓫閫夛紙瀵瑰簲 service_subtask.importance_flag_code锛屽缓浠诲姟鏃跺彇鑷�
+          pat_med_inhosp.importance_flag_code锛夈�備袱绉嶅啓娉曪細
+            鈶� 绮剧‘鍗曞��  importanceFlagCode = 'FH0165.01'锛堟垨鎻忚堪鍙e緞 '鏃ラ棿鎵嬫湳'锛�
+            鈶� 绮剧‘澶氬��  importanceFlagCodes = ['FH0165.01','FH0165.02']
+          璇ュ垪閲囬泦鏃跺氨琚嫾鎴�**鎻忚堪涓�**锛圛mportFlagEnum 鐨� desc锛夛紝澶氬�肩敤鑻辨枃閫楀彿鎷兼帴锛�
+          濡� '鏃�,鏃ラ棿鎵嬫湳'锛堣 ServiceSLTDHealthcareRecordServiceImpl#hospitalizedApply锛夆�斺��
+          绛夊��/IN 鍙懡涓崟鍊艰锛涘鍊艰锛堢幇鍦轰粎 7 鏉★紝閮藉湪鍑洪櫌璁板綍涓婏級瑕佺瓫鍏ㄩ渶鑷鍐�
+          find_in_set銆備袱绉嶅彛寰勫苟瀛橈紙鏈夊簱瀛樻灇涓剧紪鐮併�佹湁搴撳瓨涓枃鎻忚堪锛夛紝浼犱粈涔堟寜浠�涔堢簿纭瘮锛�
+          涓嶅仛鍊煎煙褰掍竴銆�
+        -->
+        <if test="importanceFlagCode != null  and importanceFlagCode != ''">
+            and importance_flag_code = #{importanceFlagCode}
+        </if>
+        <if test="importanceFlagCodes != null and importanceFlagCodes.size() > 0">
+            AND importance_flag_code IN
+            <foreach collection="importanceFlagCodes" item="impFlagItem" open="(" separator="," close=")">
+                #{impFlagItem}
+            </foreach>
+        </if>
         <if test="libtemplateid != null ">and libtemplateid = #{libtemplateid}</if>
         <if test="libtemplatename != null ">and libtemplatename = #{libtemplatename}</if>
         <if test="openid != null ">and openid = #{openid}</if>
@@ -939,26 +1010,57 @@
         </if>
         SUM(CASE WHEN ss.finishtime IS NOT NULL AND DATE(ss.visit_time) &lt;= DATE(ss.finishtime) THEN 1 ELSE 0 END) /
         COUNT(*) AS finishRate,
-        <if test="rateDay != null">
-            SUM(CASE WHEN ss.finishtime IS NOT NULL
-            AND DATEDIFF(ss.finishtime, ss.endtime) &lt;= #{rateDay} + COALESCE(cp.compensate_days, 0)
-            THEN 1 ELSE 0 END) / COUNT(*) AS rate
-        </if>
-        <if test="rateDay == null">
-            NULL AS rate
-        </if>
+        <!-- 鍙婃椂鐜囧熀鍑嗭細
+             1) 闈炰换鍔$粍(appltype != 5)锛歟ndtime + send_day(缂虹渷1) + 危琛ュ伩澶╂暟 + 1 澶╋紱
+             2) 浠诲姟缁�(appltype = 5)锛氭寜 schedule_benchmark 瑙f瀽鍩哄噯鏃堕棿
+                (1-鍏ラ櫌鏃堕棿 2-鍑洪櫌鏃堕棿 3-灏辫瘖鏃堕棿 4-鍏ョ粍鏃堕棿 0/鍏跺畠-鑷畾涔夋椂闂�)
+                + day_offset + 危琛ュ伩澶╂暟 + 1 澶╋紙涓嶅啀鍙犲姞 send_day锛夛紱
+             瀹屾垚鏃堕棿 finishtime <= 鍩哄噯鏃堕棿璁′负鍙婃椂锛屽垎姣嶄粛涓哄簲闅忚鏁般��
+             琛ュ伩澶╂暟鍙彇 service_subtask_preachform.compensate_time 鐨勬眹鎬诲�间竴娆★紝
+             閬垮厤涓庤ˉ鍋挎槑缁嗙浉鍔犻�犳垚閲嶅琛ュ伩鎴栦竴瀵瑰鏀惧ぇ鍒嗘瘝銆� -->
+        SUM(CASE
+            WHEN ss.finishtime IS NOT NULL
+             AND COALESCE(st.appltype, '') != '5'
+             AND ss.endtime IS NOT NULL
+             AND ss.finishtime &lt;= DATE_ADD(
+                   DATE_ADD(ss.endtime, INTERVAL COALESCE(st.send_day, 1) DAY),
+                   INTERVAL (COALESCE(cp.compensate_days, 0) + 1) DAY)
+            THEN 1
+            WHEN ss.finishtime IS NOT NULL
+             AND st.appltype = '5'
+             AND std.day_offset IS NOT NULL
+             AND ss.finishtime &lt;= DATE_ADD(
+                   DATE_ADD(
+                       CASE sts.schedule_benchmark
+                         WHEN 1 THEN ss.starttime
+                         WHEN 2 THEN ss.endtime
+                         WHEN 3 THEN ss.admindate
+                         WHEN 4 THEN ss.create_time
+                         ELSE sts.schedule_benchmark_custom_time
+                       END, INTERVAL std.day_offset DAY),
+                   INTERVAL (COALESCE(cp.compensate_days, 0) + 1) DAY)
+            THEN 1
+            ELSE 0
+        END) / COUNT(*) AS rate
         FROM service_subtask ss
-        <if test="rateDay != null">
-            <!-- 琛ュ伩鏃堕棿锛氬厛鎸夊瓙浠诲姟鑱氬悎鎴愪竴琛屽啀鍏宠仈锛岄伩鍏嶄竴瀵瑰鏀惧ぇ COUNT(*) 鍒嗘瘝銆�
-                 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
-        </if>
+        <!-- 杩欓噷鎸� taskid / 鍘嗗彶 schedule 蹇収鍏宠仈锛屼笉鎸� del_flag 杩囨护锛�
+             浠诲姟鎴栬鍒掕缂栬緫鍚庢棫 schedule/detail 浼氱疆涓� del_flag=1锛�
+             浣嗗巻鍙� subtask 浠嶅紩鐢ㄦ棫 ID锛岃繃婊や細涓㈠け鍘嗗彶鍙婃椂鐜囧熀鍑嗐�� -->
+        LEFT JOIN service_task st
+               ON st.taskid = ss.taskid
+        LEFT JOIN service_task_schedule sts
+               ON sts.id = ss.schedule_id
+        LEFT JOIN service_task_schedule_detail std
+               ON std.id = ss.schedule_detail_id
+        <!-- 琛ュ伩鏃堕棿锛氬厛鎸夊瓙浠诲姟鑱氬悎鎴愪竴琛屽啀鍏宠仈锛岄伩鍏嶄竴瀵瑰鏀惧ぇ COUNT(*) 鍒嗘瘝銆�
+             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.visit_time IS NOT NULL
         AND ss.sendstate != 4
@@ -1112,6 +1214,8 @@
             <if test="hospitaldistrictname != null  and hospitaldistrictname != ''">hospitaldistrictname,</if>
             <if test="deptcode != null  and deptcode != ''">deptcode,</if>
             <if test="deptname != null  and deptname != ''">deptname,</if>
+            <!-- 2026-11锛氶噸瑕佹�ф爣璁扮紪鐮侊紙鏃ラ棿鎵嬫湳/鏃ラ棿璇婄枟鈥︼級锛屽缓浠诲姟鏃朵粠 pat_med_inhosp 鍚屾 -->
+            <if test="importanceFlagCode != null  and importanceFlagCode != ''">importance_flag_code,</if>
             <if test="labelstatus != null">labelstatus,</if>
             <if test="updateBy != null">update_by,</if>
             <if test="updateTime != null">update_time,</if>
@@ -1221,6 +1325,7 @@
             <if test="hospitaldistrictname != null  and hospitaldistrictname != ''">#{hospitaldistrictname},</if>
             <if test="deptcode != null  and deptcode != ''">#{deptcode},</if>
             <if test="deptname != null  and deptname != ''">#{deptname},</if>
+            <if test="importanceFlagCode != null  and importanceFlagCode != ''">#{importanceFlagCode},</if>
             <if test="labelstatus != null">#{labelstatus},</if>
             <if test="updateBy != null">#{updateBy},</if>
             <if test="updateTime != null">#{updateTime},</if>
@@ -1416,6 +1521,25 @@
             <if test="isManuallyCalled != null ">is_manually_called = #{isManuallyCalled},</if>
         </trim>
         where id = #{id}
+    </update>
+
+    <!-- 寰俊鍏紬鍙峰凡棰嗗彇鏈~鍐欐寜榛樿閫夐」瀹屾垚锛氬彧鏇存柊褰撳墠瀛愪换鍔°��
+         鏉′欢 sendstate=1 + 鏈彁浜わ紝淇濊瘉鍙鐞嗗綋鍓嶈棰嗗彇涓旀湭濉啓鐨勫瓙浠诲姟锛屼笉娉㈠強鍏朵粬浠诲姟銆� -->
+    <update id="updateWechatDefaultComplete" parameterType="com.ruoyi.task.domain.ServiceSubtask">
+        update service_subtask
+        set sendstate = 6,
+            finishtime = #{finishtime},
+            result = #{result},
+            remark = case
+                         when remark is null or remark = '' then #{remark}
+                         else concat(remark, ',', #{remark})
+                     end,
+            update_time = now(),
+            finish_state = <include refid="finishStateExpr"/>
+        where id = #{id}
+          and orgid = #{orgid}
+          and sendstate = 1
+          and (submit is null or submit != 1)
     </update>
 
     <update id="updateServiceSubtaskByPatId" parameterType="com.ruoyi.task.domain.ServiceSubtask">
@@ -1806,6 +1930,9 @@
         nurse_name,
         taskid,
         task_name,
+        <if test="groupKey != null and groupKey == 'taskid'">
+            (SELECT st.diag_type FROM service_task st WHERE st.taskid = service_subtask.taskid LIMIT 1) AS diag_type,
+        </if>
         visit_time,
         visit_dept_code,
         finishtime,
@@ -1854,6 +1981,13 @@
             <foreach collection="deptcodes" item="deptcode" open="(" separator=","
                      close=")">
                 #{deptcode}
+            </foreach>
+        </if>
+        <if test="taskIds != null and taskIds.size() > 0">
+            AND taskid IN
+            <foreach collection="taskIds" item="taskId" open="(" separator=","
+                     close=")">
+                #{taskId}
             </foreach>
         </if>
         <if test="serviceType != null and serviceType.size() > 0">
@@ -2100,6 +2234,13 @@
                 #{hospitaldeptcode}
             </foreach>
         </if>
+        <if test="taskIds != null and taskIds.size() > 0">
+            AND taskid IN
+            <foreach collection="taskIds" item="taskId" open="(" separator=","
+                     close=")">
+                #{taskId}
+            </foreach>
+        </if>
         <if test="serviceType != null and serviceType.size() > 0">
             AND service_type IN
             <foreach collection="serviceType" item="serviceType" open="(" separator=","
@@ -2173,6 +2314,8 @@
     <resultMap type="com.ruoyi.task.domain.ServiceSubtaskStatistic" id="ServiceSubtaskScriptStatisticResult">
         <result property="groupCode" column="group_code"/>
         <result property="groupName" column="group_name"/>
+        <result property="taskId" column="taskid"/>
+        <result property="taskName" column="task_name"/>
         <result property="dischargeCount" column="discharge_count"/>
         <result property="firstVisitCount" column="first_visit_count"/>
         <result property="againVisitCount" column="again_visit_count"/>
@@ -2225,7 +2368,16 @@
         <!-- 鍒嗙粍閿搴旂殑鏄剧ず鍚嶏細鐥呭尯缁熻鏃跺氨鏄繖涓�缁勭殑鐥呭尯鍚嶃��
              浠ュ墠杩欎竴鍒楁槸 MAX(hospitaldistrictname)锛屼竴涓粍娣蜂簡澶氫釜鐥呭尯鏃朵細闅忔満鏄剧ず鍏朵腑涓�涓紝
              浜庢槸鍑虹幇鈥滈�夎娑插唴绉戠梾鍖哄嵈鏄剧ず楠ㄧ涓績涓夌梾鍖衡�濄�� -->
-        MAX(IFNULL(leavehospitaldistrictname, hospitaldistrictname)) as group_name,
+        <choose>
+            <when test="groupKey != null and groupKey == 'taskid'">
+                MAX(task_name) as group_name,
+            </when>
+            <otherwise>
+                MAX(IFNULL(leavehospitaldistrictname, hospitaldistrictname)) as group_name,
+            </otherwise>
+        </choose>
+        MAX(taskid) as taskid,
+        MAX(task_name) as task_name,
         MAX(drcode) as drcode,
         MAX(drname) as drname,
         MAX(leaveldeptcode) as deptcode,
@@ -3103,6 +3255,136 @@
         group by a.script_content, ss.type, IFNULL(ssd.matchedtext,ssd.asrtext)
     </select>
 
+    <!--
+      闂閫夐」鏁板瓧涓嬮捇锛氳繑鍥為�夋嫨浜嗘寚瀹氶�夐」鐨� service_subtask 鍒楄〃銆�
+      杩囨护鍙e緞涓� getSfStatisticsScriptDetails / getSfStatisticsScriptItemDetails 淇濇寔涓�鑷达紝
+      棰濆鏀寔 statisticaltype锛�1-鐥呭尯銆�2-绉戝銆�3-鐥呯銆�
+    -->
+    <select id="getSfStatisticsScriptDetailsHyperlink" parameterType="com.ruoyi.task.domain.ServiceSubtaskCountReq"
+            resultMap="ServiceSubtaskResult">
+        SELECT ss.*
+        FROM service_subtask ss
+        WHERE ss.del_flag = 0
+        <if test="orgid != null and orgid != ''">
+            AND ss.orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            AND ss.campusid = #{campusid}
+        </if>
+        <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
+            AND ss.leavehospitaldistrictcode IN
+            <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
+                     close=")">
+                #{leavehospitaldistrictcode}
+            </foreach>
+        </if>
+        <if test="deptcodes != null and deptcodes.size() > 0">
+            AND ss.deptcode IN
+            <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">
+                #{deptcode}
+            </foreach>
+        </if>
+        <if test="serviceType != null and serviceType.size() > 0">
+            AND ss.service_type IN
+            <foreach collection="serviceType" item="serviceType" open="(" separator="," close=")">
+                #{serviceType}
+            </foreach>
+        </if>
+        <if test="startTime != null and endTime != null">
+            AND ss.visit_time >= DATE(#{startTime})
+            AND ss.visit_time &lt; DATE_ADD(DATE(#{endTime}), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type != ''">
+            AND ss.type = #{type}
+        </if>
+
+        <!-- 缁熻缁村害锛�1-鎸夌梾鍖� 2-鎸夌瀹� 3-鎸塼askid -->
+        <if test="statisticaltype != null and statisticaltype == 1">
+            <choose>
+                <when test="deptcode != null and deptcode != ''">
+                    AND ss.leavehospitaldistrictcode = #{deptcode}
+                </when>
+                <when test="leavehospitaldistrictcode != null and leavehospitaldistrictcode != ''">
+                    AND ss.leavehospitaldistrictcode = #{leavehospitaldistrictcode}
+                </when>
+            </choose>
+        </if>
+        <if test="statisticaltype != null and statisticaltype == 2 and deptcode != null and deptcode != ''">
+            AND ss.deptcode = #{deptcode}
+        </if>
+        <if test="statisticaltype != null and statisticaltype == 3 and taskId != null">
+            AND ss.taskid = #{taskId}
+        </if>
+        <!-- 鍏煎涓嶄紶 statisticaltype 鏃舵寜鍗曞�兼潯浠惰繃婊� -->
+        <if test="statisticaltype == null">
+            <if test="leavehospitaldistrictcode != null and leavehospitaldistrictcode != ''">
+                AND ss.leavehospitaldistrictcode = #{leavehospitaldistrictcode}
+            </if>
+            <if test="deptcode != null and deptcode != ''">
+                AND ss.deptcode = #{deptcode}
+            </if>
+            <if test="taskId != null">
+                AND ss.taskid = #{taskId}
+            </if>
+        </if>
+
+        <!-- 棰樼洰 + 閫夐」鍖归厤锛氬彧淇濈暀鍥炵瓟涓�夋嫨浜嗚閫夐」鐨勫瓙浠诲姟 -->
+        AND EXISTS (
+            SELECT 1
+            FROM service_subtask_detail ssd
+            WHERE ssd.sub_id = ss.id
+              AND ssd.del_flag = 0
+            <if test="configValue != null and configValue != ''">
+                AND ssd.categoryid IN (${configValue})
+            </if>
+            <choose>
+                <when test="optionText != null">
+                    AND IFNULL(ssd.matchedtext, ssd.asrtext) = #{optionText}
+                </when>
+                <otherwise>
+                    AND 1 = 0
+                </otherwise>
+            </choose>
+            <choose>
+                <!-- 浼樺厛鎸夐鐩唴瀹瑰尮閰嶏細鍚屼竴閬撻澶嶅埗鍒板涓换鍔℃ā鏉挎椂 scriptid 涓嶅悓锛屼絾 script_content 鐩稿悓 -->
+                <when test="scriptContent != null and scriptContent != ''">
+                    AND ssd.scriptid IN (
+                        <choose>
+                            <when test="type == '1'">
+                                SELECT its.id FROM ivr_task_template_script its
+                                WHERE its.script_content = #{scriptContent}
+                            </when>
+                            <when test="type == '2'">
+                                SELECT sts.id FROM svy_task_template_script sts
+                                WHERE sts.script_content = #{scriptContent}
+                            </when>
+                            <otherwise>
+                                SELECT its.id FROM ivr_task_template_script its
+                                WHERE its.script_content = #{scriptContent}
+                                UNION
+                                SELECT sts.id FROM svy_task_template_script sts
+                                WHERE sts.script_content = #{scriptContent}
+                            </otherwise>
+                        </choose>
+                    )
+                </when>
+                <when test="scriptid != null">
+                    AND ssd.scriptid = #{scriptid}
+                </when>
+                <otherwise>
+                    AND 1 = 0
+                </otherwise>
+            </choose>
+        )
+        ORDER BY ss.endtime DESC, ss.id DESC
+        <if test="pageSize != null and pageSize > 0">
+            LIMIT #{pageSize}
+            <if test="pageNum != null and pageNum >= 0">
+                OFFSET #{pageNum}
+            </if>
+        </if>
+    </select>
+
     <select id="getDataByTime" resultMap="ServiceSubtaskResult">
 
         select id,

--
Gitblit v1.9.3