Procházet zdrojové kódy

首页-查获上报

chenshudong před 2 měsíci
rodič
revize
7c816a456d

+ 63 - 0
airport-admin/src/main/java/com/sundot/airport/web/controller/home/SeizureReportController.java

@@ -0,0 +1,63 @@
1
+package com.sundot.airport.web.controller.home;
2
+
3
+import com.sundot.airport.common.core.domain.AjaxResult;
4
+import com.sundot.airport.common.core.domain.model.LoginUser;
5
+import com.sundot.airport.common.utils.SecurityUtils;
6
+import com.sundot.airport.item.domain.home.RoleBasedSeizureReportDTO;
7
+import com.sundot.airport.item.service.SeizureReportService;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.format.annotation.DateTimeFormat;
10
+import org.springframework.web.bind.annotation.GetMapping;
11
+import org.springframework.web.bind.annotation.RequestHeader;
12
+import org.springframework.web.bind.annotation.RequestMapping;
13
+import org.springframework.web.bind.annotation.RequestParam;
14
+import org.springframework.web.bind.annotation.RestController;
15
+
16
+import java.util.Date;
17
+
18
+/**
19
+ * 查获上报 控制器
20
+ */
21
+@RestController
22
+@RequestMapping("/system/check/seizureReport")
23
+public class SeizureReportController {
24
+
25
+    @Autowired
26
+    private SeizureReportService seizureReportService;
27
+
28
+    /**
29
+     * 获取查获上报数据
30
+     *
31
+     * @param startDate  开始时间
32
+     * @param endDate    结束时间
33
+     * @param timeRange  时间范围, 可选值: week: 周, month: 月, quarter: 季度, half_year: 半年, year: 年
34
+     * @param dataSource individual=个人数据,team=班组数据(默认)
35
+     */
36
+    @GetMapping("/data")
37
+    public AjaxResult getSeizureReportData(
38
+            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
39
+            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
40
+            @RequestParam(required = false, defaultValue = "year") String timeRange,
41
+            @RequestParam(required = false, defaultValue = "team") String dataSource,
42
+            @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source
43
+    ) {
44
+        try {
45
+            // 获取当前登录用户信息
46
+            LoginUser loginUser = SecurityUtils.getLoginUser();
47
+            if (loginUser == null) {
48
+                return AjaxResult.error("用户未登录");
49
+            }
50
+
51
+            Long userId = loginUser.getUserId();
52
+            Long deptId = loginUser.getUser().getDeptId();
53
+
54
+            // 调用服务获取按角色分类的数据
55
+            RoleBasedSeizureReportDTO roleBasedDto = seizureReportService.getRoleBasedSeizureReportData(userId, deptId, startDate, endDate, timeRange, dataSource, source);
56
+
57
+            return AjaxResult.success(roleBasedDto);
58
+        } catch (Exception e) {
59
+            return AjaxResult.error("获取查获上报数据失败: " + e.getMessage());
60
+        }
61
+    }
62
+
63
+}

+ 31 - 0
airport-common/src/main/java/com/sundot/airport/common/core/domain/SeizureLargeScreenHomePageItemDto.java

@@ -0,0 +1,31 @@
1
+package com.sundot.airport.common.core.domain;
2
+
3
+import lombok.Data;
4
+
5
+import java.math.BigDecimal;
6
+
7
+/**
8
+ * 查获明细
9
+ *
10
+ * @author ruoyi
11
+ * @date 2025-09-07
12
+ */
13
+@Data
14
+public class SeizureLargeScreenHomePageItemDto {
15
+
16
+    /**
17
+     * 主键
18
+     */
19
+    private Long id;
20
+
21
+    /**
22
+     * 名称
23
+     */
24
+    private String name;
25
+
26
+    /**
27
+     * 数量
28
+     */
29
+    private BigDecimal quantity;
30
+
31
+}

+ 56 - 0
airport-common/src/main/java/com/sundot/airport/common/core/domain/SysHomeReportDetailDto.java

@@ -0,0 +1,56 @@
1
+package com.sundot.airport.common.core.domain;
2
+
3
+import lombok.Data;
4
+
5
+import java.math.BigDecimal;
6
+
7
+/**
8
+ * 首页报表-明细
9
+ *
10
+ * @author ruoyi
11
+ * @date 2025-01-06
12
+ */
13
+@Data
14
+public class SysHomeReportDetailDto {
15
+
16
+    /**
17
+     * 主键
18
+     */
19
+    private Long id;
20
+
21
+    /**
22
+     * 名称
23
+     */
24
+    private String name;
25
+
26
+    /**
27
+     * 类型(USER=用户;DEPT=部门)
28
+     */
29
+    private String type;
30
+
31
+    /**
32
+     * 总数
33
+     */
34
+    private BigDecimal totalNumber;
35
+
36
+    /**
37
+     * 平均数
38
+     */
39
+    private BigDecimal averageNumber;
40
+
41
+    /**
42
+     * 中位数
43
+     */
44
+    private BigDecimal medianNumber;
45
+
46
+    /**
47
+     * 最大值
48
+     */
49
+    private BigDecimal maxNumber;
50
+
51
+    /**
52
+     * 最小值
53
+     */
54
+    private BigDecimal minNumber;
55
+
56
+}

+ 34 - 0
airport-item/src/main/java/com/sundot/airport/item/domain/home/BrigadeLeaderSeizureReportDTO.java

@@ -0,0 +1,34 @@
1
+package com.sundot.airport.item.domain.home;
2
+
3
+import io.swagger.annotations.ApiModelProperty;
4
+import lombok.Data;
5
+
6
+import java.math.BigDecimal;
7
+import java.util.List;
8
+
9
+/**
10
+ * 经理和大队行政角色查获上报数据传输对象
11
+ */
12
+@Data
13
+public class BrigadeLeaderSeizureReportDTO {
14
+
15
+    // 大队平均数
16
+    @ApiModelProperty("大队平均数")
17
+    private BigDecimal brigadeAverage;
18
+
19
+    // 全站平均数
20
+    @ApiModelProperty("全站平均数")
21
+    private BigDecimal stationAverage;
22
+
23
+    // 科室查获总数
24
+    @ApiModelProperty("大队查获总数")
25
+    private BigDecimal brigadeSeizure;
26
+
27
+    // 科室排名前三的班组
28
+    @ApiModelProperty("大队排名前三的科室")
29
+    private List<SeizureReportDTO.TopThreeDepartmentItem> topThreeDepartment;
30
+
31
+    // 站级排名信息
32
+    @ApiModelProperty("站级排名信息")
33
+    private SeizureReportDTO.RankingInfo stationRanking;
34
+}

+ 32 - 0
airport-item/src/main/java/com/sundot/airport/item/domain/home/RoleBasedSeizureReportDTO.java

@@ -0,0 +1,32 @@
1
+package com.sundot.airport.item.domain.home;
2
+
3
+import io.swagger.annotations.ApiModelProperty;
4
+import lombok.Data;
5
+
6
+/**
7
+ * 按角色分类的查获上报数据传输对象
8
+ */
9
+@Data
10
+public class RoleBasedSeizureReportDTO {
11
+
12
+    // 站长角色数据
13
+    @ApiModelProperty(value = "站长角色数据")
14
+    private StationLeaderSeizureReportDTO stationMasterData;
15
+
16
+    // 经理和大队行政角色数据
17
+    @ApiModelProperty(value = "经理和大队行政角色数据")
18
+    private BrigadeLeaderSeizureReportDTO brigadeMasterData;
19
+
20
+    // 科长角色数据
21
+    @ApiModelProperty(value = "科室长角色数据")
22
+    private SectionMasterSeizureReportDTO sectionMasterData;
23
+
24
+    // 班组长角色数据
25
+    @ApiModelProperty(value = "班组长角色数据")
26
+    private TeamLeaderSeizureReportDTO teamLeaderData;
27
+
28
+    // 安检员角色数据
29
+    @ApiModelProperty(value = "安检员角色数据")
30
+    private SecurityCheckerSeizureReportDTO securityCheckerData;
31
+
32
+}

+ 47 - 0
airport-item/src/main/java/com/sundot/airport/item/domain/home/SectionMasterSeizureReportDTO.java

@@ -0,0 +1,47 @@
1
+package com.sundot.airport.item.domain.home;
2
+
3
+import io.swagger.annotations.ApiModelProperty;
4
+import lombok.Data;
5
+
6
+import java.math.BigDecimal;
7
+import java.util.List;
8
+
9
+/**
10
+ * 科长角色查获上报数据传输对象
11
+ */
12
+@Data
13
+public class SectionMasterSeizureReportDTO {
14
+
15
+    // 待处理数据数量 (待审批的查获审批)
16
+    @ApiModelProperty("待处理数据数量")
17
+    private Integer pendingCount;
18
+
19
+    // 科室平均数
20
+    @ApiModelProperty("科室平均数")
21
+    private BigDecimal departmentAverage;
22
+
23
+    // 大队平均数
24
+    @ApiModelProperty("大队平均数")
25
+    private BigDecimal brigadeAverage;
26
+
27
+    // 全站平均数
28
+    @ApiModelProperty("全站平均数")
29
+    private BigDecimal stationAverage;
30
+
31
+    // 科室查获总数
32
+    @ApiModelProperty("科室查获总数")
33
+    private BigDecimal departmentSeizure;
34
+
35
+    // 科室排名前三的班组
36
+    @ApiModelProperty("科室排名前三的班组")
37
+    private List<SeizureReportDTO.TopThreeTeamItem> topThreeTeams;
38
+
39
+    // 站级排名信息
40
+    @ApiModelProperty("站级排名信息")
41
+    private SeizureReportDTO.RankingInfo stationRanking;
42
+
43
+    // 大队排名信息
44
+    @ApiModelProperty("大队排名信息")
45
+    private SeizureReportDTO.RankingInfo brigadeRanking;
46
+
47
+}

