AdminUserMapper.xml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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.user.AdminUserMapper">
  4. <select id="selectPage1" resultType="cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO">
  5. SELECT
  6. a.*,
  7. COALESCE(
  8. (SELECT MIN(ua.is_graduate) FROM system_user_achievement ua WHERE ua.user_id = a.id),
  9. 1
  10. ) AS is_graduate,
  11. CASE
  12. WHEN a.photo_url IS NOT NULL AND TRIM(a.photo_url) != '' THEN 1
  13. ELSE 0
  14. END AS photoIsExist,
  15. COALESCE(system_dept.name, "测绘学院") AS deptName,
  16. supervisor_user.nickname as supervisor,
  17. supervisor_user.mobile as supervisorMobile
  18. FROM
  19. system_users a
  20. LEFT JOIN
  21. system_user_achievement ua ON ua.user_id = a.id
  22. LEFT JOIN
  23. system_users supervisor_user ON supervisor_user.id = a.supervisor_id -- 自连接获取 supervisor 的信息
  24. LEFT JOIN
  25. system_dept system_dept ON system_dept.id = a.dept_id
  26. WHERE
  27. 1=1
  28. <if test="reqVO.username != null and reqVO.username != ''">
  29. AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
  30. </if>
  31. <if test="reqVO.email != null and reqVO.email != ''">
  32. AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
  33. </if>
  34. <if test="reqVO.mobile != null and reqVO.mobile != ''">
  35. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  36. </if>
  37. <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
  38. AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
  39. </if>
  40. <if test="reqVO.nickname != null and reqVO.nickname != ''">
  41. AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
  42. </if>
  43. <if test="reqVO.userType != null">
  44. AND a.user_type = #{reqVO.userType}
  45. </if>
  46. <if test="reqVO.grade != null and reqVO.grade != ''">
  47. AND a.grade LIKE CONCAT('%', #{reqVO.grade.substring(0, 4)}, '%')
  48. </if>
  49. <if test="reqVO.supervisorId != null">
  50. AND a.supervisor_id = #{reqVO.supervisorId}
  51. </if>
  52. <if test="reqVO.major != null">
  53. AND a.major = #{reqVO.major}
  54. </if>
  55. <if test="reqVO.masterType != null">
  56. AND a.masterType = #{reqVO.masterType}
  57. </if>
  58. <if test="reqVO.status != null">
  59. AND a.status = #{reqVO.status}
  60. </if>
  61. <if test="deptIds != null and !deptIds.isEmpty()">
  62. AND a.dept_id IN
  63. <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
  64. #{deptId}
  65. </foreach>
  66. </if>
  67. <if test="roleIds != null and roleIds.contains(113L)">
  68. AND a.dept_id = #{deptId}
  69. AND a.user_type = 1
  70. </if>
  71. <if test="roleIds != null and roleIds.contains(114L)">
  72. AND a.user_type = 1
  73. </if>
  74. <if test="roleIds != null and roleIds.contains(1L)">
  75. AND a.user_type IN (1, 2)
  76. </if>
  77. <if test="reqVO.isGraduate != null">
  78. <if test="reqVO.isGraduate == 1">
  79. AND a.id NOT IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = 0)
  80. </if>
  81. <if test="reqVO.isGraduate == 0">
  82. AND a.id IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = #{reqVO.isGraduate})
  83. AND ua.is_graduate = 0
  84. </if>
  85. </if>
  86. <if test="reqVO.photoIsExist != null">
  87. <if test="reqVO.photoIsExist == 0">
  88. AND a.photo_url IS NULL
  89. </if>
  90. <if test="reqVO.photoIsExist == 1">
  91. AND a.photo_url IS NOT NULL AND a.photo_url != ''
  92. </if>
  93. </if>
  94. GROUP BY
  95. a.id
  96. ORDER BY
  97. a.id DESC
  98. LIMIT #{offset}, #{reqVO.pageSize}
  99. </select>
  100. <select id="selectPage1Count" resultType="Long">
  101. SELECT COUNT(*) AS total_count
  102. FROM (
  103. SELECT a.id
  104. FROM system_users a
  105. LEFT JOIN system_user_achievement ua ON ua.user_id = a.id
  106. WHERE 1=1
  107. <if test="reqVO.username != null and reqVO.username != ''">
  108. AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
  109. </if>
  110. <if test="reqVO.email != null and reqVO.email != ''">
  111. AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
  112. </if>
  113. <if test="reqVO.mobile != null and reqVO.mobile != ''">
  114. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  115. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  116. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  117. </if>
  118. <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
  119. AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
  120. </if>
  121. <if test="reqVO.nickname != null and reqVO.nickname != ''">
  122. AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
  123. </if>
  124. <if test="reqVO.userType != null">
  125. AND a.user_type = #{reqVO.userType}
  126. </if>
  127. <if test="reqVO.grade != null and reqVO.grade != ''">
  128. AND a.grade LIKE CONCAT('%', #{reqVO.grade.substring(0, 4)}, '%')
  129. </if>
  130. <if test="reqVO.supervisorId != null">
  131. AND a.supervisor_id = #{reqVO.supervisorId}
  132. </if>
  133. <if test="reqVO.major != null">
  134. AND a.major = #{reqVO.major}
  135. </if>
  136. <if test="reqVO.masterType != null">
  137. AND a.masterType = #{reqVO.masterType}
  138. </if>
  139. <if test="reqVO.status != null">
  140. AND a.status = #{reqVO.status}
  141. </if>
  142. <if test="deptIds != null and !deptIds.isEmpty()">
  143. AND a.dept_id IN
  144. <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
  145. #{deptId}
  146. </foreach>
  147. </if>
  148. <if test="roleIds != null and roleIds.contains(113L)">
  149. AND a.dept_id = #{deptId}
  150. AND a.user_type = 1
  151. </if>
  152. <if test="roleIds != null and roleIds.contains(114L)">
  153. AND a.user_type = 1
  154. </if>
  155. <if test="roleIds != null and roleIds.contains(1L)">
  156. AND a.dept_id IN (1, 2)
  157. </if>
  158. <if test="reqVO.isGraduate != null">
  159. <if test="reqVO.isGraduate == 1">
  160. AND a.id NOT IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = 0)
  161. </if>
  162. <if test="reqVO.isGraduate == 0">
  163. AND a.id IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = #{reqVO.isGraduate})
  164. AND ua.is_graduate = 0
  165. </if>
  166. </if>
  167. <if test="reqVO.photoIsExist != null">
  168. <if test="reqVO.photoIsExist == 0">
  169. AND a.photo_url IS NULL
  170. </if>
  171. <if test="reqVO.photoIsExist == 1">
  172. AND a.photo_url IS NOT NULL AND a.photo_url != ''
  173. </if>
  174. </if>
  175. GROUP BY a.id
  176. ) AS subquery;
  177. </select>
  178. </mapper>