| | |
| | | <result property="diagType" column="diag_type"/> |
| | | <!-- 2026-11:重要性标记编码(日间手术/日间诊疗/无…),建任务时取自 pat_med_inhosp --> |
| | | <result property="importanceFlagCode" column="importance_flag_code"/> |
| | | <!-- 2026-11:点位编码,建子任务时原样拷自 service_task.point_location --> |
| | | <result property="pointLocation" column="point_location"/> |
| | | </resultMap> |
| | | |
| | | <resultMap type="com.ruoyi.task.domain.ServiceSubtaskCount" id="ServiceSubtaskResult2"> |
| | |
| | | deptcode, |
| | | deptname, |
| | | importance_flag_code, |
| | | point_location, |
| | | stop_state, |
| | | leavehospitaldistrictcode, |
| | | leavehospitaldistrictname, |
| | |
| | | </sql> |
| | | |
| | | <!-- 超时完成、延期完成逻辑 完成时状态(finish_state)计算:仅当本次更新把 sendstate 置为 6(随访完成)时使用。 |
| | | 基准截止时间 base = endtime + send_day(缺省1) + (Σ service_subtask_preachform.compensate_time + 1) 天, |
| | | 与 RyTask/RedisMqReceiver 的 isSubtaskDeadline 口径保持一致; |
| | | 基准截止时间 base: |
| | | 非任务组(appltype != 5):endtime + send_day(缺省1) + (Σ service_subtask_preachform.compensate_time + 1) 天; |
| | | 任务组(appltype = 5):按 schedule_benchmark 解析基准时间 |
| | | (1-入院 2-出院 3-就诊 4-入组 0/其它-自定义时间) |
| | | + day_offset + (Σ compensate_time + 1) 天(不叠加 send_day); |
| | | 与 RyTask/RedisMqReceiver 的 isSubtaskDeadline、selectTimelyRateBatch 口径保持一致; |
| | | 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"> |
| | | base 为空(endtime / schedule / day_offset 缺失)时保持原值不覆盖。 --> |
| | | <sql id="finishDeadlineExpr"> |
| | | DATE_ADD( |
| | | CASE |
| | | WHEN service_subtask.endtime IS NULL THEN finish_state |
| | | WHEN COALESCE(st.appltype, '') = '5' THEN |
| | | DATE_ADD( |
| | | CASE sts.schedule_benchmark |
| | | WHEN 1 THEN service_subtask.starttime |
| | | WHEN 2 THEN service_subtask.endtime |
| | | WHEN 3 THEN service_subtask.admindate |
| | | WHEN 4 THEN service_subtask.create_time |
| | | ELSE sts.schedule_benchmark_custom_time |
| | | END, |
| | | INTERVAL std.day_offset DAY) |
| | | ELSE |
| | | DATE_ADD(service_subtask.endtime, INTERVAL COALESCE(st.send_day, 1) DAY) |
| | | END, |
| | | 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) |
| | | </sql> |
| | | |
| | | <sql id="finishStateExpr"> |
| | | COALESCE(( |
| | | SELECT |
| | | CASE |
| | | WHEN <include refid="finishDeadlineExpr"/> IS NULL THEN NULL |
| | | 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 |
| | | ) |
| | | <= <include refid="finishDeadlineExpr"/> |
| | | 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 |
| | | WHEN COALESCE(st.delay_finish_days, 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 |
| | | ) |
| | | <= DATE_ADD(<include refid="finishDeadlineExpr"/>, |
| | | INTERVAL COALESCE(st.delay_finish_days, 0) DAY) |
| | | THEN 2 |
| | | ELSE 3 |
| | | END |
| | | FROM (SELECT 1) dummy |
| | | LEFT JOIN service_task st ON st.taskid = service_subtask.taskid |
| | | LEFT JOIN service_task_schedule sts ON sts.id = service_subtask.schedule_id |
| | | LEFT JOIN service_task_schedule_detail std ON std.id = service_subtask.schedule_detail_id |
| | | LIMIT 1 |
| | | ), finish_state) |
| | | </sql> |
| | | |
| | | <!-- 当前执行方式:首次随访 current_preachform 为空时,取 preachform 的第一个执行方式兜底 --> |
| | |
| | | <if test="hospType != null and hospType != ''">and hosp_type = #{hospType}</if> |
| | | <!-- |
| | | 2026-11:重要性标记筛选(对应 service_subtask.importance_flag_code,建任务时取自 |
| | | pat_med_inhosp.importance_flag_code)。两种写法: |
| | | ① 精确单值 importanceFlagCode = 'FH0165.01'(或描述口径 '日间手术') |
| | | ② 精确多值 importanceFlagCodes = ['FH0165.01','FH0165.02'] |
| | | pat_med_inhosp.importance_flag_code)。 |
| | | ① 模糊(/patItem 用这个) importanceFlagCode → LIKE '%值%' |
| | | 传「日间」即可命中「日间手术」「日间诊疗」「无,日间手术」多值行; |
| | | 传完整值(「日间手术」/「FH0165.01」)退化为精确匹配。 |
| | | ② 精确多值 importanceFlagCodes → IN |
| | | 该列采集时就被拼成**描述串**(ImportFlagEnum 的 desc),多值用英文逗号拼接, |
| | | 如 '无,日间手术'(见 ServiceSLTDHealthcareRecordServiceImpl#hospitalizedApply)—— |
| | | 等值/IN 只命中单值行;多值行(现场仅 7 条,都在出院记录上)要筛全需自行写 |
| | | find_in_set。两种口径并存(有库存枚举编码、有库存中文描述),传什么按什么精确比, |
| | | 所以「日间」这类跨取值查询只能靠模糊;描述与 FH0165.xx 编码两种口径都按原值比, |
| | | 不做值域归一。 |
| | | ⚠️ 同一条件必须同步加到 countByCondition(列表 total / 各状态统计走那条 SQL), |
| | | 否则会出现「列表筛出 N 行、总数还是全量」的错配。 |
| | | --> |
| | | <if test="importanceFlagCode != null and importanceFlagCode != ''"> |
| | | and importance_flag_code = #{importanceFlagCode} |
| | | and importance_flag_code like concat('%', #{importanceFlagCode}, '%') |
| | | </if> |
| | | <if test="importanceFlagCodes != null and importanceFlagCodes.size() > 0"> |
| | | AND importance_flag_code IN |
| | | <foreach collection="importanceFlagCodes" item="impFlagItem" open="(" separator="," close=")"> |
| | | #{impFlagItem} |
| | | </foreach> |
| | | </if> |
| | | <!-- |
| | | 2026-11:点位筛选(对应 service_subtask.point_location,建子任务时从 service_task 快照过来)。 |
| | | 只有一条 IN 条件:单选/多选都在 ServiceSubtaskEntity#getPointLocations() 里归一 |
| | | (只传 pointLocation 会自动包成单元素集合),所以不再写等值分支。 |
| | | ⚠️ 同一条件必须同步加到 countByCondition(列表 total / 各状态统计走那条 SQL), |
| | | 否则会出现「列表筛出 N 行、总数还是全量」的错配。 |
| | | --> |
| | | <if test="pointLocations != null and pointLocations.size() > 0"> |
| | | AND point_location IN |
| | | <foreach collection="pointLocations" item="pointLocItem" open="(" separator="," close=")"> |
| | | #{pointLocItem} |
| | | </foreach> |
| | | </if> |
| | | <if test="libtemplateid != null ">and libtemplateid = #{libtemplateid}</if> |
| | |
| | | </if> |
| | | SUM(CASE WHEN ss.finishtime IS NOT NULL AND DATE(ss.visit_time) <= 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) <= #{rateDay} + COALESCE(cp.compensate_days, 0) |
| | | THEN 1 ELSE 0 END) / COUNT(*) AS rate |
| | | </if> |
| | | <if test="rateDay == null"> |
| | | NULL AS rate |
| | | </if> |
| | | <!-- 及时率基准: |
| | | 1) 非任务组(appltype != 5):endtime + send_day(缺省1) + Σ补偿天数 + 1 天; |
| | | 2) 任务组(appltype = 5):按 schedule_benchmark 解析基准时间 |
| | | (1-入院时间 2-出院时间 3-就诊时间 4-入组时间 0/其它-自定义时间) |
| | | + day_offset + Σ补偿天数 + 1 天(不再叠加 send_day); |
| | | 完成时间 finishtime <= 基准时间计为及时,分母仍为应随访数。 |
| | | 补偿天数只取 service_subtask_preachform.compensate_time 的汇总值一次, |
| | | 避免与补偿明细相加造成重复补偿或一对多放大分母。 --> |
| | | SUM(CASE |
| | | WHEN ss.finishtime IS NOT NULL |
| | | AND COALESCE(st.appltype, '') != '5' |
| | | AND ss.endtime IS NOT NULL |
| | | AND ss.finishtime <= DATE_ADD( |
| | | DATE_ADD(ss.endtime, INTERVAL COALESCE(st.send_day, 1) DAY), |
| | | INTERVAL (COALESCE(cp.compensate_days, 0) + 1) DAY) |
| | | THEN 1 |
| | | WHEN ss.finishtime IS NOT NULL |
| | | AND st.appltype = '5' |
| | | AND std.day_offset IS NOT NULL |
| | | AND ss.finishtime <= DATE_ADD( |
| | | DATE_ADD( |
| | | CASE sts.schedule_benchmark |
| | | WHEN 1 THEN ss.starttime |
| | | WHEN 2 THEN ss.endtime |
| | | WHEN 3 THEN ss.admindate |
| | | WHEN 4 THEN ss.create_time |
| | | ELSE sts.schedule_benchmark_custom_time |
| | | END, INTERVAL std.day_offset DAY), |
| | | INTERVAL (COALESCE(cp.compensate_days, 0) + 1) DAY) |
| | | THEN 1 |
| | | ELSE 0 |
| | | END) / COUNT(*) AS rate |
| | | 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> |
| | | <!-- 这里按 taskid / 历史 schedule 快照关联,不按 del_flag 过滤: |
| | | 任务或计划被编辑后旧 schedule/detail 会置为 del_flag=1, |
| | | 但历史 subtask 仍引用旧 ID,过滤会丢失历史及时率基准。 --> |
| | | LEFT JOIN service_task st |
| | | ON st.taskid = ss.taskid |
| | | LEFT JOIN service_task_schedule sts |
| | | ON sts.id = ss.schedule_id |
| | | LEFT JOIN service_task_schedule_detail std |
| | | ON std.id = ss.schedule_detail_id |
| | | <!-- 补偿时间:先按子任务聚合成一行再关联,避免一对多放大 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 |
| | | WHERE ss.del_flag = 0 |
| | | AND ss.visit_time IS NOT NULL |
| | | AND ss.sendstate != 4 |
| | |
| | | <if test="deptname != null and deptname != ''">deptname,</if> |
| | | <!-- 2026-11:重要性标记编码(日间手术/日间诊疗…),建任务时从 pat_med_inhosp 同步 --> |
| | | <if test="importanceFlagCode != null and importanceFlagCode != ''">importance_flag_code,</if> |
| | | <!-- 2026-11:点位编码,建子任务时从 service_task.point_location 同步 --> |
| | | <if test="pointLocation != null and pointLocation != ''">point_location,</if> |
| | | <if test="labelstatus != null">labelstatus,</if> |
| | | <if test="updateBy != null">update_by,</if> |
| | | <if test="updateTime != null">update_time,</if> |
| | |
| | | <if test="deptcode != null and deptcode != ''">#{deptcode},</if> |
| | | <if test="deptname != null and deptname != ''">#{deptname},</if> |
| | | <if test="importanceFlagCode != null and importanceFlagCode != ''">#{importanceFlagCode},</if> |
| | | <if test="pointLocation != null and pointLocation != ''">#{pointLocation},</if> |
| | | <if test="labelstatus != null">#{labelstatus},</if> |
| | | <if test="updateBy != null">#{updateBy},</if> |
| | | <if test="updateTime != null">#{updateTime},</if> |
| | |
| | | <if test="openid != null ">openid = #{openid},</if> |
| | | <if test="longSendTime != null ">long_send_time = #{longSendTime},</if> |
| | | <if test="sendstate != null ">sendstate = #{sendstate},</if> |
| | | <!-- 完成时间不变量(2026-11):状态一旦不是"完成(6)",就显式清空完成时间与完成时状态。 |
| | | 上面 finishtime 那一段是 if(finishtime != null),传 null 会被整段跳过, |
| | | 所以"清空"必须在这里用 SQL 的 NULL 写出来;否则 3 已发送 / 5 发送失败 / 7 超时 |
| | | 的行会一直带着历史完成时间("超时却有完成时间、及时率虚高"就是这么来的)。 --> |
| | | <if test="sendstate != null and sendstate != 6">finishtime = NULL, finish_state = NULL,</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="scheduleSeq != null ">schedule_seq = #{scheduleSeq},</if> |
| | | <if test="loopCount != null ">loop_count = #{loopCount},</if> |
| | | <if test="isManuallyCalled != null ">is_manually_called = #{isManuallyCalled},</if> |
| | | <!-- 2026-11:点位编码(建子任务时的快照;任务上改点位不会自动回写) --> |
| | | <if test="pointLocation != null and pointLocation != ''">point_location = #{pointLocation},</if> |
| | | </trim> |
| | | where id = #{id} |
| | | </update> |
| | |
| | | <if test="openid != null ">openid = #{openid},</if> |
| | | <if test="longSendTime != null ">long_send_time = #{longSendTime},</if> |
| | | <if test="sendstate != null ">sendstate = #{sendstate},</if> |
| | | <!-- 完成时间不变量(2026-11):状态一旦不是"完成(6)",就显式清空完成时间与完成时状态。 |
| | | 上面 finishtime 那一段是 if(finishtime != null),传 null 会被整段跳过, |
| | | 所以"清空"必须在这里用 SQL 的 NULL 写出来;否则 3 已发送 / 5 发送失败 / 7 超时 |
| | | 的行会一直带着历史完成时间("超时却有完成时间、及时率虚高"就是这么来的)。 --> |
| | | <if test="sendstate != null and sendstate != 6">finishtime = NULL, finish_state = NULL,</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="sex != null">sex = #{sex},</if> |
| | | <if test="delFlag != null">del_flag = #{delFlag},</if> |
| | | <if test="sendstate != null ">sendstate = #{sendstate},</if> |
| | | <!-- 完成时间不变量(2026-11):状态一旦不是"完成(6)",就显式清空完成时间与完成时状态。 |
| | | 上面 finishtime 那一段是 if(finishtime != null),传 null 会被整段跳过, |
| | | 所以"清空"必须在这里用 SQL 的 NULL 写出来;否则 3 已发送 / 5 发送失败 / 7 超时 |
| | | 的行会一直带着历史完成时间("超时却有完成时间、及时率虚高"就是这么来的)。 --> |
| | | <if test="sendstate != null and sendstate != 6">finishtime = NULL, finish_state = NULL,</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="phone != null">phone = #{phone},</if> |
| | | <if test="sex != null">sex = #{sex},</if> |
| | | <if test="sendstate != null ">sendstate = #{sendstate},</if> |
| | | <!-- 完成时间不变量(2026-11):状态一旦不是"完成(6)",就显式清空完成时间与完成时状态。 |
| | | 上面 finishtime 那一段是 if(finishtime != null),传 null 会被整段跳过, |
| | | 所以"清空"必须在这里用 SQL 的 NULL 写出来;否则 3 已发送 / 5 发送失败 / 7 超时 |
| | | 的行会一直带着历史完成时间("超时却有完成时间、及时率虚高"就是这么来的)。 --> |
| | | <if test="sendstate != null and sendstate != 6">finishtime = NULL, finish_state = NULL,</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="sendname != null and sendname != ''"> |
| | | AND sendname LIKE CONCAT('%', #{sendname}, '%') |
| | | </if> |
| | | <!-- |
| | | 2026-11:重要性标记模糊筛选 —— 必须与 serviceSubtaskWhere 里的同名条件【完全一致】, |
| | | 否则 /patItem 的列表与 total/各状态统计会错配(列表筛了、总数没筛)。 |
| | | 口径见 serviceSubtaskWhere 处的注释。 |
| | | --> |
| | | <if test="importanceFlagCode != null and importanceFlagCode != ''"> |
| | | AND importance_flag_code LIKE CONCAT('%', #{importanceFlagCode}, '%') |
| | | </if> |
| | | <!-- |
| | | 2026-11:点位筛选 —— 必须与 serviceSubtaskWhere 里的同名条件【完全一致】, |
| | | 否则 /patItem 的列表与 total/各状态统计会错配(列表筛了、总数没筛)。 |
| | | 单选/多选归一在 ServiceSubtaskEntity#getPointLocations(),这里只有一条 IN。 |
| | | --> |
| | | <if test="pointLocations != null and pointLocations.size() > 0"> |
| | | AND point_location IN |
| | | <foreach collection="pointLocations" item="pointLocItem" open="(" separator="," close=")"> |
| | | #{pointLocItem} |
| | | </foreach> |
| | | </if> |
| | | <if test="phone != null and phone != ''"> |
| | | AND phone = #{phone} |
| | | </if> |