RoomMapper.xml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.RoomMapper">
  6. <select id="getPage" parameterType="com.xjrsoft.module.room.dto.RoomPageDto" resultType="com.xjrsoft.module.room.vo.RoomPageVo">
  7. SELECT t1.id,t1.sort_code,t2.name AS bulid_name,t1.floor_number,t1.room_name,t3.name AS check_in_status_cn,t4.name AS gender_cn,t1.bed_count,
  8. (SELECT GROUP_CONCAT(c2.name) FROM room_student_appoint c1
  9. LEFT JOIN xjr_user c2 ON c1.student_user_id = c2.id
  10. WHERE c1.delete_mark = 0 AND c1.room_id = t1.id) AS student_appoint_names,
  11. (SELECT GROUP_CONCAT(c2.name) FROM room_teacher_appoint c1
  12. LEFT JOIN xjr_user c2 ON c1.user_id = c2.id
  13. WHERE c1.delete_mark = 0 AND c1.room_id = t1.id) AS teacher_appoint_names,t1.is_max,t1.remark,
  14. ifnull((
  15. SELECT COUNT(*) FROM room_bed a1
  16. INNER JOIN xjr_user a2 ON a1.student_user_id = a2.id
  17. WHERE a1.delete_mark = 0 AND a2.delete_mark = 0 AND a1.room_id = t1.id
  18. AND a1.student_user_id IS NOT NULL
  19. ), 0) AS student_count,
  20. ifnull((
  21. SELECT COUNT(*) FROM room_bed
  22. WHERE delete_mark = 0 AND room_id = t1.id
  23. AND student_user_id IS NULL
  24. ), 0) AS empty_count FROM room t1
  25. LEFT JOIN base_office_build t2 ON t1.office_build_id = t2.id
  26. LEFT JOIN xjr_dictionary_detail t3 ON t1.check_in_status = t3.code AND t3.item_id = 1739843696019435521
  27. LEFT JOIN xjr_dictionary_detail t4 ON t1.gender = t4.code AND t4.item_id = 2023000000000000004
  28. WHERE t1.delete_mark = 0
  29. <if test="dto.officeBuildId != null">
  30. and t1.office_build_id = #{dto.officeBuildId}
  31. </if>
  32. <if test="dto.floorNumber != null">
  33. and t1.floor_number = #{dto.floorNumber}
  34. </if>
  35. <if test="dto.checkInStatus != null and dto.checkInStatus != ''">
  36. and t1.check_in_status = #{dto.checkInStatus}
  37. </if>
  38. <if test="dto.gender != null and dto.gender != ''">
  39. and t1.gender = #{dto.gender}
  40. </if>
  41. ORDER BY t1.sort_code
  42. </select>
  43. <select id="getList" parameterType="com.xjrsoft.module.room.dto.RoomPageDto" resultType="com.xjrsoft.module.room.vo.RoomExcelVo">
  44. SELECT t1.id,t1.sort_code,t2.name AS bulid_name,t1.floor_number,t1.room_name,t3.name AS check_in_status_cn,t4.name AS gender_cn,t1.bed_count,
  45. (SELECT GROUP_CONCAT(c2.name) FROM room_student_appoint c1
  46. LEFT JOIN xjr_user c2 ON c1.student_user_id = c2.id
  47. WHERE c1.delete_mark = 0 AND c1.room_id = t1.id) AS student_appoint_names,
  48. (SELECT GROUP_CONCAT(c2.name) FROM room_teacher_appoint c1
  49. LEFT JOIN xjr_user c2 ON c1.user_id = c2.id
  50. WHERE c1.delete_mark = 0 AND c1.room_id = t1.id) AS teacher_appoint_names,t1.is_max,t1.remark FROM room t1
  51. LEFT JOIN base_office_build t2 ON t1.office_build_id = t2.id
  52. LEFT JOIN xjr_dictionary_detail t3 ON t1.check_in_status = t3.code AND t3.item_id = 1739843696019435521
  53. LEFT JOIN xjr_dictionary_detail t4 ON t1.gender = t4.code AND t4.item_id = 2023000000000000004
  54. WHERE t1.delete_mark = 0
  55. <if test="dto.officeBuildId != null">
  56. and t1.office_build_id = #{dto.officeBuildId}
  57. </if>
  58. <if test="dto.floorNumber != null">
  59. and t1.floor_number = #{dto.floorNumber}
  60. </if>
  61. <if test="dto.checkInStatus != null and dto.checkInStatus != ''">
  62. and t1.check_in_status = #{dto.checkInStatus}
  63. </if>
  64. <if test="dto.gender != null and dto.gender != ''">
  65. and t1.gender = #{dto.gender}
  66. </if>
  67. ORDER BY t1.sort_code
  68. </select>
  69. <select id="getMaxSortCode" resultType="java.lang.Integer">
  70. SELECT IFNULL(MAX(sort_code),1) FROM room WHERE delete_mark = 0
  71. </select>
  72. <select id="getRoomClassCount" resultType="com.xjrsoft.module.room.vo.RoomClassCountVo">
  73. SELECT id,(
  74. SELECT COUNT(*) FROM (
  75. SELECT COUNT(*) FROM base_class t1
  76. LEFT JOIN base_student_school_roll t2 ON t2.class_id = t1.id
  77. LEFT JOIN room_bed t3 ON t2.user_id = t3.student_user_id
  78. WHERE t3.room_id = room.id GROUP BY t1.id
  79. ) class_data
  80. ) AS class_count FROM room
  81. where delete_mark = 0
  82. <if test="ids != null and ids.size() > 0">
  83. and id in
  84. <foreach item="roomId" index="index" collection="ids" open="(" close=")" separator=",">
  85. #{roomId}
  86. </foreach>
  87. </if>
  88. </select>
  89. <select id="getRoomClassExistent" resultType="com.xjrsoft.module.room.vo.RoomClassExistentVo">
  90. SELECT id,(
  91. SELECT GROUP_CONCAT(DISTINCT t1.class_id) FROM base_student_school_roll t1
  92. LEFT JOIN room_bed t3 ON t1.user_id = t3.student_user_id
  93. WHERE t3.room_id = room.id AND t3.delete_mark = 0
  94. ) AS class_count FROM room
  95. where delete_mark = 0
  96. <if test="ids != null and ids.size() > 0">
  97. and id in
  98. <foreach item="roomId" index="index" collection="ids" open="(" close=")" separator=",">
  99. #{roomId}
  100. </foreach>
  101. </if>
  102. </select>
  103. <!-- 将有多个班级的寝室设置为混合寝室 -->
  104. <update id="setIsmaxTrue">
  105. UPDATE room SET is_max = 1 WHERE delete_mark = 0
  106. AND (
  107. SELECT COUNT(*) FROM (
  108. SELECT COUNT(*) FROM base_student_school_roll t1
  109. LEFT JOIN room_bed t3 ON t1.user_id = t3.student_user_id
  110. WHERE t3.room_id = room.id AND t3.delete_mark = 0 GROUP BY t1.class_id
  111. ) class_data
  112. ) > 1
  113. </update>
  114. <!-- 将没有多个班级的混合寝室清除掉 -->
  115. <update id="setIsmaxFalse">
  116. UPDATE room SET is_max = 0 WHERE delete_mark = 0
  117. AND 1 >(
  118. SELECT COUNT(*) FROM (
  119. SELECT COUNT(*) FROM base_student_school_roll t1
  120. LEFT JOIN room_bed t3 ON t1.user_id = t3.student_user_id
  121. WHERE t3.room_id = room.id AND t3.delete_mark = 0 GROUP BY t1.class_id
  122. ) class_data
  123. )
  124. </update>
  125. </mapper>