AdminUserMapper.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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.dal.dataobject.user.AdminUserDO">
  395. SELECT
  396. a.*,r.id,
  397. CASE
  398. WHEN COALESCE(MAX(r.select_type), 0) = 2 THEN 2
  399. WHEN COALESCE(MAX(r.select_type), 0) = 1 THEN 1
  400. ELSE 0
  401. END AS selectStatus,
  402. -- 计算 selectStatus 为 1 或 2 的记录 id
  403. CASE
  404. WHEN COALESCE(MAX(r.select_type), null) IN (1, 2) THEN r.id
  405. ELSE NULL
  406. END AS recordId,
  407. COALESCE(system_dept.name, "测绘学院") AS deptName,
  408. supervisor_user.nickname AS supervisor,
  409. supervisor_user.mobile AS supervisorMobile
  410. FROM
  411. system_users a
  412. LEFT JOIN
  413. student_select_supervisor_record r ON r.student_id = a.id AND r.deleted = 0
  414. LEFT JOIN
  415. system_users supervisor_user ON supervisor_user.id = a.supervisor_id AND supervisor_user.deleted = 0
  416. LEFT JOIN
  417. system_dept system_dept ON system_dept.id = a.dept_id
  418. WHERE
  419. 1=1
  420. <if test="reqVO.username != null and reqVO.username != ''">
  421. AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
  422. </if>
  423. <if test="reqVO.email != null and reqVO.email != ''">
  424. AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
  425. </if>
  426. <if test="reqVO.mobile != null and reqVO.mobile != ''">
  427. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  428. </if>
  429. <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
  430. AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
  431. </if>
  432. <if test="reqVO.nickname != null and reqVO.nickname != ''">
  433. AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
  434. </if>
  435. <if test="reqVO.userType != null">
  436. AND a.user_type = #{reqVO.userType}
  437. </if>
  438. <if test="reqVO.grade != '' and reqVO.grade != null ">
  439. AND a.grade = #{reqVO.grade}
  440. </if>
  441. <if test="reqVO.supervisorId != null and reqVO.supervisorId != '' ">
  442. AND a.supervisor_id = #{reqVO.supervisorId}
  443. </if>
  444. <if test="reqVO.major != null and reqVO.major != '' ">
  445. AND a.major = #{reqVO.major}
  446. </if>
  447. <if test="reqVO.masterType != null and reqVO.masterType != '' ">
  448. AND a.masterType = #{reqVO.masterType}
  449. </if>
  450. <if test="reqVO.status != null and reqVO.status != '' ">
  451. AND a.status = #{reqVO.status}
  452. </if>
  453. AND a.deleted = 0
  454. GROUP BY
  455. a.id
  456. <!-- 合并 HAVING 子句 -->
  457. HAVING
  458. CASE
  459. WHEN COALESCE(MAX(r.select_type), 0) = 2 THEN 2
  460. WHEN COALESCE(MAX(r.select_type), 0) = 1 THEN 1
  461. ELSE 0
  462. END
  463. <choose>
  464. <when test="isPassed == 0">IN (0, 1)</when>
  465. <when test="isPassed == 1">= 2</when>
  466. </choose>
  467. ORDER BY
  468. a.id DESC
  469. <if test="offset != -1">
  470. LIMIT #{offset}, #{reqVO.pageSize}
  471. </if>
  472. </select>
  473. <select id="getIsPassedStudentsPageCount" resultType="Long">
  474. SELECT COUNT(*) AS total_count
  475. FROM (
  476. SELECT a.id
  477. FROM system_users a
  478. LEFT JOIN student_select_supervisor_record r ON r.student_id = a.id AND r.deleted = 0
  479. LEFT JOIN system_users supervisor_user ON supervisor_user.id = a.supervisor_id AND supervisor_user.deleted = 0
  480. LEFT JOIN system_dept system_dept ON system_dept.id = a.dept_id
  481. WHERE 1 = 1
  482. <if test="reqVO.username != null and reqVO.username != ''">
  483. AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
  484. </if>
  485. <if test="reqVO.email != null and reqVO.email != ''">
  486. AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
  487. </if>
  488. <if test="reqVO.mobile != null and reqVO.mobile != ''">
  489. AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
  490. </if>
  491. <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
  492. AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
  493. </if>
  494. <if test="reqVO.nickname != null and reqVO.nickname != ''">
  495. AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
  496. </if>
  497. <if test="reqVO.userType != null">
  498. AND a.user_type = #{reqVO.userType}
  499. </if>
  500. <if test="reqVO.grade != '' and reqVO.grade != null ">
  501. AND a.grade = #{reqVO.grade}
  502. </if>
  503. <if test="reqVO.supervisorId != null and reqVO.supervisorId != '' ">
  504. AND a.supervisor_id = #{reqVO.supervisorId}
  505. </if>
  506. <if test="reqVO.major != null and reqVO.major != '' ">
  507. AND a.major = #{reqVO.major}
  508. </if>
  509. <if test="reqVO.masterType != null and reqVO.masterType != '' ">
  510. AND a.masterType = #{reqVO.masterType}
  511. </if>
  512. <if test="reqVO.status != null and reqVO.status != '' ">
  513. AND a.status = #{reqVO.status}
  514. </if>
  515. AND a.deleted = 0
  516. GROUP BY a.id
  517. <!-- 合并 HAVING 条件 -->
  518. HAVING
  519. CASE
  520. WHEN COALESCE(MAX(r.select_type), 0) = 2 THEN 2
  521. WHEN COALESCE(MAX(r.select_type), 0) = 1 THEN 1
  522. ELSE 0
  523. END
  524. <choose>
  525. <when test="isPassed == 0">IN (0, 1)</when>
  526. <when test="isPassed == 1">= 2</when>
  527. </choose>
  528. ) AS subquery;
  529. </select>
  530. </mapper>