Просмотр исходного кода

非干部月度考核分数汇总

wangxx 1 месяц назад
Родитель
Сommit
ac108b688c

+ 265 - 90
airport-admin/src/main/java/com/sundot/airport/web/controller/personnel/PersonnelNonCadreMonthlyAssessmentScoreSummaryController.java

@@ -126,10 +126,10 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
126
     }
126
     }
127
 
127
 
128
     /**
128
     /**
129
-     * 各部门参与人数占比 - 按组织架构分类
129
+     * 各部门参与人数占比
130
      *
130
      *
131
      * @param assessmentMonth 考核月份(格式:YYYYMM)
131
      * @param assessmentMonth 考核月份(格式:YYYYMM)
132
-     * @return 各部门参与人数及占比
132
+     * @return 各大队参与人数及占比
133
      */
133
      */
134
     @PreAuthorize("@ss.hasPermi('personnel:assessment:query')")
134
     @PreAuthorize("@ss.hasPermi('personnel:assessment:query')")
135
     @GetMapping("/dept-participation")
135
     @GetMapping("/dept-participation")
@@ -143,32 +143,39 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
143
 
143
 
144
             // 获取所有部门信息
144
             // 获取所有部门信息
145
             Map<Long, SysDept> deptMap = getDeptMap();
145
             Map<Long, SysDept> deptMap = getDeptMap();
146
+            
147
+            // 构建大队到其所有子部门ID的映射
148
+            Map<Long, Set<Long>> brigadeSubDeptsMap = buildBrigadeSubDeptsMap(deptMap);
146
 
149
 
147
-            // 按部门统计人数
148
-            Map<Long, Integer> deptCountMap = new HashMap<>();
150
+            // 按大队统计人数
151
+            Map<Long, Integer> brigadeCountMap = new HashMap<>();
149
             int totalCount = list.size();
152
             int totalCount = list.size();
150
 
153
 
151
             for (PersonnelNonCadreMonthlyAssessment item : list) {
154
             for (PersonnelNonCadreMonthlyAssessment item : list) {
152
-                Long deptId = getUserDeptId(item.getUserId());
153
-                if (deptId != null) {
154
-                    deptCountMap.merge(deptId, 1, Integer::sum);
155
+                Long userDeptId = getUserDeptId(item.getUserId());
156
+                if (userDeptId != null) {
157
+                    // 查找该用户所属的大队
158
+                    Long brigadeId = findUserBrigade(userDeptId, brigadeSubDeptsMap);
159
+                    if (brigadeId != null) {
160
+                        brigadeCountMap.merge(brigadeId, 1, Integer::sum);
161
+                    }
155
                 }
162
                 }
156
             }
163
             }
157
 
164
 
158
             // 构建返回结果
165
             // 构建返回结果
159
             List<DeptParticipationDto> result = new ArrayList<>();
166
             List<DeptParticipationDto> result = new ArrayList<>();
160
-            for (Map.Entry<Long, Integer> entry : deptCountMap.entrySet()) {
161
-                Long deptId = entry.getKey();
167
+            for (Map.Entry<Long, Integer> entry : brigadeCountMap.entrySet()) {
168
+                Long brigadeId = entry.getKey();
162
                 Integer count = entry.getValue();
169
                 Integer count = entry.getValue();
163
 
170
 
164
                 DeptParticipationDto dto = new DeptParticipationDto();
171
                 DeptParticipationDto dto = new DeptParticipationDto();
165
-                dto.setDeptId(deptId);
172
+                dto.setDeptId(brigadeId);
166
 
173
 
167
-                SysDept dept = deptMap.get(deptId);
168
-                if (dept != null) {
169
-                    dto.setDeptName(dept.getDeptName());
170
-                    dto.setDeptType(dept.getDeptType());
171
-                    dto.setDeptTypeDesc(dept.getDeptTypeDesc());
174
+                SysDept brigade = deptMap.get(brigadeId);
175
+                if (brigade != null) {
176
+                    dto.setDeptName(brigade.getDeptName());
177
+                    dto.setDeptType(brigade.getDeptType());
178
+                    dto.setDeptTypeDesc(brigade.getDeptTypeDesc());
172
                 }
179
                 }
173
 
180
 
174
                 dto.setCount(count);
181
                 dto.setCount(count);
@@ -196,9 +203,9 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
196
     }
203
     }
197
 
204
 
198
     /**
205
     /**
199
-     * 各部门分值分布
206
+     * 各部门分值分布(按大队级别统计)
200
      * @param assessmentMonth 考核月份(格式:YYYYMM)
207
      * @param assessmentMonth 考核月份(格式:YYYYMM)
201
-     * @return 各分数段的部门人数分布
208
+     * @return 各分数段的大队人数分布
202
      */
