From 96de4cd0f9d994919ae0c3d70652fdbe382949d3 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期二, 20 十月 2026 14:45:58 +0800
Subject: [PATCH] 【丽水】丽水中医院根据下次任务ID生成再次随访

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

diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index 6c428cf..40a1c34 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -23,6 +23,7 @@
         <result property="senduuid" column="senduuid"/>
         <result property="result" column="result"/>
         <result property="finishtime" column="finishtime"/>
+        <result property="finishState" column="finish_state"/>
         <result property="recordid" column="recordid"/>
         <result property="exrecallcount" column="exrecallcount"/>
         <result property="pulltime" column="pulltime"/>
@@ -202,6 +203,7 @@
                senduuid,
                result,
                finishtime,
+               finish_state,
                recordid,
                exrecallcount,
                pulltime,
@@ -249,6 +251,53 @@
                task_situation,
                is_manually_called
         from service_subtask
+    </sql>
+
+    <!-- 瀹屾垚鏃剁姸鎬�(finish_state)璁$畻锛氫粎褰撴湰娆℃洿鏂版妸 sendstate 缃负 6锛堥殢璁垮畬鎴愶級鏃朵娇鐢ㄣ��
+         鍩哄噯鎴鏃堕棿 base = endtime + send_day(缂虹渷1) + (危 service_subtask_preachform.compensate_time + 1) 澶╋紝
+         涓� RyTask/RedisMqReceiver 鐨� isSubtaskDeadline 鍙e緞淇濇寔涓�鑷达紱
+         delay = COALESCE(service_task.delay_finish_days, 0)锛�
+         finish_time = COALESCE(鍏ュ弬 finishtime, 搴撲腑 finishtime, NOW())锛�
+           finish_time <= base                                    -> 1 姝e父瀹屾垚
+           delay > 0 涓� finish_time <= base + delay               -> 2 寤舵湡瀹屾垚
+           鍏朵綑锛堝惈 delay 涓� 0 鎴� NULL銆佹垨宸茶秴鍑哄欢鏈熺獥鍙o級          -> 3 瓒呮椂瀹屾垚
+         finishtime 涓虹┖鏃剁敤 NOW() 鍏滃簳锛屼繚璇佸畬鎴愭椂涓�瀹氬啓鍏ョ姸鎬侊紱
+         浠呭綋 endtime 涓虹┖瀵艰嚧鏃犳硶璁$畻鏃舵墠淇濇寔鍘熷�间笉瑕嗙洊銆� -->
+    <sql id="finishStateExpr">
+        CASE
+        WHEN service_subtask.endtime IS NULL THEN finish_state
+        WHEN COALESCE(#{finishtime,jdbcType=TIMESTAMP}, service_subtask.finishtime, NOW())
+        &lt;= DATE_ADD(
+        DATE_ADD(
+        service_subtask.endtime,
+        INTERVAL COALESCE((SELECT st.send_day FROM service_task st
+        WHERE st.taskid = service_subtask.taskid AND st.del_flag = '0' LIMIT 1), 1) DAY
+        ),
+        INTERVAL (COALESCE((SELECT SUM(CAST(COALESCE(NULLIF(TRIM(pf.compensate_time), ''), '0') AS SIGNED))
+        FROM service_subtask_preachform pf
+        WHERE pf.subid = service_subtask.id AND pf.del_flag = 0), 0) + 1) DAY
+        )
+        THEN 1
+        WHEN COALESCE((SELECT st.delay_finish_days FROM service_task st
+        WHERE st.taskid = service_subtask.taskid AND st.del_flag = '0' LIMIT 1), 0) &gt; 0
+        AND COALESCE(#{finishtime,jdbcType=TIMESTAMP}, service_subtask.finishtime, NOW())
+        &lt;= DATE_ADD(
+        DATE_ADD(
+        DATE_ADD(
+        service_subtask.endtime,
+        INTERVAL COALESCE((SELECT st.send_day FROM service_task st
+        WHERE st.taskid = service_subtask.taskid AND st.del_flag = '0' LIMIT 1), 1) DAY
+        ),
+        INTERVAL (COALESCE((SELECT SUM(CAST(COALESCE(NULLIF(TRIM(pf.compensate_time), ''), '0') AS SIGNED))
+        FROM service_subtask_preachform pf
+        WHERE pf.subid = service_subtask.id AND pf.del_flag = 0), 0) + 1) DAY
+        ),
+        INTERVAL COALESCE((SELECT st.delay_finish_days FROM service_task st
+        WHERE st.taskid = service_subtask.taskid AND st.del_flag = '0' LIMIT 1), 0) DAY
+        )
+        THEN 2
+        ELSE 3
+        END
     </sql>
 
     <select id="selectServiceSubtaskBySendstate" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
@@ -950,6 +999,7 @@
             <if test="senduuid != null">senduuid,</if>
             <if test="result != null">result,</if>
             <if test="finishtime != null">finishtime,</if>
+            <if test="finishState != null">finish_state,</if>
             <if test="recordid != null">recordid,</if>
             <if test="exrecallcount != null">exrecallcount,</if>
             <if test="pulltime != null">pulltime,</if>
@@ -1048,6 +1098,7 @@
             <if test="senduuid != null">#{senduuid},</if>
             <if test="result != null">#{result},</if>
             <if test="finishtime != null">#{finishtime},</if>
+            <if test="finishState != null">#{finishState},</if>
             <if test="recordid != null">#{recordid},</if>
             <if test="exrecallcount != null">#{exrecallcount},</if>
             <if test="pulltime != null">#{pulltime},</if>
@@ -1132,6 +1183,15 @@
         </trim>
     </insert>
 
+    <!-- 浜屾闅忚骞傜瓑锛氫粎褰� is_visit_again 涓嶆槸鐩爣鍊兼椂鏇存柊锛岃繑鍥炲彈褰卞搷琛屾暟 -->
+    <update id="updateIsVisitAgainById">
+        update service_subtask
+        set is_visit_again = #{isVisitAgain},
+            update_time = now()
+        where id = #{id}
+          and (is_visit_again is null or is_visit_again &lt;&gt; #{isVisitAgain})
+    </update>
+
     <update id="updateServiceSubtask" parameterType="com.smartor.domain.ServiceSubtask">
         update service_subtask
         <trim prefix="SET" suffixOverrides=",">
@@ -1188,6 +1248,7 @@
             <if test="openid != null ">openid = #{openid},</if>
             <if test="longSendTime != null ">long_send_time = #{longSendTime},</if>
             <if test="sendstate != null ">sendstate = #{sendstate},</if>
+            <if test="sendstate != null and sendstate == 6">finish_state = <include refid="finishStateExpr"/>,</if>
             <if test="serviceType != null ">service_type = #{serviceType},</if>
             <if test="score != null ">score = #{score},</if>
             <if test="submit != null ">submit = #{submit},</if>
@@ -1292,6 +1353,7 @@
             <if test="openid != null ">openid = #{openid},</if>
             <if test="longSendTime != null ">long_send_time = #{longSendTime},</if>
             <if test="sendstate != null ">sendstate = #{sendstate},</if>
+            <if test="sendstate != null and sendstate == 6">finish_state = <include refid="finishStateExpr"/>,</if>
             <if test="serviceType != null ">service_type = #{serviceType},</if>
             <if test="score != null ">score = #{score},</if>
             <if test="visitCount != null ">visit_count = #{visitCount},</if>
@@ -1347,6 +1409,7 @@
             <if test="sex != null">sex = #{sex},</if>
             <if test="delFlag != null">del_flag = #{delFlag},</if>
             <if test="sendstate != null ">sendstate = #{sendstate},</if>
+            <if test="sendstate != null and sendstate == 6">finish_state = <include refid="finishStateExpr"/>,</if>
             <if test="age != null">age = #{age},</if>
             <if test="sfzh != null">sfzh = #{sfzh},</if>
             <if test="addr != null">addr = #{addr},</if>
@@ -1458,6 +1521,7 @@
             <if test="phone != null">phone = #{phone},</if>
             <if test="sex != null">sex = #{sex},</if>
             <if test="sendstate != null ">sendstate = #{sendstate},</if>
+            <if test="sendstate != null and sendstate == 6">finish_state = <include refid="finishStateExpr"/>,</if>
             <if test="age != null">age = #{age},</if>
             <if test="sfzh != null">sfzh = #{sfzh},</if>
             <if test="addr != null">addr = #{addr},</if>
@@ -1931,6 +1995,10 @@
             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>

--
Gitblit v1.9.3