Kaynağa Gözat

绩效分析报告页面接口优化改造

chenshudong 3 hafta önce
ebeveyn
işleme
9a7d9af120

+ 33 - 5
airport-admin/src/main/java/com/sundot/airport/web/controller/item/PerformanceDimensionController.java

@@ -509,8 +509,9 @@ public class PerformanceDimensionController {
509 509
             List<TimeBasedPerformanceResult.DataItem> dataItems = new ArrayList<>();
510 510
 
511 511
             // 为每个科室计算该时间段的数据
512
+            Map<Long, String> nameMap = getDeptNameMap(new ArrayList<>(deptIds));
512 513
             for (Long deptId : deptIds) {
513
-                String deptName = getGroupName(deptId);
514
+                String deptName = nameMap.get(deptId);
514 515
                 if (deptName == null) continue;
515 516
 
516 517
                 BigDecimal value = getDimensionValueFromPreloadedData(
@@ -589,8 +590,9 @@ public class PerformanceDimensionController {
589 590
             List<TimeBasedPerformanceResult.DataItem> dataItems = new ArrayList<>();
590 591
 
591 592
             // 为每个科室计算该时间段的数据
593
+            Map<Long, String> nameMap = getDeptNameMap(new ArrayList<>(deptIds));
592 594
             for (Long deptId : deptIds) {
593
-                String deptName = getGroupName(deptId);
595
+                String deptName = nameMap.get(deptId);
594 596
                 if (deptName == null) continue;
595 597
 
596 598
                 BigDecimal value = getDimensionValueFromPreloadedData(
@@ -659,8 +661,14 @@ public class PerformanceDimensionController {
659 661
 
660 662
 
661 663
             // 为每个人员/班组计算该时间段的数据
664
+            Map<Long, String> nameMap;
665
+            if (param.getDimension() == 1) {
666
+                nameMap = getUserNickNameMap(new ArrayList<>(ids));
667
+            } else {
668
+                nameMap = getDeptNameMap(new ArrayList<>(ids));
669
+            }
662 670
             for (Long id : ids) {
663
-                String name = param.getDimension() == 1 ? getUserNickName(id) : getGroupName(id);
671
+                String name = nameMap.get(id);
664 672
                 if (name == null) continue;
665 673
 
666 674
                 BigDecimal value = getDimensionValueFromPreloadedData(id, map.get(timeKey), param.getResultField());
@@ -1358,11 +1366,12 @@ public class PerformanceDimensionController {
1358 1366
         seizureData.forEach(item -> allUserIds.add(item.getId()));
1359 1367
         inspectionData.forEach(item -> allUserIds.add(item.getId()));
1360 1368
 
1369
+        Map<Long, String> nameMap = getUserNickNameMap(new ArrayList<>(allUserIds));
1361 1370
         for (Long userId : allUserIds) {
1362 1371
             NormalizedData normalized = new NormalizedData();
1363 1372
             normalized.id = userId;
1364 1373
             // 获取用户名
1365
-            String userName = getUserNickName(userId);
1374
+            String userName = nameMap.get(userId);
1366 1375
             normalized.name = userName != null ? userName : "未知用户";
1367 1376
 
1368 1377
             // 获取各项指标原始值
@@ -1432,12 +1441,13 @@ public class PerformanceDimensionController {
1432 1441
         seizureData.forEach(item -> allGroupIds.add(item.getId()));
1433 1442
         inspectionData.forEach(item -> allGroupIds.add(item.getId()));
1434 1443
 
1444
+        Map<Long, String> nameMap = getDeptNameMap(new ArrayList<>(allGroupIds));
1435 1445
         for (Long groupId : allGroupIds) {
1436 1446
             NormalizedData normalized = new NormalizedData();
1437 1447
             normalized.id = groupId;
1438 1448
 
1439 1449
             // 获取组名称
1440
-            String groupName = getGroupName(groupId);
1450
+            String groupName = nameMap.get(groupId);
1441 1451
             normalized.name = groupName != null ? groupName : "未知" + groupType;
1442 1452
 
1443 1453
             // 获取各项指标原始值
@@ -1667,6 +1677,24 @@ public class PerformanceDimensionController {
1667 1677
         return query;
1668 1678
     }
1669 1679
 
1680
+    /**
1681
+     * 获取用户昵称Map
1682
+     */
1683
+    private Map<Long, String> getUserNickNameMap(List<Long> userIdList) {
1684
+        List<SysUser> userList = userMapper.selectByUserIdList(userIdList);
1685
+        Map<Long, String> nameMap = userList.stream().collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName, (existing, replacement) -> existing));
1686
+        return nameMap;
1687
+    }
1688
+
1689
+    /**
1690
+     * 获取部门名称Map
1691
+     */
1692
+    private Map<Long, String> getDeptNameMap(List<Long> deptIdList) {
1693
+        List<SysDept> deptList = sysDeptService.selectDeptByIdList(deptIdList);
1694
+        Map<Long, String> nameMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName, (existing, replacement) -> existing));
1695
+        return nameMap;
1696
+    }
1697
+
1670 1698
 }
1671 1699
 
1672 1700
 

+ 34 - 2
airport-exam/src/main/java/com/sundot/airport/exam/service/impl/AccuracyStatisticsServiceImpl.java

@@ -2484,9 +2484,41 @@ public class AccuracyStatisticsServiceImpl implements IAccuracyStatisticsService
2484 2484
      */
2485 2485
     private Map<Long, BigDecimal> calculateUsersAccuracyMap(List<Long> userIds, DateRange dateRange) {
2486 2486
         Map<Long, BigDecimal> result = new HashMap<>();
2487
+        // 查询用户在时间范围内已完成的任务
2488
+        LambdaQueryWrapper<DailyTask> taskWrapper = new LambdaQueryWrapper<>();
2489
+        taskWrapper.in(DailyTask::getDtUserId, userIds);
2490
+        taskWrapper.ge(DailyTask::getDtBusinessDate, java.sql.Date.valueOf(dateRange.startDate));
2491
+        taskWrapper.le(DailyTask::getDtBusinessDate, java.sql.Date.valueOf(dateRange.endDate));
2492
+        taskWrapper.eq(DailyTask::getDtStatus, "COMPLETED");
2493
+        taskWrapper.eq(DailyTask::getDelStatus, 0);
2494
+        List<DailyTask> tasks = dailyTaskMapper.selectList(taskWrapper);
2495
+
2496
+        if (tasks.isEmpty()) {
2497
+            for (Long userId : userIds) {
2498
+                result.put(userId, BigDecimal.ZERO);
2499
+            }
2500
+        }
2501
+
2502
+        // 查询所有题目明细
2503
+        List<String> taskIds = tasks.stream().map(DailyTask::getDtId).collect(Collectors.toList());
2504
+        LambdaQueryWrapper<DailyTaskDetail> detailWrapper = new LambdaQueryWrapper<>();
2505
+        detailWrapper.in(DailyTaskDetail::getDtdTaskId, taskIds);
2506
+        detailWrapper.eq(DailyTaskDetail::getDelStatus, 0);
2507
+        detailWrapper.isNotNull(DailyTaskDetail::getDtdIsCorrect);
2508
+        List<DailyTaskDetail> details = dailyTaskDetailMapper.selectList(detailWrapper);
2509
+
2487 2510
         for (Long userId : userIds) {
2488
-            AccuracyData data = calculateUserAccuracy(userId, dateRange);
2489
-            result.put(userId, data.accuracy);
2511
+            List<DailyTask> targetTaskList = tasks.stream().filter(t -> t.getDtUserId().equals(userId)).collect(Collectors.toList());
2512
+            List<String> targetDailyTaskIdList = targetTaskList.stream().map(DailyTask::getDtId).collect(Collectors.toList());
2513
+            List<DailyTaskDetail> targetDetailList = details.stream().filter(d -> targetDailyTaskIdList.contains(d.getDtdTaskId())).collect(Collectors.toList());
2514
+            int totalCount = targetDetailList.size();
2515
+            int correctCount = (int) targetDetailList.stream()
2516
+                    .filter(d -> Boolean.TRUE.equals(d.getDtdIsCorrect()))
2517
+                    .count();
2518
+            BigDecimal accuracy = totalCount > 0
2519
+                    ? new BigDecimal(correctCount).multiply(new BigDecimal(100)).divide(new BigDecimal(totalCount), 2, RoundingMode.HALF_UP)
2520
+                    : BigDecimal.ZERO;
2521
+            result.put(userId, accuracy);
2490 2522
         }
2491 2523
         return result;
2492 2524
     }