+ 54 - 0
airport-item/src/main/java/com/sundot/airport/item/domain/home/SecurityCheckerSeizureReportDTO.java

@@ -0,0 +1,54 @@
1
+package com.sundot.airport.item.domain.home;
2
+
3
+import io.swagger.annotations.ApiModelProperty;
4
+import lombok.Data;
5
+
6
+import java.math.BigDecimal;
7
+
8
+/**
9
+ * 安检员角色查获上报数据传输对象
10
+ */
11
+@Data
12
+public class SecurityCheckerSeizureReportDTO {
13
+
14
+    // 本人查获数量
15
+    @ApiModelProperty("本人查获数量")
16
+    private BigDecimal selfSeizureCount;
17
+
18
+    // 班组平均数
19
+    @ApiModelProperty("班组平均数")
20
+    private BigDecimal teamAverage;
21
+
22
+    // 科室平均数
23
+    @ApiModelProperty("科室平均数")
24
+    private BigDecimal departmentAverage;
25
+
26
+    // 大队平均数
27
+    @ApiModelProperty("大队平均数")
28
+    private BigDecimal brigadeAverage;
29
+
30
+    // 全站平均数
31
+    @ApiModelProperty("全站平均数")
32
+    private BigDecimal stationAverage;
33
+
34
+    // 班组排名信息
35
+    @ApiModelProperty("班组排名信息")
36
+    private SeizureReportDTO.RankingInfo teamRanking;
37
+
38
+    // 科室排名信息
39
+    @ApiModelProperty("科室排名信息")
40
+    private SeizureReportDTO.RankingInfo departmentRanking;
41
+
42
+    // 科室排名信息
43
+    @ApiModelProperty("大队排名信息")
44
+    private SeizureReportDTO.RankingInfo brigadeRanking;
45
+
46
+    // 站级排名信息
47
+    @ApiModelProperty("站级排名信息")
48
+    private SeizureReportDTO.RankingInfo stationRanking;
49
+
50
+    // 待处理数据数量 (草稿箱中的数据)
51
+    @ApiModelProperty("待处理数据数量")
52
+    private Integer pendingCount;
53
+
54
+}

+ 71 - 0
airport-item/src/main/java/com/sundot/airport/item/domain/home/SeizureReportDTO.java

@@ -0,0 +1,71 @@
1
+package com.sundot.airport.item.domain.home;
2
+
3
+import io.swagger.annotations.ApiModelProperty;
4
+import lombok.Data;
5
+
6
+import java.math.BigDecimal;
7
+
8
+@Data
9
+public class SeizureReportDTO {
10
+
11
+    // 用于表示排名信息的内部类
12
+    @Data
13
+    public static class RankingInfo {
14
+        @ApiModelProperty("当前排名")
15
+        private Integer currentRank;
16
+        @ApiModelProperty("总共多少项")
17
+        private Integer totalItems;
18
+        @ApiModelProperty("排名文本(例如: \"3/10\", 表示第3名/共10个)")
19
+        private String rankingText;
20
+    }
21
+
22
+    // 用于表示大队排名项的内部类
23
+    @Data
24
+    public static class BrigadeRankingItem {
25
+        @ApiModelProperty("大队名称")
26
+        private String brigadeName;
27
+        @ApiModelProperty("大队ID")
28
+        private BigDecimal seizureCount;
29
+    }
30
+
31
+    // 用于表示科室排名项的内部类
32
+    @Data
33
+    public static class DepartmentRankingItem {
34
+        @ApiModelProperty("科室名称")
35
+        private String departmentName;
36
+        @ApiModelProperty("科室ID")
37
+        private BigDecimal seizureCount;
38
+    }
39
+
40
+    // 用于表示班组排名项的内部类
41
+    @Data
42
+    public static class TeamRankingItem {
43
+        @ApiModelProperty("班组名称(格式: 科室名称+班组名称)")
44
+        private String teamName;
45
+        @ApiModelProperty("查获数量")
46
+        private BigDecimal seizureCount;
47
+    }
48
+
49
+    // 用于表示排名前三班组的内部类
50
+    @Data
51
+    public static class TopThreeTeamItem {
52
+        @ApiModelProperty("班组名称")
53
+        private String teamName;
54
+        @ApiModelProperty("查获数量")
55
+        private BigDecimal seizureCount;
56
+        @ApiModelProperty("排名 (1, 2, 3)")
57
+        private Integer rank;
58
+    }
59
+
60
+    // 用于表示排名前三科室的内部类
61
+    @Data
62
+    public static class TopThreeDepartmentItem {
63
+        @ApiModelProperty("班组名称")
64
+        private String departmentName;
65
+        @ApiModelProperty("查获数量")
66
+        private BigDecimal seizureCount;
67
+        @ApiModelProperty("排名 (1, 2, 3)")
68
+        private Integer rank;
69
+    }
70
+
71
+}

+ 35 - 0
airport-item/src/main/java/com/sundot/airport/item/domain/home/StationLeaderSeizureReportDTO.java

@@ -0,0 +1,35 @@
1
+package com.sundot.airport.item.domain.home;
2
+
3
+import lombok.Data;
4
+
5
+import java.math.BigDecimal;
6
+import java.util.List;
7
+
8
+/**
9
+ * 站长/质检员角色查获上报数据传输对象
10
+ */
11
+@Data
12
+public class StationLeaderSeizureReportDTO {
13
+
14
+    // 全站查获总数
15
+    private BigDecimal totalStationSeizure;
16
+
17
+    // 科室排名列表
18
+//    private List<SeizureReportDTO.DepartmentRankingItem> departmentRankings;
19
+
20
+    // 班组排名列表前三
21
+    private List<SeizureReportDTO.TeamRankingItem> topThreeTeamRankings;
22
+
23
+    // 班组排名列表倒数前三
24
+    private List<SeizureReportDTO.TeamRankingItem> botomThreeTeamRankings;
25
+
26
+    // 大队排名列表
27
+    private List<SeizureReportDTO.BrigadeRankingItem> brigadeRankings;
28
+
29
+    // 科室排名列表前三
30
+    private List<SeizureReportDTO.DepartmentRankingItem> topThreeDepartmentRankings;
31
+
32
+    // 科室排名列表倒数前三
33
+    private List<SeizureReportDTO.DepartmentRankingItem> botomThreeDepartmentRankings;
34
+
35
+}

+ 54 - 0
airport-item/src/main/java/com/sundot/airport/item/domain/home/TeamLeaderSeizureReportDTO.java

@@ -0,0 +1,54 @@
1
+package com.sundot.airport.item.domain.home;
2
+
3
+import io.swagger.annotations.ApiModelProperty;
4
+import lombok.Data;
5
+
6
+import java.math.BigDecimal;
7
+
8
+/**
9
+ * 班组长角色查获上报数据传输对象
10
+ */
11
+@Data
12
+public class TeamLeaderSeizureReportDTO {
13
+
14
+    // 班组查获总数
15
+    @ApiModelProperty(value = "班组查获总数")
16
+    private BigDecimal teamSeizure;
17
+
18
+    // 待处理数据数量 (待审批的查获审批)
19
+    @ApiModelProperty(value = "待处理数据数量")
20
+    private Integer pendingCount;
21
+
22
+    // 班组平均数
23
+    @ApiModelProperty(value = "班组平均数")
24
+    private BigDecimal teamAverage;
25
+
26
+    // 科室平均数
27
+    @ApiModelProperty(value = "科室平均数")
28
+    private BigDecimal departmentAverage;
29
+
30
+    // 大队平均数
31
+    @ApiModelProperty(value = "大队平均数")
32
+    private BigDecimal brigadeAverage;
33
+
34
+    // 全站平均数
35
+    @ApiModelProperty(value = "全站平均数")
36
+    private BigDecimal stationAverage;
37
+
38
+    // 班组排名信息
39
+    @ApiModelProperty(value = "班组排名信息")
40
+    private SeizureReportDTO.RankingInfo teamRanking;
41
+
42
+    // 科室排名信息
43
+    @ApiModelProperty(value = "科室排名信息")
44
+    private SeizureReportDTO.RankingInfo departmentRanking;
45
+
46
+    // 大队排名信息
47
+    @ApiModelProperty(value = "大队排名信息")
48
+    private SeizureReportDTO.RankingInfo brigadeRanking;
49
+
50
+    // 全站排名信息
51
+    @ApiModelProperty(value = "全站排名信息")
52
+    private SeizureReportDTO.RankingInfo stationRanking;
53
+
54
+}

+ 397 - 0
airport-item/src/main/java/com/sundot/airport/item/mapper/SeizureReportMapper.java

