From c111e3eff1191b29d2d2baf2f485a4bf3a2edc00 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期六, 16 八月 2025 14:34:07 +0800
Subject: [PATCH] 代码提交

---
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml |  602 +++++++++++++++++++++++++++++++++---------------------
 1 files changed, 371 insertions(+), 231 deletions(-)

diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index 31c47bc..24ea5d6 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -74,6 +74,7 @@
         <result property="sendstate" column="sendstate"/>
         <result property="tagname" column="tagname"/>
         <result property="visitTime" column="visit_time"/>
+        <result property="leavediagname" column="leavediagname"/>
     </resultMap>
 
     <resultMap type="com.smartor.domain.ServiceSubtaskCount" id="ServiceSubtaskResult2">
@@ -123,6 +124,7 @@
                recordid,
                exrecallcount,
                pulltime,
+               leavediagname,
                deptcode,
                labelstatus,
                del_flag,
@@ -158,250 +160,160 @@
 
     <select id="selectServiceSubtaskList" parameterType="com.smartor.domain.ServiceSubtaskVO"
             resultMap="ServiceSubtaskResult">
-        select a.id,
-        a.hosp_type,
-        a.suggest,
-        a.sendstate,
-        a.endtime,
-        a.nurse_id,
-        a.nurse_name,
-        a.starttime,
-        a.submit,
-        a.inhospid,
-        a.drname,
-        a.excep,
-        a.drcode,
-        a.long_send_time,
-        a.openid,
-        a.remark,
-        a.service_type,
-        a.libtemplateid,
-        a.libtemplatename,
-        a.hospno,
-        a.score,
-        a.phone,
-        a.sex,
-        a.age,
-        a.patid,
-        a.sfzh,
-        a.addr,
-        a.senderdetail,
-        a.type,
-        a.taskid,
-        a.templateid,
-        a.templatename,
-        a.senddate,
-        a.senduuid,
-        a.result,
-        a.finishtime,
-        a.recordid,
-        a.exrecallcount,
-        a.pulltime,
-        a.deptcode,
-        a.labelstatus,
-        a.del_flag,
-        a.update_by,
-        a.update_time,
-        a.create_by,
-        a.create_time,
-        a.isupload,
-        a.upload_time,
-        a.orgid,
-        a.pid,
-        a.guid,
-        a.text_param,
-        a.preachform,
-        a.bed_no,
-        a.send_type,
-        a.task_name,
-        a.task_desc,
-        a.operator_no,
-        a.operator,
-        a.wechat,
-        a.sendname,
-        a.roomno,
-        a.admindate,
-        a.deptname,
-        a.stop_state,
-        a.visit_time,
-        a.leavehospitaldistrictcode,
-        a.leavehospitaldistrictname,
-        a.diagname,
-        COALESCE((
-        SELECT string_agg(d.tagname, ', ')
-        FROM pat_archivetag d
-        WHERE d.patid = a.patid
-        AND d.del_flag = 0
-        ), '') AS tagname
-        from service_subtask a
-        LEFT JOIN pat_archivetag c ON c.patid = a.patid
+        <include refid="selectServiceSubtaskVo"/>
         <where>