209
      */
203
     @PreAuthorize("@ss.hasPermi('personnel:assessment:query')")
210
     @PreAuthorize("@ss.hasPermi('personnel:assessment:query')")
204
     @GetMapping("/dept-score-distribution")
211
     @GetMapping("/dept-score-distribution")
@@ -212,20 +219,23 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
212
 
219
 
213
             // 获取所有部门信息
220
             // 获取所有部门信息
214
             Map<Long, SysDept> deptMap = getDeptMap();
221
             Map<Long, SysDept> deptMap = getDeptMap();
222
+            
223
+            // 构建大队到其所有子部门ID的映射
224
+            Map<Long, Set<Long>> brigadeSubDeptsMap = buildBrigadeSubDeptsMap(deptMap);
215
 
225
 
216
             // 定义6个分数段
226
             // 定义6个分数段
217
             String[] rangeKeys = {"below70", "70-75", "75-80", "80-85", "85-90", "above90"};
227
             String[] rangeKeys = {"below70", "70-75", "75-80", "80-85", "85-90", "above90"};
218
             String[] rangeLabels = {"低于70", "[70-75)", "[75-80)", "[80-85)", "[85-90)", "90以上"};
228
             String[] rangeLabels = {"低于70", "[70-75)", "[75-80)", "[80-85)", "[85-90)", "90以上"};
219
 
229
 
220
-            Map<String, Map<Long, Integer>> rangeDeptCountMap = new LinkedHashMap<>();
230
+            Map<String, Map<Long, Integer>> rangeBrigadeCountMap = new LinkedHashMap<>();
221
             for (String rangeKey : rangeKeys) {
231
             for (String rangeKey : rangeKeys) {
222
-                rangeDeptCountMap.put(rangeKey, new HashMap<>());
232
+                rangeBrigadeCountMap.put(rangeKey, new HashMap<>());
223
             }
233
             }
224
 
234
 
225
-            // 统计每个分数段下各部门的人数
235
+            // 统计每个分数段下各大队的人数
226
             for (PersonnelNonCadreMonthlyAssessment item : list) {
236
             for (PersonnelNonCadreMonthlyAssessment item : list) {
227
-                Long deptId = getUserDeptId(item.getUserId());
228
-                if (deptId == null) {
237
+                Long userDeptId = getUserDeptId(item.getUserId());
238
+                if (userDeptId == null) {
229
                     continue;
239
                     continue;
230
                 }
240
                 }
231
 
241
 
@@ -234,12 +244,18 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
234
                     continue;
244
                     continue;
235
                 }
245
                 }
236
 
246
 
247
+                // 查找该用户所属的大队
248
+                Long brigadeId = findUserBrigade(userDeptId, brigadeSubDeptsMap);
249
+                if (brigadeId == null) {
250
+                    continue;
251
+                }
252
+
237
                 // 确定分数段
253
                 // 确定分数段
238
                 String rangeKey = determineScoreRange(totalScore);
254
                 String rangeKey = determineScoreRange(totalScore);
239
 
255
 
240
-                // 累加该部门在该分数段的人数
241
-                Map<Long, Integer> deptCountMap = rangeDeptCountMap.get(rangeKey);
242
-                deptCountMap.merge(deptId, 1, Integer::sum);
256
+                // 累加该大队在该分数段的人数
257
+                Map<Long, Integer> brigadeCountMap = rangeBrigadeCountMap.get(rangeKey);
258
+                brigadeCountMap.merge(brigadeId, 1, Integer::sum);
243
             }
259
             }
244
 
260
 
245
             // 构建返回结果
261
             // 构建返回结果
@@ -249,20 +265,20 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
249
                 rangeDto.setRangeKey(rangeKeys[i]);
265
                 rangeDto.setRangeKey(rangeKeys[i]);
250
                 rangeDto.setRangeLabel(rangeLabels[i]);
266
                 rangeDto.setRangeLabel(rangeLabels[i]);
251
 
267
 
252
-                Map<Long, Integer> deptCountMap = rangeDeptCountMap.get(rangeKeys[i]);
268
+                Map<Long, Integer> brigadeCountMap = rangeBrigadeCountMap.get(rangeKeys[i]);
253
                 List<ScoreRangeDistributionDto.DeptCountItemDto> deptCounts = new ArrayList<>();
269
                 List<ScoreRangeDistributionDto.DeptCountItemDto> deptCounts = new ArrayList<>();
254
                 int rangeTotalCount = 0;
270
                 int rangeTotalCount = 0;
255
 
271
 
