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 32404e90..1cf2b897 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 @@ -77,6 +77,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; @@ -2567,24 +2568,32 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl info.getReturnCarUserId() != null) // 过滤 null 值 .collect(Collectors.groupingBy(InspectionInfo::getReturnCarUserId)); - // 先计算所有项目的总完成数 + // 先计算所有项目的总完成数和总产值 Map projectTotalMap = new HashMap<>(); + Map projectTotalOutputValueMap = new HashMap<>(); // 总产值统计 for (Map stringObjectMap : staffCount) { Set inspectionInfoIds = new HashSet<>(); + BigDecimal userTotalOutputValue = BigDecimal.ZERO; // 员工总产值 Long userId = (Long) stringObjectMap.get("userId"); List> children = (List>) stringObjectMap.get("children"); - inspectionInfoIds.addAll( - children.stream() - .map(map -> (String) map.get("inspectionInfoId")) // 获取逗号分隔的字符串 - .flatMap(idsStr -> Arrays.stream(idsStr.split(","))) // 拆分成单个ID字符串 - .map(String::trim) // 去除前后空格 - .filter(idStr -> !idStr.isEmpty()) // 过滤空字符串 - .map(Long::valueOf) // 转换为Long类型 - .collect(Collectors.toList()) - ); + // 处理项目节点 + for (Map child : children) { + BigDecimal outputValue = (BigDecimal) child.get("outputValue"); + if (outputValue != null) { + userTotalOutputValue = userTotalOutputValue.add(outputValue); + } + + inspectionInfoIds.addAll( + Arrays.stream(((String) child.get("inspectionInfoId")).split(",")) + .map(String::trim) + .filter(idStr -> !idStr.isEmpty()) + .map(Long::valueOf) + .collect(Collectors.toList()) + ); + } // 获取所有接车信息 List inspectionInfos = meetManIdCountMap.get(userId); @@ -2597,18 +2606,20 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl objectObjectHashMap = new HashMap<>(); - objectObjectHashMap.put("count", meetCount); - objectObjectHashMap.put("projectName", "接车拍照"); - children.add(objectObjectHashMap); + // 添加工单相关项目(这些项目产值暂时为0) + HashMap meetCarMap = new HashMap<>(); + meetCarMap.put("count", meetCount); + meetCarMap.put("projectName", "接车拍照"); + meetCarMap.put("outputValue", BigDecimal.ZERO); + children.add(meetCarMap); - HashMap meetCarHashMap = new HashMap<>(); - meetCarHashMap.put("count", meetGoCount); - meetCarHashMap.put("projectName", "上门接车"); - children.add(meetCarHashMap); + HashMap meetGoMap = new HashMap<>(); + meetGoMap.put("count", meetGoCount); + meetGoMap.put("projectName", "上门接车"); + meetGoMap.put("outputValue", BigDecimal.ZERO); + children.add(meetGoMap); - //还车 - //设置totalCount + // 还车信息 List returnCarInfoList = returnCarUserIdCountMap.get(userId); long returnCount = 0; long returnGoCount = 0; @@ -2616,42 +2627,43 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl i.getReturnType() != null && i.getReturnType() == 0) .count(); - returnGoCount = Optional.ofNullable(returnCarInfoList) - .orElse(Collections.emptyList()) - .stream() - .filter(Objects::nonNull) + returnGoCount = returnCarInfoList.stream() .filter(i -> i.getReturnType() != null && i.getReturnType() == 1) .count(); } - stringObjectMap.put("totalCount", Long.parseLong(String.valueOf(inspectionInfoIds.size()))); + stringObjectMap.put("totalCount", inspectionInfoIds.size()); + stringObjectMap.put("totalOutputValue", userTotalOutputValue); // 设置员工总产值 - Map objectObjectHashMap1 = new HashMap<>(); - objectObjectHashMap1.put("count", returnCount); - objectObjectHashMap1.put("projectName", "还车拍照"); - children.add(objectObjectHashMap1); + Map returnCarMap = new HashMap<>(); + returnCarMap.put("count", returnCount); + returnCarMap.put("projectName", "还车拍照"); + returnCarMap.put("outputValue", BigDecimal.ZERO); + children.add(returnCarMap); - Map returnCarHashMap = new HashMap<>(); - returnCarHashMap.put("count", returnGoCount); - returnCarHashMap.put("projectName", "上门还车"); - children.add(returnCarHashMap); + Map returnGoMap = new HashMap<>(); + returnGoMap.put("count", returnGoCount); + returnGoMap.put("projectName", "上门还车"); + returnGoMap.put("outputValue", BigDecimal.ZERO); + children.add(returnGoMap); } - // 计算每个项目的总完成数 + // 计算每个项目的总完成数和总产值 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"); + BigDecimal outputValue = (BigDecimal) child.get("outputValue"); + projectTotalMap.put(projectName, projectTotalMap.getOrDefault(projectName, 0L) + count); + projectTotalOutputValueMap.put(projectName, + projectTotalOutputValueMap.getOrDefault(projectName, BigDecimal.ZERO).add(outputValue != null ? outputValue : BigDecimal.ZERO)); } } } @@ -2675,19 +2687,22 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl staff) -> (Long) staff.getOrDefault("totalCount", 0L) + // 按总产值降序排序员工 + staffCount.sort(Comparator.comparing( + (Map staff) -> (BigDecimal) staff.getOrDefault("totalOutputValue", BigDecimal.ZERO) ).reversed()); - // 对每个员工的 children 按 count 降序排序 - // 对每个员工的 children:先移除 count == 0 的项,再按 count 降序排序 + // 对每个员工的 children 按产值降序排序 staffCount.forEach(staff -> { List> children = (List>) staff.get("children"); if (children != null) { - children.removeIf(child -> ((Long) child.getOrDefault("count", 0L)) == 0L); - children.sort(Comparator.comparingLong( - (Map child) -> (Long) child.getOrDefault("count", 0L) + children.removeIf(child -> { + Long count = (Long) child.getOrDefault("count", 0L); + BigDecimal outputValue = (BigDecimal) child.getOrDefault("outputValue", BigDecimal.ZERO); + return count == 0L && outputValue.compareTo(BigDecimal.ZERO) == 0; + }); + children.sort(Comparator.comparing( + (Map child) -> (BigDecimal) child.getOrDefault("outputValue", BigDecimal.ZERO) ).reversed()); } }); diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionWorkNodeServiceImpl.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionWorkNodeServiceImpl.java index cdd56880..670ca23a 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionWorkNodeServiceImpl.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionWorkNodeServiceImpl.java @@ -26,6 +26,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -462,6 +463,7 @@ public class InspectionWorkNodeServiceImpl extends ServiceImpl>()); return m; }); @@ -469,29 +471,50 @@ public class InspectionWorkNodeServiceImpl extends ServiceImpl> children = (List>) userEntry.get("children"); vo.setCount(vo.getCount() == null ? 0 : vo.getCount()); - if (vo.getCount() == 0) { + + // 即使count为0,但如果产值不为0,也要显示 + if (vo.getCount() == 0 && (vo.getOutputValue() == null || vo.getOutputValue().compareTo(BigDecimal.ZERO) == 0)) { continue; } + Map project = new HashMap<>(); project.put("projectName", vo.getProjectName()); project.put("count", vo.getCount()); project.put("id", vo.getId()); project.put("inspectionInfoId", vo.getInspectionInfoIds()); + project.put("outputValue", vo.getOutputValue() != null ? vo.getOutputValue() : BigDecimal.ZERO); children.add(project); - // 累加总数 + // 累加总数和总产值 Long currentTotal = (Long) userEntry.get("totalCount"); + BigDecimal currentOutputValue = (BigDecimal) userEntry.get("totalOutputValue"); userEntry.put("totalCount", currentTotal + vo.getCount()); + userEntry.put("totalOutputValue", currentOutputValue.add( + vo.getOutputValue() != null ? vo.getOutputValue() : BigDecimal.ZERO)); } - // 转成 List 并按 totalCount 降序排序 + // 转成 List 并按总产值降序排序 return tempMap.values().stream() .peek(userEntry -> { - // 排序每个用户下的项目 children + // 排序每个用户下的项目:按产值降序,产值相同按数量降序 List> children = (List>) userEntry.get("children"); - children.sort((a, b) -> Long.compare((Long) b.get("count"), (Long) a.get("count"))); + children.sort((a, b) -> { + BigDecimal outputValueA = (BigDecimal) a.get("outputValue"); + BigDecimal outputValueB = (BigDecimal) b.get("outputValue"); + int result = outputValueB.compareTo(outputValueA); + if (result == 0) { + Long countA = (Long) a.get("count"); + Long countB = (Long) b.get("count"); + return Long.compare(countB, countA); + } + return result; + }); + }) + .sorted((a, b) -> { + BigDecimal outputValueA = (BigDecimal) a.get("totalOutputValue"); + BigDecimal outputValueB = (BigDecimal) b.get("totalOutputValue"); + return outputValueB.compareTo(outputValueA); }) - .sorted((a, b) -> Long.compare((Long) b.get("totalCount"), (Long) a.get("totalCount"))) .collect(Collectors.toList()); } diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/vo/StaffProjectCountVO.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/vo/StaffProjectCountVO.java index 3c9503d4..98c53c9d 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/vo/StaffProjectCountVO.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/vo/StaffProjectCountVO.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.inspection.vo; import lombok.Data; +import java.math.BigDecimal; + @Data public class StaffProjectCountVO { private String id; @@ -12,4 +14,6 @@ public class StaffProjectCountVO { private Long nodeCount; // private Long inspectionInfoId; private String inspectionInfoIds; + private BigDecimal outputValue; // 项目产值 + private BigDecimal goodsPrice; // 商品价格 } diff --git a/dl-module-inspection/src/main/resources/mapper/InspectionWorkNodeMapper.xml b/dl-module-inspection/src/main/resources/mapper/InspectionWorkNodeMapper.xml index 93379263..5ac8b026 100644 --- a/dl-module-inspection/src/main/resources/mapper/InspectionWorkNodeMapper.xml +++ b/dl-module-inspection/src/main/resources/mapper/InspectionWorkNodeMapper.xml @@ -248,7 +248,10 @@ ip.id AS project_id, GROUP_CONCAT(iwn.inspection_info_id) AS inspectionInfoIds, su.nickname, - SUM(IF(iwn.node_count = 0,1,iwn.node_count)) count + SUM(IF(iwn.node_count = 0,1,iwn.node_count)) count, + -- 添加产值计算:合格节点的商品价格总和(单位:元) + COALESCE(SUM(CASE WHEN iwn.status = '2' AND iwn.type = '1' THEN oi.goods_price ELSE 0 END) / 100, 0) AS outputValue, + oi.goods_price FROM inspection_staff staff LEFT JOIN inspection_work_node iwn ON iwn.deal_user_id = staff.user_id @@ -256,6 +259,8 @@ AND iwn.create_time BETWEEN concat(#{datetimeRange[0]}, ' 00:00:00') AND concat(#{datetimeRange[1]}, ' 23:59:59') LEFT JOIN inspection_project ip ON ip.id = iwn.project_id + LEFT JOIN inspection_info ii ON iwn.inspection_info_id = ii.id + LEFT JOIN order_info oi ON ii.inspection_order_id = oi.id LEFT JOIN ( SELECT DISTINCT sur.user_id FROM system_user_role sur @@ -270,9 +275,8 @@ AND staff.user_id = #{userId} - - GROUP BY staff.user_id ,ip.id + GROUP BY staff.user_id, ip.id