AdminUserMapper.xml 20 KB

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