From 2d3c7bb2b88bdd09b209243fe07e756a8abeb030 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期五, 05 六月 2026 14:12:07 +0800
Subject: [PATCH] 【丽水】随访统计全部

---
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml |  951 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 815 insertions(+), 136 deletions(-)

diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index a479da0..b77ca33 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -87,6 +87,12 @@
         <result property="currentPreachform" column="current_preachform"/>
         <result property="taskSituation" column="task_situation"/>
         <result property="isabnormal" column="isabnormal"/>
+        <result property="continueFlag" column="continue_flag"/>
+        <result property="continueTimeNow" column="continue_time_now"/>
+        <result property="continueContent" column="continue_content"/>
+        <result property="continueCount" column="continue_count"/>
+        <result property="continueTimeNext" column="continue_time_next"/>
+        <result property="operationItemId" column="operation_item_id"/>
     </resultMap>
 
     <resultMap type="com.smartor.domain.ServiceSubtaskCount" id="ServiceSubtaskResult2">
@@ -115,6 +121,28 @@
         <result property="options" column="options"/>
     </resultMap>
 
+    <resultMap type="com.smartor.domain.ServiceSubtaskStatistic" id="ServiceSubtaskStatisticResult">
+        <result property="taskName" column="task_name"/>
+        <result property="drcode" column="drcode"/>
+        <result property="drname" column="drname"/>
+        <result property="dischargeCount" column="discharge_count"/>
+        <result property="nonFollowUp" column="non_follow_up"/>
+        <result property="filterCount" column="filter_count"/>
+        <result property="followUpNeeded" column="follow_up_needed"/>
+        <result property="needFollowUp" column="need_follow_up"/>
+        <result property="pendingFollowUp" column="pending_follow_up"/>
+        <result property="followUpFail" column="follow_up_fail"/>
+        <result property="manual" column="manual"/>
+        <result property="voice" column="voice"/>
+        <result property="sms" column="sms"/>
+        <result property="weChat" column="we_chat"/>
+        <result property="taskSituation1" column="task_situation1"/>
+        <result property="taskSituation2" column="task_situation2"/>
+        <result property="taskSituation3" column="task_situation3"/>
+        <result property="taskSituation4" column="task_situation4"/>
+        <result property="taskSituation5" column="task_situation5"/>
+        <result property="taskSituation6" column="task_situation6"/>
+    </resultMap>
     <sql id="selectServiceSubtaskVo">
         select id,
                hosp_type,
@@ -202,11 +230,17 @@
                visit_type,
                management_doctor,
                management_doctor_code,
+               continue_flag,
+               continue_time_now,
+               continue_content,
+               continue_count,
+               continue_time_next,
+               operation_item_id,
                task_situation
         from service_subtask
     </sql>
 
-    <select id="selectServiceSubtaskBySendstate" parameterType="com.smartor.domain.ServiceSubtaskVO"
+    <select id="selectServiceSubtaskBySendstate" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
             resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
         where 1=1
@@ -215,6 +249,10 @@
             and orgid = #{orgid}
         </if>
         <if test="taskid != null ">and taskid = #{taskid}</if>
+        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
+        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+        <if test="continueCount != null ">and continue_count = #{continueCount}</if>
+        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext}</if>
         <if test="serviceType != null ">and service_type = #{serviceType}</if>
         <if test="patid != null ">and patid = #{patid}</if>
         <if test="sendstates!=null">
@@ -226,28 +264,35 @@
         </if>
     </select>
 
-    <select id="queryServiceSubtaskList" parameterType="com.smartor.domain.ServiceSubtaskVO"
-            resultMap="ServiceSubtaskResult">
-        <include refid="selectServiceSubtaskVo"/>
-        where 1=1
-            and del_flag = 0
-            <if test="orgid != null and orgid != ''">
-                and orgid = #{orgid}
-            </if>
-            <if test="taskid != null ">and taskid = #{taskid}</if>
-            <if test="visitTime != null">
-                AND date_format(visit_time,'%y%m%d') &lt;= date_format(#{visitTime},'%y%m%d')
-            </if>
-            <if test="sendstate != null ">and sendstate = #{sendstate}</if>
-
-    </select>
-
-
-    <select id="selectServiceSubtaskList" parameterType="com.smartor.domain.ServiceSubtaskVO"
+    <select id="queryServiceSubtaskList" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
             resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
         where 1=1
         and del_flag = 0
+        <if test="orgid != null and orgid != ''">
+            and orgid = #{orgid}
+        </if>
+        <if test="taskid != null ">and taskid = #{taskid}</if>
+        <if test="visitTime != null">
+            AND date_format(visit_time,'%y%m%d') &lt;= date_format(#{visitTime},'%y%m%d')
+        </if>
+        <if test="sendstate != null ">and sendstate = #{sendstate}</if>
+        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
+        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+        <if test="continueCount != null ">and continue_count = #{continueCount}</if>
+        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext}</if>
+    </select>
+
+
+    <select id="selectServiceSubtaskList" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
+            resultMap="ServiceSubtaskResult">
+        <include refid="selectServiceSubtaskVo"/>
+        where del_flag = 0
+        <if test="subId != null ">and id = #{subId}</if>
+        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
+        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+        <if test="continueCount != null ">and continue_count = #{continueCount}</if>
+        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext}</if>
         <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
@@ -278,6 +323,12 @@
         <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="sendstates != null and sendstates.size() > 0">
