From d963031435c593b761436d819268f5493923c41d Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期二, 22 九月 2026 18:37:52 +0800
Subject: [PATCH] 1.导出新增图表

---
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml | 1556 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 1,410 insertions(+), 146 deletions(-)

diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index 6f1c4e8..e5ae35f 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -52,6 +52,7 @@
         <result property="wechat" column="wechat"/>
         <result property="leaveicd10code" column="leaveicd10code"/>
         <result property="leavediagname" column="leavediagname"/>
+        <result property="diagname" column="diagname"/>
         <result property="deptname" column="deptname"/>
         <result property="admindate" column="admindate"/>
         <result property="roomno" column="roomno"/>
@@ -92,6 +93,13 @@
         <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"/>
+        <result property="scheduleId" column="schedule_id"/>
+        <result property="scheduleDetailId" column="schedule_detail_id"/>
+        <result property="scheduleSeq" column="schedule_seq"/>
+        <result property="loopCount" column="loop_count"/>
+        <result property="isManuallyCalled" column="is_manually_called"/>
+        <result property="campusid" column="campusid"/>
     </resultMap>
 
     <resultMap type="com.smartor.domain.ServiceSubtaskCount" id="ServiceSubtaskResult2">
@@ -120,10 +128,34 @@
         <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,
+               campusid,
                task_guid,
+               diagname,
                patfrom,
                management_doctor,
                management_doctor_code,
@@ -182,7 +214,6 @@
                create_time,
                isupload,
                upload_time,
-               orgid,
                pid,
                guid,
                text_param,
@@ -205,14 +236,18 @@
                leaveicd10code,
                orgid,
                visit_type,
-               management_doctor,
-               management_doctor_code,
                continue_flag,
                continue_time_now,
                continue_content,
                continue_count,
                continue_time_next,
-               task_situation
+               operation_item_id,
+               schedule_id,
+               schedule_detail_id,
+               schedule_seq,
+               loop_count,
+               task_situation,
+               is_manually_called
         from service_subtask
     </sql>
 
@@ -221,9 +256,8 @@
         <include refid="selectServiceSubtaskVo"/>
         where 1=1
         and del_flag = 0
-        <if test="orgid != null and orgid != ''">
-            and orgid = #{orgid}
-        </if>
+        <if test="orgid != null and orgid != ''">and orgid = #{orgid}</if>
+        <if test="campusid != null and campusid != ''">and campusid = #{campusid}</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>
@@ -245,13 +279,11 @@
         <include refid="selectServiceSubtaskVo"/>
         where 1=1
         and del_flag = 0
-        <if test="orgid != null and orgid != ''">
-            and orgid = #{orgid}
-        </if>
+        <if test="orgid != null and orgid != ''">and orgid = #{orgid}</if>
+        <if test="campusid != null and campusid != ''">and campusid = #{campusid}</if>
+        <if test="subId != null">and id = #{subId}</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="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>
@@ -263,8 +295,8 @@
     <select id="selectServiceSubtaskList" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
             resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
-        where 1=1
-        and del_flag = 0
+        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>
@@ -299,12 +331,36 @@
         <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>
+        <if test="subIdList != null  and subIdList.size() > 0">
+            AND id IN
+            <foreach collection="subIdList" item="subId" open="(" separator="," close=")">
+                #{subId}
+            </foreach>
+        </if>
         <!-- taskIds绛涢�� -->
         <if test="taskIds != null and taskIds.size() > 0">
             AND taskid IN
             <foreach collection="taskIds" item="itemTaskId" open="(" separator=","
                      close=")">
                 #{itemTaskId}
+            </foreach>
+        </if>
+        <if test="operationItemIds != null and operationItemIds.size() > 0">
+            AND operation_item_id IN
+            <foreach collection="operationItemIds" item="operationItemIdItem" open="(" separator="," close=")">
+                #{operationItemIdItem}
+            </foreach>
+        </if>
+        <if test="inhospids != null and inhospids.size() > 0">
+            AND inhospid IN
+            <foreach collection="inhospids" item="inhospidItem" open="(" separator="," close=")">
+                #{inhospidItem}
             </foreach>
         </if>
         <if test="templateid != null  and templateid != ''">and templateid = #{templateid}</if>
