更新0911
This commit is contained in:
parent
17be414b84
commit
eaf2ba0ecb
@ -2518,26 +2518,35 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl<AppInspectionPa
|
||||
@Override
|
||||
public List<Map<String, Object>> getStaffCount(DlInspectionProject dlInspectionProject) {
|
||||
List<Map<String, Object>> staffCount = inspectionWorkNodeService.getStaffCount(dlInspectionProject);
|
||||
|
||||
// 根据userId查询检测工单表 接车人
|
||||
List<InspectionInfo> list = inspectionInfoService.selectMeetCarList(dlInspectionProject.getDatetimeRange(), null);
|
||||
|
||||
// 统计每个 meetManId 的数量,避免 null key 异常
|
||||
Map<Long, List<InspectionInfo>> meetManIdCountMap = list.stream()
|
||||
.filter(info -> info.getMeetManId() != null) // 过滤 null 值
|
||||
.collect(Collectors.groupingBy(InspectionInfo::getMeetManId));
|
||||
|
||||
// 根据userId查询还车人
|
||||
List<InspectionInfo> returnCarList = inspectionInfoService.list(Wrappers.<InspectionInfo>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<Long, List<InspectionInfo>> returnCarUserIdCountMap = returnCarList.stream()
|
||||
.filter(info -> info.getReturnCarUserId() != null) // 过滤 null 值
|
||||
.collect(Collectors.groupingBy(InspectionInfo::getReturnCarUserId));
|
||||
|
||||
// 先计算所有项目的总完成数
|
||||
Map<String, Long> projectTotalMap = new HashMap<>();
|
||||
|
||||
for (Map<String, Object> stringObjectMap : staffCount) {
|
||||
Set<Long> inspectionInfoIds = new HashSet<>();
|
||||
|
||||
Long userId = (Long) stringObjectMap.get("userId");
|
||||
List<Map<String, Object>> children = (List<Map<String, Object>>) stringObjectMap.get("children");
|
||||
|
||||
inspectionInfoIds.addAll(
|
||||
children.stream()
|
||||
.map(map -> (String) map.get("inspectionInfoId")) // 获取逗号分隔的字符串
|
||||
@ -2547,29 +2556,34 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl<AppInspectionPa
|
||||
.map(Long::valueOf) // 转换为Long类型
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
|
||||
// 获取所有接车信息
|
||||
List<InspectionInfo> 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<String, Object> objectObjectHashMap = new HashMap<>();
|
||||
objectObjectHashMap.put("count", meetCount);
|
||||
objectObjectHashMap.put("projectName", "接车拍照");
|
||||
children.add(objectObjectHashMap);
|
||||
|
||||
HashMap<String, Object> meetCarHashMap = new HashMap<>();
|
||||
meetCarHashMap.put("count", meetGoCount);
|
||||
meetCarHashMap.put("projectName", "上门接车");
|
||||
|
||||
children.add(meetCarHashMap);
|
||||
|
||||
//还车
|
||||
//设置totalCount
|
||||
List<InspectionInfo> 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<AppInspectionPa
|
||||
.filter(i -> i.getReturnType() != null && i.getReturnType() == 1)
|
||||
.count();
|
||||
}
|
||||
|
||||
stringObjectMap.put("totalCount", Long.parseLong(String.valueOf(inspectionInfoIds.size())));
|
||||
|
||||
Map<String, Object> objectObjectHashMap1 = new HashMap<>();
|
||||
objectObjectHashMap1.put("count", returnCount);
|
||||
objectObjectHashMap1.put("projectName", "还车拍照");
|
||||
children.add(objectObjectHashMap1);
|
||||
|
||||
Map<String, Object> returnCarHashMap = new HashMap<>();
|
||||
returnCarHashMap.put("count", returnGoCount);
|
||||
returnCarHashMap.put("projectName", "上门还车");
|
||||
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 降序排序员工
|
||||
staffCount.sort(Comparator.comparingLong(
|
||||
(Map<String, Object> staff) -> (Long) staff.getOrDefault("totalCount", 0L)
|
||||
|
@ -380,26 +380,54 @@
|
||||
ORDER BY ii.start_time DESC;
|
||||
</select>
|
||||
<select id="queryStaffCountGroupByGoods" resultType="java.util.Map">
|
||||
WITH goods_totals AS (
|
||||
SELECT
|
||||
oi.goods_title AS goodsTitle,
|
||||
COUNT(DISTINCT ii.id) AS totalCount
|
||||
oi.goods_title,
|
||||
ii.tenant_id,
|
||||
COUNT(DISTINCT ii.id) AS total_goods_count
|
||||
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
|
||||
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
|
||||
WHERE
|
||||
iwn.deal_user_id = #{userId} -- 替换为你要查询的用户ID
|
||||
AND iwn.deleted = b'0'
|
||||
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
|
||||
AND iwn.status = '2'
|
||||
AND ii.deleted = 0
|
||||
AND oi.deleted = 0
|
||||
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 id="queryStaffInspectionCount" resultType="java.util.Map">
|
||||
|
Loading…
Reference in New Issue
Block a user