From 9bd00d48acd7b80468b7eca0f6d8ec03a82191a9 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期二, 04 八月 2026 15:03:46 +0800
Subject: [PATCH] 【景宁】随访及时率加上补偿时间计算

---
 smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java |    9 ++++
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml |   57 +++++++++++++++++-----------
 2 files changed, 43 insertions(+), 23 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java b/smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
index ea93805..2deee1d 100644
--- a/smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
+++ b/smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
@@ -94,7 +94,14 @@
     public Double selectTimelyRate(ServiceSubtask ServiceSubtask);
 
     /**
-     * 闅忚鍙婃椂鐜囷細搴旈殢璁挎椂闂�<瀹為檯闅忚鏃堕棿
+     * 闅忚鍙婃椂鐜囷紙鎸� groupKey 鍒嗙粍鎵归噺缁熻锛�
+     * <p>
+     * rate锛氬嚭闄㈡椂闂�(endtime)璧� rateDay + 琛ュ伩澶╂暟 鍐呭畬鎴愰殢璁跨殑鍗犳瘮銆�
+     * 琛ュ伩澶╂暟鍙栬嚜 service_subtask_preachform.compensate_time 鎸夊瓙浠诲姟姹傚拰锛�
+     * 鐢ㄥ瓙浠诲姟蹇収鑰岄潪 service_task.preachform_desc锛屼繚璇佸巻鍙叉暟鎹笉闅忎换鍔℃敼閰嶇疆鑰屽彉鍔ㄣ��
+     * rateDay 涓虹┖鏃� rate 杩斿洖 NULL銆�
+     * <p>
+     * finishRate锛氬簲闅忚鏃堕棿(visit_time) &lt;= 瀹為檯瀹屾垚鏃堕棿(finishtime) 鐨勫崰姣旓紝褰撳墠鏈闅忚缁熻浣跨敤銆�
      *
      * @param ServiceSubtaskvo
      * @return
diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index 073c0ef..4db0375 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -758,57 +758,70 @@
     <select id="selectTimelyRateBatch" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity" resultType="map">
         SELECT
         <if test="groupKey != null and groupKey != ''">
-            ${groupKey} as groupKey,
+            ss.${groupKey} as groupKey,
         </if>
-        SUM(CASE WHEN finishtime IS NOT NULL AND DATE(visit_time) &lt;= DATE(finishtime) THEN 1 ELSE 0 END) / COUNT(*) AS finishRate,
+        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 finishtime IS NOT NULL AND DATEDIFF(finishtime, endtime) &lt;= #{rateDay} THEN 1 ELSE 0 END) / COUNT(*) AS rate
+            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>
-        FROM service_subtask
-        WHERE del_flag = 0
-        AND visit_time IS NOT NULL
+        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>
+        WHERE ss.del_flag = 0
+        AND ss.visit_time IS NOT NULL
         <if test="starttime == null and endtime==null">
-            AND DATE(visit_time) &lt; DATE(NOW())
+            AND DATE(ss.visit_time) &lt; DATE(NOW())
         </if>
         <if test="starttime != null and endtime!=null">
-            AND visit_time >= #{starttime}
-            AND visit_time &lt; DATE_ADD(#{endtime}, INTERVAL 1 DAY)
+            AND ss.visit_time >= #{starttime}
+            AND ss.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="orgid != null and orgid != ''">AND ss.orgid = #{orgid}</if>
+        <if test="deptcode != null  and deptcode != ''">and ss.deptcode = #{deptcode}</if>
+        <if test="deptname != null  and deptname != ''">and ss.deptname = #{deptname}</if>
+        <if test="isabnormal != null">and ss.isabnormal = #{isabnormal}</if>
         <if test="leavehospitaldistrictcode != null  and leavehospitaldistrictcode != ''">and
-            leavehospitaldistrictcode = #{leavehospitaldistrictcode}
+            ss.leavehospitaldistrictcode = #{leavehospitaldistrictcode}
         </if>
         <if test="leavehospitaldistrictname != null  and leavehospitaldistrictname != ''">and
-            leavehospitaldistrictname = #{leavehospitaldistrictname}
+            ss.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="managementDoctorCode != null">and ss.management_doctor_code = #{managementDoctorCode}</if>
+        <if test="managementDoctor != null">and ss.management_doctor like concat('%',#{managementDoctor}, '%')</if>
         <if test="visitCount != null and visitCount == 1">
-            AND visit_count = 1
+            AND ss.visit_count = 1
         </if>
         <if test="visitCount != null and visitCount > 1">
-            AND visit_count > 1
+            AND ss.visit_count > 1
         </if>
         <if test="serviceTypeList != null">
-            AND service_type IN
+            AND ss.service_type IN
             <foreach collection="serviceTypeList" item="serviceType" open="(" separator=","
                      close=")">
                 #{serviceType}
             </foreach>
         </if>
         <if test="groupKey != null and groupKey != ''">
-            AND ${groupKey} IN
+            AND ss.${groupKey} IN
             <foreach collection="groupKeyList" item="key" open="(" separator=","
                      close=")">
                 #{key}
             </foreach>
-            GROUP BY ${groupKey}
+            GROUP BY ss.${groupKey}
         </if>
     </select>
 

--
Gitblit v1.9.3