OperationAnalysisMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="cn.iocoder.yudao.module.system.dal.mysql.biz.OperationAnalysisMapper">
  4. <!-- 退住「已完成」判定:
  5. 1)系统审批(elderly_retreat_record.status = 1),不产生 BPM 流程;
  6. 2)BPM 审批通过(bpm_business_form.type = 2 申请退住 且 complete_status = 1)。 -->
  7. <sql id="retreatFinishedCondition">
  8. (t.status = 1
  9. OR EXISTS (
  10. SELECT 1
  11. FROM bpm_business_form bf
  12. WHERE bf.business_id = t.id
  13. AND bf.type = 2
  14. AND bf.complete_status = 1
  15. AND bf.deleted = 0
  16. ))
  17. </sql>
  18. <!-- 今日新收:长者档案的入住时间在当天 -->
  19. <select id="selectTodayNewCheckInCount"
  20. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
  21. SELECT t.tenant_id AS tenantId,
  22. COUNT(*) AS count
  23. FROM elderly_info t
  24. WHERE t.deleted = 0
  25. AND t.check_in_time &gt;= #{begin}
  26. AND t.check_in_time &lt;= #{end}
  27. AND t.tenant_id IN
  28. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  29. #{tenantId}
  30. </foreach>
  31. GROUP BY t.tenant_id
  32. </select>
  33. <!-- 今日退院:退住登记表的退住时间为当天,且已完成 -->
  34. <select id="selectTodayCheckOutCount"
  35. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
  36. SELECT t.tenant_id AS tenantId,
  37. COUNT(*) AS count
  38. FROM elderly_retreat_record t
  39. WHERE t.deleted = 0
  40. AND t.apply_type = 1
  41. AND t.current_flag = 0
  42. AND t.retreat_date = #{today}
  43. AND
  44. <include refid="retreatFinishedCondition"/>
  45. AND t.tenant_id IN
  46. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  47. #{tenantId}
  48. </foreach>
  49. GROUP BY t.tenant_id
  50. </select>
  51. <!-- 近 N 个月已完成退住趋势:按月 + 机构分组 -->
  52. <select id="selectRetreatTrend"
  53. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantMonthCountBO">
  54. SELECT t.tenant_id AS tenantId,
  55. DATE_FORMAT(t.retreat_date, '%Y-%m') AS month,
  56. COUNT(*) AS count
  57. FROM elderly_retreat_record t
  58. WHERE t.deleted = 0
  59. AND t.apply_type = 1
  60. AND t.current_flag = 0
  61. AND t.retreat_date &gt;= #{begin}
  62. AND t.retreat_date &lt; #{end}
  63. AND
  64. <include refid="retreatFinishedCondition"/>
  65. AND t.tenant_id IN
  66. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  67. #{tenantId}
  68. </foreach>
  69. GROUP BY t.tenant_id, DATE_FORMAT(t.retreat_date, '%Y-%m')
  70. </select>
  71. <!-- 请假人数:截至当前仍在请假中(已离院且未返院),按长者去重 -->
  72. <select id="selectOnLeaveCount"
  73. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
  74. SELECT t.tenant_id AS tenantId,
  75. COUNT(DISTINCT t.elder_id) AS count
  76. FROM elderly_ask_leave t
  77. WHERE (t.leave_status = 1 OR t.leave_status IS NULL)
  78. AND (t.status = 0 OR t.status IS NULL)
  79. AND t.out_date &lt;= #{end}
  80. AND (t.update_date &gt; #{now} OR t.update_date IS NULL)
  81. AND t.tenant_id IN
  82. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  83. #{tenantId}
  84. </foreach>
  85. GROUP BY t.tenant_id
  86. </select>
  87. <!-- 当天请假人数:当天离院的人数,按长者去重 -->
  88. <select id="selectTodayLeaveCount"
  89. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
  90. SELECT t.tenant_id AS tenantId,
  91. COUNT(DISTINCT t.elder_id) AS count
  92. FROM elderly_ask_leave t
  93. WHERE (t.leave_status = 1 OR t.leave_status IS NULL)
  94. AND (t.status = 0 OR t.status IS NULL)
  95. AND t.out_date &gt;= #{begin}
  96. AND t.out_date &lt;= #{end}
  97. AND t.tenant_id IN
  98. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  99. #{tenantId}
  100. </foreach>
  101. GROUP BY t.tenant_id
  102. </select>
  103. <!-- 轮候待住:轮候入住审批完成(status = 10),等待入住。该表无 deleted 字段 -->
  104. <select id="selectWaitingCount"
  105. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
  106. SELECT t.tenant_id AS tenantId,
  107. COUNT(*) AS count
  108. FROM elderly_check_in_wait t
  109. WHERE t.status = 10
  110. AND t.tenant_id IN
  111. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  112. #{tenantId}
  113. </foreach>
  114. GROUP BY t.tenant_id
  115. </select>
  116. <!-- 预订在途:已缴费(status = 2)的床位预约 -->
  117. <select id="selectReservationCount"
  118. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
  119. SELECT t.tenant_id AS tenantId,
  120. COUNT(*) AS count
  121. FROM elderly_reservation_bed t
  122. WHERE t.deleted = 0
  123. AND t.status = 2
  124. AND t.tenant_id IN
  125. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  126. #{tenantId}
  127. </foreach>
  128. GROUP BY t.tenant_id
  129. </select>
  130. <!-- 护理等级分布:在住长者(in_status = 1)按护理等级分组 -->
  131. <select id="selectNurseLevelDistribution"
  132. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationNurseLevelCountBO">
  133. SELECT e.tenant_id AS tenantId,
  134. e.nurse_level_id AS nurseLevelId,
  135. nl.nurse_level_name AS nurseLevelName,
  136. COUNT(*) AS count
  137. FROM elderly_info e
  138. LEFT JOIN nurse_level nl ON nl.id = e.nurse_level_id
  139. WHERE e.deleted = 0
  140. AND e.org_type = 1
  141. AND e.in_status = 1
  142. AND e.tenant_id IN
  143. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  144. #{tenantId}
  145. </foreach>
  146. GROUP BY e.tenant_id, e.nurse_level_id, nl.nurse_level_name
  147. ORDER BY e.tenant_id, nl.sort IS NULL, nl.sort, nl.id
  148. </select>
  149. <!-- 区间入住数:长者档案的入住时间在区间内 -->
  150. <select id="selectRangeCheckInCount"
  151. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
  152. SELECT t.tenant_id AS tenantId,
  153. COUNT(*) AS count
  154. FROM elderly_info t
  155. WHERE t.deleted = 0
  156. AND t.org_type = 1
  157. AND t.check_in_time &gt;= #{begin}
  158. AND t.check_in_time &lt;= #{end}
  159. AND t.tenant_id IN
  160. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  161. #{tenantId}
  162. </foreach>
  163. GROUP BY t.tenant_id
  164. </select>
  165. <!-- 区间退住数:退住登记表的退住时间在区间内,且已完成 -->
  166. <select id="selectRangeCheckOutCount"
  167. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
  168. SELECT t.tenant_id AS tenantId,
  169. COUNT(*) AS count
  170. FROM elderly_retreat_record t
  171. WHERE t.deleted = 0
  172. AND t.apply_type = 1
  173. AND t.current_flag = 0
  174. AND t.org_type = 1
  175. AND t.retreat_date &gt;= #{begin}
  176. AND t.retreat_date &lt;= #{end}
  177. AND
  178. <include refid="retreatFinishedCondition"/>
  179. AND t.tenant_id IN
  180. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  181. #{tenantId}
  182. </foreach>
  183. GROUP BY t.tenant_id
  184. </select>
  185. <!-- 在住人数:长者档案的在住状态为在住 -->
  186. <select id="selectInStatusCount"
  187. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantCountBO">
  188. SELECT t.tenant_id AS tenantId,
  189. COUNT(*) AS count
  190. FROM elderly_info t
  191. WHERE t.deleted = 0
  192. AND t.org_type = 1
  193. AND t.in_status = 1
  194. AND t.tenant_id IN
  195. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  196. #{tenantId}
  197. </foreach>
  198. GROUP BY t.tenant_id
  199. </select>
  200. <!-- 床位结构:按机构统计总床位、在住床位(status = 1)、空闲床位(status = 0)、临时占用(status = 2)。
  201. 该表无 deleted 字段,故不做删除过滤。 -->
  202. <select id="selectBedStructure"
  203. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantBedCountBO">
  204. SELECT t.tenant_id AS tenantId,
  205. COUNT(*) AS totalBedCount,
  206. COUNT(CASE WHEN t.status = 1 THEN 1 END) AS occupiedBedCount,
  207. COUNT(CASE WHEN t.status = 0 THEN 1 END) AS emptyBedCount,
  208. COUNT(CASE WHEN t.status = 2 THEN 1 END) AS temporaryOccupationCount
  209. FROM org_build_bed t
  210. WHERE t.org_type = 1
  211. AND t.tenant_id IN
  212. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  213. #{tenantId}
  214. </foreach>
  215. GROUP BY t.tenant_id
  216. </select>
  217. <!-- 区间入住数(按天分组):以长者档案的入住时间为准,end 传「结束日次日」以便覆盖整天 -->
  218. <select id="selectCheckInDailyTrend"
  219. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantMonthCountBO">
  220. SELECT t.tenant_id AS tenantId,
  221. DATE_FORMAT(t.check_in_time, '%Y-%m-%d') AS month,
  222. COUNT(*) AS count
  223. FROM elderly_info t
  224. WHERE t.deleted = 0
  225. AND t.org_type = #{orgType}
  226. AND t.check_in_time &gt;= #{begin}
  227. AND t.check_in_time &lt; #{end}
  228. AND t.tenant_id IN
  229. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  230. #{tenantId}
  231. </foreach>
  232. GROUP BY t.tenant_id, DATE_FORMAT(t.check_in_time, '%Y-%m-%d')
  233. </select>
  234. <!-- 区间退住数(按天分组):以退住登记表的退住时间为准,且必须是「已完成」的退住 -->
  235. <select id="selectCheckOutDailyTrend"
  236. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.OperationTenantMonthCountBO">
  237. SELECT t.tenant_id AS tenantId,
  238. DATE_FORMAT(t.retreat_date, '%Y-%m-%d') AS month,
  239. COUNT(*) AS count
  240. FROM elderly_retreat_record t
  241. WHERE t.deleted = 0
  242. AND t.apply_type = 1
  243. AND t.current_flag = 0
  244. AND t.org_type = #{orgType}
  245. AND t.retreat_date &gt;= #{begin}
  246. AND t.retreat_date &lt; #{end}
  247. AND
  248. <include refid="retreatFinishedCondition"/>
  249. AND t.tenant_id IN
  250. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  251. #{tenantId}
  252. </foreach>
  253. GROUP BY t.tenant_id, DATE_FORMAT(t.retreat_date, '%Y-%m-%d')
  254. </select>
  255. <!-- 区间起始日之前的累计入住数 -->
  256. <select id="selectCheckInCountBefore" resultType="java.lang.Long">
  257. SELECT COUNT(*)
  258. FROM elderly_info t
  259. WHERE t.deleted = 0
  260. AND t.org_type = #{orgType}
  261. AND t.check_in_time &lt; #{begin}
  262. AND t.tenant_id IN
  263. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  264. #{tenantId}
  265. </foreach>
  266. </select>
  267. <!-- 区间起始日之前的累计退住数(仅「已完成」的退住) -->
  268. <select id="selectCheckOutCountBefore" resultType="java.lang.Long">
  269. SELECT COUNT(*)
  270. FROM elderly_retreat_record t
  271. WHERE t.deleted = 0
  272. AND t.apply_type = 1
  273. AND t.current_flag = 0
  274. AND t.org_type = #{orgType}
  275. AND t.retreat_date &lt; #{begin}
  276. AND
  277. <include refid="retreatFinishedCondition"/>
  278. AND t.tenant_id IN
  279. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  280. #{tenantId}
  281. </foreach>
  282. </select>
  283. <!-- 长者结构聚合明细行:仅统计在住长者(in_status = 1) -->
  284. <select id="selectElderStructureRows"
  285. resultType="cn.iocoder.yudao.module.system.dal.mysql.biz.bo.ElderStructureRowBO">
  286. SELECT e.tenant_id AS tenantId,
  287. e.elder_sex AS elderSex,
  288. e.elder_age AS elderAge,
  289. e.birthday AS birthday,
  290. e.check_in_time AS checkInTime,
  291. e.nurse_level_id AS nurseLevelId,
  292. e.nurse_level_name AS nurseLevelName,
  293. e.degree_education AS degreeEducation,
  294. e.payment_method AS paymentMethod
  295. FROM elderly_info e
  296. WHERE e.deleted = 0
  297. AND e.org_type = #{orgType}
  298. AND e.in_status = 1
  299. AND e.tenant_id IN
  300. <foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">
  301. #{tenantId}
  302. </foreach>
  303. </select>
  304. </mapper>