256
-                for (Map.Entry<Long, Integer> entry : deptCountMap.entrySet()) {
257
-                    Long deptId = entry.getKey();
272
+                for (Map.Entry<Long, Integer> entry : brigadeCountMap.entrySet()) {
273
+                    Long brigadeId = entry.getKey();
258
                     Integer count = entry.getValue();
274
                     Integer count = entry.getValue();
259
 
275
 
260
                     ScoreRangeDistributionDto.DeptCountItemDto deptItem = new ScoreRangeDistributionDto.DeptCountItemDto();
276
                     ScoreRangeDistributionDto.DeptCountItemDto deptItem = new ScoreRangeDistributionDto.DeptCountItemDto();
261
-                    deptItem.setDeptId(deptId);
277
+                    deptItem.setDeptId(brigadeId);
262
 
278
 
263
-                    SysDept dept = deptMap.get(deptId);
264
-                    if (dept != null) {
265
-                        deptItem.setDeptName(dept.getDeptName());
279
+                    SysDept brigade = deptMap.get(brigadeId);
280
+                    if (brigade != null) {
281
+                        deptItem.setDeptName(brigade.getDeptName());
266
                     }
282
                     }
267
 
283
 
268
                     deptItem.setCount(count);
284
                     deptItem.setCount(count);
@@ -344,6 +360,29 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
344
     }
360
     }
345
 
361
 
346
     /**
362
     /**
363
+     * 构建大队到其所有子部门ID的映射
364
+     * 用于按大队级别统计,包括大队及其下属所有部门
365
+     *
366
+     * @param deptMap 部门映射表
367
+     * @return 大队ID到其所有子部门ID集合的映射
368
+     */
369
+    private Map<Long, Set<Long>> buildBrigadeSubDeptsMap(Map<Long, SysDept> deptMap) {
370
+        // 获取所有大队部门
371
+        List<SysDept> allBrigades = deptMap.values().stream()
372
+                .filter(dept -> "BRIGADE".equals(dept.getDeptType()))
373
+                .collect(Collectors.toList());
374
+
375
+        // 构建大队到其所有子部门ID的映射
376
+        Map<Long, Set<Long>> brigadeSubDeptsMap = new HashMap<>();
377
+        for (SysDept brigade : allBrigades) {
378
+            Set<Long> subDeptIds = getAllSubDeptIds(brigade.getDeptId(), deptMap);
379
+            brigadeSubDeptsMap.put(brigade.getDeptId(), subDeptIds);
380
+        }
381
+        
382
+        return brigadeSubDeptsMap;
383
+    }
384
+
385
+    /**
347
      * 汇总统计
386
      * 汇总统计
348
      * 统计考核组人数、待改进人数、不称职人数等汇总信息
387
      * 统计考核组人数、待改进人数、不称职人数等汇总信息
349
      *
388
      *
@@ -440,127 +479,141 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
440
     }
479
     }
441
 
480
 
442
     /**
481
     /**
443
-     * 各部门实际待改进人员分布
444
-     * 统计所有实际待改进人员(待改进且未被豁免),按组织架构分类
482
+     * 各部门实际待改进人员分布(按大队级别统计)
483
+     * 统计所有实际待改进人员(待改进且未被豁免),按大队分类
445
      *
484
      *
446
      * @param assessmentMonth 考核月份(格式:YYYYMM)
485
      * @param assessmentMonth 考核月份(格式:YYYYMM)
447
-     * @return 各部门实际待改进人员分布数据
486
+     * @return 各大队实际待改进人员分布数据
448
      */
487
      */
449
     @PreAuthorize("@ss.hasPermi('personnel:assessment:query')")
488
     @PreAuthorize("@ss.hasPermi('personnel:assessment:query')")
450
     @GetMapping("/actual-improvement-distribution")
489
     @GetMapping("/actual-improvement-distribution")