@@ -0,0 +1,397 @@
1
+package com.sundot.airport.item.mapper;
2
+
3
+import com.sundot.airport.item.domain.home.SeizureReportDTO;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+
7
+import java.math.BigDecimal;
8
+import java.util.Date;
9
+import java.util.List;
10
+
11
+/**
12
+ * 查获上报 Mapper接口
13
+ */
14
+@Mapper
15
+public interface SeizureReportMapper {
16
+
17
+    /**
18
+     * 查询本人查获数量
19
+     *
20
+     * @param userId    用户ID
21
+     * @param startDate 开始日期
22
+     * @param endDate   结束日期
23
+     * @return 查获数量
24
+     */
25
+    public BigDecimal selectSelfSeizureCount(@Param("userId") Long userId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
26
+
27
+    /**
28
+     * 查询班组查获总数
29
+     *
30
+     * @param deptId    部门ID (班组ID)
31
+     * @param startDate 开始日期
32
+     * @param endDate   结束日期
33
+     * @return 查获总数
34
+     */
35
+    public BigDecimal selectTeamAverage(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
36
+
37
+    /**
38
+     * 查询科室查获总数
39
+     *
40
+     * @param deptId    部门ID (科室ID)
41
+     * @param startDate 开始日期
42
+     * @param endDate   结束日期
43
+     * @return 查获总数
44
+     */
45
+    public BigDecimal selectDepartmentAverage(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
46
+
47
+    /**
48
+     * 查询大队查获总数
49
+     *
50
+     * @param deptId    部门ID (科室ID)
51
+     * @param startDate 开始日期
52
+     * @param endDate   结束日期
53
+     * @return 查获总数
54
+     */
55
+    public BigDecimal selectBrigadeAverage(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
56
+
57
+    /**
58
+     * 查询全站查获总数
59
+     *
60
+     * @param deptId    部门ID (站点ID)
61
+     * @param startDate 开始日期
62
+     * @param endDate   结束日期
63
+     * @return 查获总数
64
+     */
65
+    public BigDecimal selectStationAverage(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
66
+
67
+    /**
68
+     * 查询待处理数据数量(分配给当前用户且待审批的查获审批任务数量)
69
+     *
70
+     * @param userId    用户ID
71
+     * @param deptId    部门ID
72
+     * @param startDate 开始日期
73
+     * @param endDate   结束日期
74
+     * @return 待处理数据数量
75
+     */
76
+    public Integer selectPendingCount(@Param("userId") Long userId, @Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
77
+
78
+    /**
79
+     * 查询排名信息
80
+     *
81
+     * @param userId    用户ID
82
+     * @param deptId    部门ID
83
+     * @param level     排名级别 (team, department, station)
84
+     * @param startDate 开始日期
85
+     * @param endDate   结束日期
86
+     * @return 排名信息列表
87
+     */
88
+    public List<SeizureReportDTO.RankingInfo> selectRankingInfo(@Param("userId") Long userId, @Param("deptId") Long deptId, @Param("level") String level, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
89
+
90
+    /**
91
+     * 查询个人排名
92
+     *
93
+     * @param userId    用户ID
94
+     * @param deptId    部门ID
95
+     * @param level     排名级别 (team, department, station)
96
+     * @param startDate 开始日期
97
+     * @param endDate   结束日期
98
+     * @return 个人排名
99
+     */
100
+    public Integer selectSelfRanking(@Param("userId") Long userId, @Param("deptId") Long deptId, @Param("level") String level, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
101
+
102
+    /**
103
+     * 查询班组部门ID(根据用户ID)
104
+     *
105
+     * @param userId 用户ID
106
+     * @return 科室ID
107
+     */
108
+    public Long selectSectionDeptIdByUserId(@Param("userId") Long userId);
109
+
110
+    /**
111
+     * 查询科室部门ID(根据班组ID)
112
+     *
113
+     * @param teamId 班组ID
114
+     * @return 科室ID
115
+     */
116
+    public Long selectSectionDeptIdByTeamId(@Param("teamId") Long teamId);
117
+
118
+    /**
119
+     * 查询站点部门ID(根据部门ID)
120
+     *
121
+     * @param deptId 部门ID
122
+     * @return 站点ID
123
+     */
124
+    public Long selectStationDeptIdByDeptId(@Param("deptId") Long deptId);
125
+
126
+    /**
127
+     * 查询全站查获总数
128
+     *
129
+     * @param deptId    站点ID
130
+     * @param startDate 开始日期
131
+     * @param endDate   结束日期
132
+     * @return 全站查获总数
133
+     */
134
+    public BigDecimal selectTotalStationSeizure(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
135
+
136
+    /**
137
+     * 查询科室排名
138
+     *
139
+     * @param deptId    站点ID
140
+     * @param startDate 开始日期
141
+     * @param endDate   结束日期
142
+     * @return 科室排名列表
143
+     */
144
+    public List<SeizureReportDTO.DepartmentRankingItem> selectDepartmentRankings(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
145
+
146
+    /**
147
+     * 查询大队排名
148
+     *
149
+     * @param deptId    站点ID
150
+     * @param startDate 开始日期
151
+     * @param endDate   结束日期
152
+     * @return 科室排名列表
153
+     */
154
+    public List<SeizureReportDTO.BrigadeRankingItem> selectBrigadeRankings(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
155
+
156
+
157
+    /**
158
+     * 查询排名前三的班组(不包含排名,排名在Java代码中计算)
159
+     *
160
+     * @param deptId    科室ID
161
+     * @param startDate 开始日期
162
+     * @param endDate   结束日期
163
+     * @return 排名前三的班组列表
164
+     */
165
+    public List<SeizureReportDTO.TopThreeTeamItem> selectTopThreeTeams(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
166
+
167
+    /**
168
+     * 查询排名前三的科室(不包含排名,排名在Java代码中计算)
169
+     *
170
+     * @param deptId    科室ID
171
+     * @param startDate 开始日期
172
+     * @param endDate   结束日期
173
+     * @return 排名前三的科室列表
174
+     */
175
+    public List<SeizureReportDTO.TopThreeDepartmentItem> selectTopThreeDepartment(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
176
+
177
+    /**
178
+     * 查询前三名的班组排名
179
+     *
180
+     * @param deptId    站点ID
181
+     * @param startDate 开始日期
182
+     * @param endDate   结束日期
183
+     * @return 前五名班组排名列表
184
+     */
185
+    public List<SeizureReportDTO.TeamRankingItem> selectTopThreeTeamRankings(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("order") String order);
186
+
187
+    /**
188
+     * 查询前三名的科室排名
189
+     *
190
+     * @param deptId    站点ID
191
+     * @param startDate 开始日期
192
+     * @param endDate   结束日期
193
+     * @return 前五名班组排名列表
194
+     */
195
+    public List<SeizureReportDTO.DepartmentRankingItem> selectTopThreeDepartmentRankings(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("order") String order);
196
+
197
+    /**
198
+     * 查询班组长查获总数
199
+     *
200
+     * @param deptId    部门ID (班组ID)
201
+     * @param startDate 开始日期
202
+     * @param endDate   结束日期
203
+     * @return 班组查获总数
204
+     */
205
+    public BigDecimal selectTeamSeizure(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
206
+
207
+    /**
208
+     * 查询科室查获总数
209
+     *
210
+     * @param deptId    部门ID (科室ID)
211
+     * @param startDate 开始日期
212
+     * @param endDate   结束日期
213
+     * @return 科室查获总数
214
+     */
215
+    public BigDecimal selectDepartmentSeizure(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
216
+
217
+    /**
218
+     * 查询大队查获总数
219
+     *
220
+     * @param deptId    部门ID (科室ID)
221
+     * @param startDate 开始日期
222
+     * @param endDate   结束日期
223
+     * @return 科室查获总数
224
+     */
225
+    public BigDecimal selectBrigadeSeizure(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
226
+
227
+    /**
228
+     * 查询科室下的班组总数
229
+     *
230
+     * @param deptId 部门ID (科室ID)
231
+     * @return 班组总数
232
+     */
233
+    public Integer selectTeamCountByDepartmentId(@Param("deptId") Long deptId);
234
+
235
+    /**
236
+     * 查询科室下的班组总数
237
+     *
238
+     * @param deptId 部门ID (科室ID)
239
+     * @return 班组总数
240
+     */
241
+    public Integer selectTeamCountByBrigadeId(@Param("deptId") Long deptId);
242
+
243
+    /**
244
+     * 查询全站下的班组总数
245
+     *
246
+     * @param deptId 部门ID (站点ID)
247
+     * @return 班组总数
248
+     */
249
+    public Integer selectTeamCountByStationId(@Param("deptId") Long deptId);
250
+
251
+    /**
252
+     * 查询科室下所有班组的排名
253
+     *
254
+     * @param deptId    部门ID (科室ID)
255
+     * @param startDate 开始日期
256
+     * @param endDate   结束日期
257
+     * @return 班组排名列表
258
+     */
259
+    public List<SeizureReportDTO.TeamRankingItem> selectAllTeamRankingsInDepartment(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
260
+
261
+    /**
262
+     * 查询大队下所有班组的排名
263
+     *
264
+     * @param deptId    部门ID (科室ID)
265
+     * @param startDate 开始日期
266
+     * @param endDate   结束日期
267
+     * @return 班组排名列表
268
+     */
269
+    public List<SeizureReportDTO.TeamRankingItem> selectAllTeamRankingsInBrigade(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
270
+
271
+    /**
272
+     * 查询全站下所有班组的排名
273
+     *
274
+     * @param deptId    部门ID (站点ID)
275
+     * @param startDate 开始日期
276
+     * @param endDate   结束日期
277
+     * @return 班组排名列表
278
+     */
279
+    public List<SeizureReportDTO.TeamRankingItem> selectAllTeamRankingsInStation(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
280
+
281
+    /**
282
+     * 查询班组下用户总数
283
+     *
284
+     * @param deptId 部门ID (班组ID)
285
+     * @return 用户总数
286
+     */
287
+    public Integer selectUserCountByTeamId(@Param("deptId") Long deptId);
288
+
289
+    /**
290
+     * 查询科室下用户总数
291
+     *
292
+     * @param deptId 部门ID (科室ID)
293
+     * @return 用户总数
294
+     */
295
+    public Integer selectUserCountByDepartmentId(@Param("deptId") Long deptId);
296
+
297
+    /**
298
+     * 查询科室下用户总数
299
+     *
300
+     * @param deptId 部门ID (科室ID)
301
+     * @return 用户总数
302
+     */
303
+    public Integer selectUserCountByBrigadeId(@Param("deptId") Long deptId);
304
+
305
+    /**
306
+     * 查询全站下用户总数
307
+     *
308
+     * @param deptId 部门ID (站点ID)
309
+     * @return 用户总数
310
+     */
311
+    public Integer selectUserCountByStationId(@Param("deptId") Long deptId);
312
+
313
+    /**
314
+     * 查询全站下科室总数
315
+     *
316
+     * @param deptId 部门ID (站点ID)
317
+     * @return 科室总数
318
+     */
319
+    public Integer selectDepartmentCountByStationId(@Param("deptId") Long deptId);
320
+
321
+    /**
322
+     * 查询全站下大队总数
323
+     *
324
+     * @param deptId 部门ID (站点ID)
325
+     * @return 科室总数
326
+     */
327
+    public Integer selectBrigadeCountByStationId(@Param("deptId") Long deptId);
328
+
329
+    /**
330
+     * 查询全大队下科室总数
331
+     *
332
+     * @param deptId 部门ID (站点ID)
333
+     * @return 科室总数
334
+     */
335
+    public Integer selectDepartmentCountByBrigadeId(@Param("deptId") Long deptId);
336
+
337
+    /**
338
+     * 查询全站下所有科室的排名
339
+     *
340
+     * @param deptId    部门ID (站点ID)
341
+     * @param startDate 开始日期
342
+     * @param endDate   结束日期
343
+     * @return 科室排名列表
344
+     */
345
+    public List<SeizureReportDTO.DepartmentRankingItem> selectAllDepartmentRankingsInStation(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
346
+
347
+    /**
348
+     * 查询全站下所有大队的排名
349
+     *
350
+     * @param deptId    部门ID (站点ID)
351
+     * @param startDate 开始日期
352
+     * @param endDate   结束日期
353
+     * @return 大队排名列表
354
+     */
355
+    public List<SeizureReportDTO.BrigadeRankingItem> selectAllBrigadeRankingsInStation(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
356
+
357
+    /**
358
+     * 查询全大队下所有科室的排名
359
+     *
360
+     * @param deptId    部门ID (站点ID)
361
+     * @param startDate 开始日期
362
+     * @param endDate   结束日期
363
+     * @return 科室排名列表
364
+     */
365
+    public List<SeizureReportDTO.DepartmentRankingItem> selectAllDepartmentRankingsInBrigade(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
366
+
367
+    /**
368
+     * 查询全站范围内查获数量的最大值
369
+     *
370
+     * @param deptId    部门ID (站点ID)
371
+     * @param startDate 开始日期
372
+     * @param endDate   结束日期
373
+     * @return 最大查获数量
374
+     */
375
+    public BigDecimal selectMaxSeizureCountInStation(@Param("deptId") Long deptId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
376
+
377
+    /**
378
+     * 查询草稿箱中数据数量
379
+     *
380
+     * @param userId    用户ID
381
+     * @param startDate 开始日期
382
+     * @param endDate   结束日期
383
+     * @return 草稿箱中数据数量
384
+     */
385
+    public Integer selectDraftItemCount(@Param("userId") Long userId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
386
+
387
+    /**
388
+     * 查询查获总数
389
+     *
390
+     * @param list      用户ID
391
+     * @param startDate 开始日期
392
+     * @param endDate   结束日期
393
+     * @return 查获总数
394
+     */
395
+    public BigDecimal selectAverage(@Param("list") List<Long> list, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
396
+
397
+}

+ 639 - 0
airport-item/src/main/java/com/sundot/airport/item/service/SeizureReportService.java

@@ -0,0 +1,639 @@
1
+package com.sundot.airport.item.service;
2
+
3
+import cn.hutool.core.collection.CollectionUtil;
4
+import cn.hutool.core.util.ObjectUtil;
5
+import cn.hutool.core.util.StrUtil;
6
+import com.sundot.airport.common.core.domain.DataPermissionResult;
7
+import com.sundot.airport.common.core.domain.entity.SysDept;
8
+import com.sundot.airport.common.core.domain.entity.SysRole;
9
+import com.sundot.airport.common.core.domain.model.LoginUser;
10
+import com.sundot.airport.common.enums.DataPermissionType;
11
+import com.sundot.airport.common.enums.DeptType;
12
+import com.sundot.airport.common.enums.RoleTypeEnum;
13
+import com.sundot.airport.common.enums.SourceTypeEnum;
14
+import com.sundot.airport.common.exception.ServiceException;
15
+import com.sundot.airport.common.utils.DateUtils;
16
+import com.sundot.airport.common.utils.SecurityUtils;
17
+import com.sundot.airport.item.domain.FailedMatchItem;
18
+import com.sundot.airport.item.domain.home.*;
19
+import com.sundot.airport.system.service.ISysDeptService;
20
+import com.sundot.airport.item.mapper.SeizureReportMapper;
21
+import org.springframework.beans.factory.annotation.Autowired;
22
+import org.springframework.stereotype.Service;
23
+
24
+import java.math.BigDecimal;
25
+import java.util.Calendar;
26
+import java.util.Collections;
27
+import java.util.List;
28
+import java.util.stream.Collectors;
29
+
30
+import static com.sundot.airport.common.utils.SecurityUtils.getLoginUser;
31
+
32
+/**
33
+ * 查获上报 Service层
34
+ */
35
+@Service
36
+public class SeizureReportService {
37
+
38
+    @Autowired
39
+    private SeizureReportMapper seizureReportMapper;
40
+
41
+    @Autowired
42
+    private ISysDeptService sysDeptService;
43
+
44
+    @Autowired
45
+    private IFailedMatchItemService failedMatchItemService;
46
+
47
+    /**
48
+     * 获取按角色分类的查获上报数据
49
+     */
50
+    public RoleBasedSeizureReportDTO getRoleBasedSeizureReportData(Long userId, Long deptId, java.util.Date startDate, java.util.Date endDate, String timeRange, String dataSource, String source) {
51
+        // 1. 计算时间范围
52
+        if (startDate == null || endDate == null) {
53
+            java.util.Date[] timeRangeDates = calculateTimeRange(timeRange);
54
+            startDate = timeRangeDates[0];
55
+            endDate = timeRangeDates[1];
56
+        }
57
+        if (endDate != null) {
58
+            endDate = DateUtils.addSeconds(DateUtils.truncate(endDate, Calendar.DAY_OF_MONTH), 86399);
59
+        }
60
+
61
+        // 2. 获取数据权限
62
+        DataPermissionResult permissionResult = getDataPermission(userId, deptId);
63
+
64
+        // 3. 创建返回对象
65
+        RoleBasedSeizureReportDTO roleBasedDto = new RoleBasedSeizureReportDTO();
66
+        // 4. 根据权限类型设置查询条件
67
+        if (StrUtil.equals(SourceTypeEnum.mobile.getCode(), source)) {
68
+            if (permissionResult.getPermissionType() == DataPermissionType.SELF || (permissionResult.getPermissionType() == DataPermissionType.TEAM && "individual".equalsIgnoreCase(dataSource))) {
69
+                // 安检员数据 - 个人数据
70
+                SecurityCheckerSeizureReportDTO securityCheckerData = new SecurityCheckerSeizureReportDTO();
71
+                handleSecurityCheckRoleForSpecificDTO(userId, deptId, startDate, endDate, securityCheckerData);
72
+                roleBasedDto.setSecurityCheckerData(securityCheckerData);
73
+            } else if (permissionResult.getPermissionType() == DataPermissionType.TEAM && "team".equalsIgnoreCase(dataSource)) {
74
+                // 班组长数据 - 班组数据
75
+                TeamLeaderSeizureReportDTO teamLeaderData = new TeamLeaderSeizureReportDTO();
76
+                handleTeamLeaderRoleForSpecificDTO(userId, deptId, startDate, endDate, teamLeaderData);
77
+                roleBasedDto.setTeamLeaderData(teamLeaderData);
78
+            } else if (permissionResult.getPermissionType() == DataPermissionType.DEPARTMENT) {
79
+                // 科长数据 - 科室数据
80
+                SectionMasterSeizureReportDTO sectionMasterData = new SectionMasterSeizureReportDTO();
81
+                handleSectionLeaderRoleForSpecificDTO(userId, deptId, startDate, endDate, sectionMasterData);
82
+                roleBasedDto.setSectionMasterData(sectionMasterData);
83
+            } else if (permissionResult.getPermissionType() == DataPermissionType.BRIGADE) {
84
+                // 经理和大队行政数据 - 大队数据
85
+                BrigadeLeaderSeizureReportDTO brigadeLeaderData = new BrigadeLeaderSeizureReportDTO();
86
+                handleBrigadeLeaderRoleForSpecificDTO(userId, deptId, startDate, endDate, brigadeLeaderData);
87
+                roleBasedDto.setBrigadeMasterData(brigadeLeaderData);
88
+            } else if (permissionResult.getPermissionType() == DataPermissionType.STATION || permissionResult.getPermissionType() == DataPermissionType.ALL) {
89
+                // 站长数据 - 全站数据
90
+                StationLeaderSeizureReportDTO stationMasterData = new StationLeaderSeizureReportDTO();
91
+                handleStationLeaderRoleForSpecificDTO(userId, deptId, startDate, endDate, stationMasterData);
92
+                roleBasedDto.setStationMasterData(stationMasterData);
93
+            }
94
+        } else {
95
+            List<SysDept> sysDeptList = sysDeptService.selectAllDept(SecurityUtils.getLoginUser().getDeptId());
96
+            Collections.reverse(sysDeptList);
97
+            SysDept stationDept = sysDeptList.stream().filter(x -> StrUtil.equals(DeptType.STATION.getCode(), x.getDeptType())).findFirst().orElse(null);
98
+            if (ObjectUtil.isNull(stationDept)) {
99
+                throw new ServiceException("未查询到站级部门信息");
100
+            }
101
+            // 站长数据 - 全站数据
102
+            StationLeaderSeizureReportDTO stationMasterData = new StationLeaderSeizureReportDTO();
103
+            handleStationLeaderRoleForSpecificDTO(userId, deptId, startDate, endDate, stationMasterData);
104
+            roleBasedDto.setStationMasterData(stationMasterData);
105
+        }
106
+
107
+        return roleBasedDto;
108
+    }
109
+
110
+    /**
111
+     * 计算时间范围
112
+     *
113
+     * @param timeRange 时间范围类型
114
+     * @return [开始日期, 结束日期]
115
+     */
116
+    private java.util.Date[] calculateTimeRange(String timeRange) {
117
+        java.util.Date endDate = DateUtils.addDays(new java.util.Date(), -1); // 不包括今天
118
+        java.util.Date startDate;
119
+
120
+        if ("week".equals(timeRange)) {
121
+            startDate = DateUtils.addDays(endDate, -7); // 近一周
122
+        } else if ("month".equals(timeRange)) {
123
+            startDate = DateUtils.addDays(endDate, -30); // 近一月
124
+        } else if ("quarter".equals(timeRange)) {
125
+            startDate = DateUtils.addDays(endDate, -90); // 近三月
126
+        } else if ("half_year".equals(timeRange)) {
127
+            startDate = DateUtils.addDays(endDate, -180); // 近半年
128
+        } else if ("year".equals(timeRange) || timeRange == null) {
129
+            startDate = DateUtils.addDays(endDate, -365); // 近一年,默认选择
130
+        } else {
131
+            // 如果是自定义时间,startDate和endDate应直接传入
132
+            startDate = DateUtils.addDays(endDate, -365); // 默认近一年
133
+        }
134
+
135
+        return new java.util.Date[]{startDate, endDate};
136
+    }
137
+
138
+
139
+    /**
140
+     * 处理安检员角色
141
+     */
142
+    private void handleSecurityCheckRoleForSpecificDTO(Long userId, Long deptId, java.util.Date startDate, java.util.Date endDate, SecurityCheckerSeizureReportDTO dto) {
143
+        // 本人查获数量
144
+        BigDecimal selfSeizureCount = seizureReportMapper.selectSelfSeizureCount(userId, startDate, endDate);
145
+        dto.setSelfSeizureCount(selfSeizureCount);
146
+
147
+        // 班组平均数 - 现在先获取总查获数,再除以人数
148
+        BigDecimal totalTeamSeizure = seizureReportMapper.selectTeamAverage(deptId, startDate, endDate); // 这个方法现在返回总查获数
149
+        Integer teamUserCount = seizureReportMapper.selectUserCountByTeamId(deptId); // 获取班组人数
150
+        BigDecimal teamAverage = (teamUserCount != null && teamUserCount > 0) ?
151
+                totalTeamSeizure.divide(new BigDecimal(teamUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
152
+        dto.setTeamAverage(teamAverage);
153
+
154
+        // 科室平均数 = 科室查获总数 / 科室下所有班组长和安检员数量
155
+        Long sectionDeptId = getSectionDeptId(deptId);
156
+        BigDecimal totalDepartmentSeizure = seizureReportMapper.selectDepartmentAverage(sectionDeptId, startDate, endDate);
157
+        Integer deptUserCount = seizureReportMapper.selectUserCountByDepartmentId(sectionDeptId);
158
+        BigDecimal sectionAverage = (deptUserCount != null && deptUserCount > 0) ?
159
+                totalDepartmentSeizure.divide(new BigDecimal(deptUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
160
+        dto.setDepartmentAverage(sectionAverage);
161
+
162
+        // 大队平均数 = 大队查获总数 / 大队下所有班组长和安检员数量
163
+        Long brigadeDeptId = getSectionDeptId(sectionDeptId);
164
+        BigDecimal totalBrigadeSeizure = seizureReportMapper.selectBrigadeAverage(brigadeDeptId, startDate, endDate);
165
+        Integer brigadeUserCount = seizureReportMapper.selectUserCountByBrigadeId(brigadeDeptId);
166
+        BigDecimal brigadeAverage = (brigadeUserCount != null && brigadeUserCount > 0) ?
167
+                totalBrigadeSeizure.divide(new BigDecimal(brigadeUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
168
+        dto.setBrigadeAverage(brigadeAverage);
169
+
170
+        // 全站平均数 = 全站查获总数 / 全站所有班组长和安检员数量
171
+        Long stationDeptId = getStationDeptId(brigadeDeptId);
172
+        BigDecimal totalStationSeizure = seizureReportMapper.selectStationAverage(stationDeptId, startDate, endDate);
173
+        Integer stationUserCount = seizureReportMapper.selectUserCountByStationId(stationDeptId);
174
+        BigDecimal stationAverage = (stationUserCount != null && stationUserCount > 0) ?
175
+                totalStationSeizure.divide(new BigDecimal(stationUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
176
+        dto.setStationAverage(stationAverage);
177
+
178
+        // 设置排名信息
179
+        // 班组排名:个人排名/全班组人数
180
+        SeizureReportDTO.RankingInfo teamRanking = new SeizureReportDTO.RankingInfo();
181
+        Integer teamCurrentRank = seizureReportMapper.selectSelfRanking(userId, deptId, "team", startDate, endDate);
182
+        Integer teamTotalUsers = seizureReportMapper.selectUserCountByTeamId(deptId);
183
+        teamRanking.setCurrentRank(ObjectUtil.isNotNull(teamCurrentRank) ? teamCurrentRank : teamTotalUsers);
184
+        teamRanking.setTotalItems(teamTotalUsers);
185
+        teamRanking.setRankingText((ObjectUtil.isNotNull(teamCurrentRank) ? teamCurrentRank : teamTotalUsers) + "/" + teamTotalUsers);
186
+
187
+        // 科室排名:个人排名/全科安检员和班组长人数总和
188
+        SeizureReportDTO.RankingInfo departmentRanking = new SeizureReportDTO.RankingInfo();
189
+        Integer deptCurrentRank = seizureReportMapper.selectSelfRanking(userId, sectionDeptId, "department", startDate, endDate);
190
+        Integer deptTotalUsers = seizureReportMapper.selectUserCountByDepartmentId(sectionDeptId);
191
+        departmentRanking.setCurrentRank(ObjectUtil.isNotNull(deptCurrentRank) ? deptCurrentRank : deptTotalUsers);
192
+        departmentRanking.setTotalItems(deptTotalUsers);
193
+        departmentRanking.setRankingText((ObjectUtil.isNotNull(deptCurrentRank) ? deptCurrentRank : deptTotalUsers) + "/" + deptTotalUsers);
194
+
195
+        // 大队排名:个人排名/全大队安检员和班组长人数总和
196
+        SeizureReportDTO.RankingInfo brigadeRanking = new SeizureReportDTO.RankingInfo();
197
+        Integer brigadeCurrentRank = seizureReportMapper.selectSelfRanking(userId, brigadeDeptId, "brigade", startDate, endDate);
198
+        Integer brigadeTotalUsers = seizureReportMapper.selectUserCountByBrigadeId(brigadeDeptId);
199
+        brigadeRanking.setCurrentRank(ObjectUtil.isNotNull(brigadeCurrentRank) ? brigadeCurrentRank : brigadeTotalUsers);
200
+        brigadeRanking.setTotalItems(brigadeTotalUsers);
201
+        brigadeRanking.setRankingText((ObjectUtil.isNotNull(brigadeCurrentRank) ? brigadeCurrentRank : brigadeTotalUsers) + "/" + brigadeTotalUsers);
202
+
203
+        // 全站排名:个人排名/全站安检员和班组长人数总和
204
+        SeizureReportDTO.RankingInfo stationRanking = new SeizureReportDTO.RankingInfo();
205
+        Integer stationCurrentRank = seizureReportMapper.selectSelfRanking(userId, stationDeptId, "station", startDate, endDate);
206
+        Integer stationTotalUsers = seizureReportMapper.selectUserCountByStationId(stationDeptId);
207
+        stationRanking.setCurrentRank(ObjectUtil.isNotNull(stationCurrentRank) ? stationCurrentRank : stationTotalUsers);
208
+        stationRanking.setTotalItems(stationTotalUsers);
209
+        stationRanking.setRankingText((ObjectUtil.isNotNull(stationCurrentRank) ? stationCurrentRank : stationTotalUsers) + "/" + stationTotalUsers);
210
+
211
+        // 设置各个排名信息
212
+        dto.setTeamRanking(teamRanking);
213
+        dto.setDepartmentRanking(departmentRanking);
214
+        dto.setBrigadeRanking(brigadeRanking);
215
+        dto.setStationRanking(stationRanking);
216
+
217
+        // 设置待处理数据数量 - 草稿箱中数据数量
218
+        FailedMatchItem failedMatchItem = new FailedMatchItem();
219
+        // 设置查询条件为当前用户ID
220
+        failedMatchItem.setUserId(userId);
221
+        // 只查询未编辑的记录(app_edited=0或null)
222
+        failedMatchItem.setAppEdited(false);
223
+
224
+        List<FailedMatchItem> list = failedMatchItemService.selectFailedMatchItemList(failedMatchItem);
225
+        int pendingCount = 0;
226
+        if (CollectionUtil.isNotEmpty(list)) {
227
+            pendingCount = list.size();
228
+        }
229
+        dto.setPendingCount(pendingCount);
230
+    }
231
+
232
+
233
+    /**
234
+     * 处理班组长角色
235
+     */
236
+    private void handleTeamLeaderRoleForSpecificDTO(Long userId, Long deptId, java.util.Date startDate, java.util.Date endDate, TeamLeaderSeizureReportDTO dto) {
237
+        //班组长查获总数
238
+        BigDecimal teamSeizure = seizureReportMapper.selectTeamSeizure(deptId, startDate, endDate);
239
+        dto.setTeamSeizure(teamSeizure);
240
+
241
+        // 班组平均数 - 现在先获取总查获数,再除以人数
242
+        BigDecimal totalTeamSeizure = seizureReportMapper.selectTeamAverage(deptId, startDate, endDate); // 这个方法现在返回总查获数
243
+        Integer teamUserCount = seizureReportMapper.selectUserCountByTeamId(deptId); // 获取班组人数
244
+        BigDecimal teamAverage = (teamUserCount != null && teamUserCount > 0) ?
245
+                totalTeamSeizure.divide(new BigDecimal(teamUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
246
+        dto.setTeamAverage(teamAverage);
247
+
248
+        // 科室平均数 = 科室查获总数 / 科室下所有班组长和安检员数量
249
+        Long sectionDeptId = getSectionDeptId(deptId);
250
+        BigDecimal totalDepartmentSeizure = seizureReportMapper.selectDepartmentAverage(sectionDeptId, startDate, endDate);
251
+        Integer deptUserCount = seizureReportMapper.selectUserCountByDepartmentId(sectionDeptId);
252
+        BigDecimal sectionAverage = (deptUserCount != null && deptUserCount > 0) ?
253
+                totalDepartmentSeizure.divide(new BigDecimal(deptUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
254
+        dto.setDepartmentAverage(sectionAverage);
255
+
256
+        // 大队平均数 = 大队查获总数 / 大队下所有科室下所有班组长和安检员数量
257
+        Long brigadeDeptId = getSectionDeptId(sectionDeptId);
258
+        BigDecimal totalBrigadeSeizure = seizureReportMapper.selectBrigadeAverage(brigadeDeptId, startDate, endDate);
259
+        Integer brigadeUserCount = seizureReportMapper.selectUserCountByBrigadeId(brigadeDeptId);
260
+        BigDecimal brigadeAverage = (brigadeUserCount != null && brigadeUserCount > 0) ?
261
+                totalBrigadeSeizure.divide(new BigDecimal(brigadeUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
262
+        dto.setBrigadeAverage(brigadeAverage);
263
+
264
+        // 全站平均数 = 全站查获总数 / 全站所有班组长和安检员数量
265
+        Long stationDeptId = getStationDeptId(brigadeDeptId);
266
+        BigDecimal totalStationSeizure = seizureReportMapper.selectStationAverage(stationDeptId, startDate, endDate);
267
+        Integer stationUserCount = seizureReportMapper.selectUserCountByStationId(stationDeptId);
268
+        BigDecimal stationAverage = (stationUserCount != null && stationUserCount > 0) ?
269
+                totalStationSeizure.divide(new BigDecimal(stationUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
270
+        dto.setStationAverage(stationAverage);
271
+
272
+        SeizureReportDTO.RankingInfo selfRanking = new SeizureReportDTO.RankingInfo();
273
+        // 获取班组排名(在班组内的个人排名)
274
+        Integer teamRank = seizureReportMapper.selectSelfRanking(userId, deptId, "team", startDate, endDate);
275
+        selfRanking.setCurrentRank(teamRank);
276
+
277
+        // 获取科室排名(班组在科室内的排名)
278
+        SeizureReportDTO.RankingInfo deptRanking = new SeizureReportDTO.RankingInfo();
279
+        Integer deptTeamRank = getTeamRankInDepartment(deptId, sectionDeptId, startDate, endDate);
280
+        Integer deptTeamTotal = seizureReportMapper.selectTeamCountByDepartmentId(sectionDeptId);
281
+        deptRanking.setCurrentRank(deptTeamRank);
282
+        deptRanking.setTotalItems(deptTeamTotal);
283
+        deptRanking.setRankingText(deptTeamRank + "/" + deptTeamTotal);
284
+
285
+        // 获取大队排名(班组在大队内的排名)
286
+        SeizureReportDTO.RankingInfo brigadeRanking = new SeizureReportDTO.RankingInfo();
287
+        Integer deptBrigadeRank = getTeamRankInBrigade(deptId, brigadeDeptId, startDate, endDate);
288
+        Integer deptBrigadeTotal = seizureReportMapper.selectTeamCountByBrigadeId(brigadeDeptId);
289
+        brigadeRanking.setCurrentRank(deptBrigadeRank);
290
+        brigadeRanking.setTotalItems(deptBrigadeTotal);
291
+        brigadeRanking.setRankingText(deptBrigadeRank + "/" + deptBrigadeTotal);
292
+
293
+        // 获取全站排名(班组在全站内的排名)
294
+        SeizureReportDTO.RankingInfo stationRanking = new SeizureReportDTO.RankingInfo();
295
+        Integer stationTeamRank = getTeamRankInStation(deptId, stationDeptId, startDate, endDate);
296
+        Integer stationTeamTotal = seizureReportMapper.selectTeamCountByStationId(stationDeptId);
297
+        stationRanking.setCurrentRank(stationTeamRank);
298
+        stationRanking.setTotalItems(stationTeamTotal);
299
+        stationRanking.setRankingText(stationTeamRank + "/" + stationTeamTotal);
300
+        // 添加科室和全站排名信息
301
+        dto.setDepartmentRanking(deptRanking);
302
+        dto.setBrigadeRanking(brigadeRanking);
303
+        dto.setStationRanking(stationRanking);
304
+
305
+        // 设置待处理数据数量 - 草稿箱中数据数量
306
+        FailedMatchItem failedMatchItem = new FailedMatchItem();
307
+        // 设置查询条件为当前用户ID
308
+        failedMatchItem.setUserId(userId);
309
+        // 只查询未编辑的记录(app_edited=0或null)
310
+        failedMatchItem.setAppEdited(false);
311
+
312
+        List<FailedMatchItem> list = failedMatchItemService.selectFailedMatchItemList(failedMatchItem);
313
+        int pendingCount = 0;
314
+        if (CollectionUtil.isNotEmpty(list)) {
315
+            pendingCount = list.size();
316
+        }
317
+        dto.setPendingCount(pendingCount);
318
+    }
319
+
320
+
321
+    /**
322
+     * 处理科长角色
323
+     */
324
+    private void handleSectionLeaderRoleForSpecificDTO(Long userId, Long deptId, java.util.Date startDate, java.util.Date endDate, SectionMasterSeizureReportDTO dto) {
325
+        // 待处理数据数量 - 查获审批流程中需要当前用户审批的任务数
326
+        Integer pendingCount = seizureReportMapper.selectPendingCount(userId, null, null, null);
327
+        dto.setPendingCount(pendingCount);
328
+
329
+        // 科室平均数 = 科室查获总数 / 科室下所有班组长和安检员数量
330
+        BigDecimal totalDepartmentSeizure = seizureReportMapper.selectDepartmentAverage(deptId, startDate, endDate);
331
+        Integer deptUserCount = seizureReportMapper.selectUserCountByDepartmentId(deptId);
332
+        BigDecimal sectionAverage = (deptUserCount != null && deptUserCount > 0) ?
333
+                totalDepartmentSeizure.divide(new BigDecimal(deptUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
334
+        dto.setDepartmentAverage(sectionAverage);
335
+
336
+        // 大队平均数 = 大队查获总数 / 大队下所有科室下所有班组长和安检员数量
337
+        Long brigadeDeptId = getStationDeptId(deptId);
338
+        BigDecimal totalBrigadeSeizure = seizureReportMapper.selectBrigadeAverage(brigadeDeptId, startDate, endDate);
339
+        Integer brigadeUserCount = seizureReportMapper.selectUserCountByBrigadeId(brigadeDeptId);
340
+        BigDecimal brigadeAverage = (brigadeUserCount != null && brigadeUserCount > 0) ?
341
+                totalBrigadeSeizure.divide(new BigDecimal(brigadeUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
342
+        dto.setBrigadeAverage(brigadeAverage);
343
+
344
+        // 全站平均数 = 全站查获总数 / 全站所有班组长和安检员数量
345
+        Long stationDeptId = getStationDeptId(brigadeDeptId);
346
+        BigDecimal totalStationSeizure = seizureReportMapper.selectStationAverage(stationDeptId, startDate, endDate);
347
+        Integer stationUserCount = seizureReportMapper.selectUserCountByStationId(stationDeptId);
348
+        BigDecimal stationAverage = (stationUserCount != null && stationUserCount > 0) ?
349
+                totalStationSeizure.divide(new BigDecimal(stationUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
350
+        dto.setStationAverage(stationAverage);
351
+
352
+        // 科室查获总数
353
+        BigDecimal sectionSeizure = seizureReportMapper.selectDepartmentSeizure(deptId, startDate, endDate);
354
+        dto.setDepartmentSeizure(sectionSeizure);
355
+
356
+        // 科室排名前三的班组
357
+        List<SeizureReportDTO.TopThreeTeamItem> topThreeTeams = seizureReportMapper.selectTopThreeTeams(deptId, startDate, endDate);
358
+        // 为每个团队设置排名
359
+        for (int i = 0; i < topThreeTeams.size(); i++) {
360
+            topThreeTeams.get(i).setRank(i + 1);
361
+        }
362
+        dto.setTopThreeTeams(topThreeTeams);
363
+
364
+        // 设置全大队排名 - 科室排名/全大队科室数总和
365
+        SeizureReportDTO.RankingInfo brigadeRanking = new SeizureReportDTO.RankingInfo();
366
+        Integer deptInBrigadeRank = getDepartmentRankInBrigade(deptId, brigadeDeptId, startDate, endDate);
367
+        Integer brigadeTotalDepts = seizureReportMapper.selectDepartmentCountByBrigadeId(stationDeptId);
368
+        brigadeRanking.setCurrentRank(deptInBrigadeRank);
369
+        brigadeRanking.setTotalItems(brigadeTotalDepts);
370
+        brigadeRanking.setRankingText(deptInBrigadeRank + "/" + brigadeTotalDepts);
371
+        dto.setBrigadeRanking(brigadeRanking);
372
+
373
+        // 设置全站排名 - 科室排名/全站科室数总和
374
+        SeizureReportDTO.RankingInfo stationRanking = new SeizureReportDTO.RankingInfo();
375
+        Integer deptInStationRank = getDepartmentRankInStation(deptId, stationDeptId, startDate, endDate);
376
+        Integer stationTotalDepts = seizureReportMapper.selectDepartmentCountByStationId(stationDeptId);
377
+        stationRanking.setCurrentRank(deptInStationRank);
378
+        stationRanking.setTotalItems(stationTotalDepts);
379
+        stationRanking.setRankingText(deptInStationRank + "/" + stationTotalDepts);
380
+        dto.setStationRanking(stationRanking);
381
+    }
382
+
383
+    /**
384
+     * 处理经理和大队行政角色
385
+     */
386
+    private void handleBrigadeLeaderRoleForSpecificDTO(Long userId, Long deptId, java.util.Date startDate, java.util.Date endDate, BrigadeLeaderSeizureReportDTO dto) {
387
+        // 大队平均数 = 大队查获总数 / 大队下所有科室下所有班组长和安检员数量
388
+        BigDecimal totalBrigadeSeizure = seizureReportMapper.selectBrigadeAverage(deptId, startDate, endDate);
389
+        Integer brigadeUserCount = seizureReportMapper.selectUserCountByBrigadeId(deptId);
390
+        BigDecimal brigadeAverage = (brigadeUserCount != null && brigadeUserCount > 0) ?
391
+                totalBrigadeSeizure.divide(new BigDecimal(brigadeUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
392
+        dto.setBrigadeAverage(brigadeAverage);
393
+
394
+        // 全站平均数 = 全站查获总数 / 全站所有班组长和安检员数量
395
+        Long stationDeptId = getStationDeptId(deptId);
396
+        BigDecimal totalStationSeizure = seizureReportMapper.selectStationAverage(stationDeptId, startDate, endDate);
397
+        Integer stationUserCount = seizureReportMapper.selectUserCountByStationId(stationDeptId);
398
+        BigDecimal stationAverage = (stationUserCount != null && stationUserCount > 0) ?
399
+                totalStationSeizure.divide(new BigDecimal(stationUserCount), 2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO;
400
+        dto.setStationAverage(stationAverage);
401
+
402
+        // 大队查获总数
403
+        BigDecimal brigadeSeizure = seizureReportMapper.selectBrigadeSeizure(deptId, startDate, endDate);
404
+        dto.setBrigadeSeizure(brigadeSeizure);
405
+
406
+        // 大队排名前三的主管
407
+        List<SeizureReportDTO.TopThreeDepartmentItem> topThreeDepartment = seizureReportMapper.selectTopThreeDepartment(deptId, startDate, endDate);
408
+        // 为每个团队设置排名
409
+        for (int i = 0; i < topThreeDepartment.size(); i++) {
410
+            topThreeDepartment.get(i).setRank(i + 1);
411
+        }
412
+        dto.setTopThreeDepartment(topThreeDepartment);
413
+
414
+        // 设置全站排名 - 大队排名/全站大队数总和
415
+        SeizureReportDTO.RankingInfo stationRanking = new SeizureReportDTO.RankingInfo();
416
+        Integer deptInStationRank = getBrigadeRankInStation(deptId, stationDeptId, startDate, endDate);
417
+        Integer stationTotalDepts = seizureReportMapper.selectBrigadeCountByStationId(stationDeptId);
418
+        stationRanking.setCurrentRank(deptInStationRank);
419
+        stationRanking.setTotalItems(stationTotalDepts);
420
+        stationRanking.setRankingText(deptInStationRank + "/" + stationTotalDepts);
421
+        dto.setStationRanking(stationRanking);
422
+    }
423
+
424
+    /**
425
+     * 处理站长和质检员角色
426
+     */
427
+    private void handleStationLeaderRoleForSpecificDTO(Long userId, Long deptId, java.util.Date startDate, java.util.Date endDate, StationLeaderSeizureReportDTO dto) {
428
+        // 全站查获总数
429
+        BigDecimal totalStationSeizure = seizureReportMapper.selectTotalStationSeizure(deptId, startDate, endDate);
430
+        dto.setTotalStationSeizure(totalStationSeizure);
431
+
432
+        // 科室排名
433
+//        List<SeizureReportDTO.DepartmentRankingItem> departmentRankings = seizureReportMapper.selectDepartmentRankings(deptId, startDate, endDate);
434
+//        dto.setDepartmentRankings(departmentRankings);
435
+
436
+        // 班组排名前三
437
+        List<SeizureReportDTO.TeamRankingItem> topThreeTeamRankings = seizureReportMapper.selectTopThreeTeamRankings(deptId, startDate, endDate, "desc");
438
+        dto.setTopThreeTeamRankings(topThreeTeamRankings);
439
+
440
+        // 班组排名倒数前三
441
+        List<SeizureReportDTO.TeamRankingItem> bottomThreeTeamRankings = seizureReportMapper.selectTopThreeTeamRankings(deptId, startDate, endDate, "asc");
442
+        dto.setBotomThreeTeamRankings(bottomThreeTeamRankings);
443
+
444
+        // 大队排名
445
+        List<SeizureReportDTO.BrigadeRankingItem> brigadeRankings = seizureReportMapper.selectBrigadeRankings(deptId, startDate, endDate);
446
+        dto.setBrigadeRankings(brigadeRankings);
447
+
448
+        // 科室排名前三
449
+        List<SeizureReportDTO.DepartmentRankingItem> topThreeDepartmentRankings = seizureReportMapper.selectTopThreeDepartmentRankings(deptId, startDate, endDate, "desc");
450
+        dto.setTopThreeDepartmentRankings(topThreeDepartmentRankings);
451
+
452
+        // 科室排名倒数前三
453
+        List<SeizureReportDTO.DepartmentRankingItem> bottomThreeDepartmentRankings = seizureReportMapper.selectTopThreeDepartmentRankings(deptId, startDate, endDate, "asc");
454
+        dto.setBotomThreeDepartmentRankings(bottomThreeDepartmentRankings);
455
+    }
456
+
457
+    /**
458
+     * 获取班组在科室内的排名
459
+     */
460
+    private Integer getTeamRankInDepartment(Long teamId, Long departmentId, java.util.Date startDate, java.util.Date endDate) {
461
+        // 获取科室下所有班组的排名
462
+        List<SeizureReportDTO.TeamRankingItem> allTeamRankings = seizureReportMapper.selectAllTeamRankingsInDepartment(departmentId, startDate, endDate);
463
+
464
+        // 找到指定班组的排名
465
+        for (int i = 0; i < allTeamRankings.size(); i++) {
466
+            SeizureReportDTO.TeamRankingItem item = allTeamRankings.get(i);
467
+            // 由于TeamRankingItem的teamName只包含班组名称,我们需要通过其他方式匹配
468
+            // 我们需要查询当前班组的名称以进行匹配
469
+            SysDept currentTeam = sysDeptService.selectDeptById(teamId);
470
+            if (currentTeam != null && item.getTeamName().equals(currentTeam.getDeptName())) {
471
+                return i + 1; // 排名从1开始
472
+            }
473
+        }
474
+        return allTeamRankings.size() + 1; // 如果未找到,则为最后一名
475
+    }
476
+
477
+    /**
478
+     * 获取班组在大队内的排名
479
+     */
480
+    private Integer getTeamRankInBrigade(Long teamId, Long brigadetId, java.util.Date startDate, java.util.Date endDate) {
481
+        // 获取科室下所有班组的排名
482
+        List<SeizureReportDTO.TeamRankingItem> allBrigadeRankings = seizureReportMapper.selectAllTeamRankingsInBrigade(brigadetId, startDate, endDate);
483
+
484
+        // 找到指定班组的排名
485
+        for (int i = 0; i < allBrigadeRankings.size(); i++) {
486
+            SeizureReportDTO.TeamRankingItem item = allBrigadeRankings.get(i);
487
+            // 由于TeamRankingItem的teamName只包含班组名称,我们需要通过其他方式匹配
488
+            // 我们需要查询当前班组的名称以进行匹配
489
+            SysDept currentTeam = sysDeptService.selectDeptById(teamId);
490
+            if (currentTeam != null && item.getTeamName().equals(currentTeam.getDeptName())) {
491
+                return i + 1; // 排名从1开始
492
+            }
493
+        }
494
+        return allBrigadeRankings.size() + 1; // 如果未找到,则为最后一名
495
+    }
496
+
497
+    /**
498
+     * 获取班组在全站内的排名
499
+     */
500
+    private Integer getTeamRankInStation(Long teamId, Long stationId, java.util.Date startDate, java.util.Date endDate) {
501
+        // 获取全站下所有班组的排名
502
+        List<SeizureReportDTO.TeamRankingItem> allStationTeamRankings = seizureReportMapper.selectAllTeamRankingsInStation(stationId, startDate, endDate);
503
+
504
+        // 找到指定班组的排名
505
+        for (int i = 0; i < allStationTeamRankings.size(); i++) {
506
+            SeizureReportDTO.TeamRankingItem item = allStationTeamRankings.get(i);
507
+            // 由于TeamRankingItem的teamName包含科室名称+班组名称,我们需要通过其他方式匹配
508
+            SysDept currentTeam = sysDeptService.selectDeptById(teamId);
509
+            if (currentTeam != null) {
510
+                // 检查是否包含班组名称
511
+                if (item.getTeamName().contains(currentTeam.getDeptName())) {
512
+                    return i + 1; // 排名从1开始
513
+                }
514
+            }
515
+        }
516
+        return allStationTeamRankings.size() + 1; // 如果未找到,则为最后一名
517
+    }
518
+
519
+    /**
520
+     * 获取科室下所有班组的排名
521
+     */
522
+    private List<SeizureReportDTO.TeamRankingItem> getAllTeamRankingsInDepartment(Long departmentId, java.util.Date startDate, java.util.Date endDate) {
523
+        return seizureReportMapper.selectAllTeamRankingsInDepartment(departmentId, startDate, endDate);
524
+    }
525
+
526
+    /**
527
+     * 获取科室在全站内的排名
528
+     */
529
+    private Integer getDepartmentRankInStation(Long deptId, Long stationId, java.util.Date startDate, java.util.Date endDate) {
530
+        // 获取全站下所有科室的排名
531
+        List<SeizureReportDTO.DepartmentRankingItem> allStationDeptRankings = seizureReportMapper.selectAllDepartmentRankingsInStation(stationId, startDate, endDate);
532
+
533
+        // 找到指定科室的排名
534
+        SysDept currentDept = sysDeptService.selectDeptById(deptId);
535
+        if (currentDept != null) {
536
+            for (int i = 0; i < allStationDeptRankings.size(); i++) {
537
+                SeizureReportDTO.DepartmentRankingItem item = allStationDeptRankings.get(i);
538
+                if (item.getDepartmentName().equals(currentDept.getDeptName())) {
539
+                    return i + 1; // 排名从1开始
540
+                }
541
+            }
542
+        }
543
+        return allStationDeptRankings.size() + 1; // 如果未找到,则为最后一名
544
+    }
545
+
546
+    /**
547
+     * 获取大队在全站内的排名
548
+     */
549
+    private Integer getBrigadeRankInStation(Long deptId, Long stationId, java.util.Date startDate, java.util.Date endDate) {
550
+        // 获取全站下所有科室的排名
551
+        List<SeizureReportDTO.BrigadeRankingItem> allStationDeptRankings = seizureReportMapper.selectAllBrigadeRankingsInStation(stationId, startDate, endDate);
552
+
553
+        // 找到指定科室的排名
554
+        SysDept currentDept = sysDeptService.selectDeptById(deptId);
555
+        if (currentDept != null) {
556
+            for (int i = 0; i < allStationDeptRankings.size(); i++) {
557
+                SeizureReportDTO.BrigadeRankingItem item = allStationDeptRankings.get(i);
558
+                if (item.getBrigadeName().equals(currentDept.getDeptName())) {
559
+                    return i + 1; // 排名从1开始
560
+                }
561
+            }
562
+        }
563
+        return allStationDeptRankings.size() + 1; // 如果未找到,则为最后一名
564
+    }
565
+
566
+    /**
567
+     * 获取科室在全站内的排名
568
+     */
569
+    private Integer getDepartmentRankInBrigade(Long deptId, Long brigadeId, java.util.Date startDate, java.util.Date endDate) {
570
+        // 获取全站下所有科室的排名
571
+        List<SeizureReportDTO.DepartmentRankingItem> allStationDeptRankings = seizureReportMapper.selectAllDepartmentRankingsInBrigade(brigadeId, startDate, endDate);
572
+
573
+        // 找到指定科室的排名
574
+        SysDept currentDept = sysDeptService.selectDeptById(deptId);
575
+        if (currentDept != null) {
576
+            for (int i = 0; i < allStationDeptRankings.size(); i++) {
577
+                SeizureReportDTO.DepartmentRankingItem item = allStationDeptRankings.get(i);
578
+                if (item.getDepartmentName().equals(currentDept.getDeptName())) {
579
+                    return i + 1; // 排名从1开始
580
+                }
581
+            }
582
+        }
583
+        return allStationDeptRankings.size() + 1; // 如果未找到,则为最后一名
584
+    }
585
+
586
+    /**
587
+     * 获取全站下所有班组的排名
588
+     */
589
+    private List<SeizureReportDTO.TeamRankingItem> getAllTeamRankingsInStation(Long stationId, java.util.Date startDate, java.util.Date endDate) {
590
+        return seizureReportMapper.selectAllTeamRankingsInStation(stationId, startDate, endDate);
591
+    }
592
+
593
+    /**
594
+     * 获取科室部门ID(根据班组ID获取父级科室)
595
+     */
596
+    private Long getSectionDeptId(Long teamDeptId) {
597
+        return seizureReportMapper.selectSectionDeptIdByTeamId(teamDeptId);
598
+    }
599
+
600
+    /**
601
+     * 获取站点部门ID(根据部门ID获取站点级别ID)
602
+     */
603
+    private Long getStationDeptId(Long deptId) {
604
+        return seizureReportMapper.selectStationDeptIdByDeptId(deptId);
605
+    }
606
+
607
+    /**
608
+     * 获取数据权限
609
+     *
610
+     * @param userId 用户ID
611
+     * @param deptId 部门ID
612
+     * @return 数据权限结果
613
+     */
614
+    private DataPermissionResult getDataPermission(Long userId, Long deptId) {
615
+        LoginUser loginUser = getLoginUser();
616
+        if (loginUser == null) {
617
+            return new DataPermissionResult(DataPermissionType.ALL, null);
618
+        }
619
+
620
+        // 假设我们通过某种方式获取到用户的角色
621
+        List<SysRole> roles = loginUser.getUser().getRoles();
622
+        List<String> roleKeys = roles.stream().map(SysRole::getRoleKey).collect(Collectors.toList());
623
+
624
+        if (roleKeys.contains(RoleTypeEnum.SecurityCheck.getCode())) {
625
+            return new DataPermissionResult(DataPermissionType.SELF, userId);
626
+        } else if (roleKeys.contains(RoleTypeEnum.banzuzhang.getCode())) {
627
+            return new DataPermissionResult(DataPermissionType.TEAM, deptId);
628
+        } else if (roleKeys.contains(RoleTypeEnum.kezhang.getCode())) {
629
+            return new DataPermissionResult(DataPermissionType.DEPARTMENT, deptId);
630
+        } else if (roleKeys.contains(RoleTypeEnum.jingli.getCode()) || roleKeys.contains(RoleTypeEnum.xingzheng.getCode())) {
631
+            return new DataPermissionResult(DataPermissionType.BRIGADE, deptId);
632
+        } else if (roleKeys.contains(RoleTypeEnum.test.getCode()) || roleKeys.contains(RoleTypeEnum.zhijianke.getCode())) {
633
+            return new DataPermissionResult(DataPermissionType.STATION, deptId);
634
+        } else {
635
+            return new DataPermissionResult(DataPermissionType.ALL, null);
636
+        }
637
+    }
638
+
639
+}

+ 697 - 0
airport-item/src/main/resources/mapper/item/SeizureReportMapper.xml

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