| | |
| | | <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"/> |
| | |
| | | <result property="leavehospitaldistrictname" column="leavehospitaldistrictname"/> |
| | | <result property="excep" column="excep"/> |
| | | <result property="remark" column="remark"/> |
| | | <result property="doctorOpinion" column="doctor_opinion"/> |
| | | <result property="suggest" column="suggest"/> |
| | | <result property="sendstate" column="sendstate"/> |
| | | <result property="inhospid" column="inhospid"/> |
| | |
| | | long_send_time, |
| | | openid, |
| | | remark, |
| | | doctor_opinion, |
| | | service_type, |
| | | libtemplateid, |
| | | libtemplatename, |
| | |
| | | senduuid, |
| | | result, |
| | | finishtime, |
| | | finish_state, |
| | | recordid, |
| | | exrecallcount, |
| | | pulltime, |
| | |
| | | from service_subtask |
| | | </sql> |
| | | |
| | | <!-- 超时完成、延期完成逻辑 完成时状态(finish_state)计算:仅当本次更新把 sendstate 置为 6(随访完成)时使用。 |
| | | 基准截止时间 base = endtime + send_day(缺省1) + (Σ service_subtask_preachform.compensate_time + 1) 天, |
| | | 与 RyTask/RedisMqReceiver 的 isSubtaskDeadline 口径保持一致; |
| | | delay = COALESCE(service_task.delay_finish_days, 0); |
| | | finish_time = COALESCE(入参 finishtime, 库中 finishtime, NOW()): |
| | | finish_time <= base -> 1 正常完成 |
| | | delay > 0 且 finish_time <= base + delay -> 2 延期完成 |
| | | 其余(含 delay 为 0 或 NULL、或已超出延期窗口) -> 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()) |
| | | <= 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) > 0 |
| | | AND COALESCE(#{finishtime,jdbcType=TIMESTAMP}, service_subtask.finishtime, NOW()) |
| | | <= 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" |
| | | resultMap="ServiceSubtaskResult"> |
| | | <include refid="selectServiceSubtaskVo"/> |
| | |
| | | <if test="continueTimeNext != null ">and continue_time_next = #{continueTimeNext}</if> |
| | | </select> |
| | | |
| | | <!-- 即将超时过滤:是否即将超时(soonTimeout=1) + 即将超时时间(soonTimeoutHours,单位小时)。 |
| | | 截止时间口径与 RyTask/RedisMqReceiver 的 isSubtaskDeadline 保持一致: |
| | | service_subtask.endtime + service_task.send_day(缺省1) + (Σ service_subtask_preachform.compensate_time + 1) 天; |
| | | 仅当存在有效补偿记录时才计算截止时间(无补偿记录不参与即将超时); |
| | | 仅统计“尚未超时、且在 N 小时内将要超时”的数据。 --> |
| | | <sql id="soonTimeoutDeadlineExpr"> |
| | | ( |
| | | SELECT DATE_ADD( |
| | | DATE_ADD(ss.endtime, INTERVAL COALESCE(st.send_day, 1) DAY), |
| | | INTERVAL (COALESCE(pf.compensate_days, 0) + 1) DAY |
| | | ) |
| | | FROM service_subtask ss |
| | | LEFT JOIN service_task st ON st.taskid = ss.taskid AND st.del_flag = '0' |
| | | INNER 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 |
| | | ) pf ON pf.subid = ss.id |
| | | WHERE ss.id = service_subtask.id |
| | | ) |
| | | </sql> |
| | | |
| | | <sql id="soonTimeoutFilter"> |
| | | <if test="soonTimeout != null and soonTimeout == 1"> |
| | | AND <include refid="soonTimeoutDeadlineExpr"/> > NOW() |
| | | AND <include refid="soonTimeoutDeadlineExpr"/> <= DATE_ADD(NOW(), INTERVAL COALESCE(#{soonTimeoutHours}, 0) HOUR) |
| | | </if> |
| | | </sql> |
| | | |
| | | <select id="selectServiceSubtaskList" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity" |
| | | resultMap="ServiceSubtaskResult"> |
| | |
| | | </if> |
| | | </if> |
| | | <if test="deptOrDistrict==2"> |
| | | AND (1=1 |
| | | <if test="leavehospitaldistrictcodes != null"> |
| | | AND leavehospitaldistrictcode IN |
| | | AND ( |
| | | <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0"> |
| | | leavehospitaldistrictcode IN |
| | | <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" |
| | | separator="," |
| | | close=")"> |
| | | #{leavehospitaldistrictcode} |
| | | </foreach> |
| | | </if> |
| | | <if test=" leaveldeptcodes != null"> |
| | | OR deptcode IN |
| | | <if test="(leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0) |
| | | and (leaveldeptcodes != null and leaveldeptcodes.size() > 0)"> |
| | | OR |
| | | </if> |
| | | <if test=" leaveldeptcodes != null and leaveldeptcodes.size() > 0"> |
| | | deptcode IN |
| | | <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator="," |
| | | close=")"> |
| | | #{leaveldeptcode} |
| | |
| | | AND visit_count > 1 |
| | | </if> |
| | | <if test="remark != null">and remark = #{remark}</if> |
| | | <if test="doctorOpinion != null and doctorOpinion != ''">and doctor_opinion like concat('%', #{doctorOpinion}, '%')</if> |
| | | <if test="suggest != null">and suggest = #{suggest}</if> |
| | | <if test="createBy != null">and create_by = #{createBy}</if> |
| | | <if test="taskGuid != null">and task_guid = #{taskGuid}</if> |
| | |
| | | #{visitDeptCode} |
| | | </foreach> |
| | | </if> |
| | | <include refid="soonTimeoutFilter"/> |
| | | <if test="sort != null and sort==0">order by endtime asc</if> |
| | | <if test="sort != null and sort==1">order by endtime desc</if> |
| | | <if test="sort != null and sort==2">order by visit_time asc</if> |
| | |
| | | <if test="sort != null and sort==7">order by visit_time asc</if> |
| | | <if test="sort != null and sort==8">order by visit_time desc</if> |
| | | <if test="sort != null and sort==9">order by sendname asc</if> |
| | | <if test="pageSize != null and pageNum != null">limit ${pageSize} OFFSET ${pageNum}</if> |
| | | <if test="pageSize != null and pageNum != null"> |
| | | LIMIT ${pageSize} OFFSET ${pageNum} |
| | | </if> |
| | | </select> |
| | | |
| | | <select id="selectSatisfactionSubtaskList" parameterType="com.smartor.domain.VO.PatSatisfactionReqVO" |
| | |
| | | <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> |
| | | <include refid="soonTimeoutFilter"/> |
| | | </select> |
| | | |
| | | <select id="selectSendstateByCondition" parameterType="com.smartor.domain.ServiceSubtask" resultType="Integer"> |
| | |
| | | </if> |
| | | <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if> |
| | | <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if> |
| | | <if test="startOutHospTime != null"> |
| | | AND date_format(endtime,'%y%m%d') >= date_format(#{startOutHospTime},'%y%m%d') |
| | | </if> |
| | | <if test="endOutHospTime != null"> |
| | | AND date_format(endtime,'%y%m%d') <= date_format(#{endOutHospTime},'%y%m%d') |
| | | </if> |
| | | ) a |
| | | </select> |
| | | |
| | |
| | | </if> |
| | | WHERE ss.del_flag = 0 |
| | | AND ss.visit_time IS NOT NULL |
| | | AND ss.sendstate != 4 |
| | | <if test="starttime == null and endtime==null"> |
| | | AND DATE(ss.visit_time) < DATE(NOW()) |
| | | </if> |
| | |
| | | close=")"> |
| | | #{serviceType} |
| | | </foreach> |
| | | </if> |
| | | <if test="startOutHospTime != null"> |
| | | AND date_format(ss.endtime,'%y%m%d') >= date_format(#{startOutHospTime},'%y%m%d') |
| | | </if> |
| | | <if test="endOutHospTime != null"> |
| | | AND date_format(ss.endtime,'%y%m%d') <= date_format(#{endOutHospTime},'%y%m%d') |
| | | </if> |
| | | <if test="groupKey != null and groupKey != ''"> |
| | | AND ss.${groupKey} IN |
| | |
| | | <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> |
| | |
| | | <if test="nurseName != null ">nurse_name,</if> |
| | | <if test="nurseId != null ">nurse_id,</if> |
| | | <if test="remark != null ">remark,</if> |
| | | <if test="doctorOpinion != null ">doctor_opinion,</if> |
| | | <if test="suggest != null ">suggest,</if> |
| | | <if test="sendstate != null ">sendstate,</if> |
| | | <if test="inhospid != null ">inhospid,</if> |
| | |
| | | <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> |
| | |
| | | <if test="nurseName != null ">#{nurseName},</if> |
| | | <if test="nurseId != null ">#{nurseId},</if> |
| | | <if test="remark != null ">#{remark},</if> |
| | | <if test="doctorOpinion != null ">#{doctorOpinion},</if> |
| | | <if test="suggest != null ">#{suggest},</if> |
| | | <if test="sendstate != null ">#{sendstate},</if> |
| | | <if test="inhospid != null ">#{inhospid},</if> |
| | |
| | | <if test="isManuallyCalled != null ">#{isManuallyCalled},</if> |
| | | </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 <> #{isVisitAgain}) |
| | | </update> |
| | | |
| | | <update id="updateServiceSubtask" parameterType="com.smartor.domain.ServiceSubtask"> |
| | | update service_subtask |
| | |
| | | <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> |
| | |
| | | <if test="nurseName != null ">nurse_name=#{nurseName},</if> |
| | | <if test="nurseId != null ">nurse_id=#{nurseId},</if> |
| | | <if test="remark != null ">remark=#{remark},</if> |
| | | <if test="doctorOpinion != null ">doctor_opinion=#{doctorOpinion},</if> |
| | | <if test="suggest != null ">suggest=#{suggest},</if> |
| | | <if test="inhospid != null ">inhospid=#{inhospid},</if> |
| | | <if test="patfrom != null ">patfrom=#{patfrom},</if> |
| | |
| | | <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> |
| | |
| | | <if test="nurseName != null ">nurse_name=#{nurseName},</if> |
| | | <if test="nurseId != null ">nurse_id=#{nurseId},</if> |
| | | <if test="remark != null ">remark=#{remark},</if> |
| | | <if test="doctorOpinion != null ">doctor_opinion=#{doctorOpinion},</if> |
| | | <if test="suggest != null ">suggest=#{suggest},</if> |
| | | <if test="inhospid != null ">inhospid=#{inhospid},</if> |
| | | <if test="patfrom != null ">patfrom=#{patfrom},</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="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> |
| | |
| | | <if test="nurseName != null ">nurse_name=#{nurseName},</if> |
| | | <if test="nurseId != null ">nurse_id=#{nurseId},</if> |
| | | <if test="remark != null ">remark=#{remark},</if> |
| | | <if test="doctorOpinion != null ">doctor_opinion=#{doctorOpinion},</if> |
| | | <if test="suggest != null ">suggest=#{suggest},</if> |
| | | <if test="inhospid != null ">inhospid=#{inhospid},</if> |
| | | <if test="patfrom != null ">patfrom=#{patfrom},</if> |
| | |
| | | <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> |
| | |
| | | <if test="nurseName != null ">nurse_name=#{nurseName},</if> |
| | | <if test="nurseId != null ">nurse_id=#{nurseId},</if> |
| | | <if test="remark != null ">remark=#{remark},</if> |
| | | <if test="doctorOpinion != null ">doctor_opinion=#{doctorOpinion},</if> |
| | | <if test="suggest != null ">suggest=#{suggest},</if> |
| | | <if test="inhospid != null ">inhospid=#{inhospid},</if> |
| | | <if test="patfrom != null ">patfrom=#{patfrom},</if> |
| | |
| | | continue_content, |
| | | continue_count, |
| | | continue_time_next, |
| | | task_situation |
| | | task_situation, |
| | | finish_state, |
| | | is_manually_called |
| | | from service_subtask |
| | | where 1=1 |
| | | and del_flag = 0 |
| | |
| | | continue_count, |
| | | continue_time_next, |
| | | task_situation, |
| | | remark |
| | | remark, |
| | | doctor_opinion, |
| | | finish_state, |
| | | is_manually_called |
| | | from service_subtask |
| | | where 1=1 |
| | | and del_flag = 0 |
| | |
| | | <if test="startTime != null and endTime!=null"> |
| | | AND visit_time >= DATE(#{startTime}) |
| | | AND visit_time < DATE_ADD(DATE(#{endTime}), INTERVAL 1 DAY) |
| | | </if> |
| | | <if test="hospitalStartTime != null and hospitalEndTime!=null"> |
| | | AND endtime >= DATE(#{hospitalStartTime}) |
| | | AND endtime < 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="taskSituation != null"> |
| | | AND task_situation = #{taskSituation} |
| | | </if> |
| | | <if test="finishState != null"> |
| | | AND finish_state = #{finishState} |
| | | </if> |
| | | <if test="drcode != null and drcode != ''"> |
| | | AND drcode = #{drcode} |
| | | </if> |
| | |
| | | </if> |
| | | <if test="deptcode != null and deptcode != ''"> |
| | | AND deptcode = #{deptcode} |
| | | </if> |
| | | <if test="isManuallyCalled != null"> |
| | | AND is_manually_called = #{isManuallyCalled} |
| | | </if> |
| | | order by endtime desc |
| | | <if test="pageSize != null and pageNum != null"> |
| | |
| | | <select id="getSfStatisticsScriptDetails" parameterType="com.smartor.domain.ServiceSubtaskCountReq" |
| | | resultMap="ServiceSubtaskScriptCountResult"> |
| | | SELECT |
| | | a.id as scriptid, |
| | | a.templateid as templateid, |
| | | a.script_type, |
| | | MIN(a.id) as scriptid, |
| | | MIN(a.templateid) as templateid, |
| | | MIN(a.script_type) as script_type, |
| | | a.script_content, |
| | | b.subtask_type, |
| | | b.completed_quantity, |
| | | b.all_quantity, |
| | | ROUND(b.completed_quantity/b.all_quantity,2) as completed_percentage |
| | | SUM(b.completed_quantity) as completed_quantity, |
| | | SUM(b.all_quantity) as all_quantity, |
| | | ROUND(SUM(b.completed_quantity)/SUM(b.all_quantity),2) as completed_percentage |
| | | FROM |
| | | <if test="type == 1"> |
| | | ivr_task_template_script a |
| | |
| | | group by ssd.scriptid) b |
| | | ON a.id = b.scriptid |
| | | <!-- 适用单条查询 --> |
| | | <if test="scriptids != null"> |
| | | <if test="scriptids != null and scriptids != ''"> |
| | | AND a.scriptid in |
| | | (SELECT lib_script.scriptid FROM |
| | | svy_lib_template_script lib_script |
| | | WHERE lib_script.scriptid in (${scriptids})) |
| | | </if> |
| | | <!-- 同一道题会被复制到多个任务模板,按题目内容合并,保证一道题只返回一条 --> |
| | | GROUP BY a.script_content, b.subtask_type |
| | | ORDER BY MIN(a.id) |
| | | </select> |
| | | |
| | | <select id="getSfStatisticsScriptItemDetails" parameterType="com.smartor.domain.ServiceSubtaskCountReq" |
| | | resultMap="ServiceSubtaskScriptCountResult"> |
| | | SELECT |
| | | ssd.scriptid, |
| | | a.script_content, |
| | | ss.type as subtask_type, |
| | | IFNULL(ssd.matchedtext,ssd.asrtext) AS option_text, |
| | | COUNT(*) AS chosen_quantity |
| | | FROM |
| | | service_subtask_detail ssd |
| | | INNER JOIN service_subtask ss ON ssd.sub_id = ss.id |
| | | INNER JOIN |
| | | <if test="type == 1"> |
| | | ivr_task_template_script a ON a.id = ssd.scriptid |
| | | </if> |
| | | <if test="type == 2"> |
| | | svy_task_template_script a ON a.id = ssd.scriptid |
| | | </if> |
| | | where 1=1 |
| | | and ss.del_flag=0 |
| | | and ssd.del_flag=0 |
| | | <if test="orgid != null and orgid != ''"> |
| | | and ss.orgid = #{orgid} |
| | | </if> |
| | |
| | | <if test="configValue != null and configValue != ''"> |
| | | AND ssd.categoryid IN (${configValue}) |
| | | </if> |
| | | group by ssd.scriptid, IFNULL(ssd.matchedtext,ssd.asrtext) |
| | | group by a.script_content, ss.type, IFNULL(ssd.matchedtext,ssd.asrtext) |
| | | </select> |
| | | |
| | | <select id="getDataByTime" resultMap="ServiceSubtaskResult"> |
| | |
| | | nurse_id, |
| | | nurse_name, |
| | | remark, |
| | | doctor_opinion, |
| | | inhospid, |
| | | patfrom, |
| | | task_guid, |
| | |
| | | SUM(CASE WHEN sendstate != 2 THEN 1 ELSE 0 END) AS yfs, |
| | | SUM(CASE WHEN sendstate = 2 THEN 1 ELSE 0 END) AS wfs, |
| | | SUM(CASE WHEN sendstate = 6 THEN 1 ELSE 0 END) AS ywc, |
| | | SUM(CASE WHEN sendstate = 7 THEN 1 ELSE 0 END) AS cs, |
| | | SUM(CASE WHEN excep IS NOT NULL AND excep = '1' THEN 1 ELSE 0 END) AS yc, |
| | | SUM(CASE WHEN excep IS NOT NULL AND excep = '2' THEN 1 ELSE 0 END) AS jg, |
| | | COUNT(1) as total |
| | |
| | | </if> |
| | | </if> |
| | | <if test="deptOrDistrict==2"> |
| | | AND (1=1 |
| | | AND ( |
| | | <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0"> |
| | | AND leavehospitaldistrictcode IN |
| | | leavehospitaldistrictcode IN |
| | | <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" |
| | | separator="," |
| | | close=")"> |
| | | #{leavehospitaldistrictcode} |
| | | </foreach> |
| | | </if> |
| | | <if test="(leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0) |
| | | and (leaveldeptcodes != null and leaveldeptcodes.size() > 0)"> |
| | | OR |
| | | </if> |
| | | <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0"> |
| | | OR deptcode IN |
| | | deptcode IN |
| | | <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator="," |
| | | close=")"> |
| | | #{leaveldeptcode} |
| | |
| | | COUNT(CASE WHEN sendstate = 5 THEN 1 END) AS failedVisitCount, |
| | | SUM(CASE WHEN excep IS NOT NULL AND excep = '1' THEN 1 ELSE 0 END) AS abnormalVisitCount, |
| | | SUM(CASE WHEN excep IS NOT NULL AND excep = '2' THEN 1 ELSE 0 END) AS warnningVisitCount, |
| | | COUNT(*) AS allVisitCount |
| | | FROM service_subtask |
| | | WHERE del_flag = '0' |
| | | AND service_type = '2' |
| | | AND visit_count = 1 |
| | | COUNT(*) AS allVisitCount, |
| | | <choose> |
| | | <when test="soonTimeoutHours != null and soonTimeoutHours > 0"> |
| | | COUNT(CASE WHEN t.soon_deadline > NOW() |
| | | AND t.soon_deadline <= DATE_ADD(NOW(), INTERVAL #{soonTimeoutHours} HOUR) |
| | | THEN 1 END) AS soonTimeoutCount |
| | | </when> |
| | | <otherwise> |
| | | 0 AS soonTimeoutCount |
| | | </otherwise> |
| | | </choose> |
| | | FROM ( |
| | | SELECT ss.*, |
| | | <!-- 即将超时截止时间 = 出院时间(endtime) + 发送日(send_day, 缺省1) + 补偿天数(compensate_time 求和后再 +1 天), |
| | | 与 RyTask/RedisMqReceiver 的 isSubtaskDeadline 口径保持一致; |
| | | 无有效补偿记录(cp.subid 为空)时截止时间为 NULL,不参与即将超时统计 --> |
| | | CASE |
| | | WHEN cp.subid IS NULL THEN NULL |
| | | ELSE DATE_ADD( |
| | | DATE_ADD(ss.endtime, INTERVAL COALESCE(st.send_day, 1) DAY), |
| | | INTERVAL (COALESCE(cp.compensate_days, 0) + 1) DAY |
| | | ) |
| | | END AS soon_deadline |
| | | FROM service_subtask ss |
| | | LEFT JOIN service_task st ON st.taskid = ss.taskid AND st.del_flag = '0' |
| | | <!-- 补偿时间:先按子任务聚合成一行再关联,避免一对多放大计数; |
| | | 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 |
| | | WHERE ss.del_flag = '0' |
| | | AND ss.service_type = '2' |
| | | AND ss.visit_count = 1 |
| | | <if test="orgid != null and orgid != ''"> |
| | | AND orgid = #{orgid} |
| | | AND ss.orgid = #{orgid} |
| | | </if> |
| | | <if test="campusid != null and campusid != ''"> |
| | | and campusid = #{campusid} |
| | | and ss.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 test="(leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0) |
| | | or (leaveldeptcodes != null and leaveldeptcodes.size() > 0)"> |
| | | AND ( |
| | | <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0"> |
| | | ss.leavehospitaldistrictcode IN |
| | | <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" |
| | | separator="," |
| | | close=")"> |
| | | #{leavehospitaldistrictcode} |
| | | </foreach> |
| | | </if> |
| | | <if test="(leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0) |
| | | and (leaveldeptcodes != null and leaveldeptcodes.size() > 0)"> |
| | | OR |
| | | </if> |
| | | <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0"> |
| | | ss.deptcode IN |
| | | <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator="," |
| | | close=")"> |
| | | #{leaveldeptcode} |
| | | </foreach> |
| | | </if>) |
| | | </if> |
| | | <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0"> |
| | | AND deptcode IN |
| | | <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator="," |
| | | close=")"> |
| | | #{leaveldeptcode} |
| | | </foreach> |
| | | </if> |
| | | ) t |
| | | </select> |
| | | |
| | | <select id="querySendCount" parameterType="com.smartor.domain.entity.ServiceSubtaskSatisfactionEntity" |
| | |
| | | continue_count, |
| | | continue_time_next, |
| | | task_situation, |
| | | remark |
| | | remark, |
| | | doctor_opinion |
| | | from service_subtask |
| | | where 1=1 |
| | | and del_flag = 0 |