|
|
@@ -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
|
+}
|