| | |
| | | <result property="loopCount" column="loop_count"/> |
| | | <result property="isManuallyCalled" column="is_manually_called"/> |
| | | <result property="campusid" column="campusid"/> |
| | | <result property="diagType" column="diag_type"/> |
| | | </resultMap> |
| | | |
| | | <resultMap type="com.smartor.domain.ServiceSubtaskCount" id="ServiceSubtaskResult2"> |
| | |
| | | </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="managementDoctorCode != null ">and management_doctor_code = #{managementDoctorCode}</if> |
| | | <if test="submit != null ">and submit = #{submit}</if> |
| | | <if test="upid != null ">and upid = #{upid}</if> |
| | | <if test="visitCount != null ">and visit_count = #{visitCount}</if> |
| | | <if test="patfrom != null ">and patfrom = #{patfrom}</if> |
| | | <if test="serviceType != null ">and service_type = #{serviceType}</if> |
| | | <if test="patid != null ">and patid = #{patid}</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> |
| | | <if test="currentPreachform != null and currentPreachform != '' ">and current_preachform = #{currentPreachform}</if> |
| | | <if test="currentPreachforms != null and currentPreachforms != ''"> |
| | | and FIND_IN_SET(<include refid="effectiveCurrentPreachformExpr"/>, #{currentPreachforms}) |
| | | </if> |
| | |
| | | <if test="visitDeptName != null">and visit_dept_name = #{visitDeptName}</if> |
| | | <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if> |
| | | <if test="managementDoctor != null">and management_doctor = #{managementDoctor}</if> |
| | | <if test="currentPreachform != null">and current_preachform = #{currentPreachform}</if> |
| | | <if test="currentPreachform != null and currentPreachform != '' ">and current_preachform = #{currentPreachform}</if> |
| | | <if test="isabnormal != null">and isabnormal = #{isabnormal}</if> |
| | | <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if> |
| | | <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if> |
| | |
| | | <if test="visitTime != null ">and visit_time = #{visitTime}</if> |
| | | <if test="visitDeptCode != null">and visit_dept_code = #{visitDeptCode}</if> |
| | | <if test="visitDeptName != null">and visit_dept_name = #{visitDeptName}</if> |
| | | <if test="currentPreachform != null">and current_preachform = #{currentPreachform}</if> |
| | | <if test="currentPreachform != null and currentPreachform != '' ">and current_preachform = #{currentPreachform}</if> |
| | | <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if> |
| | | <if test="isabnormal != null">and isabnormal = #{isabnormal}</if> |
| | | <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if> |
| | |
| | | </if> |
| | | 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="visitDeptName != null">visit_dept_name,</if> |
| | | <if test="managementDoctorCode != null">management_doctor_code,</if> |
| | | <if test="managementDoctor != null">management_doctor,</if> |
| | | <if test="currentPreachform != null">current_preachform,</if> |
| | | <if test="currentPreachform != null and currentPreachform != '' ">current_preachform,</if> |
| | | <if test="taskSituation != null">task_situation,</if> |
| | | <if test="isabnormal != null">isabnormal,</if> |
| | | <if test="continueFlag != null ">continue_flag,</if> |
| | |
| | | <if test="visitDeptName != null">#{visitDeptName},</if> |
| | | <if test="managementDoctorCode != null">#{managementDoctorCode},</if> |
| | | <if test="managementDoctor != null">#{managementDoctor},</if> |
| | | <if test="currentPreachform != null">#{currentPreachform},</if> |
| | | <if test="currentPreachform != null and currentPreachform != '' ">#{currentPreachform},</if> |
| | | <if test="taskSituation != null">#{taskSituation},</if> |
| | | <if test="isabnormal != null">#{isabnormal},</if> |
| | | <if test="continueFlag != null ">#{continueFlag},</if> |
| | |
| | | <if test="visitDeptName != null">visit_dept_name = #{visitDeptName},</if> |
| | | <if test="managementDoctorCode != null">management_doctor_code = #{managementDoctorCode},</if> |
| | | <if test="managementDoctor != null">management_doctor=#{managementDoctor},</if> |
| | | <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if> |
| | | <if test="currentPreachform != null and currentPreachform != '' ">current_preachform=#{currentPreachform},</if> |
| | | <if test="taskSituation != null">task_situation=#{taskSituation},</if> |
| | | <if test="isabnormal != null">isabnormal=#{isabnormal},</if> |
| | | <if test="continueFlag != null ">continue_flag = #{continueFlag},</if> |
| | |
| | | <if test="isManuallyCalled != null ">is_manually_called = #{isManuallyCalled},</if> |
| | | </trim> |
| | | where id = #{id} |
| | | </update> |
| | | |
| | | <!-- 微信公众号已领取未填写按默认选项完成:只更新当前子任务。 |
| | | 条件 sendstate=1 + 未提交,保证只处理当前被领取且未填写的子任务,不波及其他任务。 --> |
| | | <update id="updateWechatDefaultComplete" parameterType="com.smartor.domain.ServiceSubtask"> |
| | | update service_subtask |
| | | set sendstate = 6, |
| | | finishtime = #{finishtime}, |
| | | result = #{result}, |
| | | remark = case |
| | | when remark is null or remark = '' then #{remark} |
| | | else concat(remark, ',', #{remark}) |
| | | end, |
| | | update_time = now(), |
| | | finish_state = <include refid="finishStateExpr"/> |
| | | where id = #{id} |
| | | and orgid = #{orgid} |
| | | and sendstate = 1 |
| | | and (submit is null or submit != 1) |
| | | </update> |
| | | |
| | | <update id="updateServiceSubtaskByPatId" parameterType="com.smartor.domain.ServiceSubtask"> |
| | |
| | | <if test="visitDeptName != null">visit_dept_name = #{visitDeptName},</if> |
| | | <if test="managementDoctorCode != null">management_doctor_code = #{managementDoctorCode},</if> |
| | | <if test="managementDoctor != null">management_doctor=#{managementDoctor},</if> |
| | | <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if> |
| | | <if test="currentPreachform != null and currentPreachform != '' ">current_preachform=#{currentPreachform},</if> |
| | | <if test="taskSituation != null">task_situation=#{taskSituation},</if> |
| | | <if test="isabnormal != null">isabnormal=#{isabnormal},</if> |
| | | <if test="continueFlag != null ">continue_flag = #{continueFlag},</if> |
| | |
| | | <if test="visitDeptName != null">visit_dept_name = #{visitDeptName},</if> |
| | | <if test="managementDoctorCode != null">management_doctor_code = #{managementDoctorCode},</if> |
| | | <if test="managementDoctor != null">management_doctor=#{managementDoctor},</if> |
| | | <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if> |
| | | <if test="currentPreachform != null and currentPreachform != '' ">current_preachform=#{currentPreachform},</if> |
| | | <if test="taskSituation != null">task_situation=#{taskSituation},</if> |
| | | <if test="isabnormal != null">isabnormal=#{isabnormal},</if> |
| | | <if test="continueFlag != null ">continue_flag = #{continueFlag},</if> |
| | |
| | | <if test="visitDeptName != null">visit_dept_name = #{visitDeptName},</if> |
| | | <if test="managementDoctorCode != null">management_doctor_code = #{managementDoctorCode},</if> |
| | | <if test="managementDoctor != null">management_doctor=#{managementDoctor},</if> |
| | | <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if> |
| | | <if test="currentPreachform != null and currentPreachform != '' ">current_preachform=#{currentPreachform},</if> |
| | | <if test="taskSituation != null">task_situation=#{taskSituation},</if> |
| | | <if test="isabnormal != null">isabnormal=#{isabnormal},</if> |
| | | <if test="continueFlag != null ">continue_flag = #{continueFlag},</if> |
| | |
| | | nurse_name, |
| | | taskid, |
| | | task_name, |
| | | <if test="groupKey != null and groupKey == 'taskid'"> |
| | | (SELECT st.diag_type FROM service_task st WHERE st.taskid = service_subtask.taskid LIMIT 1) AS diag_type, |
| | | </if> |
| | | visit_time, |
| | | visit_dept_code, |
| | | finishtime, |
| | |
| | | <foreach collection="deptcodes" item="deptcode" open="(" separator="," |
| | | close=")"> |
| | | #{deptcode} |
| | | </foreach> |
| | | </if> |
| | | <if test="taskIds != null and taskIds.size() > 0"> |
| | | AND taskid IN |
| | | <foreach collection="taskIds" item="taskId" open="(" separator="," |
| | | close=")"> |
| | | #{taskId} |
| | | </foreach> |
| | | </if> |
| | | <if test="serviceType != null and serviceType.size() > 0"> |
| | |
| | | #{deptcode} |
| | | </foreach> |
| | | </if> |
| | | <if test="taskIds != null and taskIds.size() > 0"> |
| | | AND taskid IN |
| | | <foreach collection="taskIds" item="taskId" open="(" separator="," |
| | | close=")"> |
| | | #{taskId} |
| | | </foreach> |
| | | </if> |
| | | <if test="serviceType != null and serviceType.size() > 0"> |
| | | AND service_type IN |
| | | <foreach collection="serviceType" item="serviceType" open="(" separator="," |
| | |
| | | </if> |
| | | <if test="groupKey != null and groupKey != ''"> |
| | | group by ${groupKey} |
| | | </if> |
| | | <if test="pageSize != null and pageNum != null"> |
| | | limit ${pageSize} OFFSET ${pageNum} |
| | | </if> |
| | | </select> |
| | | |
| | |
| | | <if test="type != null"> |
| | | and type = #{type} |
| | | </if> |
| | | <if test="visitCount != null and visitCount == 1"> |
| | | <!-- 首个再次随访:精确查 visit_count = 2,与统计口径一致 --> |
| | | <if test="hyperLinkInfoType == 'againFollowUpPushCountInfo'"> |
| | | AND visit_count = 2 |
| | | </if> |
| | | <!-- 其他类型保持原语义:1 首次,>1 再次 --> |
| | | <if test="hyperLinkInfoType != 'againFollowUpPushCountInfo' and visitCount != null and visitCount == 1"> |
| | | AND visit_count = 1 |
| | | </if> |
| | | <if test="visitCount != null and visitCount > 1"> |
| | | <if test="hyperLinkInfoType != 'againFollowUpPushCountInfo' and visitCount != null and visitCount > 1"> |
| | | AND visit_count > 1 |
| | | </if> |
| | | <if test="groupKey != null and groupKey != '' and groupKeyList != null and groupKeyList.size>0"> |
| | |
| | | #{state} |
| | | </foreach> |
| | | </if> |
| | | <if test="currentPreachform != null"> |
| | | <if test="currentPreachform != null and currentPreachform != '' "> |
| | | AND <include refid="effectiveCurrentPreachformExpr"/> = #{currentPreachform} |
| | | <if test="followUpCountStyle != null and followUpCountStyle = '1'"> |
| | | AND sendstate != 4 |
| | |
| | | </if> |
| | | <if test="isManuallyCalled != null"> |
| | | AND is_manually_called = #{isManuallyCalled} |
| | | </if> |
| | | <if test="suggest != null and suggest != ''"> |
| | | AND TRIM(suggest) = #{suggest} |
| | | </if> |
| | | order by endtime desc |
| | | <if test="pageSize != null and pageNum != null"> |
| | |
| | | group by a.script_content, ss.type, IFNULL(ssd.matchedtext,ssd.asrtext) |
| | | </select> |
| | | |
| | | <!-- |
| | | 问题选项数字下钻:返回选择了指定选项的 service_subtask 列表。 |
| | | 过滤口径与 getSfStatisticsScriptDetails / getSfStatisticsScriptItemDetails 保持一致, |
| | | 额外支持 statisticaltype:1-病区、2-科室、3-病种。 |
| | | --> |
| | | <select id="getSfStatisticsScriptDetailsHyperlink" parameterType="com.smartor.domain.ServiceSubtaskCountReq" |
| | | resultMap="ServiceSubtaskResult"> |
| | | SELECT ss.* |
| | | FROM service_subtask ss |
| | | WHERE 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 |
| | | <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator="," |
| | | close=")"> |
| | | #{leavehospitaldistrictcode} |
| | | </foreach> |
| | | </if> |
| | | <if test="deptcodes != null and deptcodes.size() > 0"> |
| | | AND ss.deptcode IN |
| | | <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")"> |
| | | #{deptcode} |
| | | </foreach> |
| | | </if> |
| | | <if test="serviceType != null and serviceType.size() > 0"> |
| | | AND ss.service_type IN |
| | | <foreach collection="serviceType" item="serviceType" open="(" separator="," close=")"> |
| | | #{serviceType} |
| | | </foreach> |
| | | </if> |
| | | <if test="startTime != null and endTime != null"> |
| | | AND ss.visit_time >= DATE(#{startTime}) |
| | | AND ss.visit_time < DATE_ADD(DATE(#{endTime}), INTERVAL 1 DAY) |
| | | </if> |
| | | <if test="type != null and type != ''"> |
| | | AND ss.type = #{type} |
| | | </if> |
| | | |
| | | <!-- 统计维度:1-按病区 2-按科室 3-按taskid --> |
| | | <if test="statisticaltype != null and statisticaltype == 1"> |
| | | <choose> |
| | | <when test="deptcode != null and deptcode != ''"> |
| | | AND ss.leavehospitaldistrictcode = #{deptcode} |
| | | </when> |
| | | <when test="leavehospitaldistrictcode != null and leavehospitaldistrictcode != ''"> |
| | | AND ss.leavehospitaldistrictcode = #{leavehospitaldistrictcode} |
| | | </when> |
| | | </choose> |
| | | </if> |
| | | <if test="statisticaltype != null and statisticaltype == 2 and deptcode != null and deptcode != ''"> |
| | | AND ss.deptcode = #{deptcode} |
| | | </if> |
| | | <if test="statisticaltype != null and statisticaltype == 3 and taskId != null"> |
| | | AND ss.taskid = #{taskId} |
| | | </if> |
| | | <!-- 兼容不传 statisticaltype 时按单值条件过滤 --> |
| | | <if test="statisticaltype == null"> |
| | | <if test="leavehospitaldistrictcode != null and leavehospitaldistrictcode != ''"> |
| | | AND ss.leavehospitaldistrictcode = #{leavehospitaldistrictcode} |
| | | </if> |
| | | <if test="deptcode != null and deptcode != ''"> |
| | | AND ss.deptcode = #{deptcode} |
| | | </if> |
| | | <if test="taskId != null"> |
| | | AND ss.taskid = #{taskId} |
| | | </if> |
| | | </if> |
| | | |
| | | <!-- 题目 + 选项匹配:只保留回答中选择了该选项的子任务 --> |
| | | AND EXISTS ( |
| | | SELECT 1 |
| | | FROM service_subtask_detail ssd |
| | | WHERE ssd.sub_id = ss.id |
| | | AND ssd.del_flag = 0 |
| | | <if test="configValue != null and configValue != ''"> |
| | | AND ssd.categoryid IN (${configValue}) |
| | | </if> |
| | | <choose> |
| | | <when test="optionText != null"> |
| | | AND IFNULL(ssd.matchedtext, ssd.asrtext) = #{optionText} |
| | | </when> |
| | | <otherwise> |
| | | AND 1 = 0 |
| | | </otherwise> |
| | | </choose> |
| | | <choose> |
| | | <!-- 优先按题目内容匹配:同一道题复制到多个任务模板时 scriptid 不同,但 script_content 相同 --> |
| | | <when test="scriptContent != null and scriptContent != ''"> |
| | | AND ssd.scriptid IN ( |
| | | <choose> |
| | | <when test="type == '1'"> |
| | | SELECT its.id FROM ivr_task_template_script its |
| | | WHERE its.script_content = #{scriptContent} |
| | | </when> |
| | | <when test="type == '2'"> |
| | | SELECT sts.id FROM svy_task_template_script sts |
| | | WHERE sts.script_content = #{scriptContent} |
| | | </when> |
| | | <otherwise> |
| | | SELECT its.id FROM ivr_task_template_script its |
| | | WHERE its.script_content = #{scriptContent} |
| | | UNION |
| | | SELECT sts.id FROM svy_task_template_script sts |
| | | WHERE sts.script_content = #{scriptContent} |
| | | </otherwise> |
| | | </choose> |
| | | ) |
| | | </when> |
| | | <when test="scriptid != null"> |
| | | AND ssd.scriptid = #{scriptid} |
| | | </when> |
| | | <otherwise> |
| | | AND 1 = 0 |
| | | </otherwise> |
| | | </choose> |
| | | ) |
| | | ORDER BY ss.endtime DESC, ss.id DESC |
| | | <if test="pageSize != null and pageSize > 0"> |
| | | LIMIT #{pageSize} |
| | | <if test="pageNum != null and pageNum >= 0"> |
| | | OFFSET #{pageNum} |
| | | </if> |
| | | </if> |
| | | </select> |
| | | |
| | | <select id="getDataByTime" resultMap="ServiceSubtaskResult"> |
| | | |
| | | select id, |