diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/AppInspectionPartnerServiceImpl.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/AppInspectionPartnerServiceImpl.java index d9361808..014bbe9a 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/AppInspectionPartnerServiceImpl.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/AppInspectionPartnerServiceImpl.java @@ -2518,26 +2518,35 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl> getStaffCount(DlInspectionProject dlInspectionProject) { List> staffCount = inspectionWorkNodeService.getStaffCount(dlInspectionProject); + // 根据userId查询检测工单表 接车人 List list = inspectionInfoService.selectMeetCarList(dlInspectionProject.getDatetimeRange(), null); + // 统计每个 meetManId 的数量,避免 null key 异常 Map> meetManIdCountMap = list.stream() .filter(info -> info.getMeetManId() != null) // 过滤 null 值 .collect(Collectors.groupingBy(InspectionInfo::getMeetManId)); + // 根据userId查询还车人 List returnCarList = inspectionInfoService.list(Wrappers.lambdaQuery() .eq(InspectionInfo::getIsReturnCar, 1) - .between(CollUtil.isNotEmpty(dlInspectionProject.getDatetimeRange()), InspectionInfo::getEndTime, dlInspectionProject.getDatetimeRange().get(0), dlInspectionProject.getDatetimeRange().get(1))); + .between(CollUtil.isNotEmpty(dlInspectionProject.getDatetimeRange()), InspectionInfo::getEndTime, + dlInspectionProject.getDatetimeRange().get(0), dlInspectionProject.getDatetimeRange().get(1))); + // 统计每个 returnCarUserId 的数量,避免 null key 异常 Map> returnCarUserIdCountMap = returnCarList.stream() .filter(info -> info.getReturnCarUserId() != null) // 过滤 null 值 .collect(Collectors.groupingBy(InspectionInfo::getReturnCarUserId)); + // 先计算所有项目的总完成数 + Map projectTotalMap = new HashMap<>(); + for (Map stringObjectMap : staffCount) { Set inspectionInfoIds = new HashSet<>(); Long userId = (Long) stringObjectMap.get("userId"); List> children = (List>) stringObjectMap.get("children"); + inspectionInfoIds.addAll( children.stream() .map(map -> (String) map.get("inspectionInfoId")) // 获取逗号分隔的字符串 @@ -2547,29 +2556,34 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl inspectionInfos = meetManIdCountMap.get(userId); long meetCount = 0; long meetGoCount = 0; + if (CollUtil.isNotEmpty(inspectionInfos)) { meetCount = inspectionInfos.stream().filter(inspectionInfo -> Integer.valueOf(0).equals(inspectionInfo.getMeetType())).count(); meetGoCount = inspectionInfos.stream().filter(inspectionInfo -> Integer.valueOf(1).equals(inspectionInfo.getMeetType())).count(); inspectionInfoIds.addAll(inspectionInfos.stream().map(InspectionInfo::getId).collect(Collectors.toList())); } + HashMap objectObjectHashMap = new HashMap<>(); objectObjectHashMap.put("count", meetCount); objectObjectHashMap.put("projectName", "接车拍照"); children.add(objectObjectHashMap); + HashMap meetCarHashMap = new HashMap<>(); meetCarHashMap.put("count", meetGoCount); meetCarHashMap.put("projectName", "上门接车"); - children.add(meetCarHashMap); + //还车 //设置totalCount List returnCarInfoList = returnCarUserIdCountMap.get(userId); long returnCount = 0; long returnGoCount = 0; + if (CollUtil.isNotEmpty(returnCarInfoList)) { inspectionInfoIds.addAll(returnCarInfoList.stream().map(InspectionInfo::getId).collect(Collectors.toList())); @@ -2587,17 +2601,51 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl i.getReturnType() != null && i.getReturnType() == 1) .count(); } + stringObjectMap.put("totalCount", Long.parseLong(String.valueOf(inspectionInfoIds.size()))); Map objectObjectHashMap1 = new HashMap<>(); objectObjectHashMap1.put("count", returnCount); objectObjectHashMap1.put("projectName", "还车拍照"); children.add(objectObjectHashMap1); + Map returnCarHashMap = new HashMap<>(); returnCarHashMap.put("count", returnGoCount); returnCarHashMap.put("projectName", "上门还车"); children.add(returnCarHashMap); } + + // 计算每个项目的总完成数 + for (Map staff : staffCount) { + List> children = (List>) staff.get("children"); + if (children != null) { + for (Map child : children) { + String projectName = (String) child.get("projectName"); + Long count = (Long) child.get("count"); + projectTotalMap.put(projectName, projectTotalMap.getOrDefault(projectName, 0L) + count); + } + } + } + + // 为每个项目添加比例 + for (Map staff : staffCount) { + List> children = (List>) staff.get("children"); + if (children != null) { + for (Map child : children) { + String projectName = (String) child.get("projectName"); + Long count = (Long) child.get("count"); + Long total = projectTotalMap.get(projectName); + + if (total != null && total > 0) { + double percentage = (count * 100.0) / total; + child.put("percentage", Double.parseDouble(String.format("%.2f", percentage))); + } else { + child.put("percentage", 0.0); + } + } + } + } + // 按 meetCarCount 降序排序员工 staffCount.sort(Comparator.comparingLong( (Map staff) -> (Long) staff.getOrDefault("totalCount", 0L) diff --git a/dl-module-inspection/src/main/resources/mapper/InspectionWorkNodeMapper.xml b/dl-module-inspection/src/main/resources/mapper/InspectionWorkNodeMapper.xml index 1598d61d..98765abf 100644 --- a/dl-module-inspection/src/main/resources/mapper/InspectionWorkNodeMapper.xml +++ b/dl-module-inspection/src/main/resources/mapper/InspectionWorkNodeMapper.xml @@ -380,26 +380,54 @@ ORDER BY ii.start_time DESC;