+            AND sendstate IN
+            <foreach collection="sendstates" item="state" open="(" separator="," close=")">
+                #{state}
+            </foreach>
+        </if>
         <!-- taskIds绛涢�� -->
         <if test="taskIds != null and taskIds.size() > 0">
             AND taskid IN
@@ -297,10 +348,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">
@@ -324,8 +375,9 @@
             </if>
         </if>
         <if test="deptOrDistrict==2">
+            AND (1=1
             <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
-                AND (leavehospitaldistrictcode IN
+                AND leavehospitaldistrictcode IN
                 <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="("
                          separator=","
                          close=")">
@@ -335,10 +387,49 @@
             <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0">
                 OR deptcode IN
                 <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
-                         close="))">
+                         close=")">
                     #{leaveldeptcode}
                 </foreach>
+            </if>)
+        </if>
+        <if test="deptOrDistrict==3">
+            AND (1=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=" visitDeptCodes != null and visitDeptCodes.size()>0">
+                AND visit_dept_code IN
+                <foreach collection="visitDeptCodes" item="visitDeptCode" open="(" separator=","
+                         close=")">
+                    #{visitDeptCode}
+                </foreach>
+            </if>
+            )
+        </if>
+
+        <if test="deptOrDistrict==4">
+            AND (1=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=" visitDeptCodes != null and visitDeptCodes.size()>0">
+                OR visit_dept_code IN
+                <foreach collection="visitDeptCodes" item="visitDeptCode" open="(" separator=","
+                         close=")">
+                    #{visitDeptCode}
+                </foreach>
+            </if>
+            )
         </if>
 
         <if test="visitTime != null">
@@ -382,7 +473,6 @@
         <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>
@@ -395,10 +485,6 @@
         <if test="taskGuid != null">and task_guid = #{taskGuid}</if>
         <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
         <if test="isVisitAgain != null">and is_visit_again = #{isVisitAgain}</if>
-        <!--            <if test="dateLimit != null and dateLimit = '1'"> and CURDATE() + 1 > long_send_time</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="("
@@ -409,16 +495,51 @@
         </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>
         <if test="sort != null  and sort==8">order by visit_time desc</if>
-
-        <!-- order by update_time desc,id desc -->
+        <if test="sort != null  and sort==9">order by sendname asc</if>
+        <if test="pageSize != null  and pageNum != null">limit ${pageSize} OFFSET ${pageNum}</if>
     </select>
-    <select id="getCompensateServiceSubtaskList" parameterType="com.smartor.domain.ServiceSubtaskVO"
+
+    <select id="selectSatisfactionSubtaskList" parameterType="com.smartor.domain.VO.PatSatisfactionReqVO"
+            resultMap="ServiceSubtaskResult">
+        <include refid="selectServiceSubtaskVo"/>
+        where 1=1
+        and del_flag = 0
+        <if test="questionType != null">and type = #{questionType}</if>
+
+        <if test="hospitaldistrictcodes != null and hospitaldistrictcodes.size() > 0">
+            AND leavehospitaldistrictcode IN
+            <foreach collection="hospitaldistrictcodes" item="hospitaldistrictcode" open="(" separator=","
+                     close=")">
+                #{hospitaldistrictcode}
+            </foreach>
+        </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="serviceTypes != null and serviceTypes.size() > 0">
+            AND service_type IN
+            <foreach collection="serviceTypes" item="serviceType" open="(" separator=","
+                     close=")">
+                #{serviceType}
+            </foreach>
+        </if>
+
+        <if test="startTime != null and endTime != null">
+            AND date_format(visit_time,'%y%m%d') >= date_format(#{startTime},'%y%m%d')
+            AND date_format(visit_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
+        </if>
+    </select>
+    <select id="getCompensateServiceSubtaskList" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
             resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
         where del_flag = 0
@@ -429,9 +550,13 @@
             AND date_format(visit_time,'%y%m%d') &lt;= date_format(#{visitTime},'%y%m%d')
         </if>
         <if test="sendstate != null ">and sendstate = #{sendstate}</if>
+        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
+        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+        <if test="continueCount != null ">and continue_count = #{continueCount}</if>
+        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext}</if>
     </select>
 
-    <select id="selectServiceSubtaskListByCreateTime" parameterType="com.smartor.domain.ServiceSubtaskVO"
+    <select id="selectServiceSubtaskListByCreateTime" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
             resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
         where del_flag = 0
@@ -454,11 +579,15 @@
         <if test="managementDoctor != null">and management_doctor = #{managementDoctor}</if>
         <if test="currentPreachform != null">and current_preachform = #{currentPreachform}</if>
         <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
+        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
+        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+        <if test="continueCount != null ">and continue_count = #{continueCount}</if>
+        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext}</if>
 
     </select>
 
 
-    <select id="selectServiceSubtaskListAgain" parameterType="com.smartor.domain.ServiceSubtaskVO"
+    <select id="selectServiceSubtaskListAgain" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
             resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
         where 1=1
@@ -511,7 +640,10 @@
         <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
         <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
         <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if>
-
+        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
+        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+        <if test="continueCount != null ">and continue_count = #{continueCount}</if>
+        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext}</if>
     </select>
 
     <select id="selectSendstateByCondition" parameterType="com.smartor.domain.ServiceSubtask" resultType="Integer">
@@ -545,6 +677,8 @@
             AND date_format(visit_time,'%y%m%d') &lt;= date_format(#{endtime},'%y%m%d')
         </if>
         <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
+        <if test="serviceType != null and serviceType != ''">and service_type = #{serviceType}</if>
+        <if test="serviceTypes != null and serviceTypes != ''">and service_type IN (#{serviceTypes})</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>
@@ -559,23 +693,29 @@
         ) a
     </select>
 
-    <select id="selectTimelyRateBatch" parameterType="com.smartor.domain.ServiceSubtask" resultType="map">
+    <select id="selectTimelyRateBatch" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity" resultType="map">
         SELECT
         <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
+        SUM(CASE WHEN finishtime IS NOT NULL AND DATE(visit_time) &lt;= DATE(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
+        </if>
+        <if test="rateDay == null">
+            NULL AS rate
+        </if>
         FROM service_subtask
         WHERE del_flag = 0
-        <if test="orgid != null">AND orgid = #{orgid}</if>
+        AND visit_time IS NOT NULL
         <if test="starttime == null and endtime==null">
-            AND visit_time &lt; NOW()
+            AND DATE(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)
         </if>
-        <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</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>
@@ -587,6 +727,19 @@
         </if>
         <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
         <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</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="serviceTypeList != null">
+            AND service_type IN
+            <foreach collection="serviceTypeList" item="serviceType" open="(" separator=","
+                     close=")">
+                #{serviceType}
+            </foreach>
+        </if>
         <if test="groupKey != null and groupKey != ''">
             AND ${groupKey} IN
             <foreach collection="groupKeyList" item="key" open="(" separator=","
@@ -616,6 +769,8 @@
             AND date_format(visit_time,'%y%m%d') &lt;= date_format(#{endtime},'%y%m%d')
         </if>
         <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
+        <if test="serviceType != null and serviceType != ''">and service_type = #{serviceType}</if>
+        <if test="serviceTypes != null and serviceTypes != ''">and service_type IN (#{serviceTypes})</if>
         <if test="isabnormal != null ">and isabnormal = #{isabnormal}</if>
         <if test="deptcode != null  and deptcode != ''">and deptcode = #{deptcode}</if>
         <if test="deptname != null  and deptname != ''">and deptname = #{deptname}</if>
@@ -639,13 +794,18 @@
             resultMap="ServiceSubtaskResult">
         select sendstate,starttime,endtime,nurse_name,phone,sex,task_name,sendname,leavediagname,visit_time FROM
         service_subtask WHERE del_flag=0
+        and service_type != 4
         <if test="leavediagname != null">and leavediagname like concat('%',#{leavediagname}, '%')</if>
         <if test="sendname != null">and sendname like concat('%',#{sendname}, '%')</if>
         <if test="taskName != null">and task_name like concat('%',#{taskName}, '%')</if>
         <if test="sendstate != null">and sendstate = #{sendstate}</if>
         <if test="orgid != null">and orgid =#{orgid}</if>
-        GROUP BY sendname,sendstate,starttime,endtime,nurse_name,phone,sex,task_name,leavediagname,visit_time ORDER BY
-        visit_time
+        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
+        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+        <if test="continueCount != null ">and continue_count = #{continueCount}</if>
+        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext}</if>
+        GROUP BY sendname,sendstate,starttime,endtime,nurse_name,phone,sex,task_name,leavediagname,visit_time
+        ORDER BY sendname,visit_time
         <if test="pageSize != null  and pageNum != null">limit ${pageSize} OFFSET ${pageNum}</if>
     </select>
 
@@ -737,6 +897,12 @@
             <if test="currentPreachform != null">current_preachform,</if>
             <if test="taskSituation != null">task_situation,</if>
             <if test="isabnormal != null">isabnormal,</if>
+            <if test="continueFlag != null ">continue_flag,</if>
+            <if test="continueTimeNow != null ">continue_time_now,</if>
+            <if test="continueCount != null ">continue_count,</if>
+            <if test="continueTimeNext != null ">continue_time_next,</if>
+            <if test="continueContent != null ">continue_content,</if>
+            <if test="operationItemId != null ">operation_item_id,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="sendname != null">#{sendname},</if>
@@ -823,6 +989,12 @@
             <if test="currentPreachform != null">#{currentPreachform},</if>
             <if test="taskSituation != null">#{taskSituation},</if>
             <if test="isabnormal != null">#{isabnormal},</if>
+            <if test="continueFlag != null ">#{continueFlag},</if>
+            <if test="continueTimeNow != null ">#{continueTimeNow,jdbcType=TIMESTAMP},</if>
+            <if test="continueCount != null ">#{continueCount},</if>
+            <if test="continueTimeNext != null ">#{continueTimeNext,jdbcType=TIMESTAMP},</if>
+            <if test="continueContent != null ">#{continueContent},</if>
+            <if test="operationItemId != null ">#{operationItemId},</if>
         </trim>
     </insert>
 
@@ -914,6 +1086,12 @@
             <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if>
             <if test="taskSituation != null">task_situation=#{taskSituation},</if>
             <if test="isabnormal != null">isabnormal=#{isabnormal},</if>
+            <if test="continueFlag != null ">continue_flag = #{continueFlag},</if>
+            <if test="continueTimeNow != null ">continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP},</if>
+            <if test="continueCount != null ">continue_count = #{continueCount},</if>
+            <if test="continueTimeNext != null ">continue_time_next = #{continueTimeNext,jdbcType=TIMESTAMP},</if>
+            <if test="continueContent != null ">continue_content = #{continueContent},</if>
+            <if test="operationItemId != null ">operation_item_id = #{operationItemId},</if>
         </trim>
         where id = #{id}
     </update>
@@ -1006,6 +1184,11 @@
             <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if>
             <if test="taskSituation != null">task_situation=#{taskSituation},</if>
             <if test="isabnormal != null">isabnormal=#{isabnormal},</if>
+            <if test="continueFlag != null ">continue_flag = #{continueFlag},</if>
+            <if test="continueTimeNow != null ">continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP},</if>
+            <if test="continueCount != null ">continue_count = #{continueCount},</if>
+            <if test="continueTimeNext != null ">continue_time_next = #{continueTimeNext,jdbcType=TIMESTAMP},</if>
+            <if test="continueContent != null ">continue_content = #{continueContent},</if>
         </trim>
         where 1=1
         <if test="patid != null ">and patid = #{patid}</if>
@@ -1021,6 +1204,7 @@
             <if test="sendname != null">sendname = #{sendname},</if>
             <if test="phone != null">phone = #{phone},</if>
             <if test="sex != null">sex = #{sex},</if>
+            <if test="delFlag != null">del_flag = #{delFlag},</if>
             <if test="sendstate != null ">sendstate = #{sendstate},</if>
             <if test="age != null">age = #{age},</if>
             <if test="sfzh != null">sfzh = #{sfzh},</if>
@@ -1102,8 +1286,16 @@
             <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if>
             <if test="taskSituation != null">task_situation=#{taskSituation},</if>
             <if test="isabnormal != null">isabnormal=#{isabnormal},</if>
+            <if test="continueFlag != null ">continue_flag = #{continueFlag},</if>
+            <if test="continueTimeNow != null ">continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP},</if>
+            <if test="continueCount != null ">continue_count = #{continueCount},</if>
+            <if test="continueTimeNext != null ">continue_time_next = #{continueTimeNext,jdbcType=TIMESTAMP},</if>
+            <if test="continueContent != null ">continue_content = #{continueContent},</if>
         </trim>
         where patid = #{patid} and taskid = #{taskid}
+        <if test="id != null ">
+            and id = #{id}
+        </if>
     </update>
 
     <update id="updateServiceSubtaskByTaskGuid" parameterType="com.smartor.domain.ServiceSubtask">
@@ -1193,6 +1385,11 @@
             <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if>
             <if test="taskSituation != null">task_situation=#{taskSituation},</if>
             <if test="isabnormal != null">isabnormal=#{isabnormal},</if>
+            <if test="continueFlag != null ">continue_flag = #{continueFlag},</if>
+            <if test="continueTimeNow != null ">continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP},</if>
+            <if test="continueCount != null ">continue_count = #{continueCount},</if>
+            <if test="continueTimeNext != null ">continue_time_next = #{continueTimeNext,jdbcType=TIMESTAMP},</if>
+            <if test="continueContent != null ">continue_content = #{continueContent},</if>
         </trim>
         where task_guid = #{taskGuid} and task_name = #{taskName}
     </update>
@@ -1216,7 +1413,45 @@
 
     <select id="getSfStatistics" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
             resultMap="ServiceSubtaskResult">
-        <include refid="selectServiceSubtaskVo"/>
+        select id,
+        visit_count,
+        is_visit_again,
+        type,
+        orgid,
+        drcode,
+        drname,
+        leavehospitaldistrictcode,
+        leavehospitaldistrictname,
+        deptcode,
+        deptname,
+        sendstate,
+        preachform,
+        current_preachform,
+        excep,
+        nurse_id,
+        nurse_name,
+        taskid,
+        task_name,
+        visit_time,
+        finishtime,
+        endtime,
+        senddate,
+        suggest,
+        result,
+        templateid,
+        templatename,
+        patid,
+        sendname,
+        send_type,
+        recordid,
+        exrecallcount,
+        continue_flag,
+        continue_time_now,
+        continue_content,
+        continue_count,
+        continue_time_next,
+        task_situation
+        from service_subtask
         where 1=1
         and del_flag = 0
         <if test="orgid != null and orgid != ''">
@@ -1250,9 +1485,19 @@
         <if test="visitDeptCode != null">and visit_dept_code = #{visitDeptCode}</if>
         <if test="visitDeptName != null">and visit_dept_name = #{visitDeptName}</if>
         <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
+        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
+        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+        <if test="continueCount != null ">and continue_count = #{continueCount}</if>
+        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext,jdbcType=TIMESTAMP}</if>
         <!-- 鐩墠鍙粺璁¤闊冲拰闂嵎 -->
         <if test="type != null">
             and type = #{type}
+        </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="groupKey != null and groupKey != '' and groupKeyList != null and groupKeyList.size>0">
             AND ${groupKey} IN
@@ -1262,6 +1507,123 @@
             </foreach>
         </if>
     </select>
+
+    <select id="getSpecialSfStatistics" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
+            resultMap="ServiceSubtaskStatisticResult">
+        select
+        <if test="groupKey != null and groupKey == 'task_name'">
+            a.task_name,
+        </if>
+        <if test="groupKey != null and groupKey == 'drcode'">
+            b.drcode,
+            b.drname,
+        </if>
+        COUNT(1) AS discharge_count,
+        SUM(CASE WHEN b.sendstate = 4 THEN 1 ELSE 0 END) AS non_follow_up,
+        SUM(CASE WHEN b.sendstate = 4 and b.task_situation = 6 THEN 1 ELSE 0 END) AS filter_count,
+        SUM(CASE WHEN b.sendstate != 4 THEN 1 ELSE 0 END) AS follow_up_needed,
+        SUM(CASE WHEN b.sendstate != 4 THEN 1 ELSE 0 END) AS need_follow_up,
+        SUM(CASE WHEN b.sendstate = 2 THEN 1 ELSE 0 END) AS pending_follow_up,
+        SUM(CASE WHEN b.sendstate = 5 or b.sendstate = 7 THEN 1 ELSE 0 END) AS follow_up_fail,
+        SUM(CASE WHEN b.current_preachform = '1' THEN 1 ELSE 0 END) AS manual,
+        SUM(CASE WHEN b.current_preachform = '3' THEN 1 ELSE 0 END) AS voice,
+        SUM(CASE WHEN b.current_preachform = '4' THEN 1 ELSE 0 END) AS sms,
+        SUM(CASE WHEN b.current_preachform = '5' THEN 1 ELSE 0 END) AS we_chat,
+        SUM(CASE WHEN b.task_situation = 1 THEN 1 ELSE 0 END) AS task_situation1,
+        SUM(CASE WHEN b.task_situation = 2 THEN 1 ELSE 0 END) AS task_situation2,
+        SUM(CASE WHEN b.task_situation = 3 THEN 1 ELSE 0 END) AS task_situation3,
+        SUM(CASE WHEN b.task_situation = 4 THEN 1 ELSE 0 END) AS task_situation4,
+        SUM(CASE WHEN b.task_situation = 5 THEN 1 ELSE 0 END) AS task_situation5,
+        SUM(CASE WHEN b.task_situation = 7 THEN 1 ELSE 0 END) AS task_situation7
+        from service_task a
+        JOIN service_subtask b on a.taskid = b.taskid
+        where 1=1
+        and a.del_flag = '0'
+        and b.del_flag = '0'
+        and a.appltype = '3'
+        <if test="orgid != null and orgid != ''">
+            and a.orgid = #{orgid}
+        </if>
+        <if test="taskId != null">
+            and a.task_id = #{taskId}
+        </if>
+        <if test="taskName != null and taskName != ''">
+            and a.task_name like concat('%', #{taskName}, '%')
+        </if>
+        <if test="diagType != null and diagType != ''">
+            and a.diag_type = #{diagType}
+        </if>
+        <if test="taskIds != null and taskIds.size() > 0">
+            AND a.task_id IN
+            <foreach collection="taskIds" item="taskIdItem" open="(" separator=","
+                     close=")">
+                #{taskIdItem}
+            </foreach>
+        </if>
+        <if test="taskNames != null and taskNames.size() > 0">
+            AND a.task_name IN
+            <foreach collection="taskNames" item="taskNameItem" open="(" separator=","
+                     close=")">
+                #{taskNameItem}
+            </foreach>
+        </if>
+        <if test="diagTypes != null and diagTypes.size() > 0">
+            AND a.diag_type IN
+            <foreach collection="diagTypes" item="diagTypeItem" open="(" separator=","
+                     close=")">
+                #{diagTypeItem}
+            </foreach>
+        </if>
+        <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
+            AND b.leavehospitaldistrictcode IN
+            <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
+                     close=")">
+                #{leavehospitaldistrictcode}
+            </foreach>
+        </if>
+        <if test="deptcodes != null and deptcodes.size() > 0">
+            AND b.deptcode IN
+            <foreach collection="deptcodes" item="deptcode" open="(" separator=","
+                     close=")">
+                #{deptcode}
+            </foreach>
+        </if>
+        <if test="serviceType != null and serviceType.size() > 0">
+            AND b.service_type IN
+            <foreach collection="serviceType" item="serviceType" open="(" separator=","
+                     close=")">
+                #{serviceType}
+            </foreach>
+        </if>
+        <if test="startTime != null and endTime!=null">
+            AND b.visit_time >= DATE(#{startTime})
+            AND b.visit_time &lt; DATE_ADD(DATE(#{endTime}), INTERVAL 1 DAY)
+        </if>
+        <if test="visitDeptCode != null">and b.visit_dept_code = #{visitDeptCode}</if>
+        <if test="visitDeptName != null">and b.visit_dept_name = #{visitDeptName}</if>
+        <if test="isabnormal != null">and b.isabnormal = #{isabnormal}</if>
+        <if test="continueFlag != null ">and b.continue_flag = #{continueFlag}</if>
+        <if test="continueTimeNow != null ">and b.continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+        <if test="continueCount != null ">and b.continue_count = #{continueCount}</if>
+        <if test="continueTimeNext != null ">and b.continue_time_next = #{continueTimeNext,jdbcType=TIMESTAMP}</if>
+        <!-- 鐩墠鍙粺璁¤闊冲拰闂嵎 -->
+        <if test="type != null">
+            and b.type = #{type}
+        </if>
+        <if test="visitCount != null and visitCount == 1">
+            AND b.visit_count = 1
+        </if>
+        <if test="visitCount != null and visitCount > 1">
+            AND b.visit_count > 1
+        </if>
+        <if test="groupKey != null and groupKey == 'task_name'">
+            GROUP BY a.task_name
+        </if>
+        <if test="groupKey != null and groupKey == 'drcode'">
+            GROUP BY b.drcode, b.drname
+        </if>
+    </select>
+
     <select id="getSfStatisticsGroupKey" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
             resultType="String">
         select
@@ -1302,9 +1664,19 @@
         <if test="visitDeptCode != null">and visit_dept_code = #{visitDeptCode}</if>
         <if test="visitDeptName != null">and visit_dept_name = #{visitDeptName}</if>
         <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
+        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
+        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+        <if test="continueCount != null ">and continue_count = #{continueCount}</if>
+        <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext,jdbcType=TIMESTAMP}</if>
         <!-- 鐩墠鍙粺璁¤闊冲拰闂嵎 -->
         <if test="type != null">
             and type = #{type}
+        </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="groupKey != null and groupKey != ''">
             group by ${groupKey}
@@ -1312,6 +1684,134 @@
         <if test="pageSize != null  and pageNum != null">
             limit ${pageSize} OFFSET ${pageNum}
         </if>
+    </select>
+
+    <select id="getSfStatisticsHyperlink" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
+            resultMap="ServiceSubtaskResult">
+            select id,
+            visit_count,
+            is_visit_again,
+            type,
+            orgid,
+            drcode,
+            drname,
+            leavehospitaldistrictcode,
+            leavehospitaldistrictname,
+            deptcode,
+            deptname,
+            sendstate,
+            preachform,
+            current_preachform,
+            excep,
+            nurse_id,
+            nurse_name,
+            taskid,
+            task_name,
+            visit_time,
+            finishtime,
+            endtime,
+            senddate,
+            suggest,
+            result,
+            templateid,
+            templatename,
+            patid,
+            sendname,
+            send_type,
+            recordid,
+            exrecallcount,
+            continue_flag,
+            continue_time_now,
+            continue_content,
+            continue_count,
+            continue_time_next,
+            task_situation
+            from service_subtask
+            where 1=1
+            and del_flag = 0
+            <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="deptcodes != null and deptcodes.size() > 0">
+                AND deptcode IN
+                <foreach collection="deptcodes" item="deptcode" open="(" separator=","
+                         close=")">
+                    #{deptcode}
+                </foreach>
+            </if>
+            <if test="serviceType != null and serviceType.size() > 0">
+                AND service_type IN
+                <foreach collection="serviceType" item="serviceType" open="(" separator=","
+                         close=")">
+                    #{serviceType}
+                </foreach>
+            </if>
+            <if test="startTime != null and endTime!=null">
+                AND visit_time >= DATE(#{startTime})
+                AND visit_time &lt; DATE_ADD(DATE(#{endTime}), INTERVAL 1 DAY)
+            </if>
+            <if test="visitDeptCode != null">and visit_dept_code = #{visitDeptCode}</if>
+            <if test="visitDeptName != null">and visit_dept_name = #{visitDeptName}</if>
+            <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
+            <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
+            <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
+            <if test="continueCount != null ">and continue_count = #{continueCount}</if>
+            <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext,jdbcType=TIMESTAMP}</if>
+            <!-- 鐩墠鍙粺璁¤闊冲拰闂嵎 -->
+            <if test="type != null">
+                and type = #{type}
+            </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="groupKey != null and groupKey != '' and groupKeyList != null and groupKeyList.size>0">
+                AND ${groupKey} IN
+                <foreach collection="groupKeyList" item="key" open="(" separator=","
+                         close=")">
+                    #{key}
+                </foreach>
+            </if>
+            AND sendstate IS NOT NULL
+            <if test="sendstates != null and sendstates.size() > 0">
+                AND sendstate IN
+                <foreach collection="sendstates" item="state" open="(" separator="," close=")">
+                    #{state}
+                </foreach>
+            </if>
+            <if test="currentPreachform != null">
+                AND current_preachform = #{currentPreachform}
+                <if test="followUpCountStyle != null and followUpCountStyle = '1'">
+                    AND sendstate != 4
+                </if>
+            </if>
+            <if test="excep != null and excep != ''">
+                AND excep = #{excep}
+            </if>
+            <if test="taskSituation != null">
+                AND task_situation = #{taskSituation}
+            </if>
+            <if test="drcode != null and drcode != ''">
+                AND drcode = #{drcode}
+            </if>
+            <if test="leavehospitaldistrictcode != null and leavehospitaldistrictcode != ''">
+                AND leavehospitaldistrictcode = #{leavehospitaldistrictcode}
+            </if>
+            <if test="deptcode != null and deptcode != ''">
+                AND deptcode = #{deptcode}
+            </if>
+            <if test="pageSize != null  and pageNum != null">
+                limit ${pageSize} OFFSET ${pageNum}
+            </if>
     </select>
 
     <select id="getSfStatisticsJoy" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
@@ -1748,10 +2248,15 @@
 
     <select id="getDeptRanking" parameterType="com.smartor.domain.PatMedReq" resultType="com.smartor.domain.PatMedRes">
         SELECT deptname,
-               count(1) AS rc
+        count(1) AS rc
         FROM service_subtask
-        WHERE DATE_FORMAT(finishtime, '%Y-%m-%d') >= #{startDate}
-          AND DATE_FORMAT(finishtime, '%Y-%m-%d') &lt;= #{endDate}
+        WHERE DATE_FORMAT(visit_time, '%Y-%m-%d') >= #{startDate}
+        AND DATE_FORMAT(visit_time, '%Y-%m-%d') &lt;= #{endDate}
+        AND service_type IN (2, 13)
+        AND del_flag = '0'
+        <if test="orgid != null">
+            AND orgid = #{orgid}
+        </if>
         GROUP BY deptname
     </select>
 
@@ -1790,6 +2295,7 @@
         FROM service_subtask
         WHERE
         del_flag = '0'
+        AND service_type IN (2, 13)
         <if test="startDate != null and endDate != null">
             AND visit_time >= #{startDate}
             AND visit_time &lt;= DATE_ADD(#{endDate}, INTERVAL 1 DAY)
@@ -1819,25 +2325,6 @@
                 #{serviceType}
             </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
 
@@ -1870,7 +2357,6 @@
             AND endtime >= #{startDate}
             AND endtime &lt;= DATE_ADD(#{endDate}, INTERVAL 1 DAY)
         </if>
-
         AND inhospstate=1
         <if test="orgid != null">
             AND orgid = #{orgid}
@@ -1890,92 +2376,55 @@
             </foreach>
         </if>
 
-        <!--        GROUP BY-->
+        <!--        UNION ALL-->
+
+        <!--        &#45;&#45; 闂ㄨ瘖浜烘鏁版嵁-->
+        <!--        SELECT-->
         <!--        <choose>-->
         <!--            <when test="timeType == 'day'">-->
-        <!--                DATE_FORMAT(endtime, '%Y-%m-%d')-->
+        <!--                DATE_FORMAT(admitdate, '%Y-%m-%d') AS timePeriod,-->
         <!--            </when>-->
         <!--            <when test="timeType == 'month'">-->
-        <!--                DATE_FORMAT(endtime, '%Y-%m')-->
+        <!--                DATE_FORMAT(admitdate, '%Y-%m') AS timePeriod,-->
         <!--            </when>-->
         <!--            <when test="timeType == 'year'">-->
-        <!--                DATE_FORMAT(endtime, '%Y')-->
+        <!--                DATE_FORMAT(admitdate, '%Y') AS timePeriod,-->
         <!--            </when>-->
         <!--            <when test="timeType == 'week'">-->
-        <!--                CONCAT(YEAR(endtime), '-W', LPAD(WEEK(endtime, 1), 2, '0'))-->
+        <!--                CONCAT(YEAR(admitdate), '-W', LPAD(WEEK(admitdate, 1), 2, '0')) AS timePeriod,-->
         <!--            </when>-->
         <!--            <otherwise>-->
-        <!--                DATE_FORMAT(endtime, '%Y-%m-%d')-->
+        <!--                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>-->
 
-        UNION ALL
+        <!--        <if test="deptcodes != null and deptcodes.size() > 0">-->
+        <!--            AND deptcode IN-->
+        <!--            <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">-->
+        <!--                #{deptcode}-->
+        <!--            </foreach>-->
+        <!--        </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>
-
-        <!--        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
     </select>
 
     <!-- 浼樺寲鐨勭粺璁℃煡璇細鐩存帴鍦ㄦ暟鎹簱灞傚畬鎴愯仛鍚堣绠� -->
-    <select id="countByCondition" parameterType="com.smartor.domain.ServiceSubtaskVO" resultType="map">
+    <select id="countByCondition" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity" resultType="map">
         SELECT
         SUM(CASE WHEN sendstate = 4 THEN 1 ELSE 0 END) AS wzx,
         SUM(CASE WHEN sendstate != 4 AND sendstate != 2 THEN 1 ELSE 0 END) AS ysf,
@@ -1983,7 +2432,9 @@
         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 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,
+        COUNT(1) as total
         FROM service_subtask
         where 1=1
         and del_flag = 0
@@ -2026,6 +2477,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}
@@ -2097,10 +2556,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')
@@ -2138,6 +2597,12 @@
         <if test="guid != null and guid != ''">
             AND guid = #{guid}
         </if>
+        <if test="excep != null ">
+            AND excep = #{excep}
+        </if>
+        <if test="taskName != null  and taskName != ''">
+            AND task_name like concat('%', #{taskName}, '%')
+        </if>
         <if test="visitCount != null and visitCount == 1">
             AND visit_count = 1
         </if>
@@ -2146,4 +2611,218 @@
         </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>
+
+    <select id="querySendCount" parameterType="com.smartor.domain.entity.ServiceSubtaskSatisfactionEntity"
+            resultType="Long">
+        select distinct id from service_subtask
+        where del_flag = 0
+        <if test="orgid != null and orgid != ''">
+            and orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            and campusid = #{campusid}
+        </if>
+        <if test="type != null ">and type = #{type}</if>
+        <if test="startTime != null">
+            AND date_format(visit_time,'%y%m%d') >= date_format(#{startTime},'%y%m%d')
+        </if>
+        <if test="endTime != null">
+            AND date_format(visit_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
+        </if>
+        <if test=" libTemplateIds != null and libTemplateIds.size()>0">
+            AND libtemplateid IN
+            <foreach collection="libTemplateIds" item="libTemplateId" open="(" separator=","
+                     close=")">
+                #{libTemplateId}
+            </foreach>
+        </if>
+        <if test="(hospitaldistrictcodes != null and hospitaldistrictcodes.size() > 0) or (deptcodes != null and deptcodes.size() > 0)">
+            AND (
+            <if test="hospitaldistrictcodes != null and hospitaldistrictcodes.size() > 0">
+                leavehospitaldistrictcode IN
+                <foreach collection="hospitaldistrictcodes" item="hospitaldistrictcode" open="("
+                         separator=","
+                         close=")">
+                    #{hospitaldistrictcode}
+                </foreach>
+            </if>
+            <if test="hospitaldistrictcodes != null and hospitaldistrictcodes.size() > 0 and deptcodes != null and deptcodes.size() > 0">
+                OR
+            </if>
+            <if test="deptcodes != null and deptcodes.size() > 0">
+                deptcode IN
+                <foreach collection="deptcodes" item="deptcode" open="(" separator=","
+                         close=")">
+                    #{deptcode}
+                </foreach>
+            </if>
+            )
+        </if>
+    </select>
+
+    <!--
+        鎸夌梾鍖烘垨绉戝鍒嗙粍缁熻 continue_flag 鏁伴噺
+        浼犱簡 leavehospitaldistrictcodes 鈫� 鎸夌梾鍖虹淮搴�
+        浼犱簡 deptcodes              鈫� 鎸夌瀹ょ淮搴�
+        閮戒笉浼�                     鈫� 鎸夌梾鍖虹淮搴︾粺璁″叏閲�
+    -->
+    <!-- 鎸夌梾鍖哄垎缁勭粺璁″欢缁姢鐞嗘暟閲� -->
+    <select id="getContinueNurseCount"
+            parameterType="com.smartor.domain.VO.ServiceSubtaskCotinueCountVO"
+            resultType="java.util.Map">
+        SELECT
+        leavehospitaldistrictcode AS groupCode,
+        leavehospitaldistrictname AS groupName,
+        SUM(CASE WHEN continue_flag = 1 THEN 1 ELSE 0 END) AS noContinueCnt,
+        SUM(CASE WHEN continue_flag = 2 THEN 1 ELSE 0 END) AS continueCnt
+        FROM service_subtask
+        WHERE del_flag = 0
+        AND continue_flag IN (1, 2)
+        AND leavehospitaldistrictcode IS NOT NULL AND leavehospitaldistrictcode != ''
+        <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="code" open="(" separator="," close=")">
+                #{code}
+            </foreach>
+        </if>
+        GROUP BY leavehospitaldistrictcode, leavehospitaldistrictname
+        ORDER BY groupCode
+    </select>
+
+    <!-- 鎸夌瀹ゅ垎缁勭粺璁″欢缁姢鐞嗘暟閲� -->
+    <select id="getContinueNurseCountByDept"
+            parameterType="com.smartor.domain.VO.ServiceSubtaskCotinueCountVO"
+            resultType="java.util.Map">
+        SELECT
+        deptcode AS groupCode,
+        deptname AS groupName,
+        SUM(CASE WHEN continue_flag = 1 THEN 1 ELSE 0 END) AS noContinueCnt,
+        SUM(CASE WHEN continue_flag = 2 THEN 1 ELSE 0 END) AS continueCnt
+        FROM service_subtask
+        WHERE del_flag = 0
+        AND continue_flag IN (1, 2)
+        AND deptcode IS NOT NULL AND deptcode != ''
+        <if test="orgid != null and orgid != ''">
+            AND orgid = #{orgid}
+        </if>
+        <if test="deptcodes != null and deptcodes.size() > 0">
+            AND deptcode IN
+            <foreach collection="deptcodes" item="code" open="(" separator="," close=")">
+                #{code}
+            </foreach>
+        </if>
+        GROUP BY deptcode, deptname
+        ORDER BY groupCode
+    </select>
+
+    <!-- 瀹f暀缁熻锛氭寜鐥呭尯鎴栫瀹ゅ垎缁勶紝缁熻鍙戦�佹�婚噺銆佸彂閫佹垚鍔熼噺锛坰endstate=6锛夈�佸凡璇婚噺锛坒inishtime涓嶄负绌猴級 -->
+    <select id="getHeLibraryCount" parameterType="com.smartor.domain.VO.HeLibraryCountVO" resultType="map">
+        SELECT
+        <choose>
+            <when test="hospitaldistrictcodes != null and hospitaldistrictcodes.size() > 0">
+                leavehospitaldistrictcode AS groupCode,
+                leavehospitaldistrictname AS groupName,
+            </when>
+            <otherwise>
+                deptcode AS groupCode,
+                deptname AS groupName,
+            </otherwise>
+        </choose>
+        COUNT(*) AS totalCount,
+        SUM(CASE WHEN sendstate = 6 THEN 1 ELSE 0 END) AS sendSuccessCount,
+        SUM(CASE WHEN finishtime IS NOT NULL THEN 1 ELSE 0 END) AS readCount
+        FROM service_subtask
+        WHERE del_flag = 0
+        AND service_type = 4
+        <if test="starttime != null">AND starttime &gt;= #{starttime}</if>
+        <if test="endtime != null">AND endtime &lt;= #{endtime}</if>
+        <if test="visittime != null">AND DATE(visit_time) = DATE(#{visittime})</if>
+        <if test="finishtime != null">AND DATE(finishtime) = DATE(#{finishtime})</if>
+        <if test="hospType != null and hospType != ''">AND hosp_type = #{hospType}</if>
+        <choose>
+            <when test="hospitaldistrictcodes != null and hospitaldistrictcodes.size() > 0">
+                AND leavehospitaldistrictcode IN
+                <foreach collection="hospitaldistrictcodes" item="code" open="(" separator="," close=")">
+                    #{code}
+                </foreach>
+                GROUP BY leavehospitaldistrictcode, leavehospitaldistrictname
+                ORDER BY groupCode
+            </when>
+            <otherwise>
+                <if test="deptcodes != null and deptcodes.size() > 0">
+                    AND deptcode IN
+                    <foreach collection="deptcodes" item="code" open="(" separator="," close=")">
+                        #{code}
+                    </foreach>
+                </if>
+                GROUP BY deptcode, deptname
+                ORDER BY groupCode
+            </otherwise>
+        </choose>
+    </select>
+
 </mapper>
+

--
Gitblit v1.9.3