SeizureReportMapper.xml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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="com.sundot.airport.item.mapper.SeizureReportMapper">
  4. <!-- 查询本人查获数量 -->
  5. <select id="selectSelfSeizureCount" resultType="java.math.BigDecimal">
  6. SELECT COALESCE(SUM(isi.quantity), 0) AS seizure_count
  7. FROM item_seizure_record isr
  8. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  9. WHERE isr.process_status=3 AND isr.inspect_user_id = #{userId}
  10. <if test="startDate != null and endDate != null">
  11. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  12. </if>
  13. </select>
  14. <!-- 查询班组查获总数 -->
  15. <select id="selectTeamAverage" resultType="java.math.BigDecimal">
  16. SELECT COALESCE(SUM(isi.quantity), 0) AS total_team_seizure
  17. FROM item_seizure_record isr
  18. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  19. WHERE isr.inspect_team_id = #{deptId}
  20. AND isr.process_status=3
  21. <if test="startDate != null and endDate != null">
  22. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  23. </if>
  24. </select>
  25. <!-- 科室查获总数 -->
  26. <select id="selectDepartmentAverage" resultType="java.math.BigDecimal">
  27. SELECT COALESCE(SUM(isi.quantity), 0) AS department_seizure
  28. FROM item_seizure_record isr
  29. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  30. WHERE isr.process_status=3 AND isr.inspect_department_id = #{deptId}
  31. <if test="startDate != null and endDate != null">
  32. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  33. </if>
  34. </select>
  35. <!-- 大队查获总数 -->
  36. <select id="selectBrigadeAverage" resultType="java.math.BigDecimal">
  37. SELECT COALESCE(SUM(isi.quantity), 0) AS brigade_seizure
  38. FROM item_seizure_record isr
  39. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  40. WHERE isr.process_status=3 AND isr.inspect_brigade_id = #{deptId}
  41. <if test="startDate != null and endDate != null">
  42. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  43. </if>
  44. </select>
  45. <!-- 全站查获总数 -->
  46. <select id="selectStationAverage" resultType="java.math.BigDecimal">
  47. SELECT COALESCE(SUM(isi.quantity), 0) AS station_seizure
  48. FROM item_seizure_record isr
  49. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  50. WHERE isr.process_status=3 AND isr.inspect_station_id = #{deptId}
  51. <if test="startDate != null and endDate != null">
  52. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  53. </if>
  54. </select>
  55. <!-- 查询待处理数据数量 -->
  56. <select id="selectPendingCount" resultType="java.lang.Integer">
  57. SELECT COUNT(*)
  58. FROM approval_instance ai
  59. JOIN approval_task at ON ai.id = at.instance_id
  60. WHERE ai.workflow_id IN (4, 5) -- 查获审批流程
  61. AND at.status = 'PENDING' -- 待审批状态
  62. AND at.assignee_id = #{userId} -- 分配给当前用户的任务
  63. <if test="startDate != null and endDate != null">
  64. AND ai.submit_time BETWEEN #{startDate} AND #{endDate}
  65. </if>
  66. </select>
  67. <!-- 查询排名信息 - -->
  68. <select id="selectRankingInfo" resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$RankingInfo">
  69. SELECT
  70. ranking AS current_rank,
  71. total_users AS total_items,
  72. CASE
  73. WHEN ranking &lt;= 3 THEN 'GREEN'
  74. ELSE 'RED'
  75. END AS color
  76. FROM (
  77. SELECT
  78. user_id,
  79. total_seizure,
  80. @rank := @rank + 1 AS ranking,
  81. @total_users AS total_items
  82. FROM (
  83. SELECT
  84. isr.inspect_user_id AS user_id,
  85. SUM(isi.quantity) AS total_seizure
  86. FROM item_seizure_record isr
  87. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  88. WHERE
  89. <if test="level == 'team'">
  90. isr.inspect_team_id = #{deptId}
  91. </if>
  92. <if test="level == 'department'">
  93. isr.inspect_department_id = #{deptId}
  94. </if>
  95. <if test="level == 'station'">
  96. isr.inspect_station_id = #{deptId}
  97. </if>
  98. AND isr.process_status=3
  99. <if test="startDate != null and endDate != null">
  100. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  101. </if>
  102. GROUP BY isr.inspect_user_id
  103. ORDER BY total_seizure DESC
  104. ) ranked_users
  105. CROSS JOIN (SELECT @rank := 0) r1,
  106. (SELECT @total_users := (
  107. SELECT COUNT(DISTINCT isr.inspect_user_id)
  108. FROM item_seizure_record isr
  109. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  110. WHERE
  111. <if test="level == 'team'">
  112. isr.inspect_team_id = #{deptId}
  113. </if>
  114. <if test="level == 'department'">
  115. isr.inspect_department_id = #{deptId}
  116. </if>
  117. <if test="level == 'station'">
  118. isr.inspect_station_id = #{deptId}
  119. </if>
  120. AND isr.process_status=3
  121. <if test="startDate != null and endDate != null">
  122. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  123. </if>
  124. )) r2
  125. ) ranked_result
  126. WHERE user_id = #{userId}
  127. </select>
  128. <!-- 查询个人排名-->
  129. <select id="selectSelfRanking" resultType="java.lang.Integer">
  130. SELECT ranking
  131. FROM (
  132. SELECT
  133. user_id,
  134. total_seizure,
  135. @rank := @rank + 1 AS ranking
  136. FROM (
  137. SELECT
  138. isr.inspect_user_id AS user_id,
  139. SUM(isi.quantity) AS total_seizure
  140. FROM item_seizure_record isr
  141. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  142. WHERE
  143. <if test="level == 'team'">
  144. isr.inspect_team_id = #{deptId}
  145. </if>
  146. <if test="level == 'department'">
  147. isr.inspect_department_id = #{deptId}
  148. </if>
  149. <if test="level == 'brigade'">
  150. isr.inspect_brigade_id = #{deptId}
  151. </if>
  152. <if test="level == 'station'">
  153. isr.inspect_station_id = #{deptId}
  154. </if>
  155. AND isr.process_status=3
  156. <if test="startDate != null and endDate != null">
  157. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  158. </if>
  159. GROUP BY isr.inspect_user_id
  160. ORDER BY total_seizure DESC
  161. ) ranked_users
  162. CROSS JOIN (SELECT @rank := 0) r
  163. ) ranked_result
  164. WHERE user_id = #{userId}
  165. </select>
  166. <!-- 查询班组部门ID(根据用户ID) -->
  167. <select id="selectSectionDeptIdByUserId" resultType="java.lang.Long">
  168. SELECT dept_id
  169. FROM sys_user
  170. WHERE user_id = #{userId}
  171. </select>
  172. <!-- 查询科室部门ID(根据班组ID) -->
  173. <select id="selectSectionDeptIdByTeamId" resultType="java.lang.Long">
  174. SELECT parent_id
  175. FROM sys_dept
  176. WHERE dept_id = #{teamId}
  177. </select>
  178. <!-- 查询站点部门ID(根据部门ID) -->
  179. <select id="selectStationDeptIdByDeptId" resultType="java.lang.Long">
  180. SELECT parent_id
  181. FROM sys_dept
  182. WHERE dept_id = #{deptId}
  183. </select>
  184. <!-- 查询全站查获总数 -->
  185. <select id="selectTotalStationSeizure" resultType="java.math.BigDecimal">
  186. SELECT COALESCE(SUM(isi.quantity), 0) AS total_seizure
  187. FROM item_seizure_record isr
  188. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  189. WHERE isr.process_status=3 AND isr.inspect_station_id = #{deptId}
  190. <if test="startDate != null and endDate != null">
  191. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  192. </if>
  193. </select>
  194. <!-- 查询科室排名 -->
  195. <select id="selectDepartmentRankings"
  196. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$DepartmentRankingItem">
  197. SELECT
  198. sd.dept_name AS departmentName,
  199. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  200. FROM sys_dept sd
  201. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_department_id
  202. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  203. AND isr.process_status = 3
  204. <if test="startDate != null and endDate != null">
  205. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  206. </if>
  207. WHERE sd.parent_id IN (SELECT dept_id
  208. FROM sys_dept
  209. WHERE parent_id = #{deptId}
  210. AND del_flag = '0'
  211. AND dept_type = 'BRIGADE')
  212. AND sd.del_flag = '0'
  213. AND sd.dept_type = 'MANAGER' -- 确保是科室
  214. GROUP BY sd.dept_id, sd.dept_name
  215. ORDER BY seizureCount DESC
  216. </select>
  217. <!-- 查询科室排名 -->
  218. <select id="selectBrigadeRankings"
  219. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$BrigadeRankingItem">
  220. SELECT sd.dept_name AS brigadeName,
  221. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  222. FROM sys_dept sd
  223. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_brigade_id
  224. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  225. AND isr.process_status = 3
  226. <if test="startDate != null and endDate != null">
  227. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  228. </if>
  229. WHERE sd.parent_id = #{deptId}
  230. AND sd.del_flag = '0'
  231. AND sd.dept_type = 'BRIGADE'
  232. GROUP BY sd.dept_id, sd.dept_name
  233. ORDER BY seizureCount DESC
  234. </select>
  235. <!-- 查询排名前三的班组 -->
  236. <select id="selectTopThreeTeams" resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TopThreeTeamItem">
  237. SELECT
  238. sd.dept_name AS teamName,
  239. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  240. FROM sys_dept sd
  241. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_team_id
  242. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  243. AND isr.process_status = 3
  244. <if test="startDate != null and endDate != null">
  245. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  246. </if>
  247. WHERE sd.parent_id = #{deptId} -- 假设parent_id是科室ID
  248. AND sd.del_flag = '0'
  249. AND sd.dept_type = 'TEAMS' -- 确保是班组
  250. GROUP BY sd.dept_id, sd.dept_name
  251. ORDER BY seizureCount DESC
  252. LIMIT 3
  253. </select>
  254. <!-- 查询排名前三的科室 -->
  255. <select id="selectTopThreeDepartment"
  256. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TopThreeDepartmentItem">
  257. SELECT
  258. sd.dept_name AS departmentName,
  259. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  260. FROM sys_dept sd
  261. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_department_id
  262. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  263. AND isr.process_status = 3
  264. <if test="startDate != null and endDate != null">
  265. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  266. </if>
  267. WHERE sd.parent_id = #{deptId}
  268. AND sd.del_flag = '0'
  269. AND sd.dept_type = 'MANAGER'
  270. GROUP BY sd.dept_id, sd.dept_name
  271. ORDER BY seizureCount DESC
  272. LIMIT 3
  273. </select>
  274. <!-- 查询前三名的班组排名 -->
  275. <select id="selectTopThreeTeamRankings"
  276. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TeamRankingItem">
  277. SELECT CONCAT(sd3.dept_name, sd2.dept_name, sd.dept_name) AS teamName, -- 大队名称+科室名称+班组名称
  278. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  279. FROM sys_dept sd
  280. LEFT JOIN sys_dept sd2 ON sd.parent_id = sd2.dept_id -- 获取科室名称
  281. LEFT JOIN sys_dept sd3 ON sd2.parent_id = sd3.dept_id -- 获取大队名称
  282. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_team_id
  283. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  284. AND isr.process_status = 3
  285. <if test="startDate != null and endDate != null">
  286. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  287. </if>
  288. WHERE sd.parent_id IN (SELECT dept_id
  289. FROM sys_dept
  290. WHERE parent_id IN (SELECT dept_id
  291. FROM sys_dept
  292. WHERE parent_id = #{deptId}
  293. AND del_flag = '0'
  294. AND dept_type = 'BRIGADE')
  295. AND del_flag = '0'
  296. AND dept_type = 'MANAGER')
  297. AND sd.del_flag = '0'
  298. AND sd.dept_type = 'TEAMS' -- 确保是班组
  299. GROUP BY sd.dept_id, sd.dept_name, sd2.dept_name, sd3.dept_name
  300. ORDER BY seizureCount
  301. <choose>
  302. <when test="order == 'desc' or order == null">
  303. DESC
  304. </when>
  305. <otherwise>
  306. ASC
  307. </otherwise>
  308. </choose>
  309. LIMIT 3
  310. </select>
  311. <!-- 查询前三名的科室排名 -->
  312. <select id="selectTopThreeDepartmentRankings"
  313. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$DepartmentRankingItem">
  314. SELECT CONCAT(sd2.dept_name, sd.dept_name) AS departmentName, -- 科室名称+班组名称
  315. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  316. FROM sys_dept sd
  317. LEFT JOIN sys_dept sd2 ON sd.parent_id = sd2.dept_id
  318. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_department_id
  319. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  320. AND isr.process_status = 3
  321. <if test="startDate != null and endDate != null">
  322. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  323. </if>
  324. WHERE sd.parent_id IN (SELECT dept_id
  325. FROM sys_dept
  326. WHERE parent_id = #{deptId}
  327. AND del_flag = '0'
  328. AND dept_type = 'BRIGADE')
  329. AND sd.del_flag = '0'
  330. AND sd.dept_type = 'MANAGER'
  331. GROUP BY sd.dept_id, sd.dept_name, sd2.dept_name
  332. ORDER BY seizureCount
  333. <choose>
  334. <when test="order == 'desc' or order == null">
  335. DESC
  336. </when>
  337. <otherwise>
  338. ASC
  339. </otherwise>
  340. </choose>
  341. LIMIT 3
  342. </select>
  343. <!-- 查询班组长查获总数 -->
  344. <select id="selectTeamSeizure" resultType="java.math.BigDecimal">
  345. SELECT COALESCE(SUM(isi.quantity), 0) AS team_seizure
  346. FROM item_seizure_record isr
  347. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  348. WHERE isr.inspect_team_id = #{deptId}
  349. AND isr.process_status=3
  350. <if test="startDate != null and endDate != null">
  351. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  352. </if>
  353. </select>
  354. <!-- 查询科室查获总数 -->
  355. <select id="selectDepartmentSeizure" resultType="java.math.BigDecimal">
  356. SELECT COALESCE(SUM(isi.quantity), 0) AS department_seizure
  357. FROM item_seizure_record isr
  358. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  359. WHERE isr.inspect_department_id = #{deptId}
  360. AND isr.process_status=3
  361. <if test="startDate != null and endDate != null">
  362. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  363. </if>
  364. </select>
  365. <!-- 查询大队查获总数 -->
  366. <select id="selectBrigadeSeizure" resultType="java.math.BigDecimal">
  367. SELECT COALESCE(SUM(isi.quantity), 0) AS brigade_seizure
  368. FROM item_seizure_record isr
  369. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  370. WHERE isr.inspect_brigade_id = #{deptId}
  371. AND isr.process_status=3
  372. <if test="startDate != null and endDate != null">
  373. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  374. </if>
  375. </select>
  376. <!-- 查询科室下的班组总数 -->
  377. <select id="selectTeamCountByDepartmentId" resultType="java.lang.Integer">
  378. SELECT COUNT(*) AS team_count
  379. FROM sys_dept
  380. WHERE parent_id = #{deptId} -- 科室ID
  381. AND del_flag = '0'
  382. AND dept_type = 'TEAMS' -- 确保是班组
  383. </select>
  384. <!-- 查询大队下的班组总数 -->
  385. <select id="selectTeamCountByBrigadeId" resultType="java.lang.Integer">
  386. SELECT COUNT(*) AS team_count
  387. FROM sys_dept
  388. WHERE parent_id IN (SELECT dept_id
  389. FROM sys_dept
  390. WHERE parent_id = #{deptId}
  391. AND del_flag = '0'
  392. AND dept_type = 'MANAGER')
  393. AND del_flag = '0'
  394. AND dept_type = 'TEAMS'
  395. </select>
  396. <!-- 查询全站下的班组总数 -->
  397. <select id="selectTeamCountByStationId" resultType="java.lang.Integer">
  398. SELECT COUNT(*) AS team_count
  399. FROM sys_dept sd
  400. WHERE sd.parent_id IN (SELECT dept_id
  401. FROM sys_dept
  402. WHERE parent_id IN (SELECT dept_id
  403. FROM sys_dept
  404. WHERE parent_id = #{deptId}
  405. AND del_flag = '0'
  406. AND dept_type = 'BRIGADE')
  407. AND del_flag = '0'
  408. AND dept_type = 'MANAGER')
  409. AND sd.del_flag = '0'
  410. AND sd.dept_type = 'TEAMS'
  411. </select>
  412. <!-- 查询科室下所有班组的排名 -->
  413. <select id="selectAllTeamRankingsInDepartment"
  414. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TeamRankingItem">
  415. SELECT
  416. sd.dept_name AS teamName,
  417. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  418. FROM sys_dept sd
  419. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_team_id
  420. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  421. AND isr.process_status = 3
  422. <if test="startDate != null and endDate != null">
  423. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  424. </if>
  425. WHERE sd.parent_id = #{deptId} -- 科室ID
  426. AND sd.del_flag = '0'
  427. AND sd.dept_type = 'TEAMS' -- 确保是班组
  428. GROUP BY sd.dept_id, sd.dept_name
  429. ORDER BY seizureCount DESC
  430. </select>
  431. <!-- 查询大队下所有班组的排名 -->
  432. <select id="selectAllTeamRankingsInBrigade"
  433. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TeamRankingItem">
  434. SELECT CONCAT(sd2.dept_name, sd.dept_name) AS teamName, -- 科室名称+班组名称
  435. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  436. FROM sys_dept sd
  437. LEFT JOIN sys_dept sd2 ON sd.parent_id = sd2.dept_id -- 获取科室名称
  438. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_team_id
  439. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  440. AND isr.process_status = 3
  441. <if test="startDate != null and endDate != null">
  442. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  443. </if>
  444. WHERE sd.parent_id IN (SELECT dept_id
  445. FROM sys_dept
  446. WHERE parent_id = #{deptId}
  447. AND del_flag = '0'
  448. AND dept_type = 'MANAGER')
  449. AND sd.del_flag = '0'
  450. AND sd.dept_type = 'TEAMS' -- 确保是班组
  451. GROUP BY sd.dept_id, sd.dept_name, sd2.dept_name
  452. ORDER BY seizureCount DESC
  453. </select>
  454. <!-- 查询全站下所有班组的排名 -->
  455. <select id="selectAllTeamRankingsInStation"
  456. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TeamRankingItem">
  457. SELECT CONCAT(sd3.dept_name, sd2.dept_name, sd.dept_name) AS teamName, -- 大队名称+科室名称+班组名称
  458. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  459. FROM sys_dept sd
  460. LEFT JOIN sys_dept sd2 ON sd.parent_id = sd2.dept_id -- 获取科室名称
  461. LEFT JOIN sys_dept sd3 ON sd2.parent_id = sd3.dept_id -- 获取大队名称
  462. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_team_id
  463. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  464. AND isr.process_status = 3
  465. <if test="startDate != null and endDate != null">
  466. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  467. </if>
  468. WHERE sd.parent_id IN (SELECT dept_id
  469. FROM sys_dept
  470. WHERE parent_id IN (SELECT dept_id
  471. FROM sys_dept
  472. WHERE parent_id = #{deptId}
  473. AND del_flag = '0'
  474. AND dept_type = 'BRIGADE')
  475. AND del_flag = '0'
  476. AND dept_type = 'MANAGER')
  477. AND sd.del_flag = '0'
  478. AND sd.dept_type = 'TEAMS' -- 确保是班组
  479. GROUP BY sd.dept_id, sd.dept_name, sd2.dept_name, sd3.dept_name
  480. ORDER BY seizureCount DESC
  481. </select>
  482. <!-- 查询班组下用户总数 -->
  483. <select id="selectUserCountByTeamId" resultType="java.lang.Integer">
  484. SELECT COUNT(DISTINCT user_id) AS user_count
  485. FROM sys_user
  486. WHERE dept_id = #{deptId}
  487. AND del_flag = '0'
  488. </select>
  489. <!-- 查询科室下用户总数(包括科室下所有班组的用户) -->
  490. <select id="selectUserCountByDepartmentId" resultType="java.lang.Integer">
  491. SELECT COUNT(DISTINCT user_id) AS user_count
  492. FROM sys_user
  493. WHERE dept_id IN
  494. (SELECT dept_id
  495. FROM sys_dept
  496. WHERE parent_id = #{deptId}
  497. AND del_flag = '0'
  498. AND dept_type = 'TEAMS')
  499. AND del_flag = '0'
  500. </select>
  501. <!-- 查询大队下用户总数(包括大队下所有科室下所有班组的用户) -->
  502. <select id="selectUserCountByBrigadeId" resultType="java.lang.Integer">
  503. SELECT COUNT(DISTINCT user_id) AS user_count
  504. FROM sys_user
  505. WHERE dept_id IN (SELECT dept_id
  506. FROM sys_dept
  507. WHERE parent_id IN (SELECT dept_id
  508. FROM sys_dept
  509. WHERE parent_id = #{deptId}
  510. AND del_flag = '0'
  511. AND dept_type = 'MANAGER')
  512. AND del_flag = '0'
  513. AND dept_type = 'TEAMS')
  514. AND del_flag = '0'
  515. </select>
  516. <!-- 查询全站下用户总数(包括全站下所有科室和班组的用户) -->
  517. <select id="selectUserCountByStationId" resultType="java.lang.Integer">
  518. SELECT COUNT(DISTINCT user_id) AS user_count
  519. FROM sys_user
  520. WHERE dept_id IN (SELECT dept_id
  521. FROM sys_dept
  522. WHERE parent_id IN (SELECT dept_id
  523. FROM sys_dept
  524. WHERE parent_id in
  525. (SELECT dept_id
  526. FROM sys_dept
  527. WHERE parent_id = #{deptId}
  528. AND del_flag = '0'
  529. AND dept_type = 'BRIGADE')
  530. AND del_flag = '0'
  531. AND dept_type = 'MANAGER')
  532. AND del_flag = '0'
  533. AND dept_type = 'TEAMS')
  534. AND del_flag = '0'
  535. </select>
  536. <!-- 查询全站下科室总数 -->
  537. <select id="selectDepartmentCountByStationId" resultType="java.lang.Integer">
  538. SELECT COUNT(*) AS department_count
  539. FROM sys_dept
  540. WHERE parent_id in (SELECT dept_id
  541. FROM sys_dept
  542. WHERE parent_id = #{deptId}
  543. AND del_flag = '0'
  544. AND dept_type = 'BRIGADE')
  545. AND del_flag = '0'
  546. AND dept_type = 'MANAGER'
  547. </select>
  548. <!-- 查询全站下大队总数 -->
  549. <select id="selectBrigadeCountByStationId" resultType="java.lang.Integer">
  550. SELECT COUNT(*) AS brigade_count
  551. FROM sys_dept
  552. WHERE parent_id = #{deptId}
  553. AND del_flag = '0'
  554. AND dept_type = 'BRIGADE'
  555. </select>
  556. <!-- 查询全大队下科室总数 -->
  557. <select id="selectDepartmentCountByBrigadeId" resultType="java.lang.Integer">
  558. SELECT COUNT(*) AS department_count
  559. FROM sys_dept
  560. WHERE parent_id = #{deptId} -- 大队ID下的科室
  561. AND del_flag = '0'
  562. AND dept_type = 'MANAGER' -- 确保是科室
  563. </select>
  564. <!-- 查询全站下所有科室的排名 -->
  565. <select id="selectAllDepartmentRankingsInStation"
  566. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$DepartmentRankingItem">
  567. SELECT sd.dept_name AS departmentName,
  568. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  569. FROM sys_dept sd
  570. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_department_id
  571. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  572. AND isr.process_status = 3
  573. WHERE sd.parent_id in (SELECT dept_id
  574. FROM sys_dept
  575. WHERE parent_id = #{deptId}
  576. AND del_flag = '0'
  577. AND dept_type = 'BRIGADE')
  578. AND sd.del_flag = '0'
  579. AND sd.dept_type = 'MANAGER'
  580. GROUP BY sd.dept_id, sd.dept_name
  581. ORDER BY seizureCount DESC
  582. </select>
  583. <!-- 查询全站下所有大队的排名 -->
  584. <select id="selectAllBrigadeRankingsInStation"
  585. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$BrigadeRankingItem">
  586. SELECT sd.dept_name AS departmentName,
  587. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  588. FROM sys_dept sd
  589. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_brigade_id
  590. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  591. AND isr.process_status = 3
  592. WHERE sd.parent_id = #{deptId}
  593. AND sd.del_flag = '0'
  594. AND sd.dept_type = 'BRIGADE'
  595. GROUP BY sd.dept_id, sd.dept_name
  596. ORDER BY seizureCount DESC
  597. </select>
  598. <!-- 查询全站下所有科室的排名 -->
  599. <select id="selectAllDepartmentRankingsInBrigade"
  600. resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$DepartmentRankingItem">
  601. SELECT
  602. sd.dept_name AS departmentName,
  603. COALESCE(SUM(isi.quantity), 0) AS seizureCount
  604. FROM sys_dept sd
  605. LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_department_id
  606. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  607. AND isr.process_status = 3
  608. <if test="startDate != null and endDate != null">
  609. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  610. </if>
  611. WHERE sd.parent_id = #{deptId}
  612. AND sd.del_flag = '0'
  613. AND sd.dept_type = 'MANAGER'
  614. GROUP BY sd.dept_id, sd.dept_name
  615. ORDER BY seizureCount DESC
  616. </select>
  617. <!-- 查询全站范围内查获数量的最大值 -->
  618. <select id="selectMaxSeizureCountInStation" resultType="java.math.BigDecimal">
  619. SELECT COALESCE(MAX(user_seizure_count), 0) AS max_seizure_count
  620. FROM (
  621. SELECT SUM(isi.quantity) AS user_seizure_count
  622. FROM item_seizure_record isr
  623. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  624. WHERE isr.process_status = 3
  625. AND isr.inspect_station_id = #{deptId}
  626. <if test="startDate != null and endDate != null">
  627. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  628. </if>
  629. GROUP BY isr.inspect_user_id
  630. ) AS user_totals
  631. </select>
  632. <!-- 查询草稿箱中数据数量 -->
  633. <select id="selectDraftItemCount" resultType="java.lang.Integer">
  634. SELECT COUNT(*)
  635. FROM item_seizure_record isr
  636. WHERE isr.inspect_user_id = #{userId}
  637. AND isr.process_status = '0' -- 草稿状态
  638. <if test="startDate != null and endDate != null">
  639. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  640. </if>
  641. </select>
  642. <!-- 查询查获总数 -->
  643. <select id="selectAverage" resultType="java.math.BigDecimal">
  644. SELECT COALESCE(SUM(isi.quantity), 0) AS total_team_seizure
  645. FROM item_seizure_record isr
  646. LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
  647. WHERE isr.inspect_user_id in
  648. <foreach collection="list" item="item" open="(" separator="," close=")">
  649. #{item}
  650. </foreach>
  651. AND isr.process_status=3
  652. <if test="startDate != null and endDate != null">
  653. AND isr.create_time BETWEEN #{startDate} AND #{endDate}
  654. </if>
  655. </select>
  656. </mapper>