From 9b96619ab91dce35b606faa3f4e0468ec702fd69 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期四, 22 一月 2026 15:25:11 +0800
Subject: [PATCH] 【丽水】getSfStatisticsScript 优化

---
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml |   36 ++++++++++++++++++++++++++++++------
 1 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index 312e13a..30e4c15 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -563,16 +563,40 @@
 
     <select id="selectTimelyRateBatch" parameterType="com.smartor.domain.ServiceSubtask" resultType="map">
         SELECT
-        <if test="deptcode != null">deptcode as groupKey,</if>
-        <if test="leavehospitaldistrictcode != null">leavehospitaldistrictcode as groupKey,</if>
-        <if test="drcode != null">drcode as groupKey,</if>
+        <if test="groupKey != null and groupKey != ''">
+            ${groupKey} as groupKey,
+        </if>
         SUM(CASE WHEN DATE(visit_time) &lt; DATE(IFNULL(finishtime, NOW())) THEN 1 ELSE 0 END) / COUNT(*) as rate
         FROM service_subtask
         WHERE del_flag = 0
-        AND visit_time >= #{starttime}
-        AND visit_time &lt; DATE_ADD(#{endtime}, INTERVAL 1 DAY)
         <if test="orgid != null">AND orgid = #{orgid}</if>
-        GROUP BY groupKey
+        <if test="starttime == null and endtime==null">
+            AND visit_time &lt; NOW()
+        </if>
+        <if test="starttime != null and endtime!=null">
+            AND visit_time >= #{starttime}
+            AND visit_time &lt; DATE_ADD(#{endtime}, INTERVAL 1 DAY)
+        </if>
+        <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
+        <if test="deptcode != null  and deptcode != ''">and deptcode = #{deptcode}</if>
+        <if test="deptname != null  and deptname != ''">and deptname = #{deptname}</if>
+        <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
+        <if test="leavehospitaldistrictcode != null  and leavehospitaldistrictcode != ''">and
+            leavehospitaldistrictcode = #{leavehospitaldistrictcode}
+        </if>
+        <if test="leavehospitaldistrictname != null  and leavehospitaldistrictname != ''">and
+            leavehospitaldistrictname = #{leavehospitaldistrictname}
+        </if>
+        <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
+        <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if>
+        <if test="groupKey != null and groupKey != ''">
+            AND ${groupKey} IN
+            <foreach collection="groupKeyList" item="key" open="(" separator=","
+                     close=")">
+                #{key}
+            </foreach>
+            GROUP BY ${groupKey}
+        </if>
     </select>
 
 

--
Gitblit v1.9.3