修改类型分布统计:从任务类型改为任务子类型(新品/优化/视频等)
This commit is contained in:
parent
b9575b5014
commit
73bea1eaef
@ -301,44 +301,24 @@ public class AnalyticsService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建类型分布
|
||||
* 构建类型分布(按任务子类型分组)
|
||||
*/
|
||||
private List<DemandStatisticsVO.TypeDistribution> buildTypeDistribution(List<Task> tasks) {
|
||||
// 优先使用 taskTypeId,如果为空则使用 demandTypeId
|
||||
Map<Long, List<Task>> 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<String, List<Task>> tasksBySubType = tasks.stream()
|
||||
.filter(t -> t.getTaskSubType() != null && !t.getTaskSubType().trim().isEmpty())
|
||||
.collect(Collectors.groupingBy(t -> t.getTaskSubType()));
|
||||
|
||||
int totalTasks = tasks.size();
|
||||
List<DemandStatisticsVO.TypeDistribution> distribution = new ArrayList<>();
|
||||
|
||||
// 预加载所有任务类型名称
|
||||
Map<Long, String> 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<Long, List<Task>> entry : tasksByType.entrySet()) {
|
||||
List<Task> typeTasks = entry.getValue();
|
||||
int count = typeTasks.size();
|
||||
for (Map.Entry<String, List<Task>> entry : tasksBySubType.entrySet()) {
|
||||
List<Task> 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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user