diff --git a/backend/src/main/java/com/designhub/service/AnalyticsService.java b/backend/src/main/java/com/designhub/service/AnalyticsService.java index 3f1a29f..7dc6f32 100644 --- a/backend/src/main/java/com/designhub/service/AnalyticsService.java +++ b/backend/src/main/java/com/designhub/service/AnalyticsService.java @@ -301,44 +301,24 @@ public class AnalyticsService { } /** - * 构建类型分布 + * 构建类型分布(按任务子类型分组) */ private List buildTypeDistribution(List tasks) { - // 优先使用 taskTypeId,如果为空则使用 demandTypeId - Map> tasksByType = tasks.stream() - .filter(t -> t.getTaskTypeId() != null || t.getDemandTypeId() != null) - .collect(Collectors.groupingBy(t -> { - if (t.getTaskTypeId() != null) { - return t.getTaskTypeId(); - } - return t.getDemandTypeId(); - })); + // 按任务子类型(taskSubType)分组 + Map> tasksBySubType = tasks.stream() + .filter(t -> t.getTaskSubType() != null && !t.getTaskSubType().trim().isEmpty()) + .collect(Collectors.groupingBy(t -> t.getTaskSubType())); int totalTasks = tasks.size(); List distribution = new ArrayList<>(); - // 预加载所有任务类型名称 - Map typeNameMap = new HashMap<>(); - for (Long typeId : tasksByType.keySet()) { - try { - DemandType demandType = demandTypeMapper.selectById(typeId); - if (demandType != null) { - typeNameMap.put(typeId, demandType.getName()); - } else { - typeNameMap.put(typeId, "未知类型"); - } - } catch (Exception e) { - typeNameMap.put(typeId, "类型" + typeId); - } - } - - for (Map.Entry> entry : tasksByType.entrySet()) { - List typeTasks = entry.getValue(); - int count = typeTasks.size(); + for (Map.Entry> entry : tasksBySubType.entrySet()) { + List subTypeTasks = entry.getValue(); + int count = subTypeTasks.size(); double percentage = totalTasks > 0 ? (double) count / totalTasks * 100 : 0.0; // 优先使用 scoreReward,其次使用 score - BigDecimal totalScore = typeTasks.stream() + BigDecimal totalScore = subTypeTasks.stream() .map(t -> { if (t.getScoreReward() != null && t.getScoreReward().compareTo(BigDecimal.ZERO) > 0) { return t.getScoreReward(); @@ -347,10 +327,10 @@ public class AnalyticsService { }) .reduce(BigDecimal.ZERO, BigDecimal::add); - String typeName = typeNameMap.getOrDefault(entry.getKey(), "类型" + entry.getKey()); + String subTypeName = entry.getKey(); distribution.add(DemandStatisticsVO.TypeDistribution.builder() - .typeName(typeName) + .typeName(subTypeName) .count(count) .percentage(percentage) .totalScore(totalScore)