-            a.del_flag=0
-            -- and c.del_flag=0
-            <if test="sendname != null  and sendname != ''">and a.sendname like concat('%', #{sendname}, '%')</if>
-            <if test="tagname != null  and tagname != ''">and c.tagname like concat('%', #{tagname}, '%')</if>
+            del_flag=0
+            <if test="sendname != null  and sendname != ''">and sendname like concat('%', #{sendname}, '%')</if>
             <if test="phone != null  and phone != ''">and phone = #{phone}</if>
             <if test="leavehospitaldistrictcode != null  and leavehospitaldistrictcode != ''">and
-                a.leavehospitaldistrictcode = #{leavehospitaldistrictcode}
+                leavehospitaldistrictcode = #{leavehospitaldistrictcode}
             </if>
             <if test="leavehospitaldistrictname != null  and leavehospitaldistrictname != ''">and
-                a.leavehospitaldistrictname = #{leavehospitaldistrictname}
+                leavehospitaldistrictname = #{leavehospitaldistrictname}
             </if>
-            <if test="sex != null  and sex != ''">and a.sex = #{sex}</if>
-            <if test="age != null ">and a.age = #{age}</if>
-            <if test="submit != null ">and a.submit = #{submit}</if>
-            <if test="serviceType != null ">and a.service_type = #{serviceType}</if>
-            <if test="patid != null ">and a.patid = #{patid}</if>
-            <if test="sfzh != null  and sfzh != ''">and a.sfzh = #{sfzh}</if>
-            <if test="addr != null  and addr != ''">and a.addr = #{addr}</if>
-            <if test="senderdetail != null  and senderdetail != ''">and a.senderdetail = #{senderdetail}</if>
-            <if test="type != null  and type != ''">and a.type = #{type}</if>
-            <if test="taskid != null ">and a.taskid = #{taskid}</if>
-            <if test="templateid != null  and templateid != ''">and a.templateid = #{templateid}</if>
-            <if test="templatename != null  and templatename != ''">and a.templatename like concat('%', #{templatename},
+            <if test="leavediagname != null  and leavediagname != ''">and leavediagname like concat('%',
+                #{leavediagname}, '%')
+            </if>
+            <if test="sex != null  and sex != ''">and sex = #{sex}</if>
+            <if test="age != null ">and age = #{age}</if>
+            <if test="patguid != null ">and patguid = #{patguid}</if>
+            <if test="subId != null ">and id = #{subId}</if>
+            <if test="inhospid != null ">and inhospid = #{inhospid}</if>
+            <if test="submit != null ">and submit = #{submit}</if>
+            <if test="upid != null ">and upid = #{upid}</if>
+            <if test="patfrom != null ">and patfrom = #{patfrom}</if>
+            <if test="serviceType != null ">and service_type = #{serviceType}</if>
+            <if test="patid != null ">and patid = #{patid}</if>
+            <if test="sfzh != null  and sfzh != ''">and sfzh = #{sfzh}</if>
+            <if test="addr != null  and addr != ''">and addr = #{addr}</if>
+            <if test="senderdetail != null  and senderdetail != ''">and senderdetail = #{senderdetail}</if>
+            <if test="type != null  and type != ''">and type = #{type}</if>
+            <if test="taskid != null ">and taskid = #{taskid}</if>
+            <if test="templateid != null  and templateid != ''">and templateid = #{templateid}</if>
+            <if test="templatename != null  and templatename != ''">and templatename like concat('%', #{templatename},
                 '%')
             </if>
             <if test="startOutHospTime != null">
-                AND TO_DATE( a.endtime,'YYYY-MM-DD') &gt;= TO_DATE(#{startOutHospTime},'YYYY-MM-DD')
+                AND to_char(endtime, 'YYMMDD') &gt;= to_char(#{startOutHospTime}::timestamp, 'YYMMDD')
             </if>
             <if test="endOutHospTime != null">
-                AND TO_DATE( a.endtime,'YYYY-MM-DD') &lt;= TO_DATE(#{endOutHospTime},'YYYY-MM-DD')
+                AND to_char(endtime, 'YYMMDD') &lt;= to_char(#{endOutHospTime}::timestamp, 'YYMMDD')
             </if>
-            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
-                AND a.leavehospitaldistrictcode IN
-                <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
-                         close=")">
-                    #{leavehospitaldistrictcode}
-                </foreach>
+            <if test="startSendDateTime != null">
+                AND to_char(long_send_time, 'YYMMDD') >= to_char(#{startSendDateTime}::timestamp, 'YYMMDD')
             </if>
-            <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0">
-                AND a.deptcode IN
-                <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
-                         close=")">
-                    #{leaveldeptcode}
-                </foreach>
+            <if test="endSendDateTime != null">
+                AND to_char(long_send_time, 'YYMMDD') &lt;= to_char(#{endSendDateTime}::timestamp, 'YYMMDD')
+            </if>
+            <if test="longSendTime != null">
+                AND to_char(long_send_time, 'YYMMDD') &lt;= to_char(#{longSendTime}::timestamp, 'YYMMDD')
+            </if>
+            <if test="deptOrDistrict==1">
+                <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>
+            </if>
+            <if test="deptOrDistrict==2">
+                <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">
+                    OR deptcode IN
+                    <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
+                             close="))">
+                        #{leaveldeptcode}
+                    </foreach>
+                </if>
             </if>
 
-            <if test="senddate != null ">and a.senddate = #{senddate}</if>
-            <if test="senduuid != null  and senduuid != ''">and a.senduuid = #{senduuid}</if>
-            <if test="result != null  and result != ''">and a.result = #{result}</if>
-            <if test="finishtime != null ">and a.finishtime = #{finishtime}</if>
-            <if test="recordid != null ">and a.recordid = #{recordid}</if>
-            <if test="exrecallcount != null ">and a.exrecallcount = #{exrecallcount}</if>
-            <if test="pulltime != null ">and a.pulltime = #{pulltime}</if>
-            <if test="deptcode != null  and deptcode != ''">and a.deptcode = #{deptcode}</if>
-            <if test="deptname != null  and deptname != ''">and a.deptname = #{deptname}</if>
-            <if test="labelstatus != null ">and a.labelstatus = #{labelstatus}</if>
-            <if test="isupload != null ">and a.isupload = #{isupload}</if>
-            <if test="uploadTime != null ">and a.upload_time = #{uploadTime}</if>
-            <if test="orgid != null  and orgid != ''">and a.orgid = #{orgid}</if>
-            <if test="pid != null ">and a.pid = #{pid}</if>
-            <if test="inhospid != null ">and a.inhospid = #{inhospid}</if>
-            <if test="preachform != null ">and a.preachform = #{preachform}</if>
-            <if test="guid != null  and guid != ''">and a.guid = #{guid}</if>
-            <if test="textParam != null  and textParam != ''">and a.text_param = #{textParam}</if>
-            <if test="bedNo != null">and a.bed_no = #{bedNo}</if>
-            <if test="sendType != null  and sendType != ''">and a.send_type = #{sendType}</if>
-            <if test="operator != null  and operator != ''">and a.operator = #{operator}</if>
-            <if test="operatorNo != null  and operatorNo != ''">and a.operator_no = #{operatorNo}</if>
-            <if test="wechat != null  and wechat != ''">and a.wechat = #{wechat}</if>
-            <if test="hospType != null  and hospType != ''">and a.hosp_type = #{hospType}</if>
-            <if test="libtemplateid != null ">and a.libtemplateid = #{libtemplateid}</if>
-            <if test="libtemplatename != null ">and a.libtemplatename = #{libtemplatename}</if>
-            <if test="openid != null ">and a.openid = #{openid}</if>
-            <if test="longSendTime != null ">and a.long_send_time = #{longSendTime}</if>
-            <if test="sendstate != null ">and a.sendstate = #{sendstate}</if>
-            <if test="drname != null  and drname != ''">and a.drname like concat('%', #{drname}, '%')</if>
-            <if test="drcode != null ">and a.drcode = #{drcode}</if>
-            <if test="starttime != null ">and a.starttime = #{starttime}</if>
-            <if test="endtime != null ">and a.endtime = #{endtime}</if>
-            <if test="excep != null ">and a.excep = #{excep}</if>
-            <if test="nurseId != null ">and a.nurse_id = #{nurseId}</if>
-            <if test="nurseName != null ">and a.nurse_name = #{nurseName}</if>
-            <if test="score != null">and a.score = #{score}</if>
-            <if test="remark != null">and a.remark = #{remark}</if>
-            <if test="suggest != null">and a.suggest = #{suggest}</if>
-            <if test="createBy != null">and a.create_by = #{createBy}</if>
-            <if test="visitTime != null">and a.visit_time = #{visitTime}</if>
+            <if test="senddate != null ">and senddate = #{senddate}</if>
+            <if test="senduuid != null  and senduuid != ''">and senduuid = #{senduuid}</if>
+            <if test="result != null  and result != ''">and result = #{result}</if>
+            <if test="finishtime != null ">and finishtime = #{finishtime}</if>
+            <if test="recordid != null ">and recordid = #{recordid}</if>
+            <if test="exrecallcount != null ">and exrecallcount = #{exrecallcount}</if>
+            <if test="pulltime != null ">and pulltime = #{pulltime}</if>
+            <if test="deptcode != null  and deptcode != ''">and deptcode = #{deptcode}</if>
+            <if test="deptname != null  and deptname != ''">and deptname = #{deptname}</if>
+            <if test="labelstatus != null ">and labelstatus = #{labelstatus}</if>
+            <if test="isupload != null ">and isupload = #{isupload}</if>
+            <if test="uploadTime != null ">and upload_time = #{uploadTime}</if>
+            <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
+            <if test="pid != null ">and pid = #{pid}</if>
+            <if test="preachform != null ">and preachform = #{preachform}</if>
+            <if test="guid != null  and guid != ''">and guid = #{guid}</if>
+            <if test="textParam != null  and textParam != ''">and text_param = #{textParam}</if>
+            <if test="bedNo != null">and bed_no = #{bedNo}</if>
+            <if test="sendType != null  and sendType != ''">and send_type = #{sendType}</if>
+            <if test="operator != null  and operator != ''">and operator = #{operator}</if>
+            <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>
+            <if test="libtemplateid != null ">and libtemplateid = #{libtemplateid}</if>
+            <if test="libtemplatename != null ">and libtemplatename = #{libtemplatename}</if>
+            <if test="openid != null ">and openid = #{openid}</if>
+            <if test="longSendTime != null ">and long_send_time = #{longSendTime}</if>
+            <if test="sendstate != null ">and sendstate = #{sendstate}</if>
+            <if test="drname != null  and drname != ''">and drname like concat('%', #{drname}, '%')</if>
+            <if test="taskName != null  and taskName != ''">and task_name like concat('%', #{taskName}, '%')</if>
+            <if test="drcode != null and drcode != ''">and (drcode = #{drcode}</if>
+            <if test="nurseId != null  and nurseId != ''">or nurse_id = #{nurseId})</if>
+            <if test="starttime != null ">and starttime = #{starttime}</if>
+            <if test="endtime != null ">and endtime = #{endtime}</if>
+            <if test="excep != null ">and excep = #{excep}</if>
+            <if test="nurseName != null ">and nurse_name = #{nurseName}</if>
+            <if test="score != null">and score = #{score}</if>
+            <!--            <if test="visitCount != null">and visit_count = #{visitCount}</if>-->
+            <if test="visitCount != null and visitCount == 1">
+                AND visit_count = 1
+            </if>
+            <if test="visitCount != null and visitCount > 1">
+                AND visit_count > 1
+            </if>
+            <if test="remark != null">and remark = #{remark}</if>
+            <if test="suggest != null">and suggest = #{suggest}</if>
+            <if test="createBy != null">and create_by = #{createBy}</if>
+            <if test="taskGuid != null">and task_guid = #{taskGuid}</if>
+            <if test="isVisitAgain != null">and is_visit_again = #{isVisitAgain}</if>
+            <if test="visitTime != null">and visit_time = #{visitTime}</if>
+            <!--<if test="visitDeptCode != null">and visit_dept_code = #{visitDeptCode}</if>
+            <if test="visitDeptName != null">and visit_dept_name = #{visitDeptName}</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>
         </where>
-        GROUP BY a.id,
-        a.hosp_type,
-        a.suggest,
-        a.sendstate,
-        a.endtime,
-        a.nurse_id,
-        a.nurse_name,
-        a.starttime,
-        a.submit,
-        a.inhospid,
-        a.drname,
-        a.excep,
-        a.drcode,
-        a.long_send_time,
-        a.openid,
-        a.remark,
-        a.service_type,
-        a.libtemplateid,
-        a.libtemplatename,
-        a.hospno,
-        a.score,
-        a.phone,
-        a.sex,
-        a.age,
-        a.patid,
-        a.sfzh,
-        a.addr,
-        a.senderdetail,
-        a.type,
-        a.taskid,
-        a.templateid,
-        a.templatename,
-        a.senddate,
-        a.visit_time,
-        a.senduuid,
-        a.result,
-        a.finishtime,
-        a.recordid,
-        a.exrecallcount,
-        a.pulltime,
-        a.deptcode,
-        a.labelstatus,
-        a.del_flag,
-        a.update_by,
-        a.update_time,
-        a.create_by,
-        a.create_time,
-        a.isupload,
-        a.upload_time,
-        a.orgid,
-        a.pid,
-        a.guid,
-        a.text_param,
-        a.preachform,
-        a.bed_no,
-        a.send_type,
-        a.task_name,
-        a.task_desc,
-        a.operator_no,
-        a.operator,
-        a.wechat,
-        a.sendname,
-        a.roomno,
-        a.admindate,
-        a.deptname,
-        a.stop_state,
-        a.leavehospitaldistrictcode,
-        a.leavehospitaldistrictname,
-        a.diagname
-        order by a.visit_time desc
-        <if test="serviceType != null  and serviceType != ''and serviceType != '2'and serviceType != '3'">
-            ,a.long_send_time desc
-        </if>
-        <if test="serviceType != null  and serviceType != ''and serviceType == '2'">,a.endtime desc</if>
-        <if test="serviceType != null  and serviceType != ''and serviceType == '3'">,a.admindate desc</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==5">order by admindate asc</if>
+        <if test="sort != null  and sort==6">order by admindate desc</if>
 
-
+        <!-- order by update_time desc,id desc -->
     </select>
+
 
     <select id="selectServiceSubtaskById" parameterType="Long" resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
@@ -491,6 +403,7 @@
             <if test="sendstate != null ">sendstate,</if>
             <if test="inhospid != null ">inhospid,</if>
             <if test="visitTime != null ">visit_time,</if>
+            <if test="leavediagname != null ">leavediagname,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="sendname != null">#{sendname},</if>
@@ -563,6 +476,7 @@
             <if test="sendstate != null ">#{sendstate},</if>
             <if test="inhospid != null ">#{inhospid},</if>
             <if test="visitTime != null ">#{visitTime},</if>
+            <if test="leavediagname != null ">#{leavediagname},</if>
         </trim>
     </insert>
 
@@ -639,6 +553,7 @@
             <if test="suggest != null ">suggest=#{suggest},</if>
             <if test="inhospid != null ">inhospid=#{inhospid},</if>
             <if test="visitTime != null ">visit_time=#{visitTime},</if>
+            <if test="leavediagname != null ">leavediagname=#{leavediagname},</if>
         </trim>
         where id = #{id}
     </update>
@@ -721,6 +636,7 @@
         <where>
             <if test="patid != null ">patid=#{patid}</if>
             <if test="taskid != null ">and taskid=#{taskid}</if>
+            <if test="leavediagname != null ">and leavediagname=#{leavediagname}</if>
         </where>
     </update>
 
@@ -797,6 +713,7 @@
             <if test="suggest != null ">suggest=#{suggest},</if>
             <if test="inhospid != null ">inhospid=#{inhospid},</if>
             <if test="visitTime != null ">visit_time=#{visitTime},</if>
+            <if test="leavediagname != null ">leavediagname=#{leavediagname},</if>
         </trim>
         where patid = #{patid} and taskid = #{taskid}
     </update>
@@ -908,6 +825,7 @@
                nurse_name,
                remark,
                visit_time,
+               leavediagname,
                diagname
         FROM service_subtask,
              JSON_TABLE(send_time_slot, '$[*]' COLUMNS (
@@ -922,7 +840,7 @@
     <!--    鑾峰彇闅忚闂ㄨ瘖姣忔湀鐨勬暟閲�-->
     <select id="getSfFzInfoEveryMonth" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
             resultMap="ServiceSubtaskResult2">
-        SELECT TO_DATE(st.finishtime, '%Y-%m') AS month,
+        SELECT to_char(st.finishtime, 'YYYY-MM') AS month,
               st.service_type as service_type,
 		      st.id as subTaskId,
     COUNT(*) AS count
@@ -934,14 +852,236 @@
         WHERE
             dd.user_id =#{userId}
           AND st.finishtime IS NOT NULL
-          and TO_DATE(st.finishtime
-            , '%Y-%m') &gt;= #{startTime}
-          and TO_DATE(st.finishtime
-            , '%Y-%m') &lt;= #{endTime}
+          and to_char(st.finishtime
+            , 'YYYY-MM') &gt;= #{startTime}
+          and to_char(st.finishtime
+            , 'YYYY-MM') &lt;= #{endTime}
         GROUP BY
             month, st.service_type, st.id
         ORDER BY
             month, st.service_type, st.id;
     </select>
 
+
+    <!-- 鏈嶅姟缁熻鏌ヨ - 鎸夋椂闂寸淮搴︾粺璁″嚭闄�/闂ㄨ瘖闅忚鏁版嵁 -->
+    <select id="getServiceStatistics" parameterType="com.smartor.domain.ServiceStatisticsRequest"
+            resultType="com.smartor.domain.ServiceStatisticsResponse">
+        SELECT
+        timePeriod,
+        SUM(dischargeFollowCount) AS dischargeFollowCount,
+        SUM(outpatientFollowCount) AS outpatientFollowCount,
+        SUM(pmiCount) AS pmiCount,
+        SUM(pmoCount) AS pmoCount
+        FROM (
+        -- 闅忚鏁版嵁
+        SELECT
+        <choose>
+            <when test="timeType == 'day'">
+                to_char(visit_time, 'YYYY-MM-DD') AS timePeriod,
+            </when>
+            <when test="timeType == 'month'">
+                to_char(visit_time, 'YYYY-MM') AS timePeriod,
+            </when>
+            <when test="timeType == 'year'">
+                to_char(visit_time, 'YYYY') AS timePeriod,
+            </when>
+            <when test="timeType == 'week'">
+                CONCAT(YEAR(visit_time), '-W', LPAD(WEEK(visit_time, 1), 2, '0')) AS timePeriod,
+            </when>
+            <otherwise>
+                to_char(visit_time, 'YYYY-MM-DD') AS timePeriod,
+            </otherwise>
+        </choose>
+        COUNT(CASE WHEN service_type = '2' THEN 1 END) AS dischargeFollowCount,
+        COUNT(CASE WHEN service_type = '3' THEN 1 END) AS outpatientFollowCount,
+        0 AS pmiCount,
+        0 AS pmoCount
+        FROM service_subtask
+        WHERE
+        del_flag = '0'
+        <if test="startDate != null and endDate != null">
+            AND  visit_time  &gt;=  #{startDate}
+            AND  visit_time  &lt;=  #{endDate}
+        </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="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
+            AND leavehospitaldistrictcode IN
+            <foreach collection="leavehospitaldistrictcodes" item="districtcode" open="(" separator="," close=")">
+                #{districtcode}
+            </foreach>
+        </if>
+
+        <if test="serviceTypes != null and serviceTypes.size() > 0">
+            AND service_type IN
+            <foreach collection="serviceTypes" item="serviceType" open="(" separator="," close=")">
+                #{serviceType}
+            </foreach>
+        </if>
+
+        GROUP BY
+        <choose>
+            <when test="timeType == 'day'">
+                to_char(visit_time, 'YYYY-MM-DD')
+            </when>
+            <when test="timeType == 'month'">
+                to_char(visit_time, 'YYYY-MM')
+            </when>
+            <when test="timeType == 'year'">
+                to_char(visit_time, 'YYYY')
+            </when>
+            <when test="timeType == 'week'">
+                CONCAT(YEAR(visit_time), '-W', LPAD(WEEK(visit_time, 1), 2, '0'))
+            </when>
+            <otherwise>
+                to_char(visit_time, 'YYYY-MM-DD')
+            </otherwise>
+        </choose>
+
+        UNION ALL
+
+        -- 鍑洪櫌浜烘鏁版嵁
+        SELECT
+        <choose>
+            <when test="timeType == 'day'">
+                to_char(endtime, 'YYYY-MM-DD') AS timePeriod,
+            </when>
+            <when test="timeType == 'month'">
+                to_char(endtime, 'YYYY-MM') AS timePeriod,
+            </when>
+            <when test="timeType == 'year'">
+                to_char(endtime, 'YYYY') AS timePeriod,
+            </when>
+            <when test="timeType == 'week'">
+                CONCAT(YEAR(endtime), '-W', LPAD(WEEK(endtime, 1), 2, '0')) AS timePeriod,
+            </when>
+            <otherwise>
+                to_char(endtime, 'YYYY-MM-DD') AS timePeriod,
+            </otherwise>
+        </choose>
+        0 AS dischargeFollowCount,
+        0 AS outpatientFollowCount,
+        COUNT( patid) AS pmiCount,
+        0 AS pmoCount
+        FROM pat_med_inhosp
+        WHERE del_flag = '0'
+        <if test="startDate != null and endDate != null">
+            AND endtime  &gt;=  #{startDate}
+            AND  endtime  &lt;=  #{endDate}
+        </if>
+
+        AND inhospstate=1
+        <if test="orgid != null">
+            AND orgid = #{orgid}
+        </if>
+
+        <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
+            AND leavehospitaldistrictcode IN
+            <foreach collection="leavehospitaldistrictcodes" item="districtcode" open="(" separator="," close=")">
+                #{districtcode}
+            </foreach>
+        </if>
+
+        <if test="deptcodes != null and deptcodes.size() > 0">
+            AND leaveldeptcode IN
+            <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">
+                #{deptcode}
+            </foreach>
+        </if>
+
+        GROUP BY
+        <choose>
+            <when test="timeType == 'day'">
+                to_char(endtime, 'YYYY-MM-DD')
+            </when>
+            <when test="timeType == 'month'">
+                to_char(endtime, 'YYYY-MM')
+            </when>
+            <when test="timeType == 'year'">
+                to_char(endtime, 'YYYY')
+            </when>
+            <when test="timeType == 'week'">
+                CONCAT(YEAR(endtime), '-W', LPAD(WEEK(endtime, 1), 2, '0'))
+            </when>
+            <otherwise>
+                to_char(endtime, 'YYYY-MM-DD')
+            </otherwise>
+        </choose>
+
+        UNION ALL
+
+        -- 闂ㄨ瘖浜烘鏁版嵁
+        SELECT
+        <choose>
+            <when test="timeType == 'day'">
+                to_char(admitdate, 'YYYY-MM-DD') AS timePeriod,
+            </when>
+            <when test="timeType == 'month'">
+                to_char(admitdate, 'YYYY-MM') AS timePeriod,
+            </when>
+            <when test="timeType == 'year'">
+                to_char(admitdate, 'YYYY') AS timePeriod,
+            </when>
+            <when test="timeType == 'week'">
+                CONCAT(YEAR(admitdate), '-W', LPAD(WEEK(admitdate, 1), 2, '0')) AS timePeriod,
+            </when>
+            <otherwise>
+                to_char(admitdate, 'YYYY-MM-DD') AS timePeriod,
+            </otherwise>
+        </choose>
+        0 AS dischargeFollowCount,
+        0 AS outpatientFollowCount,
+        0 AS pmiCount,
+        COUNT( patid) AS pmoCount
+        FROM pat_med_outhosp
+        WHERE del_flag = '0'
+        <if test="startDate != null and endDate != null">
+            AND admitdate &gt;= #{startDate}
+            AND admitdate &lt;= #{endDate}
+        </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>
+
+        GROUP BY
+        <choose>
+            <when test="timeType == 'day'">
+                to_char(admitdate, 'YYYY-MM-DD')
+            </when>
+            <when test="timeType == 'month'">
+                to_char(admitdate, 'YYYY-MM')
+            </when>
+            <when test="timeType == 'year'">
+                to_char(admitdate, 'YYYY')
+            </when>
+            <when test="timeType == 'week'">
+                CONCAT(YEAR(admitdate), '-W', LPAD(WEEK(admitdate, 1), 2, '0'))
+            </when>
+            <otherwise>
+                to_char(admitdate, 'YYYY-MM-DD')
+            </otherwise>
+        </choose>
+        ) AS combined_data
+        GROUP BY timePeriod
+        ORDER BY timePeriod DESC
+    </select>
+
+
 </mapper>

--
Gitblit v1.9.3