@@ -323,7 +379,12 @@
         <if test="endSendDateTime != null">
             AND date_format(visit_time,'%y%m%d') &lt;= date_format(#{endSendDateTime},'%y%m%d')
         </if>
-
+        <if test="finishtimeStart != null">
+            AND date_format(finishtime,'%y%m%d') &gt;= date_format(#{finishtimeStart},'%y%m%d')
+        </if>
+        <if test="finishtimeEnd != null">
+            AND date_format(finishtime,'%y%m%d') &lt;= date_format(#{finishtimeEnd},'%y%m%d')
+        </if>
         <if test="longSendTime != null">
             AND date_format(long_send_time,'%y%m%d') &lt;= date_format(#{longSendTime},'%y%m%d')
         </if>
@@ -345,25 +406,28 @@
             </if>
         </if>
         <if test="deptOrDistrict==2">
-            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
-                AND (leavehospitaldistrictcode IN
+            AND (1=1
+            <if test="leavehospitaldistrictcodes != null">
+                AND leavehospitaldistrictcode IN
                 <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="("
                          separator=","
                          close=")">
                     #{leavehospitaldistrictcode}
                 </foreach>
             </if>
-            <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0">
+            <if test=" leaveldeptcodes != null">
                 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
+                AND leavehospitaldistrictcode IN
                 <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="("
                          separator=","
                          close=")">
@@ -371,17 +435,18 @@
                 </foreach>
             </if>
             <if test=" visitDeptCodes != null and visitDeptCodes.size()>0">
-                and visit_dept_code IN
+                AND visit_dept_code IN
                 <foreach collection="visitDeptCodes" item="visitDeptCode" open="(" separator=","
-                         close="))">
+                         close=")">
                     #{visitDeptCode}
                 </foreach>
             </if>
+            )
         </if>
-
         <if test="deptOrDistrict==4">
+            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=")">
@@ -391,12 +456,12 @@
             <if test=" visitDeptCodes != null and visitDeptCodes.size()>0">
                 OR visit_dept_code IN
                 <foreach collection="visitDeptCodes" item="visitDeptCode" open="(" separator=","
-                         close="))">
+                         close=")">
                     #{visitDeptCode}
                 </foreach>
             </if>
+            )
         </if>
-
         <if test="visitTime != null">
             AND date_format(visit_time,'%y%m%d') = date_format(#{visitTime},'%y%m%d')
         </if>
@@ -413,6 +478,7 @@
         <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="campusid != null  and campusid != ''">and campusid = #{campusid}</if>
         <if test="pid != null ">and pid = #{pid}</if>
         <if test="preachform != null ">and preachform = #{preachform}</if>
         <if test="currentPreachform != null ">and current_preachform = #{currentPreachform}</if>
@@ -427,8 +493,8 @@
         <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="operationItemId != null ">and operation_item_id = #{operationItemId}</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>
@@ -449,13 +515,14 @@
         <if test="createBy != null">and create_by = #{createBy}</if>
         <if test="taskGuid != null">and task_guid = #{taskGuid}</if>
         <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
+        <if test="isManuallyCalled != null">and is_manually_called = #{isManuallyCalled}</if>
         <if test="isVisitAgain != null">and is_visit_again = #{isVisitAgain}</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="("
+            <foreach collection="visitDeptCodes" item="visitDeptCode" open="("
                      separator=","
                      close=")">
-                #{visitDeptCodes}
+                #{visitDeptCode}
             </foreach>
         </if>
         <if test="sort != null  and sort==0">order by endtime asc</if>
@@ -508,11 +575,27 @@
             resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
         where del_flag = 0
-        <if test="orgid != null and orgid != ''">
-            and orgid = #{orgid}
-        </if>
+        and sendstate != 5
+        <if test="orgid != null and orgid != ''">and orgid = #{orgid}</if>
+        <if test="campusid != null and campusid != ''">and campusid = #{campusid}</if>
+        <if test="visitTime != null">and date_format(visit_time,'%y%m%d') &lt;= date_format(#{visitTime},'%y%m%d') </if>
+        <if test="subId != null">and id = #{subId} </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>
+        UNION ALL
+        <include refid="selectServiceSubtaskVo"/>
+        where del_flag = 0
+        and sendstate = 5
+        <if test="orgid != null and orgid != ''">and orgid = #{orgid}</if>
+        <if test="campusid != null and campusid != ''">and campusid = #{campusid}</if>
         <if test="visitTime != null">
-            AND date_format(visit_time,'%y%m%d') &lt;= date_format(#{visitTime},'%y%m%d')
+            AND date_format(visit_time,'%y%m%d') &lt;= date_format(DATE_ADD(#{visitTime}, INTERVAL 1 DAY),'%y%m%d')
+        </if>
+        <if test="subId != null">
+            AND id = #{subId}
         </if>
         <if test="sendstate != null ">and sendstate = #{sendstate}</if>
         <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
@@ -525,9 +608,8 @@
             resultMap="ServiceSubtaskResult">
         <include refid="selectServiceSubtaskVo"/>
         where del_flag = 0
-        <if test="orgid != null and orgid != ''">
-            and orgid = #{orgid}
-        </if>
+        <if test="orgid != null and orgid != ''">and orgid = #{orgid}</if>
+        <if test="campusid != null and campusid != ''">and campusid = #{campusid}</if>
         <if test="createStartTime != null  and createEndTime != null">and create_time BETWEEN #{createStartTime} AND
             #{createEndTime}
         </if>
@@ -574,7 +656,8 @@
         <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="orgid != null and orgid != ''">and orgid = #{orgid}</if>
+        <if test="campusid != null and campusid != ''">and campusid = #{campusid}</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>
@@ -622,9 +705,8 @@
             DATE_FORMAT(b.create_time, '%Y-%m-%d') LIKE CONCAT(#{createTimeNew}, '%')
         </if>
         <if test="sendstate != null ">and b.sendstate = #{sendstate}</if>
-        <if test="orgid != null and orgid != ''">
-            and b.orgid = #{orgid}
-        </if>
+        <if test="orgid != null and orgid != ''">and b.orgid = #{orgid}</if>
+        <if test="campusid != null and campusid != ''">and b.campusid = #{campusid}</if>
     </select>
 
     <select id="selectTimelyRate" parameterType="com.smartor.domain.ServiceSubtask" resultType="double">
@@ -641,7 +723,10 @@
             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>
-        <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
+        <if test="orgid != null and orgid != ''">and orgid = #{orgid}</if>
+        <if test="campusid != null and campusid != ''">and campusid = #{campusid}</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>
@@ -656,49 +741,75 @@
         ) 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,
+            ss.${groupKey} as groupKey,
         </if>
-        SUM(CASE WHEN DATE(visit_time) &lt; DATE(IFNULL(finishtime, NOW())) THEN 1 ELSE 0 END) / COUNT(*) as rate
-        FROM service_subtask
-        WHERE del_flag = 0
-        AND visit_time IS NOT NULL
-        AND finishtime IS NOT NULL
-        <if test="orgid != null">AND orgid = #{orgid}</if>
+        SUM(CASE WHEN ss.finishtime IS NOT NULL AND DATE(ss.visit_time) &lt;= DATE(ss.finishtime) THEN 1 ELSE 0 END) /
+        COUNT(*) AS finishRate,
+        <if test="rateDay != null">
+            SUM(CASE WHEN ss.finishtime IS NOT NULL
+            AND DATEDIFF(ss.finishtime, ss.endtime) &lt;= #{rateDay} + COALESCE(cp.compensate_days, 0)
+            THEN 1 ELSE 0 END) / COUNT(*) AS rate
+        </if>
+        <if test="rateDay == null">
+            NULL AS rate
+        </if>
+        FROM service_subtask ss
+        <if test="rateDay != null">
+            <!-- 琛ュ伩鏃堕棿锛氬厛鎸夊瓙浠诲姟鑱氬悎鎴愪竴琛屽啀鍏宠仈锛岄伩鍏嶄竴瀵瑰鏀惧ぇ COUNT(*) 鍒嗘瘝銆�
+                 compensate_time 鏄� varchar 涓斿彲鑳藉瓨鎴愮┖涓诧紝闇�鍏堢疆绌哄啀杞暟瀛� -->
+            LEFT JOIN (
+            SELECT subid,
+            SUM(CAST(COALESCE(NULLIF(TRIM(compensate_time), ''), '0') AS SIGNED)) AS compensate_days
+            FROM service_subtask_preachform
+            WHERE del_flag = 0
+            GROUP BY subid
+            ) cp ON cp.subid = ss.id
+        </if>
+        WHERE ss.del_flag = 0
+        AND ss.visit_time IS NOT NULL
         <if test="starttime == null and endtime==null">
-            AND visit_time &lt; NOW()
+            AND DATE(ss.visit_time) &lt; DATE(NOW())
         </if>
         <if test="starttime != null and endtime!=null">
-            AND visit_time >= #{starttime}
-            AND visit_time &lt; DATE_ADD(#{endtime}, INTERVAL 1 DAY)
+            AND ss.visit_time >= #{starttime}
+            AND ss.visit_time &lt; DATE_ADD(#{endtime}, INTERVAL 1 DAY)
         </if>
-        <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
-        <if test="deptcode != null  and deptcode != ''">and deptcode = #{deptcode}</if>
-        <if test="deptname != null  and deptname != ''">and deptname = #{deptname}</if>
-        <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
+        <if test="orgid != null and orgid != ''">AND ss.orgid = #{orgid}</if>
+        <if test="campusid != null and campusid != ''">and ss.campusid = #{campusid}</if>
+        <if test="deptcode != null  and deptcode != ''">and ss.deptcode = #{deptcode}</if>
+        <if test="deptname != null  and deptname != ''">and ss.deptname = #{deptname}</if>
+        <if test="isabnormal != null">and ss.isabnormal = #{isabnormal}</if>
         <if test="leavehospitaldistrictcode != null  and leavehospitaldistrictcode != ''">and
-            leavehospitaldistrictcode = #{leavehospitaldistrictcode}
+            ss.leavehospitaldistrictcode = #{leavehospitaldistrictcode}
         </if>
         <if test="leavehospitaldistrictname != null  and leavehospitaldistrictname != ''">and
-            leavehospitaldistrictname = #{leavehospitaldistrictname}
+            ss.leavehospitaldistrictname = #{leavehospitaldistrictname}
         </if>
-        <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
-        <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if>
+        <if test="managementDoctorCode != null">and ss.management_doctor_code = #{managementDoctorCode}</if>
+        <if test="managementDoctor != null">and ss.management_doctor like concat('%',#{managementDoctor}, '%')</if>
         <if test="visitCount != null and visitCount == 1">
-            AND visit_count = 1
+            AND ss.visit_count = 1
         </if>
         <if test="visitCount != null and visitCount > 1">
-            AND visit_count > 1
+            AND ss.visit_count > 1
+        </if>
+        <if test="serviceTypeList != null">
+            AND ss.service_type IN
+            <foreach collection="serviceTypeList" item="serviceType" open="(" separator=","
+                     close=")">
+                #{serviceType}
+            </foreach>
         </if>
         <if test="groupKey != null and groupKey != ''">
-            AND ${groupKey} IN
+            AND ss.${groupKey} IN
             <foreach collection="groupKeyList" item="key" open="(" separator=","
                      close=")">
                 #{key}
             </foreach>
-            GROUP BY ${groupKey}
+            GROUP BY ss.${groupKey}
         </if>
     </select>
 
@@ -721,6 +832,9 @@
             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="campusid != null and campusid != ''">and campusid = #{campusid}</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>
@@ -749,11 +863,18 @@
         <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>
+        <if test="orgid != null and orgid != ''">and orgid = #{orgid} </if>
+        <if test="campusid != null and campusid != ''">and campusid = #{campusid}</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="startOutHospTime != null">
+            AND date_format(endtime,'%y%m%d') &gt;= date_format(#{startOutHospTime},'%y%m%d')
+        </if>
+        <if test="endOutHospTime != null">
+            AND date_format(endtime,'%y%m%d') &lt;= date_format(#{endOutHospTime},'%y%m%d')
+        </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>
@@ -789,7 +910,8 @@
             <if test="createTime != null">create_time,</if>
             <if test="isupload != null">isupload,</if>
             <if test="uploadTime != null">upload_time,</if>
-            <if test="orgid != null">orgid,</if>
+            <if test="orgid != null and orgid != ''">orgid,</if>
+            <if test="campusid != null and campusid != ''">campusid,</if>
             <if test="pid != null">pid,</if>
             <if test="guid != null">guid,</if>
             <if test="textParam != null">text_param,</if>
@@ -852,6 +974,12 @@
             <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>
+            <if test="scheduleId != null ">schedule_id,</if>
+            <if test="scheduleDetailId != null ">schedule_detail_id,</if>
+            <if test="scheduleSeq != null ">schedule_seq,</if>
+            <if test="loopCount != null ">loop_count,</if>
+            <if test="isManuallyCalled != null ">is_manually_called,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="sendname != null">#{sendname},</if>
@@ -880,7 +1008,8 @@
             <if test="createTime != null">#{createTime},</if>
             <if test="isupload != null">#{isupload},</if>
             <if test="uploadTime != null">#{uploadTime},</if>
-            <if test="orgid != null">#{orgid},</if>
+            <if test="orgid != null and orgid != ''">#{orgid},</if>
+            <if test="campusid != null and campusid != ''">#{campusid},</if>
             <if test="pid != null">#{pid},</if>
             <if test="guid != null">#{guid},</if>
             <if test="textParam != null">#{textParam},</if>
@@ -943,6 +1072,12 @@
             <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>
+            <if test="scheduleId != null ">#{scheduleId},</if>
+            <if test="scheduleDetailId != null ">#{scheduleDetailId},</if>
+            <if test="scheduleSeq != null ">#{scheduleSeq},</if>
+            <if test="loopCount != null ">#{loopCount},</if>
+            <if test="isManuallyCalled != null ">#{isManuallyCalled},</if>
         </trim>
     </insert>
 
@@ -976,7 +1111,8 @@
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="isupload != null">isupload = #{isupload},</if>
             <if test="uploadTime != null">upload_time = #{uploadTime},</if>
-            <if test="orgid != null">orgid = #{orgid},</if>
+            <if test="orgid != null and orgid != ''">orgid = #{orgid},</if>
+            <if test="campusid != null and campusid != ''">campusid = #{campusid},</if>
             <if test="pid != null">pid = #{pid},</if>
             <if test="guid != null">guid = #{guid},</if>
             <if test="textParam != null">text_param = #{textParam},</if>
@@ -1039,6 +1175,12 @@
             <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>
+            <if test="scheduleId != null ">schedule_id = #{scheduleId},</if>
+            <if test="scheduleDetailId != null ">schedule_detail_id = #{scheduleDetailId},</if>
+            <if test="scheduleSeq != null ">schedule_seq = #{scheduleSeq},</if>
+            <if test="loopCount != null ">loop_count = #{loopCount},</if>
+            <if test="isManuallyCalled != null ">is_manually_called = #{isManuallyCalled},</if>
         </trim>
         where id = #{id}
     </update>
@@ -1073,7 +1215,8 @@
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="isupload != null">isupload = #{isupload},</if>
             <if test="uploadTime != null">upload_time = #{uploadTime},</if>
-            <if test="orgid != null">orgid = #{orgid},</if>
+            <if test="orgid != null and orgid != ''">orgid = #{orgid},</if>
+            <if test="campusid != null and campusid != ''">campusid = #{campusid},</if>
             <if test="pid != null">pid = #{pid},</if>
             <if test="guid != null">guid = #{guid},</if>
             <if test="textParam != null">text_param = #{textParam},</if>
@@ -1136,13 +1279,13 @@
             <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="isManuallyCalled != null ">is_manually_called = #{isManuallyCalled},</if>
         </trim>
         where 1=1
         <if test="patid != null ">and patid = #{patid}</if>
         <if test="taskid != null ">and taskid = #{taskid}</if>
-        <if test="orgid != null and orgid != ''">
-            and orgid = #{orgid}
-        </if>
+        <if test="orgid != null and orgid != ''">and orgid = #{orgid}</if>
+        <if test="campusid != null and campusid != ''">and campusid = #{campusid}</if>
     </update>
 
     <update id="updateServiceSubtaskByCondition" parameterType="com.smartor.domain.ServiceSubtask">
@@ -1151,6 +1294,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>
@@ -1175,7 +1319,8 @@
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="isupload != null">isupload = #{isupload},</if>
             <if test="uploadTime != null">upload_time = #{uploadTime},</if>
-            <if test="orgid != null">orgid = #{orgid},</if>
+            <if test="orgid != null and orgid != ''">orgid = #{orgid},</if>
+            <if test="campusid != null and campusid != ''">campusid = #{campusid},</if>
             <if test="pid != null">pid = #{pid},</if>
             <if test="guid != null">guid = #{guid},</if>
             <if test="visitCount != null">visit_count = #{visitCount},</if>
@@ -1237,8 +1382,22 @@
             <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="isManuallyCalled != null ">is_manually_called = #{isManuallyCalled},</if>
         </trim>
-        where patid = #{patid} and taskid = #{taskid}
+        <where>
+            <if test="patid != null ">
+                patid = #{patid}
+            </if>
+            <if test="taskid != null ">
+                and taskid = #{taskid}
+            </if>
+            <if test="id != null ">
+                and id = #{id}
+            </if>
+            <if test="inhospid != null ">
+                and inhospid = #{inhospid}
+            </if>
+        </where>
     </update>
 
     <update id="updateServiceSubtaskByTaskGuid" parameterType="com.smartor.domain.ServiceSubtask">
@@ -1271,7 +1430,8 @@
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="isupload != null">isupload = #{isupload},</if>
             <if test="uploadTime != null">upload_time = #{uploadTime},</if>
-            <if test="orgid != null">orgid = #{orgid},</if>
+            <if test="orgid != null and orgid != ''">orgid = #{orgid},</if>
+            <if test="campusid != null and campusid != ''">campusid = #{campusid},</if>
             <if test="pid != null">pid = #{pid},</if>
             <if test="guid != null">guid = #{guid},</if>
             <if test="textParam != null">text_param = #{textParam},</if>
@@ -1333,6 +1493,7 @@
             <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="isManuallyCalled != null ">is_manually_called = #{isManuallyCalled},</if>
         </trim>
         where task_guid = #{taskGuid} and task_name = #{taskName}
     </update>
@@ -1363,12 +1524,15 @@
         orgid,
         drcode,
         drname,
+        management_doctor_code,
+        management_doctor,
         leavehospitaldistrictcode,
         leavehospitaldistrictname,
         deptcode,
         deptname,
         sendstate,
         preachform,
+        current_preachform,
         excep,
         nurse_id,
         nurse_name,
@@ -1398,6 +1562,296 @@
         and 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="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="hospitalStartTime != null and hospitalEndTime!=null">
+            AND endtime >= DATE(#{hospitalStartTime})
+            AND endtime &lt; DATE_ADD(DATE(#{hospitalEndTime}), 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>
+    </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="campusid != null and campusid != ''">and b.campusid = #{campusid}</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
+        <if test="groupKey != null and groupKey != ''">
+            ${groupKey} as groupKey
+        </if>
+        from service_subtask
+        where 1=1
+        and 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="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="hospitalStartTime != null and hospitalEndTime!=null">
+            AND endtime >= DATE(#{hospitalStartTime})
+            AND endtime &lt; DATE_ADD(DATE(#{hospitalEndTime}), 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 != ''">
+            group by ${groupKey}
+        </if>
+        <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,
+        remark
+        from service_subtask
+        where 1=1
+        and 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="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
             AND leavehospitaldistrictcode IN
@@ -1448,64 +1902,35 @@
                 #{key}
             </foreach>
         </if>
-    </select>
-    <select id="getSfStatisticsGroupKey" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
-            resultType="String">
-        select
-        <if test="groupKey != null and groupKey != ''">
-            ${groupKey} as groupKey
-        </if>
-        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}
+        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="deptcodes != null and deptcodes.size() > 0">
-            AND deptcode IN
-            <foreach collection="deptcodes" item="deptcode" open="(" separator=","
-                     close=")">
-                #{deptcode}
-            </foreach>
+        <if test="currentPreachform != null">
+            AND current_preachform = #{currentPreachform}
+            <if test="followUpCountStyle != null and followUpCountStyle = '1'">
+                AND sendstate != 4
+            </if>
         </if>
-        <if test="serviceType != null and serviceType.size() > 0">
-            AND service_type IN
-            <foreach collection="serviceType" item="serviceType" open="(" separator=","
-                     close=")">
-                #{serviceType}
-            </foreach>
+        <if test="excep != null and excep != ''">
+            AND excep = #{excep}
         </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 test="taskSituation != null">
+            AND task_situation = #{taskSituation}
         </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 test="drcode != null and drcode != ''">
+            AND drcode = #{drcode}
         </if>
-        <if test="visitCount != null and visitCount == 1">
-            AND visit_count = 1
+        <if test="leavehospitaldistrictcode != null and leavehospitaldistrictcode != ''">
+            AND leavehospitaldistrictcode = #{leavehospitaldistrictcode}
         </if>
-        <if test="visitCount != null and visitCount > 1">
-            AND visit_count > 1
+        <if test="deptcode != null and deptcode != ''">
+            AND deptcode = #{deptcode}
         </if>
-        <if test="groupKey != null and groupKey != ''">
-            group by ${groupKey}
-        </if>
+        order by endtime desc
         <if test="pageSize != null  and pageNum != null">
             limit ${pageSize} OFFSET ${pageNum}
         </if>
@@ -1522,6 +1947,9 @@
         and 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="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
             AND leavehospitaldistrictcode IN
@@ -1567,6 +1995,9 @@
         <if test="orgid != null and orgid != ''">
             and orgid = #{orgid}
         </if>
+        <if test="campusid != null and campusid != ''">
+            and campusid = #{campusid}
+        </if>
         <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
             AND leavehospitaldistrictcode IN
             <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
@@ -1598,6 +2029,9 @@
         and 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="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">AND
             leavehospitaldistrictcode IN
@@ -1653,6 +2087,9 @@
         AND t.del_flag=0
         <if test="orgid != null and orgid != ''">
             and t.orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            and t.campusid = #{campusid}
         </if>
         <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
             AND t.leavehospitaldistrictcode IN
@@ -1737,6 +2174,9 @@
         <if test="orgid != null and orgid != ''">
             AND ss.orgid = #{orgid}
         </if>
+        <if test="campusid != null and campusid != ''">
+            AND ss.campusid = #{campusid}
+        </if>
         <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
             AND ss.leavehospitaldistrictcode IN
             <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
@@ -1793,6 +2233,9 @@
         and ss.del_flag=0
         <if test="orgid != null and orgid != ''">
             and ss.orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            and ss.campusid = #{campusid}
         </if>
         <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
             AND ss.leavehospitaldistrictcode IN
@@ -1947,10 +2390,15 @@
         SELECT deptname,
         count(1) AS rc
         FROM service_subtask
-        WHERE DATE_FORMAT(finishtime, '%Y-%m-%d') >= #{startDate}
-        AND DATE_FORMAT(finishtime, '%Y-%m-%d') &lt;= #{endDate}
-        <if test="orgid != null">
+        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 != ''">
             AND orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            AND campusid = #{campusid}
         </if>
         GROUP BY deptname
     </select>
@@ -1990,15 +2438,18 @@
         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)
         </if>
 
-        <if test="orgid != null">
+        <if test="orgid != null and orgid != ''">
             AND orgid = #{orgid}
         </if>
-
+        <if test="campusid != null and campusid != ''">
+            AND campusid = #{campusid}
+        </if>
         <if test="deptcodes != null and deptcodes.size() > 0">
             AND deptcode IN
             <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">
@@ -2051,12 +2502,13 @@
             AND endtime >= #{startDate}
             AND endtime &lt;= DATE_ADD(#{endDate}, INTERVAL 1 DAY)
         </if>
-
         AND inhospstate=1
-        <if test="orgid != null">
+        <if test="orgid != null and orgid != ''">
             AND orgid = #{orgid}
         </if>
-
+        <if test="campusid != null and campusid != ''">
+            AND campusid = #{campusid}
+        </if>
         <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
             AND leavehospitaldistrictcode IN
             <foreach collection="leavehospitaldistrictcodes" item="districtcode" open="(" separator="," close=")">
@@ -2103,9 +2555,11 @@
         <!--            AND admitdate &lt;= DATE_ADD(#{endDate}, INTERVAL 1 DAY)-->
         <!--        </if>-->
         <!--        <if test="orgid != null">-->
-        <!--            AND orgid = #{orgid}-->
+        <!--             AND orgid = #{orgid}-->
         <!--        </if>-->
-
+        <!--        <if test="campusid != null">-->
+        <!--             AND campusid = #{campusid}-->
+        <!--        </if>-->
         <!--        <if test="deptcodes != null and deptcodes.size() > 0">-->
         <!--            AND deptcode IN-->
         <!--            <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">-->
@@ -2125,18 +2579,29 @@
         SUM(CASE WHEN sendstate != 4 AND sendstate != 2 THEN 1 ELSE 0 END) AS ysf,
         SUM(CASE WHEN sendstate = 5 THEN 1 ELSE 0 END) AS fssb,
         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 sendstate = 4 THEN 1 ELSE 0 END) AS wxsf,
+        SUM(CASE WHEN sendstate != 4 THEN 1 ELSE 0 END) AS xsf,
+        SUM(CASE WHEN (sendstate = 1 OR sendstate = 2 OR sendstate = 3 OR sendstate = 5 OR sendstate = 7 ) THEN 1 ELSE 0
+        END) AS dsf,
+        SUM(CASE WHEN sendstate = 6 THEN 1 ELSE 0 END) AS ywc,
         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
+        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
+        where del_flag = 0
+        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</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="finishtimeStart != null">
+            AND date_format(finishtime,'%y%m%d') &gt;= date_format(#{finishtimeStart},'%y%m%d')
+        </if>
+        <if test="finishtimeEnd != null">
+            AND date_format(finishtime,'%y%m%d') &lt;= date_format(#{finishtimeEnd},'%y%m%d')
         </if>
         <if test="deptOrDistrict==1">
             <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
@@ -2156,8 +2621,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=")">
@@ -2167,17 +2633,18 @@
             <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="visitCount != null and visitCount > 1 and visitDeptCodes != null and visitDeptCodes.size() > 0">
             AND visit_dept_code IN
-            <foreach collection="visitDeptCodes" item="visitDeptCodes" open="("
+            <foreach collection="visitDeptCodes" item="visitDeptCode" open="("
                      separator=","
                      close=")">
-                #{visitDeptCodes}
+                #{visitDeptCode}
             </foreach>
         </if>
         <if test="leavehospitaldistrictname != null and leavehospitaldistrictname != ''">
@@ -2288,6 +2755,9 @@
         <if test="orgid != null and orgid != ''">
             AND orgid = #{orgid}
         </if>
+        <if test="campusid != null and campusid != ''">
+            AND campusid = #{campusid}
+        </if>
         <if test="guid != null and guid != ''">
             AND guid = #{guid}
         </if>
@@ -2303,6 +2773,9 @@
         <if test="visitCount != null and visitCount > 1">
             AND visit_count > 1
         </if>
+        <if test="drname != null  and drname != ''">
+            AND drname like concat('%', #{drname}, '%')
+        </if>
     </select>
 
 
@@ -2316,8 +2789,11 @@
         where 1=1
         and del_flag = 0
         and service_type=3
-        <if test="orgid != null">
-            and orgid = #{orgid}
+        <if test="orgid != null and orgid != ''">
+            AND orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            AND campusid = #{campusid}
         </if>
         <if test="startDate != null">
             AND date_format( visit_time, '%y%m%d' ) &gt;= date_format( #{startDate}, '%y%m%d' )
@@ -2348,6 +2824,9 @@
         AND visit_count = 1
         <if test="orgid != null and orgid != ''">
             AND orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            and campusid = #{campusid}
         </if>
         <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
             AND leavehospitaldistrictcode IN
@@ -2414,4 +2893,789 @@
         </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="campusid != null and campusid != ''">
+            AND campusid = #{campusid}
+        </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="campusid != null and campusid != ''">
+            AND campusid = #{campusid}
+        </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="orgid != null and orgid != ''">
+            and orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            and campusid = #{campusid}
+        </if>
+        <if test="sendstate != null">
+            AND sendstate = #{sendstate}
+        </if>
+        <if test="isFinished != null and isFinished != ''">
+            and finishtime is not null
+        </if>
+        <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>
+
+    <!-- 浠诲姟缁勶紙appltype=5锛夋粴鍔ㄨ皟搴︾敤锛氭湰杞粛鍦ㄨ窇鐨勬暟閲� -->
+    <select id="countActiveByScheduleIdAndLoop" resultType="int">
+        select count(1)
+        from service_subtask
+        where schedule_id = #{scheduleId}
+          and loop_count = #{loopCount}
+          and (del_flag is null or del_flag = '0')
+          and sendstate in (1, 2, 3)
+    </select>
+
+    <select id="mydTrend" resultType="com.smartor.domain.DTO.MydTrendReqDTO">
+        SELECT CASE #{type}
+                   WHEN 'year' THEN DATE_FORMAT(d.create_time, '%Y')
+                   WHEN 'quarter' THEN CONCAT(YEAR(d.create_time), '-Q', QUARTER(d.create_time))
+                   WHEN 'month' THEN DATE_FORMAT(d.create_time, '%Y-%m')
+                   WHEN 'week' THEN FLOOR(DATEDIFF(d.create_time, #{startFinishTime}) / 7) + 1
+                   ELSE DATE_FORMAT(d.create_time, '%Y-%m-%d')
+                   END                AS period,
+               ROUND(avg(d.score), 2) AS totalScore
+        FROM service_subtask_detail d
+                 JOIN service_task t ON d.taskid = t.taskid
+        WHERE t.service_type IN (14)
+          AND t.del_flag = 0
+          AND d.del_flag = 0
+          AND d.create_time >= #{startFinishTime}
+          AND d.create_time &lt; DATE_ADD(#{endFinishTime}, INTERVAL 1 DAY)
+        GROUP BY period
+        ORDER BY period;
+    </select>
+
+    <select id="sltdMydTotalByDimension" resultType="com.smartor.domain.DTO.MydTrendReqDTO">
+        SELECT
+        p.period,
+        dim.dimension,
+        IFNULL(ROUND(SUM(d.score), 2), 0) AS totalScore
+        FROM (
+        <!-- 鐢熸垚鏌ヨ鑼冨洿鍐呭疄闄呭嚭鐜拌繃鐨勬椂闂存 -->
+        SELECT DISTINCT
+        CASE #{type}
+        WHEN 'year' THEN DATE_FORMAT(d.create_time, '%Y')
+        WHEN 'quarter' THEN CONCAT(YEAR(d.create_time), '-Q', QUARTER(d.create_time))
+        WHEN 'month' THEN DATE_FORMAT(d.create_time, '%Y-%m')
+        WHEN 'week' THEN FLOOR(DATEDIFF(d.create_time, #{startFinishTime}) / 7) + 1
+        ELSE DATE_FORMAT(d.create_time, '%Y-%m-%d')
+        END AS period
+        FROM service_subtask_detail d
+        WHERE d.del_flag = 0
+        AND d.create_time >= #{startFinishTime}
+        AND d.create_time &lt; #{endFinishTime}
+        ) p
+        CROSS JOIN (
+        <!-- 鎵�鏈夐渶瑕佸睍绀虹殑 dimension -->
+        SELECT DISTINCT dimension
+        FROM service_subtask_detail
+        WHERE del_flag = 0
+        AND dimension IS NOT NULL
+        ) dim
+        LEFT JOIN service_task t
+        ON t.service_type IN (6, 14)
+        AND t.del_flag = 0
+        LEFT JOIN service_subtask_detail d
+        ON d.taskid = t.taskid
+        AND d.del_flag = 0
+        AND d.dimension = dim.dimension
+        AND CASE #{type}
+        WHEN 'year' THEN DATE_FORMAT(d.create_time, '%Y')
+        WHEN 'quarter' THEN CONCAT(YEAR(d.create_time), '-Q', QUARTER(d.create_time))
+        WHEN 'month' THEN DATE_FORMAT(d.create_time, '%Y-%m')
+        WHEN 'week' THEN FLOOR(DATEDIFF(d.create_time, #{startFinishTime}) / 7) + 1
+        ELSE DATE_FORMAT(d.create_time, '%Y-%m-%d')
+        END = p.period
+        AND d.create_time >= #{startFinishTime}
+        AND d.create_time &lt; #{endFinishTime}
+        GROUP BY p.period, dim.dimension
+        ORDER BY p.period, dim.dimension
+    </select>
+
+    <select id="sltdMydTotalByYQ" resultType="com.smartor.domain.DTO.MydTrendReqDTO">
+        SELECT p.period,
+               c.campusid,
+               IFNULL(ROUND(AVG(d.score), 2), 0) AS totalScore
+        FROM (
+                 -- 鐢熸垚鏌ヨ鑼冨洿鍐呭疄闄呭嚭鐜拌繃鐨勬椂闂存
+                 SELECT DISTINCT CASE #{type}
+                                     WHEN 'year' THEN DATE_FORMAT(d.create_time, '%Y')
+                                     WHEN 'quarter' THEN CONCAT(YEAR(d.create_time), '-Q', QUARTER(d.create_time))
+                                     WHEN 'month' THEN DATE_FORMAT(d.create_time, '%Y-%m')
+                                     WHEN 'week' THEN FLOOR(DATEDIFF(d.create_time, #{startFinishTime}) / 7) + 1
+                                     ELSE DATE_FORMAT(d.create_time, '%Y-%m-%d')
+                                     END AS period
+                 FROM service_subtask_detail d
+                 WHERE d.del_flag = 0
+                   AND d.create_time >= #{startFinishTime}
+                   AND d.create_time &lt; #{endFinishTime}) p
+                 CROSS JOIN (
+            -- 鎵�鏈夐渶瑕佸睍绀虹殑闄㈠尯
+            SELECT DISTINCT campusid
+            FROM service_task
+            WHERE service_type IN (6, 14)
+              AND del_flag = 0
+              AND campusid IS NOT NULL) c
+                 LEFT JOIN service_task t
+                           ON t.campusid = c.campusid
+                               AND t.service_type IN (6, 14)
+                               AND t.del_flag = 0
+                 LEFT JOIN service_subtask_detail d
+                           ON d.taskid = t.taskid
+                               AND d.del_flag = 0
+                               AND CASE #{type}
+                                       WHEN 'year' THEN DATE_FORMAT(d.create_time, '%Y')
+                                       WHEN 'quarter' THEN CONCAT(YEAR(d.create_time), '-Q', QUARTER(d.create_time))
+                                       WHEN 'month' THEN DATE_FORMAT(d.create_time, '%Y-%m')
+                                       WHEN 'week' THEN FLOOR(DATEDIFF(d.create_time, #{startFinishTime}) / 7) + 1
+                                       ELSE DATE_FORMAT(d.create_time, '%Y-%m-%d')
+                                       END = p.period
+                               AND d.create_time >= #{startFinishTime}
+                               AND d.create_time &lt; #{endFinishTime}
+        GROUP BY p.period, c.campusid
+        ORDER BY p.period, c.campusid;
+    </select>
+
+    <!-- 浠诲姟缁勶紙appltype=5锛夋粴鍔ㄨ皟搴︾敤锛氭媺鏈疆鍏ㄩ噺 subtask锛屼綔涓轰笅涓�杞殑鍏嬮殕妯℃澘 -->
+    <select id="selectByScheduleIdAndLoop" resultMap="ServiceSubtaskResult">
+        <include refid="selectServiceSubtaskVo"/>
+        where schedule_id = #{scheduleId}
+        and loop_count = #{loopCount}
+        and (del_flag is null or del_flag = '0')
+        order by schedule_seq asc, id asc
+    </select>
+
+    <select id="gethelibraryCountHyperlink" parameterType="com.smartor.domain.VO.HeLibraryCountVO"
+            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,
+        remark
+        from service_subtask
+        where 1=1
+        and del_flag = 0
+        AND service_type = 4
+        <if test="orgid != null and orgid != ''">
+            and orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            and campusid = #{campusid}
+        </if>
+        <if test="sendstate != null">
+            AND sendstate = #{sendstate}
+        </if>
+        <if test="isFinished != null and isFinished != ''">
+            and finishtime is not null
+        </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="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>
+        order by endtime desc
+        <if test="pageSize != null  and pageNum != null">
+            limit ${pageSize} OFFSET ${pageNum}
+        </if>
+    </select>
+
+    <select id="statQuestionOption" resultType="com.smartor.domain.ServiceSubtaskDetailRatioExport">
+        SELECT
+        d.questiontext AS questiontext,
+        t.taskid AS taskid,
+        t.task_name AS taskName,
+        d.asrtext AS optionresult,
+        d.score AS score,
+        d.targetvalue AS targetvalue,
+        d.value_type AS valueType,
+        COUNT(*) AS count,
+        CONCAT(ROUND(COUNT(*) * 100.0 / t2.total_count, 2), '%') AS ratio
+        FROM
+        service_task t
+        INNER JOIN service_subtask s ON s.taskid = t.taskid
+        INNER JOIN service_subtask_detail d ON d.sub_id = s.id
+        INNER JOIN (
+        SELECT
+        t.taskid,
+        d.questiontext,
+        COUNT(*) AS total_count
+        FROM
+        service_task t
+        INNER JOIN service_subtask s ON s.taskid = t.taskid
+        INNER JOIN service_subtask_detail d ON d.sub_id = s.id
+        WHERE 1=1
+        <if test="taskIds != null and taskIds.size() > 0">
+            AND t.taskid IN
+            <foreach collection="taskIds" item="taskId" open="(" separator="," close=")">
+                #{taskId}
+            </foreach>
+        </if>
+        <!-- 浼犱簡 subtaskIds 鍙粺璁¤繖鎵瑰瓙浠诲姟锛堟湰娆″鍑虹殑鎮h�咃級 -->
+        <if test="subtaskIds != null and subtaskIds.size() > 0">
+            AND s.id IN
+            <foreach collection="subtaskIds" item="subtaskId" open="(" separator="," close=")">
+                #{subtaskId}
+            </foreach>
+        </if>
+        <if test="valueType != null">AND d.value_type = #{valueType}</if>
+        <if test="scoreStart != null">AND d.score &gt;= #{scoreStart}</if>
+        <if test="scoreEnd != null">AND d.score &lt;= #{scoreEnd}</if>
+        <if test="questiontext != null  and questiontext != ''">and d.questiontext like concat('%', #{questiontext},
+            '%')
+        </if>
+        and s.sendstate=6
+        and d.del_flag=0
+        <!-- 鍒嗘瘝蹇呴』鍜屾槑缁嗙敤鍚屼竴濂楁椂闂存潯浠讹紝鍚﹀垯閫変簡鏃堕棿鑼冨洿鍚庢瘮渚嬩細鎸夊叏閲忓巻鍙茶绋�閲� -->
+        <if test="startOutHospTime != null">
+            AND date_format(s.endtime,'%y%m%d') &gt;= date_format(#{startOutHospTime},'%y%m%d')
+        </if>
+        <if test="endOutHospTime != null">
+            AND date_format(s.endtime,'%y%m%d') &lt;= date_format(#{endOutHospTime},'%y%m%d')
+        </if>
+        <if test="startFinishTime != null">
+            AND date_format(s.finishtime,'%y%m%d') &gt;= date_format(#{startFinishTime},'%y%m%d')
+        </if>
+        <if test="endFinishTime != null">
+            AND date_format(s.finishtime,'%y%m%d') &lt;= date_format(#{endFinishTime},'%y%m%d')
+        </if>
+        GROUP BY
+        t.taskid,
+        d.questiontext
+        ) t2 ON t2.taskid = t.taskid AND t2.questiontext = d.questiontext
+        WHERE 1=1
+        <if test="taskIds != null and taskIds.size() > 0">
+            AND t.taskid IN
+            <foreach collection="taskIds" item="taskId" open="(" separator="," close=")">
+                #{taskId}
+            </foreach>
+        </if>
+        <if test="subtaskIds != null and subtaskIds.size() > 0">
+            AND s.id IN
+            <foreach collection="subtaskIds" item="subtaskId" open="(" separator="," close=")">
+                #{subtaskId}
+            </foreach>
+        </if>
+        <if test="valueType != null">AND d.value_type = #{valueType}</if>
+        <if test="scoreStart != null">AND d.score &gt;= #{scoreStart}</if>
+        <if test="scoreEnd != null">AND d.score &lt;= #{scoreEnd}</if>
+        <if test="questiontext != null  and questiontext != ''">and d.questiontext like concat('%', #{questiontext},
+            '%')
+        </if>
+        AND s.sendstate = 6
+        and d.del_flag=0
+        <if test="startOutHospTime != null">
+            AND date_format(s.endtime,'%y%m%d') &gt;= date_format(#{startOutHospTime},'%y%m%d')
+        </if>
+        <if test="endOutHospTime != null">
+            AND date_format(s.endtime,'%y%m%d') &lt;= date_format(#{endOutHospTime},'%y%m%d')
+        </if>
+        <if test="startFinishTime != null">
+            AND date_format(s.finishtime,'%y%m%d') &gt;= date_format(#{startFinishTime},'%y%m%d')
+        </if>
+        <if test="endFinishTime != null">
+            AND date_format(s.finishtime,'%y%m%d') &lt;= date_format(#{endFinishTime},'%y%m%d')
+        </if>
+        GROUP BY
+        t.taskid,
+        d.questiontext,
+        d.score,
+        d.targetvalue,
+        d.asrtext,
+        d.value_type
+        ORDER BY
+        d.questiontext,
+        t.taskid
+    </select>
+
+    <!--
+      瀵煎嚭銆岄棶棰樿鎯呭崰姣斻�嶄笓鐢ㄧ粺璁★紙鍙粺璁℃湰娆″鍑虹殑杩欐壒鎮h�咃級
+      鏁伴噺 = 閫夋嫨璇ラ�夐」鐨勬偅鑰呮暟锛圕OUNT(DISTINCT s.id)锛屽苟鐢� MAX(id) 淇濊瘉鍚屼竴鎮h�呭悓涓�棰樺彧绠楁渶鏂颁竴鏉★級
+      鍒嗘暟 = 璇ラ�夐」鏄庣粏鐨� score 涔嬪拰
+      姣斾緥 = 鏁伴噺 / 璇ラ浣滅瓟鎮h�呮暟锛屽湪 Java 渚х粺涓�璁$畻锛屽洜姝ゃ�屽崟棰樺悇閫夐」鏁伴噺涔嬪拰 = 璇ラ浣滅瓟鎮h�呮暟銆�
+    -->
+    <select id="statMydQuestionOptionForExport" resultType="com.smartor.domain.DTO.ServiceSubtaskOptionStatDTO">
+        SELECT
+        t.taskid AS taskid,
+        t.task_name AS taskName,
+        d.questiontext AS questiontext,
+        d.asrtext AS optionresult,
+        d.targetvalue AS targetvalue,
+        d.value_type AS valueType,
+        COUNT(DISTINCT s.id) AS patientCount,
+        SUM(COALESCE(CAST(d.score AS DECIMAL(18,2)), 0)) AS scoreSum
+        FROM
+        service_task t
+        INNER JOIN service_subtask s ON s.taskid = t.taskid
+        INNER JOIN service_subtask_detail d ON d.sub_id = s.id
+        WHERE 1=1
+        AND s.del_flag = '0'
+        AND d.del_flag = 0
+        <if test="subtaskIds != null and subtaskIds.size() > 0">
+            AND s.id IN
+            <foreach collection="subtaskIds" item="subtaskId" open="(" separator="," close=")">
+                #{subtaskId}
+            </foreach>
+        </if>
+        <!-- 涓嶄紶瀛愪换鍔℃椂鐩存帴鏌ヤ笉鍒版暟鎹紝閬垮厤璇粺璁″叏閲� -->
+        <if test="subtaskIds == null or subtaskIds.size() == 0">
+            AND 1 = 0
+        </if>
+        <if test="questiontext != null and questiontext != ''">
+            AND d.questiontext LIKE CONCAT('%', #{questiontext}, '%')
+        </if>
+        <!-- 鍚屼竴鎮h�呭悓涓�棰樼洰鍙繚鐣欐渶鏂颁竴鏉★紝閲嶇瓟涓嶉噸澶嶈鍏ユ暟閲� -->
+        AND d.id = (
+        SELECT MAX(d2.id)
+        FROM service_subtask_detail d2
+        WHERE d2.sub_id = d.sub_id
+        AND d2.questiontext &lt;=&gt; d.questiontext
+        AND d2.del_flag = '0'
+        )
+        GROUP BY
+        t.taskid,
+        t.task_name,
+        d.questiontext,
+        d.asrtext,
+        d.targetvalue,
+        d.value_type
+        <!-- 鎸変换鍔″悕绉板垎缁勫睍绀猴細鍏堜换鍔″悕绉般�佸啀浠诲姟缂栧彿锛屽悓涓�浠诲姟鐨勯鐩�/閫夐」杩炵画鎺掑垪 -->
+        ORDER BY
+        t.task_name,
+        t.taskid,
+        d.questiontext
+    </select>
+
+    <!-- 鏂版柟娉曪細鏍规嵁瀛愪换鍔� ID 缁熻闂閫夐」鐧惧垎姣� (鐢ㄤ簬婊℃剰搴︾粺璁� serviceType=6) -->
+    <select id="statQuestionOptionBySubtaskIds" resultType="com.smartor.domain.ServiceSubtaskDetailRatioExport">
+        SELECT
+        d.questiontext AS questiontext,
+        t.taskid AS taskid,
+        t.task_name AS taskName,
+        d.asrtext AS optionresult,
+        d.score AS score,
+        s.deptcode AS deptcode,
+        s.deptname AS deptname,
+        s.leavehospitaldistrictcode AS leavehospitaldistrictcode,
+        s.leavehospitaldistrictname AS leavehospitaldistrictname,
+        d.targetvalue AS targetvalue,
+        d.value_type AS valueType,
+        COUNT(*) AS count,
+        CONCAT(ROUND(COUNT(*) * 100.0 / t2.total_count, 2), '%') AS ratio
+        FROM
+        service_task t
+        INNER JOIN service_subtask s ON s.taskid = t.taskid
+        INNER JOIN service_subtask_detail d ON d.sub_id = s.id
+        <!-- 鍘婚噸锛氬悓涓�瀛愪换鍔″悓涓�棰樼洰鍙繚鐣欐渶鏂颁竴鏉★紝閬垮厤閲嶇瓟/閲嶅鍥炶皟鎶婂悓涓�閬撻閲嶅璁″叆椤规暟锛堜笌 mzMydScoreRank 鍙e緞涓�鑷达級 -->
+        AND d.id = (
+        SELECT MAX(d2.id)
+        FROM service_subtask_detail d2
+        WHERE d2.sub_id = d.sub_id
+        AND d2.questiontext &lt;=&gt; d.questiontext
+        AND d2.del_flag = '0'
+        )
+        INNER JOIN (
+        SELECT
+        d.questiontext,
+        COUNT(*) AS total_count
+        FROM
+        service_task t
+        INNER JOIN service_subtask s ON s.taskid = t.taskid
+        INNER JOIN service_subtask_detail d ON d.sub_id = s.id
+        <!-- 鍘婚噸锛氬垎姣嶏紙璇ラ鏈夋晥绛斿嵎鎬绘暟锛変笌鏄庣粏鍙e緞淇濇寔涓�鑷达紝淇濊瘉鍚勯�夐」姣斾緥鍚堣 100% -->
+        AND d.id = (
+        SELECT MAX(d4.id)
+        FROM service_subtask_detail d4
+        WHERE d4.sub_id = d.sub_id
+        AND d4.questiontext &lt;=&gt; d.questiontext
+        AND d4.del_flag = '0'
+        )
+        WHERE 1=1
+        <if test="subtaskIds != null and subtaskIds.size() > 0">
+            AND s.id IN
+            <foreach collection="subtaskIds" item="subtaskId" open="(" separator="," close=")">
+                #{subtaskId}
+            </foreach>
+        </if>
+        <if test="valueType != null">AND d.value_type &gt;= #{valueType}</if>
+        <if test="scoreStart != null">AND d.score &gt;= #{scoreStart}</if>
+        <if test="scoreEnd != null">AND d.score &lt;= #{scoreEnd}</if>
+        <if test="questiontext != null  and questiontext != ''">and d.questiontext like concat('%', #{questiontext},
+            '%')
+        </if>
+        AND s.sendstate = 6
+        AND d.del_flag=0
+        <!-- 鍒嗘瘝涓庢槑缁嗙敤鍚屼竴濂楁椂闂存潯浠讹紝鍚﹀垯閫変簡鏃ユ湡鍖洪棿鍚庡悇閫夐」姣斾緥鍚堣涓嶅埌 100% -->
+        <if test="startOutHospTime != null">
+            AND date_format(s.endtime,'%y%m%d') &gt;= date_format(#{startOutHospTime},'%y%m%d')
+        </if>
+        <if test="endOutHospTime != null">
+            AND date_format(s.endtime,'%y%m%d') &lt;= date_format(#{endOutHospTime},'%y%m%d')
+        </if>
+        <if test="startFinishTime != null">
+            AND date_format(s.finishtime,'%y%m%d') &gt;= date_format(#{startFinishTime},'%y%m%d')
+        </if>
+        <if test="endFinishTime != null">
+            AND date_format(s.finishtime,'%y%m%d') &lt;= date_format(#{endFinishTime},'%y%m%d')
+        </if>
+        GROUP BY d.questiontext
+        ) t2 ON t2.questiontext = d.questiontext
+        WHERE 1=1
+        <!-- 鍘婚噸锛氭槑缁嗚鍚屼竴瀛愪换鍔″悓涓�棰樼洰鍙繚鐣欐渶鏂颁竴鏉★紝閲嶇瓟涓嶉噸澶嶈鍏ラ」鏁� -->
+        AND d.id = (
+        SELECT MAX(d3.id)
+        FROM service_subtask_detail d3
+        WHERE d3.sub_id = d.sub_id
+        AND d3.questiontext &lt;=&gt; d.questiontext
+        AND d3.del_flag = '0'
+        )
+        <if test="subtaskIds != null and subtaskIds.size() > 0">
+            AND s.id IN
+            <foreach collection="subtaskIds" item="subtaskId" open="(" separator="," close=")">
+                #{subtaskId}
+            </foreach>
+        </if>
+        AND s.sendstate = 6
+        AND d.del_flag=0
+        <if test="valueType != null">AND d.value_type &gt;= #{valueType}</if>
+        <if test="scoreStart != null">AND d.score &gt;= #{scoreStart}</if>
+        <if test="scoreEnd != null">AND d.score &lt;= #{scoreEnd}</if>
+        <if test="questiontext != null  and questiontext != ''">and d.questiontext like concat('%', #{questiontext},
+            '%')
+        </if>
+        <if test="startOutHospTime != null">
+            AND date_format(s.endtime,'%y%m%d') &gt;= date_format(#{startOutHospTime},'%y%m%d')
+        </if>
+        <if test="endOutHospTime != null">
+            AND date_format(s.endtime,'%y%m%d') &lt;= date_format(#{endOutHospTime},'%y%m%d')
+        </if>
+        <if test="startFinishTime != null">
+            AND date_format(s.finishtime,'%y%m%d') &gt;= date_format(#{startFinishTime},'%y%m%d')
+        </if>
+        <if test="endFinishTime != null">
+            AND date_format(s.finishtime,'%y%m%d') &lt;= date_format(#{endFinishTime},'%y%m%d')
+        </if>
+        GROUP BY
+        t.taskid,
+        d.questiontext,
+        d.score,
+        d.targetvalue,
+        d.asrtext,
+        t.task_name,
+        s.deptcode,
+        s.deptname,
+        s.leavehospitaldistrictcode,
+        s.leavehospitaldistrictname,
+        d.value_type
+        ORDER BY
+        d.questiontext,
+        t.taskid
+    </select>
+
+    <select id="statQuestionOptionByKsOrBq" resultType="com.smartor.domain.DTO.QuestionCountKsOrBqDTO"
+            parameterType="com.smartor.domain.VO.QuestionCountKsOrBqVO">
+        SELECT
+        s.deptname AS deptname,
+        s.leavehospitaldistrictname AS leavehospitaldistrictname,
+        d.questiontext AS questionText,
+        d.targetvalue AS targetvalue, -- 鎵�鏈夐�夐」鎷兼帴
+        d.asrtext AS asrtext, -- 鐢ㄦ埛瀹為檯閫変腑鐨勯�夐」
+        d.score AS singleScore -- 鍗曟潯璁板綍鐨勫垎鏁�
+        FROM service_subtask_detail d
+        JOIN service_subtask s ON d.sub_id = s.id
+        WHERE s.del_flag = 0
+        AND d.del_flag = 0
+        AND s.service_type IN ('6', '14')
+        <if test="taskTemplateid != null">
+            AND s.templateid = #{taskTemplateid}
+        </if>
+        <if test="endFinishTime != null">
+            AND d.create_time &lt; #{endFinishTime}
+        </if>
+        <if test="startFinishTime != null">
+            AND d.create_time &gt;= #{startFinishTime}
+        </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>
+    </select>
+
+    <select id="selectServiceSubtaskListDeadLine" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
+            resultMap="ServiceSubtaskResult">
+        <include refid="selectServiceSubtaskVo"/>
+        where 1=1
+        and del_flag = 0
+        and visit_count = 1
+        and endtime
+    </select>
+
+    <!-- 闂ㄨ瘖婊℃剰搴︾患鍚堝緱鍒嗘帓鍚嶏紙鎸夌瀹ゆ垨鐥呭尯锛� -->
+    <!-- 缁煎悎婊℃剰搴� = 危(璇勫垎鏄庣粏鏉冮噸) / 璇勫垎鏄庣粏鏉℃暟 脳 100%锛屾潈閲嶅彧鍙� 1銆�0.8銆�0.6銆�0.4銆�0.2 浜旀。 -->
+    <select id="selectMzMydScoreRank" parameterType="com.smartor.domain.VO.MzMydScoreRankVO"
+            resultType="com.smartor.domain.DTO.MzMydScoreRankDTO">
+        SELECT
+        t.code                   AS code,
+        t.name                   AS name,
+        ROUND(AVG(t.w) * 100, 2) AS score,
+        COUNT(*)                 AS itemCount
+        FROM (
+        SELECT
+        <choose>
+            <when test='dimensionType == "2"'>
+                s.leavehospitaldistrictcode AS code,
+                s.leavehospitaldistrictname AS name,
+            </when>
+            <otherwise>
+                s.deptcode AS code,
+                s.deptname AS name,
+            </otherwise>
+        </choose>
+        CAST(d.score AS DECIMAL(10,4)) AS w
+        FROM service_subtask s
+        INNER JOIN service_subtask_detail d ON d.sub_id = s.id
+        WHERE s.del_flag = '0'
+        AND d.del_flag = '0'
+        AND s.sendstate = 6
+        <if test="serviceTypes != null and serviceTypes.size() > 0">
+            AND service_type IN
+            <foreach collection="serviceTypes" item="serviceType" open="(" separator=","
+                     close=")">
+                #{serviceType}
+            </foreach>
+        </if>
+<!--        &lt;!&ndash; 鍙彇鍏紡閲岀殑浜旀。鏉冮噸锛岀┖鍊�/0/鏈瓟绛夋棦涓嶈繘鍒嗗瓙涔熶笉杩涘垎姣� &ndash;&gt;-->
+<!--        AND CAST(d.score AS DECIMAL(10,4)) IN (1, 0.8, 0.6, 0.4, 0.2)-->
+        <!-- 鍚屼竴瀛愪换鍔″悓涓�棰樼洰鍙繚鐣欐渶鏂颁竴鏉★紝閬垮厤閲嶇瓟琚噸澶嶈鍏ラ」鏁� -->
+        AND d.id = (
+        SELECT MAX(d2.id)
+        FROM service_subtask_detail d2
+        WHERE d2.sub_id = d.sub_id
+        AND d2.questiontext &lt;=&gt; d.questiontext
+        AND d2.del_flag = '0'
+        )
+        <if test="orgid != null and orgid != ''">
+            AND s.orgid = #{orgid}
+        </if>
+        <if test="campusid != null and campusid != ''">
+            AND s.campusid = #{campusid}
+        </if>
+        <if test="startFinishTime != null">
+            AND s.finishtime &gt;= #{startFinishTime}
+        </if>
+        <if test="endFinishTime != null">
+            AND s.finishtime &lt; DATE_ADD(#{endFinishTime}, INTERVAL 1 DAY)
+        </if>
+        <if test="questionText != null  and questionText != ''">and d.questiontext like concat('%', #{questionText},
+            '%')
+        </if>
+        <choose>
+            <when test='dimensionType == "2"'>
+                AND s.leavehospitaldistrictcode IS NOT NULL AND s.leavehospitaldistrictcode &lt;&gt; ''
+                AND s.leavehospitaldistrictname IS NOT NULL AND s.leavehospitaldistrictname &lt;&gt; ''
+                <if test="districtCodes != null and districtCodes.size() > 0">
+                    AND s.leavehospitaldistrictcode IN
+                    <foreach collection="districtCodes" item="districtCode" open="(" separator="," close=")">
+                        #{districtCode}
+                    </foreach>
+                </if>
+            </when>
+            <otherwise>
+                AND s.deptcode IS NOT NULL AND s.deptcode &lt;&gt; ''
+                AND s.deptname IS NOT NULL AND s.deptname &lt;&gt; ''
+                <if test="deptCodes != null and deptCodes.size() > 0">
+                    AND s.deptcode IN
+                    <foreach collection="deptCodes" item="deptCode" open="(" separator="," close=")">
+                        #{deptCode}
+                    </foreach>
+                </if>
+            </otherwise>
+        </choose>
+        ) t
+        GROUP BY t.code, t.name
+        ORDER BY AVG(t.w) DESC, COUNT(*) DESC
+        <if test="limit != null and limit > 0">
+            LIMIT #{limit}
+        </if>
+    </select>
+
+
 </mapper>
+

--
Gitblit v1.9.3