|
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+package com.sundot.airport.personnel.service.impl;
|
|
|
2
|
+
|
|
|
3
|
+import com.sundot.airport.common.core.domain.entity.SysDept;
|
|
|
4
|
+import com.sundot.airport.common.core.domain.entity.SysUser;
|
|
|
5
|
+import com.sundot.airport.common.exception.ServiceException;
|
|
|
6
|
+import com.sundot.airport.personnel.domain.PersonnelMonthlyAssessment;
|
|
|
7
|
+import com.sundot.airport.personnel.mapper.PersonnelMonthlyAssessmentMapper;
|
|
|
8
|
+import com.sundot.airport.personnel.service.IPersonnelMonthlyAssessmentService;
|
|
|
9
|
+import com.sundot.airport.system.mapper.SysDeptMapper;
|
|
|
10
|
+import com.sundot.airport.system.mapper.SysUserMapper;
|
|
|
11
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12
|
+import org.springframework.stereotype.Service;
|
|
|
13
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
14
|
+
|
|
|
15
|
+import java.math.BigDecimal;
|
|
|
16
|
+import java.util.*;
|
|
|
17
|
+import java.util.stream.Collectors;
|
|
|
18
|
+
|
|
|
19
|
+/**
|
|
|
20
|
+ * 人员月度考核Service业务层处理
|
|
|
21
|
+ *
|
|
|
22
|
+ * @author ruoyi
|
|
|
23
|
+ * @date 2026-05-07
|
|
|
24
|
+ */
|
|
|
25
|
+@Service
|
|
|
26
|
+public class PersonnelMonthlyAssessmentServiceImpl implements IPersonnelMonthlyAssessmentService {
|
|
|
27
|
+ @Autowired
|
|
|
28
|
+ private PersonnelMonthlyAssessmentMapper personnelMonthlyAssessmentMapper;
|
|
|
29
|
+
|
|
|
30
|
+ @Autowired
|
|
|
31
|
+ private SysDeptMapper sysDeptMapper;
|
|
|
32
|
+
|
|
|
33
|
+ @Autowired
|
|
|
34
|
+ private SysUserMapper sysUserMapper;
|
|
|
35
|
+
|
|
|
36
|
+ /**
|
|
|
37
|
+ * 查询人员月度考核
|
|
|
38
|
+ *
|
|
|
39
|
+ * @param id 人员月度考核主键
|
|
|
40
|
+ * @return 人员月度考核
|
|
|
41
|
+ */
|
|
|
42
|
+ @Override
|
|
|
43
|
+ public PersonnelMonthlyAssessment selectPersonnelMonthlyAssessmentById(Long id) {
|
|
|
44
|
+ return personnelMonthlyAssessmentMapper.selectPersonnelMonthlyAssessmentById(id);
|
|
|
45
|
+ }
|
|
|
46
|
+
|
|
|
47
|
+ /**
|
|
|
48
|
+ * 查询人员月度考核列表
|
|
|
49
|
+ *
|
|
|
50
|
+ * @param personnelMonthlyAssessment 人员月度考核
|
|
|
51
|
+ * @return 人员月度考核
|
|
|
52
|
+ */
|
|
|
53
|
+ @Override
|
|
|
54
|
+ public List<PersonnelMonthlyAssessment> selectPersonnelMonthlyAssessmentList(PersonnelMonthlyAssessment personnelMonthlyAssessment) {
|
|
|
55
|
+ return personnelMonthlyAssessmentMapper.selectPersonnelMonthlyAssessmentList(personnelMonthlyAssessment);
|
|
|
56
|
+ }
|
|
|
57
|
+
|
|
|
58
|
+ /**
|
|
|
59
|
+ * 新增人员月度考核
|
|
|
60
|
+ *
|
|
|
61
|
+ * @param personnelMonthlyAssessment 人员月度考核
|
|
|
62
|
+ * @return 结果
|
|
|
63
|
+ */
|
|
|
64
|
+ @Override
|
|
|
65
|
+ public int insertPersonnelMonthlyAssessment(PersonnelMonthlyAssessment personnelMonthlyAssessment) {
|
|
|
66
|
+ // 校验同一用户同一年份月份是否已存在考核记录
|
|
|
67
|
+ PersonnelMonthlyAssessment existing = personnelMonthlyAssessmentMapper.selectByUserIdAndYearMonth(
|
|
|
68
|
+ personnelMonthlyAssessment.getUserId(),
|
|
|
69
|
+ personnelMonthlyAssessment.getYear(),
|
|
|
70
|
+ personnelMonthlyAssessment.getMonth()
|
|
|
71
|
+ );
|
|
|
72
|
+ if (existing != null) {
|
|
|
73
|
+ throw new ServiceException("该用户在此考核月份已存在考核记录,请勿重复添加!");
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ // 计算总分:100 - 红线扣分 - 违规排名扣分 - 技能排名扣分
|
|
|
77
|
+ calculateTotalScore(personnelMonthlyAssessment);
|
|
|
78
|
+
|
|
|
79
|
+ return personnelMonthlyAssessmentMapper.insertPersonnelMonthlyAssessment(personnelMonthlyAssessment);
|
|
|
80
|
+ }
|
|
|
81
|
+
|
|
|
82
|
+ /**
|
|
|
83
|
+ * 修改人员月度考核
|
|
|
84
|
+ *
|
|
|
85
|
+ * @param personnelMonthlyAssessment 人员月度考核
|
|
|
86
|
+ * @return 结果
|
|
|
87
|
+ */
|
|
|
88
|
+ @Override
|
|
|
89
|
+ public int updatePersonnelMonthlyAssessment(PersonnelMonthlyAssessment personnelMonthlyAssessment) {
|
|
|
90
|
+ // 计算总分:100 - 红线扣分 - 违规排名扣分 - 技能排名扣分
|
|
|
91
|
+ calculateTotalScore(personnelMonthlyAssessment);
|
|
|
92
|
+
|
|
|
93
|
+ return personnelMonthlyAssessmentMapper.updatePersonnelMonthlyAssessment(personnelMonthlyAssessment);
|
|
|
94
|
+ }
|
|
|
95
|
+
|
|
|
96
|
+ /**
|
|
|
97
|
+ * 批量删除人员月度考核
|
|
|
98
|
+ *
|
|
|
99
|
+ * @param ids 需要删除的人员月度考核主键
|
|
|
100
|
+ * @return 结果
|
|
|
101
|
+ */
|
|
|
102
|
+ @Override
|
|
|
103
|
+ public int deletePersonnelMonthlyAssessmentByIds(Long[] ids) {
|
|
|
104
|
+ return personnelMonthlyAssessmentMapper.deletePersonnelMonthlyAssessmentByIds(ids);
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ /**
|
|
|
108
|
+ * 删除人员月度考核信息
|
|
|
109
|
+ *
|
|
|
110
|
+ * @param id 人员月度考核主键
|
|
|
111
|
+ * @return 结果
|
|
|
112
|
+ */
|
|
|
113
|
+ @Override
|
|
|
114
|
+ public int deletePersonnelMonthlyAssessmentById(Long id) {
|
|
|
115
|
+ return personnelMonthlyAssessmentMapper.deletePersonnelMonthlyAssessmentById(id);
|
|
|
116
|
+ }
|
|
|
117
|
+
|
|
|
118
|
+ /**
|
|
|
119
|
+ * 根据用户ID、年份和月份查询考核记录
|
|
|
120
|
+ *
|
|
|
121
|
+ * @param userId 用户ID
|
|
|
122
|
+ * @param year 年份
|
|
|
123
|
+ * @param month 月份
|
|
|
124
|
+ * @return 人员月度考核
|
|
|
125
|
+ */
|
|
|
126
|
+ @Override
|
|
|
127
|
+ public PersonnelMonthlyAssessment selectByUserIdAndYearMonth(Long userId, Integer year, Integer month) {
|
|
|
128
|
+ return personnelMonthlyAssessmentMapper.selectByUserIdAndYearMonth(userId, year, month);
|
|
|
129
|
+ }
|
|
|
130
|
+
|
|
|
131
|
+ /**
|
|
|
132
|
+ * 计算总分
|
|
|
133
|
+ * 总分 = 100 - 红线扣分 - 违规排名扣分 - 技能排名扣分
|
|
|
134
|
+ *
|
|
|
135
|
+ * @param assessment 考核对象
|
|
|
136
|
+ */
|
|
|
137
|
+ private void calculateTotalScore(PersonnelMonthlyAssessment assessment) {
|
|
|
138
|
+ int redLineDeduction = assessment.getRedLineDeduction() == null ? 0 : assessment.getRedLineDeduction();
|
|
|
139
|
+ int violationRankingDeduction = assessment.getViolationRankingDeduction() == null ? 0 : assessment.getViolationRankingDeduction();
|
|
|
140
|
+ int skillRankingDeduction = assessment.getSkillRankingDeduction() == null ? 0 : assessment.getSkillRankingDeduction();
|
|
|
141
|
+
|
|
|
142
|
+ int totalScore = 100 - redLineDeduction - violationRankingDeduction - skillRankingDeduction;
|
|
|
143
|
+ assessment.setTotalScore(totalScore);
|
|
|
144
|
+ }
|
|
|
145
|
+
|
|
|
146
|
+ /**
|
|
|
147
|
+ * 过滤出需要生成本月考核的人员
|
|
|
148
|
+ *
|
|
|
149
|
+ * @param managers 所有经理列表
|
|
|
150
|
+ * @param year 年份
|
|
|
151
|
+ * @param month 月份
|
|
|
152
|
+ * @return 需要生成考核的经理列表
|
|
|
153
|
+ */
|
|
|
154
|
+ private List<PersonnelMonthlyAssessment> filterManagersForMonth(List<PersonnelMonthlyAssessment> managers, Integer year, Integer month) {
|
|
|
155
|
+ List<PersonnelMonthlyAssessment> result = new ArrayList<>();
|
|
|
156
|
+
|
|
|
157
|
+ // 计算本月的月初和月末日期
|
|
|
158
|
+ java.util.Calendar calendar = java.util.Calendar.getInstance();
|
|
|
159
|
+ calendar.set(year, month - 1, 1); // 月初(month-1因为Calendar的月份从0开始)
|
|
|
160
|
+ java.util.Date monthStart = calendar.getTime();
|
|
|
161
|
+
|
|
|
162
|
+ calendar.set(year, month - 1, calendar.getActualMaximum(java.util.Calendar.DAY_OF_MONTH)); // 月末
|
|
|
163
|
+ java.util.Date monthEnd = calendar.getTime();
|
|
|
164
|
+
|
|
|
165
|
+ for (PersonnelMonthlyAssessment manager : managers) {
|
|
|
166
|
+ boolean shouldGenerate = false;
|
|
|
167
|
+
|
|
|
168
|
+ if ("是".equals(manager.getTakeAssessment())) {
|
|
|
169
|
+ // 条件1:参加考核
|
|
|
170
|
+ shouldGenerate = true;
|
|
|
171
|
+ } else if ("否".equals(manager.getTakeAssessment())) {
|
|
|
172
|
+ // 条件2:不参加考核,但需要检查免考核时间
|
|
|
173
|
+ if (manager.getExemptTakeAssessmentStartTime() != null && manager.getExemptTakeAssessmentEndTime() != null) {
|
|
|
174
|
+ // 判断免考核时间是否包括整个月份
|
|
|
175
|
+ boolean exemptCoversWholeMonth =
|
|
|
176
|
+ !manager.getExemptTakeAssessmentStartTime().after(monthStart) &&
|
|
|
177
|
+ !manager.getExemptTakeAssessmentEndTime().before(monthEnd);
|
|
|
178
|
+
|
|
|
179
|
+ // 如果免考核时间不包括整个月份,则需要生成考核
|
|
|
180
|
+ if (!exemptCoversWholeMonth) {
|
|
|
181
|
+ shouldGenerate = true;
|
|
|
182
|
+ }
|
|
|
183
|
+ }
|
|
|
184
|
+ }
|
|
|
185
|
+
|
|
|
186
|
+ if (shouldGenerate) {
|
|
|
187
|
+ result.add(manager);
|
|
|
188
|
+ }
|
|
|
189
|
+ }
|
|
|
190
|
+
|
|
|
191
|
+ return result;
|
|
|
192
|
+ }
|
|
|
193
|
+
|
|
|
194
|
+ /**
|
|
|
195
|
+ * 获取经理/副经理的下属用户ID列表
|
|
|
196
|
+ *
|
|
|
197
|
+ * @param managerUserId 经理/副经理用户ID
|
|
|
198
|
+ * @param workArea 工作区域(副经理有值,经理为null或空)
|
|
|
199
|
+ * @return 下属用户ID列表
|
|
|
200
|
+ */
|
|
|
201
|
+ private List<Long> getSubordinateUserIds(Long managerUserId, String workArea) {
|
|
|
202
|
+ // 1. 查询经理/副经理的用户信息
|
|
|
203
|
+ SysUser manager = sysUserMapper.selectUserById(managerUserId);
|
|
|
204
|
+ if (manager == null || manager.getDeptId() == null) {
|
|
|
205
|
+ return Collections.emptyList();
|
|
|
206
|
+ }
|
|
|
207
|
+
|
|
|
208
|
+ // 2. 获取该部门及所有子部门的ID列表
|
|
|
209
|
+ List<Long> deptIds = getAllSubDeptIds(manager.getDeptId());
|
|
|
210
|
+
|
|
|
211
|
+ // 3. 根据条件查询下属用户
|
|
|
212
|
+ boolean isManager = (workArea == null || workArea.isEmpty());
|
|
|
213
|
+ return personnelMonthlyAssessmentMapper.selectSubordinateUserIds(deptIds, workArea, isManager);
|
|
|
214
|
+ }
|
|
|
215
|
+
|
|
|
216
|
+ /**
|
|
|
217
|
+ * 获取部门及所有子部门的ID列表
|
|
|
218
|
+ *
|
|
|
219
|
+ * @param deptId 部门ID
|
|
|
220
|
+ * @return 部门ID列表(包含当前部门及所有子部门)
|
|
|
221
|
+ */
|
|
|
222
|
+ private List<Long> getAllSubDeptIds(Long deptId) {
|
|
|
223
|
+ List<Long> result = new ArrayList<>();
|
|
|
224
|
+ result.add(deptId); // 添加当前部门
|
|
|
225
|
+
|
|
|
226
|
+ // 查询所有子部门
|
|
|
227
|
+ List<SysDept> subDepts = sysDeptMapper.selectChildrenDeptById(deptId);
|
|
|
228
|
+ if (subDepts != null && !subDepts.isEmpty()) {
|
|
|
229
|
+ for (SysDept subDept : subDepts) {
|
|
|
230
|
+ if ("0".equals(subDept.getDelFlag())) { // 只包含未删除的部门
|
|
|
231
|
+ result.add(subDept.getDeptId());
|
|
|
232
|
+ }
|
|
|
233
|
+ }
|
|
|
234
|
+ }
|
|
|
235
|
+
|
|
|
236
|
+ return result;
|
|
|
237
|
+ }
|
|
|
238
|
+
|
|
|
239
|
+ /**
|
|
|
240
|
+ * 生成本月考核数据
|
|
|
241
|
+ *
|
|
|
242
|
+ * @param year 年份
|
|
|
243
|
+ * @param month 月份
|
|
|
244
|
+ * @return 生成的记录数
|
|
|
245
|
+ */
|
|
|
246
|
+ @Override
|
|
|
247
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
248
|
+ public int generateMonthlyAssessment(Integer year, Integer month) {
|
|
|
249
|
+ // 1. 查询需要考核的经理/副经理列表
|
|
|
250
|
+ List<PersonnelMonthlyAssessment> managers = personnelMonthlyAssessmentMapper.selectManagersForAssessment();
|
|
|
251
|
+ if (managers == null || managers.isEmpty()) {
|
|
|
252
|
+ throw new ServiceException("未找到需要考核的经理人员!");
|
|
|
253
|
+ }
|
|
|
254
|
+
|
|
|
255
|
+ // 2. 过滤出需要生成本月考核的人员
|
|
|
256
|
+ List<PersonnelMonthlyAssessment> filteredManagers = filterManagersForMonth(managers, year, month);
|
|
|
257
|
+ if (filteredManagers.isEmpty()) {
|
|
|
258
|
+ throw new ServiceException("没有需要生成本月考核记录的人员!");
|
|
|
259
|
+ }
|
|
|
260
|
+
|
|
|
261
|
+ // 3. 检查是否已生成本月考核数据,收集需要更新的ID
|
|
|
262
|
+ Map<Long, Long> existingRecordMap = new HashMap<>(); // userId -> 已存在的记录ID
|
|
|
263
|
+ for (PersonnelMonthlyAssessment manager : filteredManagers) {
|
|
|
264
|
+ PersonnelMonthlyAssessment existing = personnelMonthlyAssessmentMapper.selectByUserIdAndYearMonth(
|
|
|
265
|
+ manager.getUserId(), year, month);
|
|
|
266
|
+ if (existing != null) {
|
|
|
267
|
+ existingRecordMap.put(manager.getUserId(), existing.getId());
|
|
|
268
|
+ }
|
|
|
269
|
+ }
|
|
|
270
|
+
|
|
|
271
|
+ // 4. 为每个经理收集下属用户ID
|
|
|
272
|
+ Map<Long, List<Long>> managerSubordinatesMap = new HashMap<>();
|
|
|
273
|
+ List<Long> allSubordinateIds = new ArrayList<>();
|
|
|
274
|
+ for (PersonnelMonthlyAssessment manager : filteredManagers) {
|
|
|
275
|
+ // 获取下属用户ID列表
|
|
|
276
|
+ List<Long> subordinateIds = getSubordinateUserIds(manager.getUserId(), manager.getArea());
|
|
|
277
|
+ managerSubordinatesMap.put(manager.getUserId(), subordinateIds);
|
|
|
278
|
+ allSubordinateIds.addAll(subordinateIds);
|
|
|
279
|
+ }
|
|
|
280
|
+
|
|
|
281
|
+ // 5. 批量查询所有下属的红线行为次数
|
|
|
282
|
+ Map<Long, Integer> redLineCountMap = batchQueryRedLineCounts(allSubordinateIds, year, month);
|
|
|
283
|
+
|
|
|
284
|
+ // 6. 批量查询所有下属的SOC/品控扣分
|
|
|
285
|
+ Map<Long, BigDecimal> socQcDeductionMap = batchQuerySocQcDeductions(allSubordinateIds, year, month);
|
|
|
286
|
+
|
|
|
287
|
+ // 7. 批量查询所有下属的月考成绩
|
|
|
288
|
+ Map<Long, List<Map<String, Object>>> examScoresMap = batchQueryExamScores(allSubordinateIds, year, month);
|
|
|
289
|
+
|
|
|
290
|
+ // 8. 计算每个经理的各项扣分
|
|
|
291
|
+ Map<Long, Integer> redLineDeductionMap = new HashMap<>();
|
|
|
292
|
+ Map<Long, BigDecimal> teamDeductionMap = new HashMap<>();
|
|
|
293
|
+ Map<Long, BigDecimal> teamPassRateMap = new HashMap<>();
|
|
|
294
|
+
|
|
|
295
|
+ for (PersonnelMonthlyAssessment manager : filteredManagers) {
|
|
|
296
|
+ Long managerId = manager.getUserId();
|
|
|
297
|
+ List<Long> subordinateIds = managerSubordinatesMap.get(managerId);
|
|
|
298
|
+
|
|
|
299
|
+ // 计算红线扣分
|
|
|
300
|
+ int totalRedLineCount = 0;
|
|
|
301
|
+ for (Long subId : subordinateIds) {
|
|
|
302
|
+ totalRedLineCount += redLineCountMap.getOrDefault(subId, 0);
|
|
|
303
|
+ }
|
|
|
304
|
+ redLineDeductionMap.put(managerId, calculateRedLineDeduction(totalRedLineCount));
|
|
|
305
|
+
|
|
|
306
|
+ // 判断是否为经理(workArea为空或null表示经理,有值表示副经理)
|
|
|
307
|
+ boolean isManager = (manager.getArea() == null || manager.getArea().isEmpty());
|
|
|
308
|
+
|
|
|
309
|
+ if (isManager) {
|
|
|
310
|
+ // 经理的扣分 = 所有下属副经理扣分*50% 的总和
|
|
|
311
|
+ BigDecimal managerDeduction = calculateManagerDeduction(
|
|
|
312
|
+ manager, filteredManagers, managerSubordinatesMap, socQcDeductionMap
|
|
|
313
|
+ );
|
|
|
314
|
+ teamDeductionMap.put(managerId, managerDeduction);
|
|
|
315
|
+ } else {
|
|
|
316
|
+ // 副经理的扣分是其下属所有用户的扣分总和
|
|
|
317
|
+ BigDecimal teamDeduction = BigDecimal.ZERO;
|
|
|
318
|
+ for (Long subId : subordinateIds) {
|
|
|
319
|
+ teamDeduction = teamDeduction.add(socQcDeductionMap.getOrDefault(subId, BigDecimal.ZERO));
|
|
|
320
|
+ }
|
|
|
321
|
+ teamDeductionMap.put(managerId, teamDeduction);
|
|
|
322
|
+ }
|
|
|
323
|
+
|
|
|
324
|
+ // 计算团队通过率
|
|
|
325
|
+ BigDecimal passRate = calculateTeamPassRate(subordinateIds, examScoresMap);
|
|
|
326
|
+ teamPassRateMap.put(managerId, passRate);
|
|
|
327
|
+ }
|
|
|
328
|
+
|
|
|
329
|
+ // 8. 计算违规排名扣分(全局排序)
|
|
|
330
|
+ Map<Long, Integer> violationDeductionMap = calculateViolationRankingDeduction(teamDeductionMap);
|
|
|
331
|
+
|
|
|
332
|
+ // 9. 计算技能排名扣分(全局排序)
|
|
|
333
|
+ Map<Long, Integer> skillDeductionMap = calculateSkillRankingDeduction(teamPassRateMap);
|
|
|
334
|
+
|
|
|
335
|
+ // 10. 查询上月通过率用于豁免判断
|
|
|
336
|
+ Map<Long, BigDecimal> lastMonthPassRateMap = batchQueryLastMonthPassRate(filteredManagers, year, month);
|
|
|
337
|
+
|
|
|
338
|
+ // 11. 构建考核记录列表
|
|
|
339
|
+ List<PersonnelMonthlyAssessment> insertList = new ArrayList<>();
|
|
|
340
|
+ List<PersonnelMonthlyAssessment> updateList = new ArrayList<>();
|
|
|
341
|
+
|
|
|
342
|
+ for (PersonnelMonthlyAssessment manager : filteredManagers) {
|
|
|
343
|
+ PersonnelMonthlyAssessment assessment = new PersonnelMonthlyAssessment();
|
|
|
344
|
+ assessment.setUserId(manager.getUserId());
|
|
|
345
|
+ assessment.setName(manager.getName());
|
|
|
346
|
+ assessment.setPost(manager.getPost());
|
|
|
347
|
+ assessment.setArea(manager.getArea());
|
|
|
348
|
+ assessment.setDeptId(manager.getDeptId());
|
|
|
349
|
+ assessment.setDeptName(manager.getDeptName());
|
|
|
350
|
+ assessment.setYear(year);
|
|
|
351
|
+ assessment.setMonth(month);
|
|
|
352
|
+
|
|
|
353
|
+ // 设置各项扣分
|
|
|
354
|
+ assessment.setRedLineDeduction(redLineDeductionMap.getOrDefault(manager.getUserId(), 0));
|
|
|
355
|
+ assessment.setViolationRankingDeduction(violationDeductionMap.getOrDefault(manager.getUserId(), 0));
|
|
|
356
|
+ assessment.setSkillRankingDeduction(skillDeductionMap.getOrDefault(manager.getUserId(), 0));
|
|
|
357
|
+
|
|
|
358
|
+ // 检查豁免情况
|
|
|
359
|
+ BigDecimal currentPassRate = teamPassRateMap.get(manager.getUserId());
|
|
|
360
|
+ BigDecimal lastPassRate = lastMonthPassRateMap.get(manager.getUserId());
|
|
|
361
|
+ if (currentPassRate != null && lastPassRate != null
|
|
|
362
|
+ && currentPassRate.compareTo(BigDecimal.ZERO) > 0
|
|
|
363
|
+ && lastPassRate.compareTo(BigDecimal.ZERO) > 0
|
|
|
364
|
+ && currentPassRate.compareTo(lastPassRate) > 0) {
|
|
|
365
|
+ assessment.setSkillExemptionStatus("通过率较上月提升,豁免技能排名扣分");
|
|
|
366
|
+ assessment.setSkillRankingDeduction(0);
|
|
|
367
|
+ } else {
|
|
|
368
|
+ assessment.setSkillExemptionStatus("无豁免");
|
|
|
369
|
+ }
|
|
|
370
|
+
|
|
|
371
|
+ // 计算总分
|
|
|
372
|
+ calculateTotalScore(assessment);
|
|
|
373
|
+
|
|
|
374
|
+ // 计算考核结果和备注
|
|
|
375
|
+ calculateAssessmentResult(assessment);
|
|
|
376
|
+
|
|
|
377
|
+ // 判断是新增还是更新
|
|
|
378
|
+ Long existingId = existingRecordMap.get(manager.getUserId());
|
|
|
379
|
+ if (existingId != null) {
|
|
|
380
|
+ // 已存在,设置为更新
|
|
|
381
|
+ assessment.setId(existingId);
|
|
|
382
|
+ updateList.add(assessment);
|
|
|
383
|
+ } else {
|
|
|
384
|
+ // 不存在,设置为新增
|
|
|
385
|
+ insertList.add(assessment);
|
|
|
386
|
+ }
|
|
|
387
|
+ }
|
|
|
388
|
+
|
|
|
389
|
+ // 12. 批量插入和更新
|
|
|
390
|
+ int insertCount = 0;
|
|
|
391
|
+ int updateCount = 0;
|
|
|
392
|
+
|
|
|
393
|
+ if (!insertList.isEmpty()) {
|
|
|
394
|
+ insertCount = personnelMonthlyAssessmentMapper.batchInsertPersonnelMonthlyAssessment(insertList);
|
|
|
395
|
+ }
|
|
|
396
|
+
|
|
|
397
|
+ if (!updateList.isEmpty()) {
|
|
|
398
|
+ for (PersonnelMonthlyAssessment assessment : updateList) {
|
|
|
399
|
+ updateCount += personnelMonthlyAssessmentMapper.updatePersonnelMonthlyAssessment(assessment);
|
|
|
400
|
+ }
|
|
|
401
|
+ }
|
|
|
402
|
+
|
|
|
403
|
+ return insertCount + updateCount;
|
|
|
404
|
+ }
|
|
|
405
|
+
|
|
|
406
|
+ /**
|
|
|
407
|
+ * 计算红线扣分
|
|
|
408
|
+ * 1次扣5分,2次扣10分,3次及以上扣20分
|
|
|
409
|
+ *
|
|
|
410
|
+ * @param redLineCount 红线行为次数
|
|
|
411
|
+ * @return 扣分分值
|
|
|
412
|
+ */
|
|
|
413
|
+ private int calculateRedLineDeduction(int redLineCount) {
|
|
|
414
|
+ if (redLineCount <= 0) {
|
|
|
415
|
+ return 0;
|
|
|
416
|
+ } else if (redLineCount == 1) {
|
|
|
417
|
+ return 5;
|
|
|
418
|
+ } else if (redLineCount == 2) {
|
|
|
419
|
+ return 10;
|
|
|
420
|
+ } else {
|
|
|
421
|
+ return 20;
|
|
|
422
|
+ }
|
|
|
423
|
+ }
|
|
|
424
|
+
|
|
|
425
|
+ /**
|
|
|
426
|
+ * 批量查询红线行为次数
|
|
|
427
|
+ */
|
|
|
428
|
+ private Map<Long, Integer> batchQueryRedLineCounts(List<Long> userIds, Integer year, Integer month) {
|
|
|
429
|
+ Map<Long, Integer> resultMap = new HashMap<>();
|
|
|
430
|
+ if (userIds == null || userIds.isEmpty()) {
|
|
|
431
|
+ return resultMap;
|
|
|
432
|
+ }
|
|
|
433
|
+
|
|
|
434
|
+ List<HashMap<String, Object>> results = personnelMonthlyAssessmentMapper.batchCountRedLineViolations(userIds, year, month);
|
|
|
435
|
+ for (HashMap<String, Object> row : results) {
|
|
|
436
|
+ Long userId = ((Number) row.get("userId")).longValue();
|
|
|
437
|
+ Integer count = ((Number) row.get("redLineCount")).intValue();
|
|
|
438
|
+ resultMap.put(userId, count);
|
|
|
439
|
+ }
|
|
|
440
|
+ return resultMap;
|
|
|
441
|
+ }
|
|
|
442
|
+
|
|
|
443
|
+ /**
|
|
|
444
|
+ * 批量查询SOC/品控扣分
|
|
|
445
|
+ */
|
|
|
446
|
+ private Map<Long, BigDecimal> batchQuerySocQcDeductions(List<Long> userIds, Integer year, Integer month) {
|
|
|
447
|
+ Map<Long, BigDecimal> resultMap = new HashMap<>();
|
|
|
448
|
+ if (userIds == null || userIds.isEmpty()) {
|
|
|
449
|
+ return resultMap;
|
|
|
450
|
+ }
|
|
|
451
|
+
|
|
|
452
|
+ List<HashMap<String, Object>> results = personnelMonthlyAssessmentMapper.batchGetSocQcDeductions(userIds, year, month);
|
|
|
453
|
+ for (HashMap<String, Object> row : results) {
|
|
|
454
|
+ Long userId = ((Number) row.get("userId")).longValue();
|
|
|
455
|
+ BigDecimal deduction = new BigDecimal(row.get("totalDeduction").toString());
|
|
|
456
|
+ resultMap.put(userId, deduction);
|
|
|
457
|
+ }
|
|
|
458
|
+ return resultMap;
|
|
|
459
|
+ }
|
|
|
460
|
+
|
|
|
461
|
+ /**
|
|
|
462
|
+ * 批量查询月考成绩
|
|
|
463
|
+ */
|
|
|
464
|
+ private Map<Long, List<Map<String, Object>>> batchQueryExamScores(List<Long> userIds, Integer year, Integer month) {
|
|
|
465
|
+ Map<Long, List<Map<String, Object>>> resultMap = new HashMap<>();
|
|
|
466
|
+ if (userIds == null || userIds.isEmpty()) {
|
|
|
467
|
+ return resultMap;
|
|
|
468
|
+ }
|
|
|
469
|
+
|
|
|
470
|
+ List<HashMap<String, Object>> results = personnelMonthlyAssessmentMapper.batchGetExamScores(userIds, year, month);
|
|
|
471
|
+ for (HashMap<String, Object> row : results) {
|
|
|
472
|
+ Long userId = ((Number) row.get("userId")).longValue();
|
|
|
473
|
+ resultMap.computeIfAbsent(userId, k -> new ArrayList<>()).add(row);
|
|
|
474
|
+ }
|
|
|
475
|
+ return resultMap;
|
|
|
476
|
+ }
|
|
|
477
|
+
|
|
|
478
|
+ /**
|
|
|
479
|
+ * 计算团队通过率
|
|
|
480
|
+ */
|
|
|
481
|
+ private BigDecimal calculateTeamPassRate(List<Long> subordinateIds, Map<Long, List<Map<String, Object>>> examScoresMap) {
|
|
|
482
|
+ if (subordinateIds == null || subordinateIds.isEmpty()) {
|
|
|
483
|
+ return BigDecimal.ZERO;
|
|
|
484
|
+ }
|
|
|
485
|
+
|
|
|
486
|
+ int totalCount = 0;
|
|
|
487
|
+ int passCount = 0;
|
|
|
488
|
+
|
|
|
489
|
+ for (Long userId : subordinateIds) {
|
|
|
490
|
+ List<Map<String, Object>> scores = examScoresMap.get(userId);
|
|
|
491
|
+ if (scores != null) {
|
|
|
492
|
+ for (Map<String, Object> score : scores) {
|
|
|
493
|
+ totalCount++;
|
|
|
494
|
+ String post = (String) score.get("post");
|
|
|
495
|
+ BigDecimal scoreValue = new BigDecimal(score.get("score").toString());
|
|
|
496
|
+
|
|
|
497
|
+ // X光机操作员90分合格,四级安检员60分合格
|
|
|
498
|
+ if (("X光机操作员".equals(post) && scoreValue.compareTo(new BigDecimal("90")) >= 0)
|
|
|
499
|
+ || ("四级安检员".equals(post) && scoreValue.compareTo(new BigDecimal("60")) >= 0)) {
|
|
|
500
|
+ passCount++;
|
|
|
501
|
+ }
|
|
|
502
|
+ }
|
|
|
503
|
+ }
|
|
|
504
|
+ }
|
|
|
505
|
+
|
|
|
506
|
+ if (totalCount == 0) {
|
|
|
507
|
+ return BigDecimal.ZERO;
|
|
|
508
|
+ }
|
|
|
509
|
+
|
|
|
510
|
+ return new BigDecimal(passCount).multiply(new BigDecimal("100")).divide(new BigDecimal(totalCount), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
511
|
+ }
|
|
|
512
|
+
|
|
|
513
|
+ /**
|
|
|
514
|
+ * 批量查询上月通过率
|
|
|
515
|
+ */
|
|
|
516
|
+ private Map<Long, BigDecimal> batchQueryLastMonthPassRate(List<PersonnelMonthlyAssessment> managers, Integer year, Integer month) {
|
|
|
517
|
+ Map<Long, BigDecimal> resultMap = new HashMap<>();
|
|
|
518
|
+
|
|
|
519
|
+ // 计算上月的年月
|
|
|
520
|
+ int lastYear = year;
|
|
|
521
|
+ int lastMonth = month - 1;
|
|
|
522
|
+ if (lastMonth == 0) {
|
|
|
523
|
+ lastMonth = 12;
|
|
|
524
|
+ lastYear = year - 1;
|
|
|
525
|
+ }
|
|
|
526
|
+
|
|
|
527
|
+ // 为每个经理查询上月通过率
|
|
|
528
|
+ for (PersonnelMonthlyAssessment manager : managers) {
|
|
|
529
|
+ List<Long> subordinateIds = getSubordinateUserIds(manager.getUserId(), manager.getArea());
|
|
|
530
|
+ Map<Long, List<Map<String, Object>>> examScoresMap = batchQueryExamScores(subordinateIds, lastYear, lastMonth);
|
|
|
531
|
+ BigDecimal passRate = calculateTeamPassRate(subordinateIds, examScoresMap);
|
|
|
532
|
+ resultMap.put(manager.getUserId(), passRate);
|
|
|
533
|
+ }
|
|
|
534
|
+
|
|
|
535
|
+ return resultMap;
|
|
|
536
|
+ }
|
|
|
537
|
+
|
|
|
538
|
+ /**
|
|
|
539
|
+ * 计算违规排名扣分
|
|
|
540
|
+ * 末位扣3分,倒数第二扣2分,倒数第三扣1分
|
|
|
541
|
+ *
|
|
|
542
|
+ * @param teamDeductionMap 经理ID -> 团队扣分总额的映射
|
|
|
543
|
+ * @return 经理ID -> 扣分的映射
|
|
|
544
|
+ */
|
|
|
545
|
+ private Map<Long, Integer> calculateViolationRankingDeduction(Map<Long, BigDecimal> teamDeductionMap) {
|
|
|
546
|
+ Map<Long, Integer> deductionMap = new HashMap<>();
|
|
|
547
|
+
|
|
|
548
|
+ if (teamDeductionMap == null || teamDeductionMap.isEmpty()) {
|
|
|
549
|
+ return deductionMap;
|
|
|
550
|
+ }
|
|
|
551
|
+
|
|
|
552
|
+ // 按扣分总额从高到低排序
|
|
|
553
|
+ List<Map.Entry<Long, BigDecimal>> sortedList = new ArrayList<>(teamDeductionMap.entrySet());
|
|
|
554
|
+ sortedList.sort((e1, e2) -> e2.getValue().compareTo(e1.getValue()));
|
|
|
555
|
+
|
|
|
556
|
+ int size = sortedList.size();
|
|
|
557
|
+ if (size >= 3) {
|
|
|
558
|
+ // 末位(扣分最少)扣3分
|
|
|
559
|
+ deductionMap.put(sortedList.get(size - 1).getKey(), 3);
|
|
|
560
|
+ // 倒数第二扣2分
|
|
|
561
|
+ deductionMap.put(sortedList.get(size - 2).getKey(), 2);
|
|
|
562
|
+ // 倒数第三扣1分
|
|
|
563
|
+ deductionMap.put(sortedList.get(size - 3).getKey(), 1);
|
|
|
564
|
+ } else if (size == 2) {
|
|
|
565
|
+ deductionMap.put(sortedList.get(1).getKey(), 3);
|
|
|
566
|
+ deductionMap.put(sortedList.get(0).getKey(), 2);
|
|
|
567
|
+ } else if (size == 1) {
|
|
|
568
|
+ deductionMap.put(sortedList.get(0).getKey(), 3);
|
|
|
569
|
+ }
|
|
|
570
|
+
|
|
|
571
|
+ return deductionMap;
|
|
|
572
|
+ }
|
|
|
573
|
+
|
|
|
574
|
+ /**
|
|
|
575
|
+ * 计算技能排名扣分
|
|
|
576
|
+ * 末位扣3分,倒数第二扣2分,倒数第三扣1分
|
|
|
577
|
+ *
|
|
|
578
|
+ * @param teamPassRateMap 经理ID -> 团队通过率的映射
|
|
|
579
|
+ * @return 经理ID -> 扣分的映射
|
|
|
580
|
+ */
|
|
|
581
|
+ private Map<Long, Integer> calculateSkillRankingDeduction(Map<Long, BigDecimal> teamPassRateMap) {
|
|
|
582
|
+ Map<Long, Integer> deductionMap = new HashMap<>();
|
|
|
583
|
+
|
|
|
584
|
+ if (teamPassRateMap == null || teamPassRateMap.isEmpty()) {
|
|
|
585
|
+ return deductionMap;
|
|
|
586
|
+ }
|
|
|
587
|
+
|
|
|
588
|
+ // 按通过率从低到高排序
|
|
|
589
|
+ List<Map.Entry<Long, BigDecimal>> sortedList = new ArrayList<>(teamPassRateMap.entrySet());
|
|
|
590
|
+ sortedList.sort((e1, e2) -> e1.getValue().compareTo(e2.getValue()));
|
|
|
591
|
+
|
|
|
592
|
+ int size = sortedList.size();
|
|
|
593
|
+ if (size >= 3) {
|
|
|
594
|
+ // 末位(通过率最低)扣3分
|
|
|
595
|
+ deductionMap.put(sortedList.get(0).getKey(), 3);
|
|
|
596
|
+ // 倒数第二扣2分
|
|
|
597
|
+ deductionMap.put(sortedList.get(1).getKey(), 2);
|
|
|
598
|
+ // 倒数第三扣1分
|
|
|
599
|
+ deductionMap.put(sortedList.get(2).getKey(), 1);
|
|
|
600
|
+ } else if (size == 2) {
|
|
|
601
|
+ deductionMap.put(sortedList.get(0).getKey(), 3);
|
|
|
602
|
+ deductionMap.put(sortedList.get(1).getKey(), 2);
|
|
|
603
|
+ } else if (size == 1) {
|
|
|
604
|
+ deductionMap.put(sortedList.get(0).getKey(), 3);
|
|
|
605
|
+ }
|
|
|
606
|
+
|
|
|
607
|
+ return deductionMap;
|
|
|
608
|
+ }
|
|
|
609
|
+
|
|
|
610
|
+ /**
|
|
|
611
|
+ * 计算考核结果和备注
|
|
|
612
|
+ * 预警:得分低于90分
|
|
|
613
|
+ * 待改进:得分低于85分
|
|
|
614
|
+ * 不称职:得分低于80分
|
|
|
615
|
+ *
|
|
|
616
|
+ * @param assessment 考核对象
|
|
|
617
|
+ */
|
|
|
618
|
+ private void calculateAssessmentResult(PersonnelMonthlyAssessment assessment) {
|
|
|
619
|
+ int totalScore = assessment.getTotalScore() == null ? 100 : assessment.getTotalScore();
|
|
|
620
|
+
|
|
|
621
|
+ if (totalScore < 80) {
|
|
|
622
|
+ assessment.setAssessmentResult("不称职");
|
|
|
623
|
+ assessment.setAssessmentRemark("得分低于80分,认定不称职,建议调整岗位或降职处理");
|
|
|
624
|
+ // 应用方式:降职降薪
|
|
|
625
|
+ assessment.setApplicationMethod("降职降薪");
|
|
|
626
|
+ assessment.setApplicationRemark("考核结果为不称职的,则进行降职降薪处理。");
|
|
|
627
|
+ } else if (totalScore < 85) {
|
|
|
628
|
+ assessment.setAssessmentResult("待改进");
|
|
|
629
|
+ assessment.setAssessmentRemark("得分低于85分,认定待改进,同时启动干部任职画像民主测评");
|
|
|
630
|
+ // 应用方式:民主测评
|
|
|
631
|
+ assessment.setApplicationMethod("民主测评");
|
|
|
632
|
+ assessment.setApplicationRemark("考核结果为待改进,启动干部任职画像民主测评,围绕专业能力、统筹协调能力、群众基础三个维度进行评价,据测评结果确定后续处置意见:");
|
|
|
633
|
+ } else if (totalScore < 90) {
|
|
|
634
|
+ assessment.setAssessmentResult("预警");
|
|
|
635
|
+ assessment.setAssessmentRemark("得分低于90分,启动预警机制,由分管部门班子进行专项督导,推动管理提升");
|
|
|
636
|
+ // 预警暂无特定应用方式
|
|
|
637
|
+ assessment.setApplicationMethod(null);
|
|
|
638
|
+ assessment.setApplicationRemark(null);
|
|
|
639
|
+ } else {
|
|
|
640
|
+ assessment.setAssessmentResult(null);
|
|
|
641
|
+ assessment.setAssessmentRemark(null);
|
|
|
642
|
+ assessment.setApplicationMethod(null);
|
|
|
643
|
+ assessment.setApplicationRemark(null);
|
|
|
644
|
+ }
|
|
|
645
|
+ }
|
|
|
646
|
+
|
|
|
647
|
+ /**
|
|
|
648
|
+ * 计算经理的品控扣分
|
|
|
649
|
+ * 规则:经理的扣分 = 所有下属副经理扣分*50% 的总和
|
|
|
650
|
+ *
|
|
|
651
|
+ * @param manager 经理对象
|
|
|
652
|
+ * @param allManagers 所有经理/副经理列表
|
|
|
653
|
+ * @param managerSubordinatesMap 经理ID -> 下属用户ID列表的映射
|
|
|
654
|
+ * @param socQcDeductionMap 用户ID -> SOC/品控扣分的映射
|
|
|
655
|
+ * @return 经理的品控扣分
|
|
|
656
|
+ */
|
|
|
657
|
+ private BigDecimal calculateManagerDeduction(
|
|
|
658
|
+ PersonnelMonthlyAssessment manager,
|
|
|
659
|
+ List<PersonnelMonthlyAssessment> allManagers,
|
|
|
660
|
+ Map<Long, List<Long>> managerSubordinatesMap,
|
|
|
661
|
+ Map<Long, BigDecimal> socQcDeductionMap) {
|
|
|
662
|
+
|
|
|
663
|
+ // 1. 找出该经理下属的所有副经理(同一部门且有workArea)
|
|
|
664
|
+ List<PersonnelMonthlyAssessment> viceManagersUnderManager = allManagers.stream()
|
|
|
665
|
+ .filter(m -> m.getArea() != null && !m.getArea().isEmpty()) // 是副经理
|
|
|
666
|
+ .filter(m -> {
|
|
|
667
|
+ // 判断副经理是否属于该经理的部门
|
|
|
668
|
+ SysUser viceManager = sysUserMapper.selectUserById(m.getUserId());
|
|
|
669
|
+ return viceManager != null && viceManager.getDeptId() != null
|
|
|
670
|
+ && viceManager.getDeptId().equals(manager.getDeptId());
|
|
|
671
|
+ })
|
|
|
672
|
+ .collect(Collectors.toList());
|
|
|
673
|
+
|
|
|
674
|
+ // 2. 计算每个副经理的扣分*50%,然后累加
|
|
|
675
|
+ BigDecimal managerTotalDeduction = BigDecimal.ZERO;
|
|
|
676
|
+ for (PersonnelMonthlyAssessment viceManager : viceManagersUnderManager) {
|
|
|
677
|
+ // 获取该副经理的下属用户ID列表
|
|
|
678
|
+ List<Long> viceManagerSubIds = managerSubordinatesMap.get(viceManager.getUserId());
|
|
|
679
|
+
|
|
|
680
|
+ // 累加该副经理下属的所有扣分
|
|
|
681
|
+ BigDecimal viceManagerTotalDeduction = BigDecimal.ZERO;
|
|
|
682
|
+ for (Long subId : viceManagerSubIds) {
|
|
|
683
|
+ viceManagerTotalDeduction = viceManagerTotalDeduction.add(
|
|
|
684
|
+ socQcDeductionMap.getOrDefault(subId, BigDecimal.ZERO)
|
|
|
685
|
+ );
|
|
|
686
|
+ }
|
|
|
687
|
+
|
|
|
688
|
+ // 该副经理的扣分 * 50%
|
|
|
689
|
+ viceManagerTotalDeduction = viceManagerTotalDeduction.multiply(new BigDecimal("0.5"));
|
|
|
690
|
+
|
|
|
691
|
+ // 累加到经理的总扣分
|
|
|
692
|
+ managerTotalDeduction = managerTotalDeduction.add(viceManagerTotalDeduction);
|
|
|
693
|
+ }
|
|
|
694
|
+
|
|
|
695
|
+ return managerTotalDeduction;
|
|
|
696
|
+ }
|
|
|
697
|
+}
|