From 21ce122193e2fb57d206dbfca59e8d2ab2114fd0 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期一, 23 三月 2026 17:12:56 +0800
Subject: [PATCH] 新增病区与科室组合

---
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml |  255 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 152 insertions(+), 103 deletions(-)

diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index 0cc9e60..1877ccc 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -318,10 +318,10 @@
             AND date_format(endtime,'%y%m%d') &lt;= date_format(#{endOutHospTime},'%y%m%d')
         </if>
         <if test="startSendDateTime != null">
-            AND date_format(long_send_time,'%y%m%d') &gt;= date_format(#{startSendDateTime},'%y%m%d')
+            AND date_format(visit_time,'%y%m%d') &gt;= date_format(#{startSendDateTime},'%y%m%d')
         </if>
         <if test="endSendDateTime != null">
-            AND date_format(long_send_time,'%y%m%d') &lt;= date_format(#{endSendDateTime},'%y%m%d')
+            AND date_format(visit_time,'%y%m%d') &lt;= date_format(#{endSendDateTime},'%y%m%d')
         </if>
 
         <if test="longSendTime != null">
@@ -358,6 +358,41 @@
                 <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
                          close="))">
                     #{leaveldeptcode}
+                </foreach>
+            </if>
+        </if>
+        <if test="deptOrDistrict==3">
+            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
+                AND (leavehospitaldistrictcode IN
+                <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="("
+                         separator=","
+                         close=")">
+                    #{leavehospitaldistrictcode}
+                </foreach>
+            </if>
+            <if test=" visitDeptCodes != null and visitDeptCodes.size()>0">
+                and visit_dept_name IN
+                <foreach collection="visitDeptCodes" item="visitDeptCode" open="(" separator=","
+                         close="))">
+                    #{visitDeptCode}
+                </foreach>
+            </if>
+        </if>
+
+        <if test="deptOrDistrict==4">
+            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
+                AND (leavehospitaldistrictcode IN
+                <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="("
+                         separator=","
+                         close=")">
+                    #{leavehospitaldistrictcode}
+                </foreach>
+            </if>
+            <if test=" visitDeptCodes != null and visitDeptCodes.size()>0">
+                OR visit_dept_name IN
+                <foreach collection="visitDeptCodes" item="visitDeptCode" open="(" separator=","
+                         close="))">
+                    #{visitDeptCode}
                 </foreach>
             </if>
         </if>
@@ -425,8 +460,8 @@
         </if>
         <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 long_send_time asc</if>
-        <if test="sort != null  and sort==3">order by long_send_time desc</if>
+        <if test="sort != null  and sort==2">order by visit_time asc</if>
+        <if test="sort != null  and sort==3">order by visit_time desc</if>
         <if test="sort != null  and sort==5">order by admindate asc</if>
         <if test="sort != null  and sort==6">order by admindate desc</if>
         <if test="sort != null  and sort==7">order by visit_time asc</if>
@@ -1927,25 +1962,6 @@
             </foreach>
         </if>
 
-        <!--        GROUP BY-->
-        <!--        <choose>-->
-        <!--            <when test="timeType == 'day'">-->
-        <!--                DATE_FORMAT(visit_time, '%Y-%m-%d')-->
-        <!--            </when>-->
-        <!--            <when test="timeType == 'month'">-->
-        <!--                DATE_FORMAT(visit_time, '%Y-%m')-->
-        <!--            </when>-->
-        <!--            <when test="timeType == 'year'">-->
-        <!--                DATE_FORMAT(visit_time, '%Y')-->
-        <!--            </when>-->
-        <!--            <when test="timeType == 'week'">-->
-        <!--                CONCAT(YEAR(visit_time), '-W', LPAD(WEEK(visit_time, 1), 2, '0'))-->
-        <!--            </when>-->
-        <!--            <otherwise>-->
-        <!--                DATE_FORMAT(visit_time, '%Y-%m-%d')-->
-        <!--            </otherwise>-->
-        <!--        </choose>-->
-
         UNION ALL
 
         -- 鍑洪櫌浜烘鏁版嵁
@@ -1997,85 +2013,48 @@
             </foreach>
         </if>
 
-        <!--        GROUP BY-->
-        <!--        <choose>-->
-        <!--            <when test="timeType == 'day'">-->
-        <!--                DATE_FORMAT(endtime, '%Y-%m-%d')-->
-        <!--            </when>-->
-        <!--            <when test="timeType == 'month'">-->
-        <!--                DATE_FORMAT(endtime, '%Y-%m')-->
-        <!--            </when>-->
-        <!--            <when test="timeType == 'year'">-->
-        <!--                DATE_FORMAT(endtime, '%Y')-->
-        <!--            </when>-->
-        <!--            <when test="timeType == 'week'">-->
-        <!--                CONCAT(YEAR(endtime), '-W', LPAD(WEEK(endtime, 1), 2, '0'))-->
-        <!--            </when>-->
-        <!--            <otherwise>-->
-        <!--                DATE_FORMAT(endtime, '%Y-%m-%d')-->
-        <!--            </otherwise>-->
-        <!--        </choose>-->
+<!--        UNION ALL-->
 
-        UNION ALL
+<!--        &#45;&#45; 闂ㄨ瘖浜烘鏁版嵁-->
+<!--        SELECT-->
+<!--        <choose>-->
+<!--            <when test="timeType == 'day'">-->
+<!--                DATE_FORMAT(admitdate, '%Y-%m-%d') AS timePeriod,-->
+<!--            </when>-->
+<!--            <when test="timeType == 'month'">-->
+<!--                DATE_FORMAT(admitdate, '%Y-%m') AS timePeriod,-->
+<!--            </when>-->
+<!--            <when test="timeType == 'year'">-->
+<!--                DATE_FORMAT(admitdate, '%Y') AS timePeriod,-->
+<!--            </when>-->
+<!--            <when test="timeType == 'week'">-->
+<!--                CONCAT(YEAR(admitdate), '-W', LPAD(WEEK(admitdate, 1), 2, '0')) AS timePeriod,-->
+<!--            </when>-->
+<!--            <otherwise>-->
+<!--                DATE_FORMAT(admitdate, '%Y-%m-%d') AS timePeriod,-->
+<!--            </otherwise>-->
+<!--        </choose>-->
+<!--        0 AS dischargeFollowCount,-->
+<!--        0 AS outpatientFollowCount,-->
+<!--        0 AS pmiCount,-->
+<!--        1 AS pmoCount-->
+<!--        FROM pat_med_outhosp-->
+<!--        WHERE del_flag = '0'-->
+<!--        <if test="startDate != null and endDate != null">-->
+<!--            AND admitdate >= #{startDate}-->
+<!--            AND admitdate &lt;= DATE_ADD(#{endDate}, INTERVAL 1 DAY)-->
+<!--        </if>-->
+<!--        <if test="orgid != null">-->
+<!--            AND orgid = #{orgid}-->
+<!--        </if>-->
 
-        -- 闂ㄨ瘖浜烘鏁版嵁
-        SELECT
-        <choose>
-            <when test="timeType == 'day'">
-                DATE_FORMAT(admitdate, '%Y-%m-%d') AS timePeriod,
-            </when>
-            <when test="timeType == 'month'">
-                DATE_FORMAT(admitdate, '%Y-%m') AS timePeriod,
-            </when>
-            <when test="timeType == 'year'">
-                DATE_FORMAT(admitdate, '%Y') AS timePeriod,
-            </when>
-            <when test="timeType == 'week'">
-                CONCAT(YEAR(admitdate), '-W', LPAD(WEEK(admitdate, 1), 2, '0')) AS timePeriod,
-            </when>
-            <otherwise>
-                DATE_FORMAT(admitdate, '%Y-%m-%d') AS timePeriod,
-            </otherwise>
-        </choose>
-        0 AS dischargeFollowCount,
-        0 AS outpatientFollowCount,
-        0 AS pmiCount,
-        1 AS pmoCount
-        FROM pat_med_outhosp
-        WHERE del_flag = '0'
-        <if test="startDate != null and endDate != null">
-            AND admitdate >= #{startDate}
-            AND admitdate &lt;= DATE_ADD(#{endDate}, INTERVAL 1 DAY)
-        </if>
-        <if test="orgid != null">
-            AND orgid = #{orgid}
-        </if>
+<!--        <if test="deptcodes != null and deptcodes.size() > 0">-->
+<!--            AND deptcode IN-->
+<!--            <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">-->
+<!--                #{deptcode}-->
+<!--            </foreach>-->
+<!--        </if>-->
 
-        <if test="deptcodes != null and deptcodes.size() > 0">
-            AND deptcode IN
-            <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">
-                #{deptcode}
-            </foreach>
-        </if>
-
-        <!--        GROUP BY-->
-        <!--        <choose>-->
-        <!--            <when test="timeType == 'day'">-->
-        <!--                DATE_FORMAT(admitdate, '%Y-%m-%d')-->
-        <!--            </when>-->
-        <!--            <when test="timeType == 'month'">-->
-        <!--                DATE_FORMAT(admitdate, '%Y-%m')-->
-        <!--            </when>-->
-        <!--            <when test="timeType == 'year'">-->
-        <!--                DATE_FORMAT(admitdate, '%Y')-->
-        <!--            </when>-->
-        <!--            <when test="timeType == 'week'">-->
-        <!--                CONCAT(YEAR(admitdate), '-W', LPAD(WEEK(admitdate, 1), 2, '0'))-->
-        <!--            </when>-->
-        <!--            <otherwise>-->
-        <!--                DATE_FORMAT(admitdate, '%Y-%m-%d')-->
-        <!--            </otherwise>-->
-        <!--        </choose>-->
         ) AS combined_data
         GROUP BY timePeriod
         ORDER BY timePeriod DESC
@@ -2090,8 +2069,8 @@
         SUM(CASE WHEN sendstate >= 3 OR sendstate = 1 THEN 1 ELSE 0 END) AS yfs,
         SUM(CASE WHEN sendstate = 2 THEN 1 ELSE 0 END) AS dsf,
         SUM(CASE WHEN sendstate = 1 THEN 1 ELSE 0 END) AS blq,
-        SUM(CASE WHEN excep IS NOT NULL AND excep != '0' THEN 1 ELSE 0 END) AS yc,
-        SUM(CASE WHEN isabnormal IS NOT NULL AND isabnormal = 2 THEN 1 ELSE 0 END) AS jg
+        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
         FROM service_subtask
         where 1=1
         and del_flag = 0
@@ -2134,6 +2113,14 @@
                     #{leaveldeptcode}
                 </foreach>
             </if>
+        </if>
+        <if test="visitCount != null and visitCount > 1 and visitDeptCodes != null and visitDeptCodes.size() > 0">
+            AND visit_dept_code IN
+            <foreach collection="visitDeptCodes" item="visitDeptCodes" open="("
+                     separator=","
+                     close=")">
+                #{visitDeptCodes}
+            </foreach>
         </if>
         <if test="leavehospitaldistrictname != null and leavehospitaldistrictname != ''">
             AND leavehospitaldistrictname = #{leavehospitaldistrictname}
@@ -2205,10 +2192,10 @@
             AND DATE_FORMAT(endtime,'%y%m%d') &lt;= DATE_FORMAT(#{endOutHospTime},'%y%m%d')
         </if>
         <if test="startSendDateTime != null">
-            AND DATE_FORMAT(long_send_time,'%y%m%d') &gt;= DATE_FORMAT(#{startSendDateTime},'%y%m%d')
+            AND DATE_FORMAT(visit_time,'%y%m%d') &gt;= DATE_FORMAT(#{startSendDateTime},'%y%m%d')
         </if>
         <if test="endSendDateTime != null">
-            AND DATE_FORMAT(long_send_time,'%y%m%d') &lt;= DATE_FORMAT(#{endSendDateTime},'%y%m%d')
+            AND DATE_FORMAT(visit_time,'%y%m%d') &lt;= DATE_FORMAT(#{endSendDateTime},'%y%m%d')
         </if>
         <if test="longSendTime != null">
             AND DATE_FORMAT(long_send_time,'%y%m%d') &lt;= DATE_FORMAT(#{longSendTime},'%y%m%d')
@@ -2246,6 +2233,9 @@
         <if test="guid != null and guid != ''">
             AND guid = #{guid}
         </if>
+        <if test="excep != null ">
+            AND excep = #{excep}
+        </if>
         <if test="visitCount != null and visitCount == 1">
             AND visit_count = 1
         </if>
@@ -2254,4 +2244,63 @@
         </if>
     </select>
 
+
+    <select id="selectVisitCount" parameterType="com.smartor.domain.PatMedReq"
+            resultType="com.smartor.domain.PatMedRes">
+        select
+        0 AS rc,
+        count(1) AS rs
+        FROM
+        service_subtask
+        where 1=1
+        and del_flag = 0
+        and service_type=3
+        <if test="orgid != null">
+            and orgid = #{orgid}
+        </if>
+        <if test="startDate != null">
+            AND date_format( visit_time, '%y%m%d' ) &gt;= date_format( #{startDate}, '%y%m%d' )
+        </if>
+        <if test="endDate != null">
+            AND date_format( visit_time, '%y%m%d' ) &lt;= date_format(#{endDate},'%y%m%d')
+        </if>
+        <if test="deptcodeList != null and deptcodeList.size()>0">
+            and deptcode in
+            <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
+                #{deptcode}
+            </foreach>
+        </if>
+    </select>
+
+    <select id="getCurrentUserServiceSubtaskCount" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity" resultType="map">
+        SELECT
+        COUNT(CASE WHEN sendstate = 2 AND date_format(visit_time,'%y%m%d') &lt;= date_format(CURDATE(),'%y%m%d') THEN 1 END) AS pendingVisitCount,
+        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
+        <if test="orgid != null and orgid != ''">
+            AND orgid = #{orgid}
+        </if>
+        <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
+            AND leavehospitaldistrictcode IN
+            <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="("
+                     separator=","
+                     close=")">
+                #{leavehospitaldistrictcode}
+            </foreach>
+        </if>
+        <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0">
+            AND deptcode IN
+            <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
+                     close=")">
+                #{leaveldeptcode}
+            </foreach>
+        </if>
+    </select>
+
 </mapper>

--
Gitblit v1.9.3