451
     public AjaxResult getActualImprovementDistribution(@RequestParam String assessmentMonth) {
490
     public AjaxResult getActualImprovementDistribution(@RequestParam String assessmentMonth) {
452
         try {
491
         try {
453
             List<PersonnelNonCadreMonthlyAssessment> list = queryByMonth(assessmentMonth);
492
             List<PersonnelNonCadreMonthlyAssessment> list = queryByMonth(assessmentMonth);
454
-
493
+    
455
             if (list == null || list.isEmpty()) {
494
             if (list == null || list.isEmpty()) {
456
                 return success(Collections.emptyList());
495
                 return success(Collections.emptyList());
457
             }
496
             }
458
-
497
+    
459
             // 获取所有部门信息
498
             // 获取所有部门信息
460
             Map<Long, SysDept> deptMap = getDeptMap();
499
             Map<Long, SysDept> deptMap = getDeptMap();
461
-
462
-            // 筛选出实际待改进人员:考核结果为"待改进"且未被豁免
500
+                
501
+            // 构建大队到其所有子部门ID的映射
502
+            Map<Long, Set<Long>> brigadeSubDeptsMap = buildBrigadeSubDeptsMap(deptMap);
503
+    
504
+            // 筛选出实际待改进人员:考核结果为“待改进”且未被豁免
463
             List<PersonnelNonCadreMonthlyAssessment> actualImprovementList = list.stream()
505
             List<PersonnelNonCadreMonthlyAssessment> actualImprovementList = list.stream()
464
                     .filter(item -> RESULT_IMPROVEMENT.equals(item.getAssessmentResult()))
506
                     .filter(item -> RESULT_IMPROVEMENT.equals(item.getAssessmentResult()))
465
                     .filter(item -> !EXEMPTION_YES.equals(item.getExemption()))
507
                     .filter(item -> !EXEMPTION_YES.equals(item.getExemption()))
466
                     .collect(Collectors.toList());
508
                     .collect(Collectors.toList());
467
-
509
+    
468
             if (actualImprovementList.isEmpty()) {
510
             if (actualImprovementList.isEmpty()) {
469
                 return success(Collections.emptyList());
511
                 return success(Collections.emptyList());
470
             }
512
             }
471
-
513
+    
472
             // 批量查询用户部门信息,避免N+1问题
514
             // 批量查询用户部门信息,避免N+1问题
473
             Set<Long> userIds = actualImprovementList.stream()
515
             Set<Long> userIds = actualImprovementList.stream()
474
                     .map(PersonnelNonCadreMonthlyAssessment::getUserId)
516
                     .map(PersonnelNonCadreMonthlyAssessment::getUserId)
475
                     .filter(Objects::nonNull)
517
                     .filter(Objects::nonNull)
476
                     .collect(Collectors.toSet());
518
                     .collect(Collectors.toSet());
477
-
519
+    
478
             Map<Long, Long> userDeptIdMap = buildUserDeptIdMap(userIds);
520
             Map<Long, Long> userDeptIdMap = buildUserDeptIdMap(userIds);
479
-
480
-            // 按部门统计人数
481
-            Map<Long, Integer> deptCountMap = new HashMap<>();
521
+    
522
+            // 按大队统计人数
523
+            Map<Long, Integer> brigadeCountMap = new HashMap<>();
482
             int totalCount = actualImprovementList.size();
524
             int totalCount = actualImprovementList.size();
483
-
525
+    
484
             for (PersonnelNonCadreMonthlyAssessment item : actualImprovementList) {
526
             for (PersonnelNonCadreMonthlyAssessment item : actualImprovementList) {
485
-                Long deptId = userDeptIdMap.get(item.getUserId());
486
-                if (deptId != null) {
487
-                    deptCountMap.merge(deptId, 1, Integer::sum);
527
+                Long userDeptId = userDeptIdMap.get(item.getUserId());
528
+                if (userDeptId != null) {
529
+                    // 查找该用户所属的大队
530
+                    Long brigadeId = findUserBrigade(userDeptId, brigadeSubDeptsMap);
531
+                    if (brigadeId != null) {
532
+                        brigadeCountMap.merge(brigadeId, 1, Integer::sum);
533
+                    }
488
                 }
534
                 }
489
             }
535
             }
490
-
536
+    
491
             // 构建返回结果
537
             // 构建返回结果
492
             List<DeptActualImprovementDistributionDto> result = buildDeptDistributionResult(
538
             List<DeptActualImprovementDistributionDto> result = buildDeptDistributionResult(
493
-                    deptCountMap, deptMap, totalCount, DeptActualImprovementDistributionDto::new);
494
-
539
+                    brigadeCountMap, deptMap, totalCount, DeptActualImprovementDistributionDto::new);
540
+    
495
             // 按人数降序排序
541
             // 按人数降序排序
496
             result.sort((a, b) -> b.getCount().compareTo(a.getCount()));
542
             result.sort((a, b) -> b.getCount().compareTo(a.getCount()));
497
-
543
+    
498
             return success(result);
544
             return success(result);
499
         } catch (Exception e) {
545
         } catch (Exception e) {
500
-            logger.error("各部门实际待改进人员分布统计异常", e);
546
+            logger.error("各大队实际待改进人员分布统计异常", e);
501
             return error("统计失败:" + e.getMessage());
547
             return error("统计失败:" + e.getMessage());
502
         }
548
         }
503
     }
549
     }
504
 
550
 
