更新0911

This commit is contained in:
xyc 2025-09-11 13:23:28 +08:00
parent 17be414b84
commit eaf2ba0ecb
2 changed files with 91 additions and 15 deletions

View File

@ -2518,26 +2518,35 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl<AppInspectionPa
@Override @Override
public List<Map<String, Object>> getStaffCount(DlInspectionProject dlInspectionProject) { public List<Map<String, Object>> getStaffCount(DlInspectionProject dlInspectionProject) {
List<Map<String, Object>> staffCount = inspectionWorkNodeService.getStaffCount(dlInspectionProject); List<Map<String, Object>> staffCount = inspectionWorkNodeService.getStaffCount(dlInspectionProject);
// 根据userId查询检测工单表 接车人 // 根据userId查询检测工单表 接车人
List<InspectionInfo> list = inspectionInfoService.selectMeetCarList(dlInspectionProject.getDatetimeRange(), null); List<InspectionInfo> list = inspectionInfoService.selectMeetCarList(dlInspectionProject.getDatetimeRange(), null);
// 统计每个 meetManId 的数量避免 null key 异常 // 统计每个 meetManId 的数量避免 null key 异常
Map<Long, List<InspectionInfo>> meetManIdCountMap = list.stream() Map<Long, List<InspectionInfo>> meetManIdCountMap = list.stream()
.filter(info -> info.getMeetManId() != null) // 过滤 null .filter(info -> info.getMeetManId() != null) // 过滤 null
.collect(Collectors.groupingBy(InspectionInfo::getMeetManId)); .collect(Collectors.groupingBy(InspectionInfo::getMeetManId));
// 根据userId查询还车人 // 根据userId查询还车人
List<InspectionInfo> returnCarList = inspectionInfoService.list(Wrappers.<InspectionInfo>lambdaQuery() List<InspectionInfo> returnCarList = inspectionInfoService.list(Wrappers.<InspectionInfo>lambdaQuery()
.eq(InspectionInfo::getIsReturnCar, 1) .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 异常 // 统计每个 returnCarUserId 的数量避免 null key 异常
Map<Long, List<InspectionInfo>> returnCarUserIdCountMap = returnCarList.stream() Map<Long, List<InspectionInfo>> returnCarUserIdCountMap = returnCarList.stream()
.filter(info -> info.getReturnCarUserId() != null) // 过滤 null .filter(info -> info.getReturnCarUserId() != null) // 过滤 null
.collect(Collectors.groupingBy(InspectionInfo::getReturnCarUserId)); .collect(Collectors.groupingBy(InspectionInfo::getReturnCarUserId));
// 先计算所有项目的总完成数
Map<String, Long> projectTotalMap = new HashMap<>();
for (Map<String, Object> stringObjectMap : staffCount) { for (Map<String, Object> stringObjectMap : staffCount) {
Set<Long> inspectionInfoIds = new HashSet<>(); Set<Long> inspectionInfoIds = new HashSet<>();
Long userId = (Long) stringObjectMap.get("userId"); Long userId = (Long) stringObjectMap.get("userId");
List<Map<String, Object>> children = (List<Map<String, Object>>) stringObjectMap.get("children"); List<Map<String, Object>> children = (List<Map<String, Object>>) stringObjectMap.get("children");
inspectionInfoIds.addAll( inspectionInfoIds.addAll(
children.stream() children.stream()
.map(map -> (String) map.get("inspectionInfoId")) // 获取逗号分隔的字符串 .map(map -> (String) map.get("inspectionInfoId")) // 获取逗号分隔的字符串
@ -2547,29 +2556,34 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl<AppInspectionPa
.map(Long::valueOf) // 转换为Long类型 .map(Long::valueOf) // 转换为Long类型
.collect(Collectors.toList()) .collect(Collectors.toList())
); );
// 获取所有接车信息 // 获取所有接车信息
List<InspectionInfo> inspectionInfos = meetManIdCountMap.get(userId); List<InspectionInfo> inspectionInfos = meetManIdCountMap.get(userId);
long meetCount = 0; long meetCount = 0;
long meetGoCount = 0; long meetGoCount = 0;
if (CollUtil.isNotEmpty(inspectionInfos)) { if (CollUtil.isNotEmpty(inspectionInfos)) {
meetCount = inspectionInfos.stream().filter(inspectionInfo -> Integer.valueOf(0).equals(inspectionInfo.getMeetType())).count(); meetCount = inspectionInfos.stream().filter(inspectionInfo -> Integer.valueOf(0).equals(inspectionInfo.getMeetType())).count();
meetGoCount = inspectionInfos.stream().filter(inspectionInfo -> Integer.valueOf(1).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())); inspectionInfoIds.addAll(inspectionInfos.stream().map(InspectionInfo::getId).collect(Collectors.toList()));
} }
HashMap<String, Object> objectObjectHashMap = new HashMap<>(); HashMap<String, Object> objectObjectHashMap = new HashMap<>();
objectObjectHashMap.put("count", meetCount); objectObjectHashMap.put("count", meetCount);
objectObjectHashMap.put("projectName", "接车拍照"); objectObjectHashMap.put("projectName", "接车拍照");
children.add(objectObjectHashMap); children.add(objectObjectHashMap);
HashMap<String, Object> meetCarHashMap = new HashMap<>(); HashMap<String, Object> meetCarHashMap = new HashMap<>();
meetCarHashMap.put("count", meetGoCount); meetCarHashMap.put("count", meetGoCount);
meetCarHashMap.put("projectName", "上门接车"); meetCarHashMap.put("projectName", "上门接车");
children.add(meetCarHashMap); children.add(meetCarHashMap);
//还车 //还车
//设置totalCount //设置totalCount
List<InspectionInfo> returnCarInfoList = returnCarUserIdCountMap.get(userId); List<InspectionInfo> returnCarInfoList = returnCarUserIdCountMap.get(userId);
long returnCount = 0; long returnCount = 0;
long returnGoCount = 0; long returnGoCount = 0;
if (CollUtil.isNotEmpty(returnCarInfoList)) { if (CollUtil.isNotEmpty(returnCarInfoList)) {
inspectionInfoIds.addAll(returnCarInfoList.stream().map(InspectionInfo::getId).collect(Collectors.toList())); inspectionInfoIds.addAll(returnCarInfoList.stream().map(InspectionInfo::getId).collect(Collectors.toList()));
@ -2587,17 +2601,51 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl<AppInspectionPa
.filter(i -> i.getReturnType() != null && i.getReturnType() == 1) .filter(i -> i.getReturnType() != null && i.getReturnType() == 1)
.count(); .count();
} }
stringObjectMap.put("totalCount", Long.parseLong(String.valueOf(inspectionInfoIds.size()))); stringObjectMap.put("totalCount", Long.parseLong(String.valueOf(inspectionInfoIds.size())));
Map<String, Object> objectObjectHashMap1 = new HashMap<>(); Map<String, Object> objectObjectHashMap1 = new HashMap<>();
objectObjectHashMap1.put("count", returnCount); objectObjectHashMap1.put("count", returnCount);
objectObjectHashMap1.put("projectName", "还车拍照"); objectObjectHashMap1.put("projectName", "还车拍照");
children.add(objectObjectHashMap1); children.add(objectObjectHashMap1);
Map<String, Object> returnCarHashMap = new HashMap<>(); Map<String, Object> returnCarHashMap = new HashMap<>();
returnCarHashMap.put("count", returnGoCount); returnCarHashMap.put("count", returnGoCount);
returnCarHashMap.put("projectName", "上门还车"); returnCarHashMap.put("projectName", "上门还车");
children.add(returnCarHashMap); children.add(returnCarHashMap);
} }
// 计算每个项目的总完成数
for (Map<String, Object> staff : staffCount) {
List<Map<String, Object>> children = (List<Map<String, Object>>) staff.get("children");
if (children != null) {
for (Map<String, Object> child : children) {
String projectName = (String) child.get("projectName");
Long count = (Long) child.get("count");
projectTotalMap.put(projectName, projectTotalMap.getOrDefault(projectName, 0L) + count);
}
}
}
// 为每个项目添加比例
for (Map<String, Object> staff : staffCount) {
List<Map<String, Object>> children = (List<Map<String, Object>>) staff.get("children");
if (children != null) {
for (Map<String, Object> 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 降序排序员工 // meetCarCount 降序排序员工
staffCount.sort(Comparator.comparingLong( staffCount.sort(Comparator.comparingLong(
(Map<String, Object> staff) -> (Long) staff.getOrDefault("totalCount", 0L) (Map<String, Object> staff) -> (Long) staff.getOrDefault("totalCount", 0L)

View File

@ -380,26 +380,54 @@
ORDER BY ii.start_time DESC; ORDER BY ii.start_time DESC;
</select> </select>
<select id="queryStaffCountGroupByGoods" resultType="java.util.Map"> <select id="queryStaffCountGroupByGoods" resultType="java.util.Map">
WITH goods_totals AS (
SELECT SELECT
oi.goods_title AS goodsTitle, oi.goods_title,
COUNT(DISTINCT ii.id) AS totalCount ii.tenant_id,
COUNT(DISTINCT ii.id) AS total_goods_count
FROM FROM
inspection_work_node iwn inspection_work_node iwn
JOIN JOIN
inspection_info ii ON iwn.inspection_info_id = ii.id inspection_info ii ON iwn.inspection_info_id = ii.id
JOIN JOIN
order_info oi ON ii.inspection_order_id = oi.id order_info oi ON ii.inspection_order_id = oi.id
WHERE WHERE
iwn.deal_user_id = #{userId} -- 替换为你要查询的用户ID iwn.deleted = b'0'
AND iwn.deleted = b'0'
<if test="datetimeRange != null and datetimeRange.size() == 2"> <if test="datetimeRange != null and datetimeRange.size() == 2">
AND ii.create_time BETWEEN CONCAT(#{datetimeRange[0]}, ' 00:00:00') AND CONCAT(#{datetimeRange[1]}, ' 23:59:59') AND ii.create_time BETWEEN CONCAT(#{datetimeRange[0]}, ' 00:00:00') AND CONCAT(#{datetimeRange[1]}, ' 23:59:59')
</if> </if>
AND iwn.status = '2' AND iwn.status = '2'
AND ii.deleted = 0 AND ii.deleted = 0
AND oi.deleted = 0 AND oi.deleted = 0
GROUP BY GROUP BY
oi.goods_title; oi.goods_title
)
SELECT
oi.goods_title AS goodsTitle,
COUNT(DISTINCT ii.id) AS totalCount,
gt.total_goods_count AS goodsTotalCount,
ROUND(COUNT(DISTINCT ii.id) * 100.0 / gt.total_goods_count, 2) AS percentage
FROM
inspection_work_node iwn
JOIN
inspection_info ii ON iwn.inspection_info_id = ii.id
JOIN
order_info oi ON ii.inspection_order_id = oi.id
JOIN
goods_totals gt ON oi.goods_title = gt.goods_title
WHERE
iwn.deal_user_id = #{userId}
AND iwn.deleted = b'0'
<if test="datetimeRange != null and datetimeRange.size() == 2">
AND ii.create_time BETWEEN CONCAT(#{datetimeRange[0]}, ' 00:00:00') AND CONCAT(#{datetimeRange[1]}, ' 23:59:59')
</if>
AND iwn.status = '2'
AND ii.deleted = 0
AND oi.deleted = 0
GROUP BY
oi.goods_title, gt.total_goods_count
ORDER BY
totalCount DESC;
</select> </select>
<select id="queryStaffInspectionCount" resultType="java.util.Map"> <select id="queryStaffInspectionCount" resultType="java.util.Map">