AdminUserMapper.xml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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="selectPageForGraduate" 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
  24. ON supervisor_user.id = a.supervisor_id
  25. AND supervisor_user.deleted = 0
  26. LEFT JOIN
  27. system_dept system_dept ON system_dept.id = a.dept_id
  28. WHERE
  29. 1=1
  30. <if test="reqVO.username != null and reqVO.username != ''">
  31. AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
  32. </if>
  33. <if test="reqVO.email != null and reqVO.email != ''">
  34. AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
  35. </if>
  36. <if test="reqVO.mobile != null and reqVO.mobile != ''">
  37. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  38. </if>
  39. <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
  40. AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
  41. </if>
  42. <if test="reqVO.nickname != null and reqVO.nickname != ''">
  43. AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
  44. </if>
  45. <if test="reqVO.userType != null">
  46. AND a.user_type = #{reqVO.userType}
  47. </if>
  48. <bind name="gradePrefix" value="reqVO.grade != null and reqVO.grade.length() >= 4 ? reqVO.grade.substring(0, 4) : ''"/>
  49. <if test="gradePrefix != ''">
  50. AND a.grade LIKE CONCAT('%', #{gradePrefix}, '%')
  51. </if>
  52. <if test="reqVO.supervisorId != null">
  53. AND a.supervisor_id = #{reqVO.supervisorId}
  54. </if>
  55. <if test="reqVO.major != null">
  56. AND a.major = #{reqVO.major}
  57. </if>
  58. <if test="reqVO.masterType != null">
  59. AND a.masterType = #{reqVO.masterType}
  60. </if>
  61. <if test="reqVO.status != null">
  62. AND a.status = #{reqVO.status}
  63. </if>
  64. <if test="deptIds != null and !deptIds.isEmpty()">
  65. AND a.dept_id IN
  66. <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
  67. #{deptId}
  68. </foreach>
  69. </if>
  70. <choose>
  71. <when test="type == 0">
  72. AND a.user_type = 1
  73. </when>
  74. <when test="type == 1">
  75. AND a.user_type = 1
  76. AND (
  77. ( a.dept_id != 0
  78. AND a.dept_id = #{deptId}
  79. AND a.dept_id IS NOT NULL
  80. AND a.dept_id != ''
  81. )
  82. OR (
  83. a.supervisor_id = #{loginId}
  84. AND a.supervisor_id IS NOT NULL
  85. AND a.supervisor_id != ''
  86. )
  87. )
  88. </when>
  89. </choose>
  90. <if test="reqVO.isGraduate != null">
  91. <if test="reqVO.isGraduate == 1">
  92. AND a.id NOT IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = 0)
  93. </if>
  94. <if test="reqVO.isGraduate == 0">
  95. AND a.id IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = #{reqVO.isGraduate})
  96. AND ua.is_graduate = 0
  97. </if>
  98. </if>
  99. <if test="reqVO.photoIsExist != null">
  100. <if test="reqVO.photoIsExist == 0">
  101. AND a.photo_url IS NULL
  102. </if>
  103. <if test="reqVO.photoIsExist == 1">
  104. AND a.photo_url IS NOT NULL AND a.photo_url != ''
  105. </if>
  106. </if>
  107. AND a.deleted = 0
  108. GROUP BY
  109. a.id
  110. ORDER BY
  111. a.id DESC
  112. <if test="offset != -1">
  113. LIMIT #{offset}, #{reqVO.pageSize}
  114. </if>
  115. </select>
  116. <select id="selectPage1Count" resultType="Long">
  117. SELECT COUNT(*) AS total_count
  118. FROM (
  119. SELECT a.id
  120. FROM system_users a
  121. LEFT JOIN system_user_achievement ua ON ua.user_id = a.id
  122. WHERE 1=1
  123. <if test="reqVO.username != null and reqVO.username != ''">
  124. AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
  125. </if>
  126. <if test="reqVO.email != null and reqVO.email != ''">
  127. AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
  128. </if>
  129. <if test="reqVO.mobile != null and reqVO.mobile != ''">
  130. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  131. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  132. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  133. </if>
  134. <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
  135. AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
  136. </if>
  137. <if test="reqVO.nickname != null and reqVO.nickname != ''">
  138. AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
  139. </if>
  140. <if test="reqVO.userType != null">
  141. AND a.user_type = #{reqVO.userType}
  142. </if>
  143. <bind name="gradePrefix" value="reqVO.grade != null and reqVO.grade.length() >= 4 ? reqVO.grade.substring(0, 4) : ''"/>
  144. <if test="gradePrefix != ''">
  145. AND a.grade LIKE CONCAT('%', #{gradePrefix}, '%')
  146. </if>
  147. <if test="reqVO.supervisorId != null">
  148. AND a.supervisor_id = #{reqVO.supervisorId}
  149. </if>
  150. <if test="reqVO.major != null">
  151. AND a.major = #{reqVO.major}
  152. </if>
  153. <if test="reqVO.masterType != null">
  154. AND a.masterType = #{reqVO.masterType}
  155. </if>
  156. <if test="reqVO.status != null">
  157. AND a.status = #{reqVO.status}
  158. </if>
  159. <if test="deptIds != null and !deptIds.isEmpty()">
  160. AND a.dept_id IN
  161. <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
  162. #{deptId}
  163. </foreach>
  164. </if>
  165. <choose>
  166. <when test="type == 0">
  167. AND a.user_type = 1
  168. </when>
  169. <when test="type == 1">
  170. AND a.user_type = 1
  171. AND (
  172. ( a.dept_id != 0
  173. AND a.dept_id = #{deptId}
  174. AND a.dept_id IS NOT NULL
  175. AND a.dept_id != ''
  176. )
  177. OR (
  178. a.supervisor_id = #{loginId}
  179. AND a.supervisor_id IS NOT NULL
  180. AND a.supervisor_id != ''
  181. )
  182. )
  183. </when>
  184. </choose>
  185. <if test="reqVO.isGraduate != null">
  186. <if test="reqVO.isGraduate == 1">
  187. AND a.id NOT IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = 0)
  188. </if>
  189. <if test="reqVO.isGraduate == 0">
  190. AND a.id IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = #{reqVO.isGraduate})
  191. AND ua.is_graduate = 0
  192. </if>
  193. </if>
  194. <if test="reqVO.photoIsExist != null">
  195. <if test="reqVO.photoIsExist == 0">
  196. AND a.photo_url IS NULL
  197. </if>
  198. <if test="reqVO.photoIsExist == 1">
  199. AND a.photo_url IS NOT NULL AND a.photo_url != ''
  200. </if>
  201. </if>
  202. AND a.deleted = 0
  203. GROUP BY a.id
  204. ) AS subquery;
  205. </select>
  206. <select id="selectList1" resultType="cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO">
  207. SELECT
  208. a.*,
  209. COALESCE(
  210. (SELECT MIN(ua.is_graduate) FROM system_user_achievement ua WHERE ua.user_id = a.id),
  211. 1
  212. ) AS is_graduate,
  213. CASE
  214. WHEN a.photo_url IS NOT NULL AND TRIM(a.photo_url) != '' THEN 1
  215. ELSE 0
  216. END AS photoIsExist,
  217. COALESCE(system_dept.name, "测绘学院") AS deptName,
  218. supervisor_user.nickname as supervisor,
  219. supervisor_user.mobile as supervisorMobile
  220. FROM
  221. system_users a
  222. LEFT JOIN
  223. system_user_achievement ua ON ua.user_id = a.id
  224. LEFT JOIN
  225. system_users supervisor_user
  226. ON supervisor_user.id = a.supervisor_id
  227. AND supervisor_user.deleted = 0
  228. LEFT JOIN
  229. system_dept system_dept ON system_dept.id = a.dept_id
  230. WHERE
  231. 1=1
  232. <if test="reqVO.username != null and reqVO.username != ''">
  233. AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
  234. </if>
  235. <if test="reqVO.email != null and reqVO.email != ''">
  236. AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
  237. </if>
  238. <if test="reqVO.mobile != null and reqVO.mobile != ''">
  239. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  240. </if>
  241. <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
  242. AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
  243. </if>
  244. <if test="reqVO.nickname != null and reqVO.nickname != ''">
  245. AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
  246. </if>
  247. <if test="reqVO.userType != null">
  248. AND a.user_type = #{reqVO.userType}
  249. </if>
  250. <bind name="gradePrefix" value="reqVO.grade != null and reqVO.grade.length() >= 4 ? reqVO.grade.substring(0, 4) : ''"/>
  251. <if test="gradePrefix != ''">
  252. AND a.grade LIKE CONCAT('%', #{gradePrefix}, '%')
  253. </if>
  254. <if test="reqVO.supervisorId != null">
  255. AND a.supervisor_id = #{reqVO.supervisorId}
  256. </if>
  257. <if test="reqVO.major != null">
  258. AND a.major = #{reqVO.major}
  259. </if>
  260. <if test="reqVO.masterType != null">
  261. AND a.masterType = #{reqVO.masterType}
  262. </if>
  263. <if test="reqVO.status != null">
  264. AND a.status = #{reqVO.status}
  265. </if>
  266. <if test="deptIds != null and !deptIds.isEmpty()">
  267. AND a.dept_id IN
  268. <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
  269. #{deptId}
  270. </foreach>
  271. </if>
  272. <if test="roleIds != null and roleIds.contains(113L)">
  273. AND a.supervisor_id =#{loginId}
  274. AND a.user_type = 1
  275. </if>
  276. <if test="roleIds != null and roleIds.contains(114L)">
  277. AND a.user_type = 1
  278. </if>
  279. <if test="roleIds != null and roleIds.contains(1L)">
  280. AND a.user_type IN (1, 2)
  281. </if>
  282. <if test="reqVO.isGraduate != null">
  283. <if test="reqVO.isGraduate == 1">
  284. AND a.id NOT IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = 0)
  285. </if>
  286. <if test="reqVO.isGraduate == 0">
  287. AND a.id IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = #{reqVO.isGraduate})
  288. AND ua.is_graduate = 0
  289. </if>
  290. </if>
  291. <if test="reqVO.photoIsExist != null">
  292. <if test="reqVO.photoIsExist == 0">
  293. AND a.photo_url IS NULL
  294. </if>
  295. <if test="reqVO.photoIsExist == 1">
  296. AND a.photo_url IS NOT NULL AND a.photo_url != ''
  297. </if>
  298. </if>
  299. AND a.deleted = 0
  300. GROUP BY
  301. a.id
  302. ORDER BY
  303. a.id
  304. </select>
  305. <select id="selectAllList" resultType="cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO">
  306. SELECT
  307. a.*,
  308. COALESCE(
  309. (SELECT MIN(ua.is_graduate) FROM system_user_achievement ua WHERE ua.user_id = a.id),
  310. 1
  311. ) AS is_graduate,
  312. CASE
  313. WHEN a.photo_url IS NOT NULL AND TRIM(a.photo_url) != '' THEN 1
  314. ELSE 0
  315. END AS photoIsExist,
  316. COALESCE(system_dept.name, "测绘学院") AS deptName,
  317. supervisor_user.nickname as supervisor,
  318. supervisor_user.mobile as supervisorMobile
  319. FROM
  320. system_users a
  321. LEFT JOIN
  322. system_user_achievement ua ON ua.user_id = a.id
  323. LEFT JOIN
  324. system_users supervisor_user
  325. ON supervisor_user.id = a.supervisor_id
  326. AND supervisor_user.deleted = 0
  327. LEFT JOIN
  328. system_dept system_dept ON system_dept.id = a.dept_id
  329. WHERE
  330. 1=1
  331. <if test="reqVO.username != null and reqVO.username != ''">
  332. AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
  333. </if>
  334. <if test="reqVO.email != null and reqVO.email != ''">
  335. AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
  336. </if>
  337. <if test="reqVO.mobile != null and reqVO.mobile != ''">
  338. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  339. </if>
  340. <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
  341. AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
  342. </if>
  343. <if test="reqVO.nickname != null and reqVO.nickname != ''">
  344. AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
  345. </if>
  346. <if test="reqVO.userType != null">
  347. AND a.user_type = #{reqVO.userType}
  348. </if>
  349. <bind name="gradePrefix" value="reqVO.grade != null and reqVO.grade.length() >= 4 ? reqVO.grade.substring(0, 4) : ''"/>
  350. <if test="gradePrefix != ''">
  351. AND a.grade LIKE CONCAT('%', #{gradePrefix}, '%')
  352. </if>
  353. <if test="reqVO.supervisorId != null">
  354. AND a.supervisor_id = #{reqVO.supervisorId}
  355. </if>
  356. <if test="reqVO.major != null">
  357. AND a.major = #{reqVO.major}
  358. </if>
  359. <if test="reqVO.masterType != null">
  360. AND a.masterType = #{reqVO.masterType}
  361. </if>
  362. <if test="reqVO.status != null">
  363. AND a.status = #{reqVO.status}
  364. </if>
  365. <if test="deptIds != null and !deptIds.isEmpty()">
  366. AND a.dept_id IN
  367. <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
  368. #{deptId}
  369. </foreach>
  370. </if>
  371. <if test="reqVO.isGraduate != null">
  372. <if test="reqVO.isGraduate == 1">
  373. AND a.id NOT IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = 0)
  374. </if>
  375. <if test="reqVO.isGraduate == 0">
  376. AND a.id IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = #{reqVO.isGraduate})
  377. AND ua.is_graduate = 0
  378. </if>
  379. </if>
  380. <if test="reqVO.photoIsExist != null">
  381. <if test="reqVO.photoIsExist == 0">
  382. AND a.photo_url IS NULL
  383. </if>
  384. <if test="reqVO.photoIsExist == 1">
  385. AND a.photo_url IS NOT NULL AND a.photo_url != ''
  386. </if>
  387. </if>
  388. AND a.deleted = 0
  389. GROUP BY
  390. a.id
  391. ORDER BY
  392. a.id
  393. </select>
  394. <select id="getIsPassedStudentsPage" resultType="cn.iocoder.yudao.module.system.controller.admin.user.vo.user.StudentProjectRespVO">
  395. SELECT
  396. a.*,r.id,r.project_id,r.supervisor_id,
  397. CASE
  398. WHEN COALESCE(MAX(CASE WHEN r.select_type = 4 THEN 1 ELSE 0 END),0) = 1 THEN 4 -- 如果有 4
  399. WHEN COALESCE(MAX(CASE WHEN r.select_type = 2 THEN 1 ELSE 0 END),0) = 1 THEN 2 -- 如果有 2
  400. WHEN COALESCE(MAX(CASE WHEN r.select_type = 1 THEN 1 ELSE 0 END),0) = 1 THEN 1 -- 如果没有 2,但有 1
  401. ELSE 0 -- 其他情况
  402. END AS selectStatus,
  403. -- 计算 selectStatus 为 1 或 2 的记录 id
  404. CASE
  405. WHEN COALESCE(MAX(r.select_type), null) IN (1, 2) THEN r.id
  406. ELSE NULL
  407. END AS recordId,
  408. COALESCE(system_dept.name, "测绘学院") AS deptName,
  409. supervisor_user.nickname AS supervisor,
  410. supervisor_user.mobile AS supervisorMobile,
  411. externalSupervisor_user.nickname AS externalSupervisor,
  412. selectSupervisor_user.nickname AS selectSupervisor,
  413. r.supervisor_id AS selectSupervisorId
  414. FROM
  415. system_users a
  416. LEFT JOIN
  417. student_select_supervisor_record r ON r.student_id = a.id AND r.deleted = 0 AND r.project_id = #{projectId}
  418. LEFT JOIN
  419. system_users supervisor_user ON supervisor_user.id = a.supervisor_id AND supervisor_user.deleted = 0
  420. LEFT JOIN
  421. system_users externalSupervisor_user ON externalSupervisor_user.id = a.external_supervisor_id AND externalSupervisor_user.deleted = 0
  422. LEFT JOIN
  423. system_users selectSupervisor_user ON selectSupervisor_user.id = a.id AND selectSupervisor_user.deleted = 0
  424. LEFT JOIN
  425. system_dept system_dept ON system_dept.id = a.dept_id
  426. WHERE
  427. 1=1
  428. <if test="reqVO.username != null and reqVO.username != ''">
  429. AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
  430. </if>
  431. <if test="reqVO.email != null and reqVO.email != ''">
  432. AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
  433. </if>
  434. <if test="reqVO.mobile != null and reqVO.mobile != ''">
  435. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  436. </if>
  437. <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
  438. AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
  439. </if>
  440. <if test="reqVO.nickname != null and reqVO.nickname != ''">
  441. AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
  442. </if>
  443. <if test="reqVO.userType != null">
  444. AND a.user_type = #{reqVO.userType}
  445. </if>
  446. <if test="reqVO.grade != '' and reqVO.grade != null ">
  447. AND a.grade = #{reqVO.grade}
  448. </if>
  449. <if test="reqVO.supervisorId != null and reqVO.supervisorId != '' ">
  450. AND a.supervisor_id = #{reqVO.supervisorId}
  451. </if>
  452. <if test="reqVO.major != null and reqVO.major != '' ">
  453. AND a.major = #{reqVO.major}
  454. </if>
  455. <if test="reqVO.masterType != null and reqVO.masterType != '' ">
  456. AND a.masterType = #{reqVO.masterType}
  457. </if>
  458. <if test="reqVO.status != null and reqVO.status != '' ">
  459. AND a.status = #{reqVO.status}
  460. </if>
  461. AND a.deleted = 0
  462. GROUP BY
  463. a.id
  464. <!-- 合并 HAVING 子句 -->
  465. HAVING
  466. CASE
  467. WHEN COALESCE(MAX(CASE WHEN r.select_type = 4 THEN 1 ELSE 0 END),0) = 1 THEN 4 -- 如果有 2
  468. WHEN COALESCE(MAX(CASE WHEN r.select_type = 2 THEN 1 ELSE 0 END),0) = 1 THEN 2 -- 如果有 2
  469. WHEN COALESCE(MAX(CASE WHEN r.select_type = 1 THEN 1 ELSE 0 END),0) = 1 THEN 1 -- 如果没有 2,但有 1
  470. ELSE 0
  471. END
  472. <choose>
  473. <when test="isPassed == 0">IN (0, 1)</when>
  474. <when test="isPassed == 1">in (2,4)</when>
  475. </choose>
  476. ORDER BY
  477. a.id DESC
  478. <if test="offset != -1">
  479. LIMIT #{offset}, #{reqVO.pageSize}
  480. </if>
  481. </select>
  482. <select id="getIsPassedStudentsPageCount" resultType="Long">
  483. SELECT COUNT(*) AS total_count
  484. FROM (
  485. SELECT a.id
  486. FROM system_users a
  487. LEFT JOIN student_select_supervisor_record r ON r.student_id = a.id AND r.deleted = 0 AND r.project_id = #{projectId}
  488. LEFT JOIN system_users supervisor_user ON supervisor_user.id = a.supervisor_id AND supervisor_user.deleted = 0
  489. LEFT JOIN system_users externalSupervisor_user ON externalSupervisor_user.id = a.external_supervisor_id AND externalSupervisor_user.deleted = 0
  490. LEFT JOIN system_users selectSupervisor_user ON selectSupervisor_user.id = a.id AND selectSupervisor_user.deleted = 0
  491. LEFT JOIN system_dept system_dept ON system_dept.id = a.dept_id
  492. WHERE 1 = 1
  493. <if test="reqVO.username != null and reqVO.username != ''">
  494. AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
  495. </if>
  496. <if test="reqVO.email != null and reqVO.email != ''">
  497. AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
  498. </if>
  499. <if test="reqVO.mobile != null and reqVO.mobile != ''">
  500. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  501. </if>
  502. <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
  503. AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
  504. </if>
  505. <if test="reqVO.nickname != null and reqVO.nickname != ''">
  506. AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
  507. </if>
  508. <if test="reqVO.userType != null">
  509. AND a.user_type = #{reqVO.userType}
  510. </if>
  511. <if test="reqVO.grade != '' and reqVO.grade != null ">
  512. AND a.grade = #{reqVO.grade}
  513. </if>
  514. <if test="reqVO.supervisorId != null and reqVO.supervisorId != '' ">
  515. AND a.supervisor_id = #{reqVO.supervisorId}
  516. </if>
  517. <if test="reqVO.major != null and reqVO.major != '' ">
  518. AND a.major = #{reqVO.major}
  519. </if>
  520. <if test="reqVO.masterType != null and reqVO.masterType != '' ">
  521. AND a.masterType = #{reqVO.masterType}
  522. </if>
  523. <if test="reqVO.status != null and reqVO.status != '' ">
  524. AND a.status = #{reqVO.status}
  525. </if>
  526. AND a.deleted = 0
  527. GROUP BY a.id
  528. <!-- 合并 HAVING 条件 -->
  529. HAVING
  530. CASE
  531. WHEN COALESCE(MAX(CASE WHEN r.select_type = 4 THEN 1 ELSE 0 END),0) = 1 THEN 4 -- 如果有 2
  532. WHEN COALESCE(MAX(CASE WHEN r.select_type = 2 THEN 1 ELSE 0 END),0) = 1 THEN 2 -- 如果有 2
  533. WHEN COALESCE(MAX(CASE WHEN r.select_type = 1 THEN 1 ELSE 0 END),0) = 1 THEN 1 -- 如果没有 2,但有 1
  534. ELSE 0
  535. END
  536. <choose>
  537. <when test="isPassed == 0">IN (0, 1)</when>
  538. <when test="isPassed == 1">in (2,4)</when>
  539. </choose>
  540. ) AS subquery;
  541. </select>
  542. </mapper>