RoomBedMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.xjrsoft.module.room.mapper.RoomBedMapper">
  6. <select id="getPage" parameterType="com.xjrsoft.module.room.dto.RoomBedPageDto" resultType="com.xjrsoft.module.room.vo.RoomBedPageVo">
  7. SELECT t1.id,t1.sort_code,t3.name AS build_name,t2.floor_number,t2.room_name,t1.bed_number,t4.name AS student_name,t5.student_id,
  8. t4.mobile,t9.name as gender_cn,t7.name AS grade_name,t8.name AS class_name FROM room_bed t1
  9. LEFT JOIN room t2 ON t1.room_id = t2.id
  10. LEFT JOIN base_office_build t3 ON t2.office_build_id = t3.id
  11. LEFT JOIN xjr_user t4 ON t1.student_user_id = t4.id
  12. LEFT JOIN base_student t5 ON t1.student_user_id = t5.user_id
  13. LEFT JOIN base_student_school_roll t6 ON t1.student_user_id = t6.user_id
  14. LEFT JOIN base_grade t7 ON t6.grade_id = t7.id
  15. LEFT JOIN base_class t8 ON t6.class_id = t8.id
  16. LEFT JOIN xjr_dictionary_detail t9 ON t2.gender = t9.code AND t9.item_id = 2023000000000000004
  17. where t1.delete_mark = 0 and t2.delete_mark = 0
  18. <if test="dto.officeBuildId != null">
  19. and t2.office_build_id = #{dto.officeBuildId}
  20. </if>
  21. <if test="dto.floorNumber != null">
  22. and t2.floor_number = #{dto.floorNumber}
  23. </if>
  24. <if test="dto.roomId != null">
  25. and t2.room_id = #{dto.roomId}
  26. </if>
  27. <if test="dto.gender != null and dto.gender != ''">
  28. and t2.gender = #{dto.gender}
  29. </if>
  30. <if test="dto.gradeId != null">
  31. and t7.id = #{dto.gradeId}
  32. </if>
  33. <if test="dto.classId != null">
  34. and t8.id = #{dto.classId}
  35. </if>
  36. <if test="dto.studentName != null">
  37. and t4.name like concat('%',#{dto.studentName},'%')
  38. </if>
  39. <if test="dto.studentId != null">
  40. and t5.student_id like concat('%',#{dto.studentId},'%')
  41. </if>
  42. <if test="dto.identity != null and dto.identity != ''">
  43. and t2.check_in_status like concat('%',#{dto.identity},'%')
  44. </if>
  45. ORDER BY t1.sort_code
  46. </select>
  47. <select id="getList" parameterType="com.xjrsoft.module.room.dto.RoomBedPageDto" resultType="com.xjrsoft.module.room.vo.RoomBedExcelVo">
  48. SELECT t1.sort_code,t3.name AS build_name,t2.floor_number,t2.room_name,t1.bed_number,t4.name AS student_name,t5.student_id,
  49. t4.mobile,t9.name as gender_cn,t7.name AS grade_name,t8.name AS class_name FROM room_bed t1
  50. LEFT JOIN room t2 ON t1.room_id = t2.id
  51. LEFT JOIN base_office_build t3 ON t2.office_build_id = t3.id
  52. LEFT JOIN xjr_user t4 ON t1.student_user_id = t4.id
  53. LEFT JOIN base_student t5 ON t1.student_user_id = t5.user_id
  54. LEFT JOIN base_student_school_roll t6 ON t1.student_user_id = t6.user_id
  55. LEFT JOIN base_grade t7 ON t6.grade_id = t7.id
  56. LEFT JOIN base_class t8 ON t6.class_id = t8.id
  57. LEFT JOIN xjr_dictionary_detail t9 ON t2.gender = t9.code AND t9.item_id = 2023000000000000004
  58. where t1.delete_mark = 0 and t2.delete_mark = 0
  59. <if test="dto.officeBuildId != null">
  60. and t2.office_build_id = #{dto.officeBuildId}
  61. </if>
  62. <if test="dto.floorNumber != null">
  63. and t2.floor_number = #{dto.floorNumber}
  64. </if>
  65. <if test="dto.roomId != null">
  66. and t2.room_id = #{dto.roomId}
  67. </if>
  68. <if test="dto.gender != null and dto.gender != ''">
  69. and t2.gender = #{dto.gender}
  70. </if>
  71. <if test="dto.gradeId != null">
  72. and t7.id = #{dto.gradeId}
  73. </if>
  74. <if test="dto.classId != null">
  75. and t8.id = #{dto.classId}
  76. </if>
  77. <if test="dto.studentName != null">
  78. and t4.name like concat('%',#{dto.studentName},'%')
  79. </if>
  80. <if test="dto.studentId != null">
  81. and t5.student_id like concat('%',#{dto.studentId},'%')
  82. </if>
  83. <if test="dto.identity != null and dto.identity != ''">
  84. and t2.check_in_status like concat('%',#{dto.identity},'%')
  85. </if>
  86. ORDER BY t1.sort_code
  87. </select>
  88. <select id="getMaxSortCode" resultType="java.lang.Integer">
  89. SELECT IFNULL(MAX(sort_code),0) FROM room_bed WHERE delete_mark = 0
  90. </select>
  91. <select id="getDistributeClassInfo" parameterType="com.xjrsoft.module.room.dto.DistributeClassPageDto" resultType="com.xjrsoft.module.room.vo.DistributeClassPageVo">
  92. SELECT t1.id,t2.name AS grade_name,t3.name AS org_name,t1.name AS class_name,
  93. (SELECT COUNT(*) FROM base_student c1
  94. LEFT JOIN base_student_school_roll c2 ON c1.user_id = c2.user_id
  95. LEFT JOIN xjr_dictionary_detail c3 ON c2.stduy_status = c3.code AND c3.item_id = 2023000000000000030
  96. left join xjr_user c4 on c1.user_id = c4.id
  97. WHERE c1.delete_mark = 0 AND c2.delete_mark = 0
  98. AND c3.code = 'FB3002' AND c2.class_id = t1.id
  99. <if test="dto.gender != null">
  100. <if test="dto.gender == 'SB10001'">
  101. and c4.gender = 1
  102. </if>
  103. <if test="dto.gender == 'SB10002'">
  104. and c4.gender = 2
  105. </if>
  106. </if>
  107. ) AS need_count,
  108. (
  109. SELECT COUNT(*) FROM room_bed a1
  110. LEFT JOIN base_student_school_roll a2 ON a1.student_user_id = a2.user_id
  111. left join xjr_user c4 on a2.user_id = c4.id
  112. WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
  113. AND a2.class_id = t1.id
  114. <if test="dto.gender != null">
  115. <if test="dto.gender == 'SB10001'">
  116. and c4.gender = 1
  117. </if>
  118. <if test="dto.gender == 'SB10002'">
  119. and c4.gender = 2
  120. </if>
  121. </if>
  122. ) AS distribute_count FROM base_class t1
  123. LEFT JOIN base_grade t2 ON t1.grade_id = t2.id
  124. LEFT JOIN xjr_department t3 ON t1.org_id = t3.id
  125. WHERE t1.delete_mark = 0
  126. and (
  127. SELECT COUNT(*) FROM base_student c1
  128. LEFT JOIN base_student_school_roll c2 ON c1.user_id = c2.user_id
  129. LEFT JOIN xjr_dictionary_detail c3 ON c2.stduy_status = c3.code AND c3.item_id = 2023000000000000030
  130. left join xjr_user c4 on c4.id = c1.user_id
  131. WHERE c1.delete_mark = 0 AND c2.delete_mark = 0
  132. AND c3.code = 'FB3002' AND c2.class_id = t1.id
  133. <if test="dto.gender != null">
  134. <if test="dto.gender == 'SB10001'">
  135. and c4.gender = 1
  136. </if>
  137. <if test="dto.gender == 'SB10002'">
  138. and c4.gender = 2
  139. </if>
  140. </if>
  141. ) >
  142. (
  143. SELECT COUNT(*) FROM room_bed a1
  144. LEFT JOIN base_student_school_roll a2 ON a1.student_user_id = a2.user_id
  145. left join room a3 on a3.id = a1.room_id
  146. WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
  147. AND a2.class_id = t1.id
  148. <if test="dto.gender != null">
  149. and a3.gender = #{dto.gender}
  150. </if>
  151. )
  152. <if test="dto.gradeId != null">
  153. and t1.grade_id = #{dto.gradeId}
  154. </if>
  155. <if test="dto.classId != null">
  156. and t1.id = #{dto.classId}
  157. </if>
  158. </select>
  159. <!--查询分配床位班级列表的各个人数 - 开始 -->
  160. <!-- 查询班上需要住宿的人数 -->
  161. <select id="getAllStayCount" resultType="com.xjrsoft.module.room.vo.ClassStudentCountVo">
  162. SELECT t1.id as class_id,COUNT(*) as student_count FROM base_class t1
  163. LEFT JOIN base_student_school_roll t2 ON t1.id = t2.class_id
  164. LEFT JOIN xjr_user t3 ON t2.user_id = t3.id
  165. WHERE t1.delete_mark = 0
  166. AND t2.delete_mark = 0 AND t3.delete_mark = 0
  167. AND t2.stduy_status = 'FB3002' GROUP BY t1.id
  168. </select>
  169. <!-- 需要安排的男生总人数 -->
  170. <select id="getAllStayMaleCount" resultType="com.xjrsoft.module.room.vo.ClassStudentCountVo">
  171. SELECT t1.id as class_id,COUNT(*) as student_count FROM base_class t1
  172. LEFT JOIN base_student_school_roll t2 ON t1.id = t2.class_id
  173. LEFT JOIN xjr_user t3 ON t2.user_id = t3.id
  174. WHERE t1.delete_mark = 0
  175. AND t2.delete_mark = 0 AND t3.delete_mark = 0
  176. AND t3.gender = 1
  177. AND t2.stduy_status = 'FB3002' GROUP BY t1.id
  178. </select>
  179. <!-- 需要安排的女生总人数 -->
  180. <select id="getAllStayFemaleCount" resultType="com.xjrsoft.module.room.vo.ClassStudentCountVo">
  181. SELECT t1.id as class_id,COUNT(*) as student_count FROM base_class t1
  182. LEFT JOIN base_student_school_roll t2 ON t1.id = t2.class_id
  183. LEFT JOIN xjr_user t3 ON t2.user_id = t3.id
  184. WHERE t1.delete_mark = 0
  185. AND t2.delete_mark = 0 AND t3.delete_mark = 0
  186. AND t3.gender = 2
  187. AND t2.stduy_status = 'FB3002' GROUP BY t1.id
  188. </select>
  189. <!-- 已分配的总人数 -->
  190. <select id="getAllArrangedCount" resultType="com.xjrsoft.module.room.vo.ClassStudentCountVo">
  191. SELECT a1.id as class_id,COUNT(*) as student_count FROM base_class a1
  192. LEFT JOIN base_student_school_roll a2 ON a1.id = a2.class_id
  193. LEFT JOIN room_bed a3 ON a2.user_id = a3.student_user_id
  194. LEFT JOIN xjr_user a4 ON a3.student_user_id = a4.id
  195. WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
  196. AND a4.delete_mark = 0
  197. GROUP BY a1.id
  198. </select>
  199. <!-- 已分配的男生人数 -->
  200. <select id="getAllArrangedMaleCount" resultType="com.xjrsoft.module.room.vo.ClassStudentCountVo">
  201. SELECT a1.id as class_id,COUNT(*) as student_count FROM base_class a1
  202. LEFT JOIN base_student_school_roll a2 ON a1.id = a2.class_id
  203. LEFT JOIN room_bed a3 ON a2.user_id = a3.student_user_id
  204. LEFT JOIN xjr_user a4 ON a3.student_user_id = a4.id AND a4.gender = 1
  205. WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
  206. AND a4.delete_mark = 0
  207. GROUP BY a1.id
  208. </select>
  209. <!-- 已分配的女生人数 -->
  210. <select id="getAllArrangedFemaleCount" resultType="com.xjrsoft.module.room.vo.ClassStudentCountVo">
  211. SELECT a1.id as class_id,COUNT(*) as student_count FROM base_class a1
  212. LEFT JOIN base_student_school_roll a2 ON a1.id = a2.class_id
  213. LEFT JOIN room_bed a3 ON a2.user_id = a3.student_user_id
  214. LEFT JOIN xjr_user a4 ON a3.student_user_id = a4.id AND a4.gender = 2
  215. WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
  216. AND a4.delete_mark = 0
  217. GROUP BY a1.id
  218. </select>
  219. <!--查询分配床位班级列表的各个人数 - 结束 -->
  220. <select id="getDistributeRoomBedInfo" parameterType="com.xjrsoft.module.room.dto.DistributeRoomBedPageDto" resultType="com.xjrsoft.module.room.vo.DistributeRoomBedPageVo">
  221. SELECT t1.id,t1.sort_code,t2.name AS build_name,t1.floor_number,t1.room_name,t4.name AS gender_cn, t3.name AS check_in_status_cn,
  222. t1.bed_count,(
  223. SELECT COUNT(*) FROM room_bed
  224. WHERE delete_mark = 0 AND room_id = t1.id
  225. AND student_user_id IS NOT NULL
  226. ) AS into_count,(
  227. SELECT GROUP_CONCAT(DISTINCT(c3.name)) FROM room_bed c1
  228. LEFT JOIN base_student_school_roll c2 ON c1.student_user_id = c2.user_id
  229. LEFT JOIN base_class c3 ON c2.class_id = c3.id
  230. WHERE c1.delete_mark = 0 AND c1.room_id = t1.id
  231. AND c1.student_user_id IS NOT NULL
  232. ) AS into_class FROM room t1
  233. LEFT JOIN base_office_build t2 ON t1.office_build_id = t2.id
  234. LEFT JOIN xjr_dictionary_detail t3 ON t1.check_in_status = t3.code AND t3.item_id = 1739843696019435521
  235. LEFT JOIN xjr_dictionary_detail t4 ON t1.gender = t4.code AND t4.item_id = 2023000000000000004
  236. WHERE t1.delete_mark = 0
  237. and
  238. (
  239. SELECT COUNT(*) FROM room_bed
  240. WHERE delete_mark = 0 AND room_id = t1.id
  241. AND student_user_id IS NOT NULL
  242. ) != t1.bed_count
  243. <if test="dto.gender != null and dto.gender != ''">
  244. and t1.gender = #{dto.gender}
  245. </if>
  246. <if test="dto.officeBuildId != null">
  247. and t2.id = #{dto.officeBuildId}
  248. </if>
  249. <if test="dto.floorNumber != null">
  250. and t1.floor_number = #{dto.floorNumber}
  251. </if>
  252. <if test="dto.checkInStatus != null and dto.checkInStatus !=''">
  253. and t1.check_in_status = #{dto.checkInStatus}
  254. </if>
  255. <if test="dto.roomName != null and dto.roomName !=''">
  256. and t1.room_name like concat('%',#{dto.roomName},'%')
  257. </if>
  258. ORDER BY t1.sort_code
  259. </select>
  260. <select id="getBedInfo" resultType="com.xjrsoft.module.room.vo.RoomBedVo">
  261. SELECT t1.* FROM room_bed t1
  262. LEFT JOIN room t2 ON t1.room_id = t2.id
  263. WHERE t1.delete_mark = 0 AND t1.room_id IN
  264. <foreach item="roomId" index="index" collection="ids" open="(" close=")" separator=",">
  265. #{roomId}
  266. </foreach>
  267. ORDER BY t2.sort_code,t1.sort_code
  268. </select>
  269. <select id="getDistributeResult" parameterType="com.xjrsoft.module.room.dto.DistributeRoomBedDto" resultType="com.xjrsoft.module.room.vo.DistributeResultListVo">
  270. SELECT t5.class_id,t4.name,t6.name AS gender_cn,t3.name AS build_name,t2.room_name,t1.bed_number FROM room_bed t1
  271. LEFT JOIN room t2 ON t1.room_id = t2.id
  272. LEFT JOIN base_office_build t3 ON t2.office_build_id = t3.id
  273. LEFT JOIN xjr_user t4 ON t1.student_user_id = t4.id
  274. LEFT JOIN base_student_school_roll t5 ON t5.user_id = t4.id
  275. LEFT JOIN xjr_dictionary_detail t6 ON t2.gender = t6.code AND t6.item_id = 2023000000000000004
  276. WHERE t1.student_user_id IS NOT NULL AND t1.delete_mark = 0
  277. AND t1.room_id IN
  278. <foreach item="roomId" index="index" collection="dto.roomIds" open="(" close=")" separator=",">
  279. #{roomId}
  280. </foreach>
  281. AND t5.class_id IN
  282. <foreach item="classId" index="index" collection="dto.classIds" open="(" close=")" separator=",">
  283. #{classId}
  284. </foreach>
  285. ORDER BY t2.sort_code,t1.sort_code
  286. </select>
  287. <select id="getClassStudetBed" parameterType="com.xjrsoft.module.room.dto.AdjustClassPageDto" resultType="com.xjrsoft.module.room.vo.AdjustBedClassStudentPageVo">
  288. SELECT t1.user_id,t4.id AS class_id, t4.name AS class_name,t2.name AS student_name,REPLACE(REPLACE(t2.gender,'SB10001','男'),'SB10002','女') AS gender_cn,t7.name AS build_name,t6.room_name,t5.bed_number FROM base_student t1
  289. LEFT JOIN xjr_user t2 ON t1.user_id = t2.id
  290. LEFT JOIN base_student_school_roll t3 ON t1.user_id = t3.user_id
  291. LEFT JOIN base_class t4 ON t3.class_id = t4.id
  292. LEFT JOIN room_bed t5 ON t5.student_user_id = t1.user_id
  293. LEFT JOIN room t6 ON t5.room_id = t6.id
  294. LEFT JOIN base_office_build t7 ON t6.office_build_id = t7.id
  295. WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
  296. and t3.stduy_status = 'FB3002'
  297. <if test="dto.gradeId != null">
  298. and t4.grade_id = #{dto.gradeId}
  299. </if>
  300. <if test="dto.classId != null">
  301. and t4.id = #{dto.classId}
  302. </if>
  303. <if test="dto.gender != null and dto.gender != ''">
  304. and REPLACE(REPLACE(t2.gender,1,'SB10001'),2,'SB10002') = #{dto.gender}
  305. </if>
  306. <if test="dto.isDistribute != null">
  307. <if test="dto.isDistribute == 1">
  308. and t5.student_user_id is not null
  309. </if>
  310. <if test="dto.isDistribute == 0">
  311. and t5.student_user_id is null
  312. </if>
  313. </if>
  314. <if test="dto.studentName != null and dto.studentName != ''">
  315. and t2.name like concat('%', #{dto.studentName}, '%')
  316. </if>
  317. </select>
  318. <select id="getBedStudentInfo" parameterType="com.xjrsoft.module.room.dto.AdjustBedPageDto" resultType="com.xjrsoft.module.room.vo.AdjustBedStudentPageVo">
  319. SELECT t1.id,t3.name AS build_name,t2.room_name,t5.name AS gender_cn,t1.bed_number,t4.name AS student_name,t4.id as student_user_id,t2.is_max,t2.id as room_id FROM room_bed t1
  320. LEFT JOIN room t2 ON t1.room_id = t2.id
  321. LEFT JOIN base_office_build t3 ON t2.office_build_id = t3.id
  322. LEFT JOIN xjr_user t4 ON t1.student_user_id = t4.id
  323. LEFT JOIN xjr_dictionary_detail t5 ON t2.gender = t5.code AND t5.item_id = 2023000000000000004
  324. LEFT JOIN base_student_school_roll t7 ON t4.id = t7.user_id
  325. WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
  326. <if test="dto.isEmptyRoom != null">
  327. <if test="dto.isEmptyRoom == 1">
  328. and t2.bed_count = (SELECT COUNT(*) FROM room_bed WHERE delete_mark = 0 AND student_user_id IS NULL AND is_check_in = 0 AND room_id = t2.id)
  329. </if>
  330. <if test="dto.isEmptyRoom == 0">
  331. and t2.bed_count != (SELECT COUNT(*) FROM room_bed WHERE delete_mark = 0 AND student_user_id IS NULL AND is_check_in = 0 AND room_id = t2.id)
  332. </if>
  333. </if>
  334. <if test="dto.roomName != null">
  335. and t2.room_name like concat('%', #{dto.roomName}, '%')
  336. </if>
  337. <if test="dto.gender != null and dto.gender != ''">
  338. and t2.gender = #{dto.gender}
  339. </if>
  340. <if test="dto.isMax != null">
  341. and t2.is_max = #{dto.isMax}
  342. </if>
  343. <if test="dto.floorNumber != null">
  344. and t2.floor_number = #{dto.floorNumber}
  345. </if>
  346. <if test="dto.floorNumber != null">
  347. and t2.floor_number = #{dto.floorNumber}
  348. </if>
  349. <if test="dto.classId != null">
  350. AND t2.id IN (
  351. SELECT DISTINCT c1.room_id FROM room_bed c1
  352. INNER JOIN base_student_school_roll c2 ON c1.student_user_id = c2.user_id
  353. WHERE c2.class_id = #{dto.classId}
  354. )
  355. </if>
  356. <if test="dto.buildId != null">
  357. and t3.id = #{dto.buildId}
  358. </if>
  359. ORDER BY t2.sort_code,t1.sort_code
  360. </select>
  361. <select id="getNoBedStudent" parameterType="com.xjrsoft.module.room.dto.AdjustBedPageDto" resultType="com.xjrsoft.module.room.vo.NoBedStudentPageVo">
  362. SELECT t1.user_id, t2.name AS student_name,REPLACE(REPLACE(t2.gender,'SB10001','男'),'SB10002','女') as gender_cn,t4.name AS class_name FROM base_student t1
  363. INNER JOIN xjr_user t2 ON t1.user_id = t2.id
  364. LEFT JOIN base_student_school_roll t3 ON t1.user_id = t3.user_id
  365. LEFT JOIN base_class t4 ON t3.class_id = t4.id
  366. WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
  367. AND t3.stduy_status = 'FB3001'
  368. AND t1.user_id NOT IN (
  369. SELECT student_user_id FROM room_bed WHERE delete_mark = 0 AND student_user_id IS NOT NULL
  370. )
  371. </select>
  372. <select id="getBedInfoByUserId" resultType="com.xjrsoft.module.room.vo.RoomBedInfoVo">
  373. SELECT t3.name as build_name,t2.room_name,t1.bed_number,t1.id FROM room_bed t1
  374. LEFT JOIN room t2 ON t1.room_id = t2.id
  375. LEFT JOIN base_office_build t3 ON t2.office_build_id = t3.id
  376. WHERE t3.build_type = 'FB3604'
  377. AND t1.student_user_id = #{id}
  378. </select>
  379. </mapper>