From 73bea1eaef88b7a1eb85a499d53e434063c38786 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 13 Jan 2026 14:35:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=B1=BB=E5=9E=8B=E5=88=86?= =?UTF-8?q?=E5=B8=83=E7=BB=9F=E8=AE=A1=EF=BC=9A=E4=BB=8E=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=94=B9=E4=B8=BA=E4=BB=BB=E5=8A=A1=E5=AD=90?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=EF=BC=88=E6=96=B0=E5=93=81/=E4=BC=98?= =?UTF-8?q?=E5=8C=96/=E8=A7=86=E9=A2=91=E7=AD=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designhub/service/AnalyticsService.java | 42 +++++-------------- 1 file changed, 11 insertions(+), 31 deletions(-) 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)