505
     /**
551
     /**
506
-     * 各部门实际不称职人员分布
507
-     * 统计所有实际不称职人员(不称职且未被豁免),按组织架构分类
552
+     * 各部门实际不称职人员分布(按大队级别统计)
553
+     * 统计所有实际不称职人员(不称职且未被豁免),按大队分类
508
      *
554
      *
509
      * @param assessmentMonth 考核月份(格式:YYYYMM)
555
      * @param assessmentMonth 考核月份(格式:YYYYMM)
510
-     * @return 各部门实际不称职人员分布数据
556
+     * @return 各大队实际不称职人员分布数据
511
      */
557
      */
512
     @PreAuthorize("@ss.hasPermi('personnel:assessment:query')")
558
     @PreAuthorize("@ss.hasPermi('personnel:assessment:query')")
513
     @GetMapping("/actual-incompetent-distribution")
559
     @GetMapping("/actual-incompetent-distribution")
514
     public AjaxResult getActualIncompetentDistribution(@RequestParam String assessmentMonth) {
560
     public AjaxResult getActualIncompetentDistribution(@RequestParam String assessmentMonth) {
515
         try {
561
         try {
516
             List<PersonnelNonCadreMonthlyAssessment> list = queryByMonth(assessmentMonth);
562
             List<PersonnelNonCadreMonthlyAssessment> list = queryByMonth(assessmentMonth);
517
-
563
+    
518
             if (list == null || list.isEmpty()) {
564
             if (list == null || list.isEmpty()) {
519
                 return success(Collections.emptyList());
565
                 return success(Collections.emptyList());
520
             }
566
             }
521
-
567
+    
522
             // 获取所有部门信息
568
             // 获取所有部门信息
523
             Map<Long, SysDept> deptMap = getDeptMap();
569
             Map<Long, SysDept> deptMap = getDeptMap();
524
-
525
-            // 筛选出实际不称职人员:考核结果为"不称职"且未被豁免
570
+                
571
+            // 构建大队到其所有子部门ID的映射
572
+            Map<Long, Set<Long>> brigadeSubDeptsMap = buildBrigadeSubDeptsMap(deptMap);
573
+    
574
+            // 筛选出实际不称职人员:考核结果为“不称职”且未被豁免
526
             List<PersonnelNonCadreMonthlyAssessment> actualIncompetentList = list.stream()
575
             List<PersonnelNonCadreMonthlyAssessment> actualIncompetentList = list.stream()
527
                     .filter(item -> RESULT_INCOMPETENT.equals(item.getAssessmentResult()))
576
                     .filter(item -> RESULT_INCOMPETENT.equals(item.getAssessmentResult()))
528
                     .filter(item -> !EXEMPTION_YES.equals(item.getExemption()))
577
                     .filter(item -> !EXEMPTION_YES.equals(item.getExemption()))
529
                     .collect(Collectors.toList());
578
                     .collect(Collectors.toList());
530
-
579
+    
531
             if (actualIncompetentList.isEmpty()) {
580
             if (actualIncompetentList.isEmpty()) {
532
                 return success(Collections.emptyList());
581
                 return success(Collections.emptyList());
533
             }
582
             }
534
-
583
+    
535
             // 批量查询用户部门信息,避免N+1问题
584
             // 批量查询用户部门信息,避免N+1问题
536
             Set<Long> userIds = actualIncompetentList.stream()
585
             Set<Long> userIds = actualIncompetentList.stream()
537
                     .map(PersonnelNonCadreMonthlyAssessment::getUserId)
586
                     .map(PersonnelNonCadreMonthlyAssessment::getUserId)
538
                     .filter(Objects::nonNull)
587
                     .filter(Objects::nonNull)
539
                     .collect(Collectors.toSet());
588
                     .collect(Collectors.toSet());
540
-
589
+    
541
             Map<Long, Long> userDeptIdMap = buildUserDeptIdMap(userIds);
590
             Map<Long, Long> userDeptIdMap = buildUserDeptIdMap(userIds);
542
-
543
-            // 按部门统计人数
544
-            Map<Long, Integer> deptCountMap = new HashMap<>();
591
+    
592
+            // 按大队统计人数
593
+            Map<Long, Integer> brigadeCountMap = new HashMap<>();
545
             int totalCount = actualIncompetentList.size();
594
             int totalCount = actualIncompetentList.size();
546
-
595
+    
547
             for (PersonnelNonCadreMonthlyAssessment item : actualIncompetentList) {
596
             for (PersonnelNonCadreMonthlyAssessment item : actualIncompetentList) {
548
-                Long deptId = userDeptIdMap.get(item.getUserId());
549
-                if (deptId != null) {
550
-                    deptCountMap.merge(deptId, 1, Integer::sum);
597
+                Long userDeptId = userDeptIdMap.get(item.getUserId());
598
+                if (userDeptId != null) {
599
+                    // 查找该用户所属的大队
600
+                    Long brigadeId = findUserBrigade(userDeptId, brigadeSubDeptsMap);
601
+                    if (brigadeId != null) {
602
+                        brigadeCountMap.merge(brigadeId, 1, Integer::sum);
603
+                    }
551
                 }
604
                 }
552
             }
605
             }
553
-
606
+    
554
             // 构建返回结果
607
             // 构建返回结果
555
             List<DeptActualIncompetentDistributionDto> result = buildDeptDistributionResult(
608
             List<DeptActualIncompetentDistributionDto> result = buildDeptDistributionResult(
556
-                    deptCountMap, deptMap, totalCount, DeptActualIncompetentDistributionDto::new);
557
-
609
+                    brigadeCountMap, deptMap, totalCount, DeptActualIncompetentDistributionDto::new);
610
+    
558
             // 按人数降序排序
611
             // 按人数降序排序
559
             result.sort((a, b) -> b.getCount().compareTo(a.getCount()));
612
             result.sort((a, b) -> b.getCount().compareTo(a.getCount()));
560
-
613
+    
561
             return success(result);
614
             return success(result);
562
         } catch (Exception e) {
615
         } catch (Exception e) {
563
-            logger.error("各部门实际不称职人员分布统计异常", e);
616
+            logger.error("各大队实际不称职人员分布统计异常", e);
564
             return error("统计失败:" + e.getMessage());
617
             return error("统计失败:" + e.getMessage());
565
         }
618
         }
566
     }
619
     }
