| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="cn.iocoder.yudao.module.system.dal.mysql.biz.OperationAnalysisMapper">
- <!-- 退住「已完成」判定:
- 1)系统审批(elderly_retreat_record.status = 1),不产生 BPM 流程;
- 2)BPM 审批通过(bpm_business_form.type = 2 申请退住 且 complete_status = 1)。 -->
- <sql id="retreatFinishedCondition">
- (t.status = 1
- OR EXISTS (
- SELECT 1
- FROM bpm_business_form bf
- WHERE bf.business_id = t.id
- AND bf.type = 2
- AND bf.complete_status = 1
- AND bf.deleted = 0
- ))
- </sql>
- <!-- 今日新收:长者档案的入住时间在当天 -->
- <select id="selectTodayNewCheckInCount"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
- SELECT t.tenant_id AS tenantId,
- COUNT(*) AS count
- FROM elderly_info t
- WHERE t.deleted = 0
- AND t.check_in_time >= #{begin}
- AND t.check_in_time <= #{end}
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id
- </select>
- <!-- 今日退院:退住登记表的退住时间为当天,且已完成 -->
- <select id="selectTodayCheckOutCount"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
- SELECT t.tenant_id AS tenantId,
- COUNT(*) AS count
- FROM elderly_retreat_record t
- WHERE t.deleted = 0
- AND t.apply_type = 1
- AND t.current_flag = 0
- AND t.retreat_date = #{today}
- AND
- <include refid="retreatFinishedCondition"/>
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id
- </select>
- <!-- 近 N 个月已完成退住趋势:按月 + 机构分组 -->
- <select id="selectRetreatTrend"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantMonthCountBO">
- SELECT t.tenant_id AS tenantId,
- DATE_FORMAT(t.retreat_date, '%Y-%m') AS month,
- COUNT(*) AS count
- FROM elderly_retreat_record t
- WHERE t.deleted = 0
- AND t.apply_type = 1
- AND t.current_flag = 0
- AND t.retreat_date >= #{begin}
- AND t.retreat_date < #{end}
- AND
- <include refid="retreatFinishedCondition"/>
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id, DATE_FORMAT(t.retreat_date, '%Y-%m')
- </select>
- <!-- 请假人数:截至当前仍在请假中(已离院且未返院),按长者去重 -->
- <select id="selectOnLeaveCount"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
- SELECT t.tenant_id AS tenantId,
- COUNT(DISTINCT t.elder_id) AS count
- FROM elderly_ask_leave t
- WHERE (t.leave_status = 1 OR t.leave_status IS NULL)
- AND (t.status = 0 OR t.status IS NULL)
- AND t.out_date <= #{end}
- AND (t.update_date > #{now} OR t.update_date IS NULL)
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id
- </select>
- <!-- 当天请假人数:当天离院的人数,按长者去重 -->
- <select id="selectTodayLeaveCount"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
- SELECT t.tenant_id AS tenantId,
- COUNT(DISTINCT t.elder_id) AS count
- FROM elderly_ask_leave t
- WHERE (t.leave_status = 1 OR t.leave_status IS NULL)
- AND (t.status = 0 OR t.status IS NULL)
- AND t.out_date >= #{begin}
- AND t.out_date <= #{end}
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id
- </select>
- <!-- 轮候待住:轮候入住审批完成(status = 10),等待入住。该表无 deleted 字段 -->
- <select id="selectWaitingCount"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
- SELECT t.tenant_id AS tenantId,
- COUNT(*) AS count
- FROM elderly_check_in_wait t
- WHERE t.status = 10
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id
- </select>
- <!-- 预订在途:已缴费(status = 2)的床位预约 -->
- <select id="selectReservationCount"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
- SELECT t.tenant_id AS tenantId,
- COUNT(*) AS count
- FROM elderly_reservation_bed t
- WHERE t.deleted = 0
- AND t.status = 2
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id
- </select>
- <!-- 护理等级分布:在住长者(in_status = 1)按护理等级分组 -->
- <select id="selectNurseLevelDistribution"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationNurseLevelCountBO">
- SELECT e.tenant_id AS tenantId,
- e.nurse_level_id AS nurseLevelId,
- nl.nurse_level_name AS nurseLevelName,
- COUNT(*) AS count
- FROM elderly_info e
- LEFT JOIN nurse_level nl ON nl.id = e.nurse_level_id
- WHERE e.deleted = 0
- AND e.org_type = 1
- AND e.in_status = 1
- AND e.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY e.tenant_id, e.nurse_level_id, nl.nurse_level_name
- ORDER BY e.tenant_id, nl.sort IS NULL, nl.sort, nl.id
- </select>
- <!-- 区间入住数:长者档案的入住时间在区间内 -->
- <select id="selectRangeCheckInCount"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
- SELECT t.tenant_id AS tenantId,
- COUNT(*) AS count
- FROM elderly_info t
- WHERE t.deleted = 0
- AND t.org_type = 1
- AND t.check_in_time >= #{begin}
- AND t.check_in_time <= #{end}
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id
- </select>
- <!-- 区间退住数:退住登记表的退住时间在区间内,且已完成 -->
- <select id="selectRangeCheckOutCount"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
- SELECT t.tenant_id AS tenantId,
- COUNT(*) AS count
- FROM elderly_retreat_record t
- WHERE t.deleted = 0
- AND t.apply_type = 1
- AND t.current_flag = 0
- AND t.org_type = 1
- AND t.retreat_date >= #{begin}
- AND t.retreat_date <= #{end}
- AND
- <include refid="retreatFinishedCondition"/>
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id
- </select>
- <!-- 在住人数:长者档案的在住状态为在住 -->
- <select id="selectInStatusCount"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
- SELECT t.tenant_id AS tenantId,
- COUNT(*) AS count
- FROM elderly_info t
- WHERE t.deleted = 0
- AND t.org_type = 1
- AND t.in_status = 1
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id
- </select>
- <!-- 床位结构:按机构统计总床位、在住床位(status = 1)、空闲床位(status = 0)、临时占用(status = 2)。
- 该表无 deleted 字段,故不做删除过滤。 -->
- <select id="selectBedStructure"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantBedCountBO">
- SELECT t.tenant_id AS tenantId,
- COUNT(*) AS totalBedCount,
- COUNT(CASE WHEN t.status = 1 THEN 1 END) AS occupiedBedCount,
- COUNT(CASE WHEN t.status = 0 THEN 1 END) AS emptyBedCount,
- COUNT(CASE WHEN t.status = 2 THEN 1 END) AS temporaryOccupationCount
- FROM org_build_bed t
- WHERE t.org_type = 1
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id
- </select>
- <!-- 区间入住数(按天分组):以长者档案的入住时间为准,end 传「结束日次日」以便覆盖整天 -->
- <select id="selectCheckInDailyTrend"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantMonthCountBO">
- SELECT t.tenant_id AS tenantId,
- DATE_FORMAT(t.check_in_time, '%Y-%m-%d') AS month,
- COUNT(*) AS count
- FROM elderly_info t
- WHERE t.deleted = 0
- AND t.org_type = #{orgType}
- AND t.check_in_time >= #{begin}
- AND t.check_in_time < #{end}
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id, DATE_FORMAT(t.check_in_time, '%Y-%m-%d')
- </select>
- <!-- 区间退住数(按天分组):以退住登记表的退住时间为准,且必须是「已完成」的退住 -->
- <select id="selectCheckOutDailyTrend"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantMonthCountBO">
- SELECT t.tenant_id AS tenantId,
- DATE_FORMAT(t.retreat_date, '%Y-%m-%d') AS month,
- COUNT(*) AS count
- FROM elderly_retreat_record t
- WHERE t.deleted = 0
- AND t.apply_type = 1
- AND t.current_flag = 0
- AND t.org_type = #{orgType}
- AND t.retreat_date >= #{begin}
- AND t.retreat_date < #{end}
- AND
- <include refid="retreatFinishedCondition"/>
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- GROUP BY t.tenant_id, DATE_FORMAT(t.retreat_date, '%Y-%m-%d')
- </select>
- <!-- 区间起始日之前的累计入住数 -->
- <select id="selectCheckInCountBefore" resultType="java.lang.Long">
- SELECT COUNT(*)
- FROM elderly_info t
- WHERE t.deleted = 0
- AND t.org_type = #{orgType}
- AND t.check_in_time < #{begin}
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- </select>
- <!-- 区间起始日之前的累计退住数(仅「已完成」的退住) -->
- <select id="selectCheckOutCountBefore" resultType="java.lang.Long">
- SELECT COUNT(*)
- FROM elderly_retreat_record t
- WHERE t.deleted = 0
- AND t.apply_type = 1
- AND t.current_flag = 0
- AND t.org_type = #{orgType}
- AND t.retreat_date < #{begin}
- AND
- <include refid="retreatFinishedCondition"/>
- AND t.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- </select>
- <!-- 长者结构聚合明细行:仅统计在住长者(in_status = 1) -->
- <select id="selectElderStructureRows"
- resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.ElderStructureRowBO">
- SELECT e.tenant_id AS tenantId,
- e.elder_sex AS elderSex,
- e.elder_age AS elderAge,
- e.birthday AS birthday,
- e.check_in_time AS checkInTime,
- e.nurse_level_id AS nurseLevelId,
- e.nurse_level_name AS nurseLevelName,
- e.degree_education AS degreeEducation,
- e.payment_method AS paymentMethod
- FROM elderly_info e
- WHERE e.deleted = 0
- AND e.org_type = #{orgType}
- AND e.in_status = 1
- AND e.tenant_id IN
- <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
- #{tenantId}
- </foreach>
- </select>
- </mapper>
|