| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.sundot.airport.item.mapper.SeizureReportMapper">
- <!-- 查询本人查获数量 -->
- <select id="selectSelfSeizureCount" resultType="java.math.BigDecimal">
- SELECT COALESCE(SUM(isi.quantity), 0) AS seizure_count
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.process_status=3 AND isr.inspect_user_id = #{userId}
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 查询班组查获总数 -->
- <select id="selectTeamAverage" resultType="java.math.BigDecimal">
- SELECT COALESCE(SUM(isi.quantity), 0) AS total_team_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.inspect_team_id = #{deptId}
- AND isr.process_status=3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 科室查获总数 -->
- <select id="selectDepartmentAverage" resultType="java.math.BigDecimal">
- SELECT COALESCE(SUM(isi.quantity), 0) AS department_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.process_status=3 AND isr.inspect_department_id = #{deptId}
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 大队查获总数 -->
- <select id="selectBrigadeAverage" resultType="java.math.BigDecimal">
- SELECT COALESCE(SUM(isi.quantity), 0) AS brigade_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.process_status=3 AND isr.inspect_brigade_id = #{deptId}
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 全站查获总数 -->
- <select id="selectStationAverage" resultType="java.math.BigDecimal">
- SELECT COALESCE(SUM(isi.quantity), 0) AS station_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.process_status=3 AND isr.inspect_station_id = #{deptId}
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 查询待处理数据数量 -->
- <select id="selectPendingCount" resultType="java.lang.Integer">
- SELECT COUNT(*)
- FROM approval_instance ai
- JOIN approval_task at ON ai.id = at.instance_id
- WHERE ai.workflow_id IN (4, 5) -- 查获审批流程
- AND at.status = 'PENDING' -- 待审批状态
- AND at.assignee_id = #{userId} -- 分配给当前用户的任务
- <if test="startDate != null and endDate != null">
- AND ai.submit_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 查询排名信息 - -->
- <select id="selectRankingInfo" resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$RankingInfo">
- SELECT
- ranking AS current_rank,
- total_users AS total_items,
- CASE
- WHEN ranking <= 3 THEN 'GREEN'
- ELSE 'RED'
- END AS color
- FROM (
- SELECT
- user_id,
- total_seizure,
- @rank := @rank + 1 AS ranking,
- @total_users AS total_items
- FROM (
- SELECT
- isr.inspect_user_id AS user_id,
- SUM(isi.quantity) AS total_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE
- <if test="level == 'team'">
- isr.inspect_team_id = #{deptId}
- </if>
- <if test="level == 'department'">
- isr.inspect_department_id = #{deptId}
- </if>
- <if test="level == 'station'">
- isr.inspect_station_id = #{deptId}
- </if>
- AND isr.process_status=3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- GROUP BY isr.inspect_user_id
- ORDER BY total_seizure DESC
- ) ranked_users
- CROSS JOIN (SELECT @rank := 0) r1,
- (SELECT @total_users := (
- SELECT COUNT(DISTINCT isr.inspect_user_id)
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE
- <if test="level == 'team'">
- isr.inspect_team_id = #{deptId}
- </if>
- <if test="level == 'department'">
- isr.inspect_department_id = #{deptId}
- </if>
- <if test="level == 'station'">
- isr.inspect_station_id = #{deptId}
- </if>
- AND isr.process_status=3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- )) r2
- ) ranked_result
- WHERE user_id = #{userId}
- </select>
- <!-- 查询个人排名-->
- <select id="selectSelfRanking" resultType="java.lang.Integer">
- SELECT ranking
- FROM (
- SELECT
- user_id,
- total_seizure,
- @rank := @rank + 1 AS ranking
- FROM (
- SELECT
- isr.inspect_user_id AS user_id,
- SUM(isi.quantity) AS total_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE
- <if test="level == 'team'">
- isr.inspect_team_id = #{deptId}
- </if>
- <if test="level == 'department'">
- isr.inspect_department_id = #{deptId}
- </if>
- <if test="level == 'brigade'">
- isr.inspect_brigade_id = #{deptId}
- </if>
- <if test="level == 'station'">
- isr.inspect_station_id = #{deptId}
- </if>
- AND isr.process_status=3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- GROUP BY isr.inspect_user_id
- ORDER BY total_seizure DESC
- ) ranked_users
- CROSS JOIN (SELECT @rank := 0) r
- ) ranked_result
- WHERE user_id = #{userId}
- </select>
- <!-- 查询班组部门ID(根据用户ID) -->
- <select id="selectSectionDeptIdByUserId" resultType="java.lang.Long">
- SELECT dept_id
- FROM sys_user
- WHERE user_id = #{userId}
- </select>
- <!-- 查询科室部门ID(根据班组ID) -->
- <select id="selectSectionDeptIdByTeamId" resultType="java.lang.Long">
- SELECT parent_id
- FROM sys_dept
- WHERE dept_id = #{teamId}
- </select>
- <!-- 查询站点部门ID(根据部门ID) -->
- <select id="selectStationDeptIdByDeptId" resultType="java.lang.Long">
- SELECT parent_id
- FROM sys_dept
- WHERE dept_id = #{deptId}
- </select>
- <!-- 查询全站查获总数 -->
- <select id="selectTotalStationSeizure" resultType="java.math.BigDecimal">
- SELECT COALESCE(SUM(isi.quantity), 0) AS total_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.process_status=3 AND isr.inspect_station_id = #{deptId}
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 查询科室排名 -->
- <select id="selectDepartmentRankings"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$DepartmentRankingItem">
- SELECT
- sd.dept_name AS departmentName,
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_department_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- WHERE sd.parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'BRIGADE')
- AND sd.del_flag = '0'
- AND sd.dept_type = 'MANAGER' -- 确保是科室
- GROUP BY sd.dept_id, sd.dept_name
- ORDER BY seizureCount DESC
- </select>
- <!-- 查询科室排名 -->
- <select id="selectBrigadeRankings"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$BrigadeRankingItem">
- SELECT sd.dept_name AS brigadeName,
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_brigade_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- WHERE sd.parent_id = #{deptId}
- AND sd.del_flag = '0'
- AND sd.dept_type = 'BRIGADE'
- GROUP BY sd.dept_id, sd.dept_name
- ORDER BY seizureCount DESC
- </select>
- <!-- 查询排名前三的班组 -->
- <select id="selectTopThreeTeams" resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TopThreeTeamItem">
- SELECT
- sd.dept_name AS teamName,
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_team_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- WHERE sd.parent_id = #{deptId} -- 假设parent_id是科室ID
- AND sd.del_flag = '0'
- AND sd.dept_type = 'TEAMS' -- 确保是班组
- GROUP BY sd.dept_id, sd.dept_name
- ORDER BY seizureCount DESC
- LIMIT 3
- </select>
- <!-- 查询排名前三的科室 -->
- <select id="selectTopThreeDepartment"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TopThreeDepartmentItem">
- SELECT
- sd.dept_name AS departmentName,
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_department_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- WHERE sd.parent_id = #{deptId}
- AND sd.del_flag = '0'
- AND sd.dept_type = 'MANAGER'
- GROUP BY sd.dept_id, sd.dept_name
- ORDER BY seizureCount DESC
- LIMIT 3
- </select>
- <!-- 查询前三名的班组排名 -->
- <select id="selectTopThreeTeamRankings"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TeamRankingItem">
- SELECT CONCAT(sd3.dept_name, sd2.dept_name, sd.dept_name) AS teamName, -- 大队名称+科室名称+班组名称
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN sys_dept sd2 ON sd.parent_id = sd2.dept_id -- 获取科室名称
- LEFT JOIN sys_dept sd3 ON sd2.parent_id = sd3.dept_id -- 获取大队名称
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_team_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- WHERE sd.parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'BRIGADE')
- AND del_flag = '0'
- AND dept_type = 'MANAGER')
- AND sd.del_flag = '0'
- AND sd.dept_type = 'TEAMS' -- 确保是班组
- GROUP BY sd.dept_id, sd.dept_name, sd2.dept_name, sd3.dept_name
- ORDER BY seizureCount
- <choose>
- <when test="order == 'desc' or order == null">
- DESC
- </when>
- <otherwise>
- ASC
- </otherwise>
- </choose>
- LIMIT 3
- </select>
- <!-- 查询前三名的科室排名 -->
- <select id="selectTopThreeDepartmentRankings"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$DepartmentRankingItem">
- SELECT CONCAT(sd2.dept_name, sd.dept_name) AS departmentName, -- 科室名称+班组名称
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN sys_dept sd2 ON sd.parent_id = sd2.dept_id
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_department_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- WHERE sd.parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'BRIGADE')
- AND sd.del_flag = '0'
- AND sd.dept_type = 'MANAGER'
- GROUP BY sd.dept_id, sd.dept_name, sd2.dept_name
- ORDER BY seizureCount
- <choose>
- <when test="order == 'desc' or order == null">
- DESC
- </when>
- <otherwise>
- ASC
- </otherwise>
- </choose>
- LIMIT 3
- </select>
- <!-- 查询班组长查获总数 -->
- <select id="selectTeamSeizure" resultType="java.math.BigDecimal">
- SELECT COALESCE(SUM(isi.quantity), 0) AS team_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.inspect_team_id = #{deptId}
- AND isr.process_status=3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 查询科室查获总数 -->
- <select id="selectDepartmentSeizure" resultType="java.math.BigDecimal">
- SELECT COALESCE(SUM(isi.quantity), 0) AS department_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.inspect_department_id = #{deptId}
- AND isr.process_status=3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 查询大队查获总数 -->
- <select id="selectBrigadeSeizure" resultType="java.math.BigDecimal">
- SELECT COALESCE(SUM(isi.quantity), 0) AS brigade_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.inspect_brigade_id = #{deptId}
- AND isr.process_status=3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 查询科室下的班组总数 -->
- <select id="selectTeamCountByDepartmentId" resultType="java.lang.Integer">
- SELECT COUNT(*) AS team_count
- FROM sys_dept
- WHERE parent_id = #{deptId} -- 科室ID
- AND del_flag = '0'
- AND dept_type = 'TEAMS' -- 确保是班组
- </select>
- <!-- 查询大队下的班组总数 -->
- <select id="selectTeamCountByBrigadeId" resultType="java.lang.Integer">
- SELECT COUNT(*) AS team_count
- FROM sys_dept
- WHERE parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'MANAGER')
- AND del_flag = '0'
- AND dept_type = 'TEAMS'
- </select>
- <!-- 查询全站下的班组总数 -->
- <select id="selectTeamCountByStationId" resultType="java.lang.Integer">
- SELECT COUNT(*) AS team_count
- FROM sys_dept sd
- WHERE sd.parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'BRIGADE')
- AND del_flag = '0'
- AND dept_type = 'MANAGER')
- AND sd.del_flag = '0'
- AND sd.dept_type = 'TEAMS'
- </select>
- <!-- 查询科室下所有班组的排名 -->
- <select id="selectAllTeamRankingsInDepartment"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TeamRankingItem">
- SELECT
- sd.dept_name AS teamName,
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_team_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- WHERE sd.parent_id = #{deptId} -- 科室ID
- AND sd.del_flag = '0'
- AND sd.dept_type = 'TEAMS' -- 确保是班组
- GROUP BY sd.dept_id, sd.dept_name
- ORDER BY seizureCount DESC
- </select>
- <!-- 查询大队下所有班组的排名 -->
- <select id="selectAllTeamRankingsInBrigade"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TeamRankingItem">
- SELECT CONCAT(sd2.dept_name, sd.dept_name) AS teamName, -- 科室名称+班组名称
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN sys_dept sd2 ON sd.parent_id = sd2.dept_id -- 获取科室名称
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_team_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- WHERE sd.parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'MANAGER')
- AND sd.del_flag = '0'
- AND sd.dept_type = 'TEAMS' -- 确保是班组
- GROUP BY sd.dept_id, sd.dept_name, sd2.dept_name
- ORDER BY seizureCount DESC
- </select>
- <!-- 查询全站下所有班组的排名 -->
- <select id="selectAllTeamRankingsInStation"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$TeamRankingItem">
- SELECT CONCAT(sd3.dept_name, sd2.dept_name, sd.dept_name) AS teamName, -- 大队名称+科室名称+班组名称
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN sys_dept sd2 ON sd.parent_id = sd2.dept_id -- 获取科室名称
- LEFT JOIN sys_dept sd3 ON sd2.parent_id = sd3.dept_id -- 获取大队名称
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_team_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- WHERE sd.parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'BRIGADE')
- AND del_flag = '0'
- AND dept_type = 'MANAGER')
- AND sd.del_flag = '0'
- AND sd.dept_type = 'TEAMS' -- 确保是班组
- GROUP BY sd.dept_id, sd.dept_name, sd2.dept_name, sd3.dept_name
- ORDER BY seizureCount DESC
- </select>
- <!-- 查询班组下用户总数 -->
- <select id="selectUserCountByTeamId" resultType="java.lang.Integer">
- SELECT COUNT(DISTINCT user_id) AS user_count
- FROM sys_user
- WHERE dept_id = #{deptId}
- AND del_flag = '0'
- </select>
- <!-- 查询科室下用户总数(包括科室下所有班组的用户) -->
- <select id="selectUserCountByDepartmentId" resultType="java.lang.Integer">
- SELECT COUNT(DISTINCT user_id) AS user_count
- FROM sys_user
- WHERE dept_id IN
- (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'TEAMS')
- AND del_flag = '0'
- </select>
- <!-- 查询大队下用户总数(包括大队下所有科室下所有班组的用户) -->
- <select id="selectUserCountByBrigadeId" resultType="java.lang.Integer">
- SELECT COUNT(DISTINCT user_id) AS user_count
- FROM sys_user
- WHERE dept_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'MANAGER')
- AND del_flag = '0'
- AND dept_type = 'TEAMS')
- AND del_flag = '0'
- </select>
- <!-- 查询全站下用户总数(包括全站下所有科室和班组的用户) -->
- <select id="selectUserCountByStationId" resultType="java.lang.Integer">
- SELECT COUNT(DISTINCT user_id) AS user_count
- FROM sys_user
- WHERE dept_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id IN (SELECT dept_id
- FROM sys_dept
- WHERE parent_id in
- (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'BRIGADE')
- AND del_flag = '0'
- AND dept_type = 'MANAGER')
- AND del_flag = '0'
- AND dept_type = 'TEAMS')
- AND del_flag = '0'
- </select>
- <!-- 查询全站下科室总数 -->
- <select id="selectDepartmentCountByStationId" resultType="java.lang.Integer">
- SELECT COUNT(*) AS department_count
- FROM sys_dept
- WHERE parent_id in (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'BRIGADE')
- AND del_flag = '0'
- AND dept_type = 'MANAGER'
- </select>
- <!-- 查询全站下大队总数 -->
- <select id="selectBrigadeCountByStationId" resultType="java.lang.Integer">
- SELECT COUNT(*) AS brigade_count
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'BRIGADE'
- </select>
- <!-- 查询全大队下科室总数 -->
- <select id="selectDepartmentCountByBrigadeId" resultType="java.lang.Integer">
- SELECT COUNT(*) AS department_count
- FROM sys_dept
- WHERE parent_id = #{deptId} -- 大队ID下的科室
- AND del_flag = '0'
- AND dept_type = 'MANAGER' -- 确保是科室
- </select>
- <!-- 查询全站下所有科室的排名 -->
- <select id="selectAllDepartmentRankingsInStation"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$DepartmentRankingItem">
- SELECT sd.dept_name AS departmentName,
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_department_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- WHERE sd.parent_id in (SELECT dept_id
- FROM sys_dept
- WHERE parent_id = #{deptId}
- AND del_flag = '0'
- AND dept_type = 'BRIGADE')
- AND sd.del_flag = '0'
- AND sd.dept_type = 'MANAGER'
- GROUP BY sd.dept_id, sd.dept_name
- ORDER BY seizureCount DESC
- </select>
- <!-- 查询全站下所有大队的排名 -->
- <select id="selectAllBrigadeRankingsInStation"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$BrigadeRankingItem">
- SELECT sd.dept_name AS departmentName,
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_brigade_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- WHERE sd.parent_id = #{deptId}
- AND sd.del_flag = '0'
- AND sd.dept_type = 'BRIGADE'
- GROUP BY sd.dept_id, sd.dept_name
- ORDER BY seizureCount DESC
- </select>
- <!-- 查询全站下所有科室的排名 -->
- <select id="selectAllDepartmentRankingsInBrigade"
- resultType="com.sundot.airport.item.domain.home.SeizureReportDTO$DepartmentRankingItem">
- SELECT
- sd.dept_name AS departmentName,
- COALESCE(SUM(isi.quantity), 0) AS seizureCount
- FROM sys_dept sd
- LEFT JOIN item_seizure_record isr ON sd.dept_id = isr.inspect_department_id
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- AND isr.process_status = 3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- WHERE sd.parent_id = #{deptId}
- AND sd.del_flag = '0'
- AND sd.dept_type = 'MANAGER'
- GROUP BY sd.dept_id, sd.dept_name
- ORDER BY seizureCount DESC
- </select>
- <!-- 查询全站范围内查获数量的最大值 -->
- <select id="selectMaxSeizureCountInStation" resultType="java.math.BigDecimal">
- SELECT COALESCE(MAX(user_seizure_count), 0) AS max_seizure_count
- FROM (
- SELECT SUM(isi.quantity) AS user_seizure_count
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.process_status = 3
- AND isr.inspect_station_id = #{deptId}
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- GROUP BY isr.inspect_user_id
- ) AS user_totals
- </select>
- <!-- 查询草稿箱中数据数量 -->
- <select id="selectDraftItemCount" resultType="java.lang.Integer">
- SELECT COUNT(*)
- FROM item_seizure_record isr
- WHERE isr.inspect_user_id = #{userId}
- AND isr.process_status = '0' -- 草稿状态
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- <!-- 查询查获总数 -->
- <select id="selectAverage" resultType="java.math.BigDecimal">
- SELECT COALESCE(SUM(isi.quantity), 0) AS total_team_seizure
- FROM item_seizure_record isr
- LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
- WHERE isr.inspect_user_id in
- <foreach collection="list" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- AND isr.process_status=3
- <if test="startDate != null and endDate != null">
- AND isr.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- </select>
- </mapper>
|