@@ -591,6 +644,43 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
591
     }
644
     }
592
 
645
 
593
     /**
646
     /**
647
+     * 获取指定部门及其所有子部门的ID集合
648
+     *
649
+     * @param deptId 部门ID
650
+     * @param deptMap 部门映射表
651
+     * @return 包含当前部门及所有子部门的ID集合
652
+     */
653
+    private Set<Long> getAllSubDeptIds(Long deptId, Map<Long, SysDept> deptMap) {
654
+        Set<Long> result = new HashSet<>();
655
+        result.add(deptId); // 包含当前部门
656
+        
657
+        for (SysDept dept : deptMap.values()) {
658
+            if (dept.getParentId() != null && dept.getParentId().equals(deptId)) {
659
+                // 递归获取子部门的子部门
660
+                result.addAll(getAllSubDeptIds(dept.getDeptId(), deptMap));
661
+            }
662
+        }
663
+        
664
+        return result;
665
+    }
666
+
667
+    /**
668
+     * 查找用户所属的大队ID
669
+     *
670
+     * @param userDeptId 用户所在部门ID
671
+     * @param brigadeSubDeptsMap 大队到其所有子部门ID的映射
672
+     * @return 所属大队ID,如果未找到则返回null
673
+     */
674
+    private Long findUserBrigade(Long userDeptId, Map<Long, Set<Long>> brigadeSubDeptsMap) {
675
+        for (Map.Entry<Long, Set<Long>> entry : brigadeSubDeptsMap.entrySet()) {
676
+            if (entry.getValue().contains(userDeptId)) {
677
+                return entry.getKey();
678
+            }
679
+        }
680
+        return null;
681
+    }
682
+
683
+    /**
594
      * 部门分布结果
684
      * 部门分布结果
595
      */
685
      */
596
     private <T> List<T> buildDeptDistributionResult(
686
     private <T> List<T> buildDeptDistributionResult(
@@ -732,6 +822,78 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
732
     }
822
     }
733
 
823
 
734
     /**
824
     /**
825
+     * 各考核组实际不称职人员分布
826
+     * 统计所有实际不称职人员(不称职且未被豁免),按考核组分类
827
+     *
828
+     * @param assessmentMonth 考核月份(格式:YYYYMM)
829
+     * @return 各考核组实际不称职人员分布数据
830
+     */
831
+    @PreAuthorize("@ss.hasPermi('personnel:assessment:query')")
832
+    @GetMapping("/assessment-team-incompetent-distribution")
833
+    public AjaxResult getAssessmentTeamIncompetentDistribution(@RequestParam String assessmentMonth) {
834
+        try {
835
+            List<PersonnelNonCadreMonthlyAssessment> list = queryByMonth(assessmentMonth);
836
+
837
+            if (list == null || list.isEmpty()) {
838
+                return success(Collections.emptyList());
839
+            }
840
+
841
+            // 筛选出实际不称职人员:考核结果为"不称职"且未被豁免,且考核组不为空
842
+            List<PersonnelNonCadreMonthlyAssessment> actualIncompetentList = list.stream()
843
+                    .filter(item -> RESULT_INCOMPETENT.equals(item.getAssessmentResult()))
844
+                    .filter(item -> !EXEMPTION_YES.equals(item.getExemption()))
845
+                    .filter(item -> item.getAssessmentTeam() != null && !item.getAssessmentTeam().isEmpty())
846
+                    .collect(Collectors.toList());
847
+
848
+            if (actualIncompetentList.isEmpty()) {
849
+                return success(Collections.emptyList());
850
+            }
851
+
852
+            // 按考核组统计人数
853
+            Map<String, Integer> teamCountMap = new HashMap<>();
854
+            int totalCount = actualIncompetentList.size();
855
+
856
+            for (PersonnelNonCadreMonthlyAssessment item : actualIncompetentList) {
857
+                String assessmentTeam = item.getAssessmentTeam();
858
+                if (assessmentTeam != null && !assessmentTeam.isEmpty()) {
859
+                    teamCountMap.merge(assessmentTeam, 1, Integer::sum);
860
+                }
861
+            }
862
+
863
+            // 构建返回结果
864
+            List<AssessmentTeamActualIncompetentDistributionDto> result = new ArrayList<>();
865
+            for (Map.Entry<String, Integer> entry : teamCountMap.entrySet()) {
866
+                String assessmentTeam = entry.getKey();
867
+                Integer count = entry.getValue();
868
+
869
+                AssessmentTeamActualIncompetentDistributionDto dto = new AssessmentTeamActualIncompetentDistributionDto();
870
+                dto.setAssessmentTeam(assessmentTeam);
871
+                dto.setCount(count);
872
+
873
+                // 计算占比
874
+                if (totalCount > 0) {
875
+                    BigDecimal percentage = new BigDecimal(count)
876
+                            .divide(new BigDecimal(totalCount), 4, BigDecimal.ROUND_HALF_UP)
877
+                            .multiply(HUNDRED);
878
+                    dto.setPercentage(percentage.setScale(1, BigDecimal.ROUND_HALF_UP));
879
+                } else {
880
+                    dto.setPercentage(BigDecimal.ZERO);
881
+                }
882
+
883
+                result.add(dto);
884
+            }
885
+
886
+            // 按人数降序排序
887
+            result.sort((a, b) -> b.getCount().compareTo(a.getCount()));
888
+
889
+            return success(result);
890
+        } catch (Exception e) {
891
+            logger.error("各考核组实际不称职人员分布统计异常", e);
892
+            return error("统计失败:" + e.getMessage());
893
+        }
894
+    }
895
+
896
+    /**
735
      * 大队考核组统计
897
      * 大队考核组统计
736
      * 先按大队筛选,再按考核组统计,应用汇总统计规则
898
      * 先按大队筛选,再按考核组统计,应用汇总统计规则
737
      *
899
      *
@@ -761,13 +923,16 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
761
 
923
 
762
             Map<Long, Long> userDeptIdMap = buildUserDeptIdMap(userIds);
924
             Map<Long, Long> userDeptIdMap = buildUserDeptIdMap(userIds);
763
 
925
 
764
-            // 如果指定了大队ID,先筛选该大队的人员
926
+            // 如果指定了大队ID,先筛选该大队的人员(包括大队及其所有子部门)
765
             List<PersonnelNonCadreMonthlyAssessment> filteredList = allList;
927
             List<PersonnelNonCadreMonthlyAssessment> filteredList = allList;
766
             if (deptId != null) {
928
             if (deptId != null) {
929
+                // 获取该大队及其所有子部门的ID集合
930
+                Set<Long> brigadeSubDeptIds = getAllSubDeptIds(deptId, deptIdMap);
931
+                
767
                 filteredList = allList.stream()
932
                 filteredList = allList.stream()
768
                         .filter(item -> {
933
                         .filter(item -> {
769
                             Long userDeptId = userDeptIdMap.get(item.getUserId());
934
                             Long userDeptId = userDeptIdMap.get(item.getUserId());
770
-                            return deptId.equals(userDeptId);
935
+                            return userDeptId != null && brigadeSubDeptIds.contains(userDeptId);
771
                         })
936
                         })
772
                         .collect(Collectors.toList());
937
                         .collect(Collectors.toList());
773
             }
938
             }
@@ -918,20 +1083,25 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
918
             if (allList == null || allList.isEmpty()) {
1083
             if (allList == null || allList.isEmpty()) {
919
                 return success(Collections.emptyList());
1084
                 return success(Collections.emptyList());
920
             }
1085
             }
921
-
922
-
1086
+            
1087
+            // 获取所有部门信息
1088
+            Map<Long, SysDept> deptMap = getDeptMap();
1089
+            
923
             Set<Long> userIds = allList.stream()
1090
             Set<Long> userIds = allList.stream()
924
                     .map(PersonnelNonCadreMonthlyAssessment::getUserId)
1091
                     .map(PersonnelNonCadreMonthlyAssessment::getUserId)
925
                     .filter(Objects::nonNull)
1092
                     .filter(Objects::nonNull)
926
                     .collect(Collectors.toSet());
1093
                     .collect(Collectors.toSet());
927
-
1094
+            
928
             Map<Long, Long> userDeptIdMap = buildUserDeptIdMap(userIds);
1095
             Map<Long, Long> userDeptIdMap = buildUserDeptIdMap(userIds);
929
-
930
-            // 筛选指定大队的实际待改进人员:属于该大队、考核结果为"待改进"且未被豁免、考核组不为空
1096
+            
1097
+            // 获取该大队及其所有子部门的ID集合
1098
+            Set<Long> brigadeSubDeptIds = getAllSubDeptIds(deptId, deptMap);
1099
+            
1100
+            // 筛选指定大队的实际待改进人员:属于该大队(包括子部门)、考核结果为“待改进”且未被豁免、考核组不为空
931
             List<PersonnelNonCadreMonthlyAssessment> actualImprovementList = allList.stream()
1101
             List<PersonnelNonCadreMonthlyAssessment> actualImprovementList = allList.stream()
932
                     .filter(item -> {
1102
                     .filter(item -> {
933
                         Long userDeptId = userDeptIdMap.get(item.getUserId());
1103
                         Long userDeptId = userDeptIdMap.get(item.getUserId());
934
-                        return deptId.equals(userDeptId);
1104
+                        return userDeptId != null && brigadeSubDeptIds.contains(userDeptId);
935
                     })
1105
                     })
936
                     .filter(item -> RESULT_IMPROVEMENT.equals(item.getAssessmentResult()))
1106
                     .filter(item -> RESULT_IMPROVEMENT.equals(item.getAssessmentResult()))
937
                     .filter(item -> !EXEMPTION_YES.equals(item.getExemption()))
1107
                     .filter(item -> !EXEMPTION_YES.equals(item.getExemption()))
@@ -1005,20 +1175,25 @@ public class PersonnelNonCadreMonthlyAssessmentScoreSummaryController extends Ba
1005
             if (allList == null || allList.isEmpty()) {
1175
             if (allList == null || allList.isEmpty()) {
1006
                 return success(Collections.emptyList());
1176
                 return success(Collections.emptyList());
1007
             }
1177
             }
1008
-
1009
-
1178
+            
1179
+            // 获取所有部门信息
1180
+            Map<Long, SysDept> deptMap = getDeptMap();
1181
+            
1010
             Set<Long> userIds = allList.stream()
1182
             Set<Long> userIds = allList.stream()
1011
                     .map(PersonnelNonCadreMonthlyAssessment::getUserId)
1183
                     .map(PersonnelNonCadreMonthlyAssessment::getUserId)
1012
                     .filter(Objects::nonNull)
1184
                     .filter(Objects::nonNull)
1013
                     .collect(Collectors.toSet());
1185
                     .collect(Collectors.toSet());
1014
-
1186
+            
1015
             Map<Long, Long> userDeptIdMap = buildUserDeptIdMap(userIds);
1187
             Map<Long, Long> userDeptIdMap = buildUserDeptIdMap(userIds);
1016
-
1017
-            // 筛选指定大队的实际不称职人员:属于该大队、考核结果为"不称职"且未被豁免、考核组不为空
1188
+            
1189
+            // 获取该大队及其所有子部门的ID集合
1190
+            Set<Long> brigadeSubDeptIds = getAllSubDeptIds(deptId, deptMap);
1191
+            
1192
+            // 筛选指定大队的实际不称职人员:属于该大队(包括子部门)、考核结果为“不称职”且未被豁免、考核组不为空
1018
             List<PersonnelNonCadreMonthlyAssessment> actualIncompetentList = allList.stream()
1193
             List<PersonnelNonCadreMonthlyAssessment> actualIncompetentList = allList.stream()
1019
                     .filter(item -> {
1194
                     .filter(item -> {
1020
                         Long userDeptId = userDeptIdMap.get(item.getUserId());
1195
                         Long userDeptId = userDeptIdMap.get(item.getUserId());
1021
-                        return deptId.equals(userDeptId);
1196
+                        return userDeptId != null && brigadeSubDeptIds.contains(userDeptId);
1022
                     })
1197
                     })
1023
                     .filter(item -> RESULT_INCOMPETENT.equals(item.getAssessmentResult()))
1198
                     .filter(item -> RESULT_INCOMPETENT.equals(item.getAssessmentResult()))
1024
                     .filter(item -> !EXEMPTION_YES.equals(item.getExemption()))
1199
                     .filter(item -> !EXEMPTION_YES.equals(item.getExemption()))