- 新表 user_priority_weights(每用户一行,默认 0.35/0.25/0.20/0.10/0.10) - PriorityWeightsService:读取/保存权重,权重和必须为 1,保存后重算全部任务 - TaskController:GET/PUT /tasks/priority-weights - CalculatedPriorityTool 支持自定义权重 - 修复 updateTask 不重算优先级的问题
30 lines
1.2 KiB
Java
30 lines
1.2 KiB
Java
package com.guo.learningprogresstracker.utils;
|
|
|
|
import com.guo.learningprogresstracker.dto.PriorityDto;
|
|
import com.guo.learningprogresstracker.entity.UserPriorityWeightsEntity;
|
|
|
|
/**
|
|
* 加权优先级计算工具
|
|
*/
|
|
public class CalculatedPriorityTool {
|
|
|
|
/**
|
|
* 使用系统默认权重计算加权优先级。
|
|
* 急迫性 0.35 / 重要性 0.25 / 内容难度 0.20 / 未来价值 0.10 / 主观优先级 0.10
|
|
*/
|
|
public static Double calculatedPriority(PriorityDto priorityDto) {
|
|
return calculatedPriority(priorityDto, UserPriorityWeightsEntity.defaults());
|
|
}
|
|
|
|
/**
|
|
* 使用用户自定义权重计算加权优先级。
|
|
*/
|
|
public static Double calculatedPriority(PriorityDto priorityDto, UserPriorityWeightsEntity weights) {
|
|
return (priorityDto.getUrgency() * weights.getUrgencyWeight()) +
|
|
(priorityDto.getImportance() * weights.getImportanceWeight()) +
|
|
(priorityDto.getContentDifficulty() * weights.getContentDifficultyWeight()) +
|
|
(priorityDto.getFutureValue() * weights.getFutureValueWeight()) +
|
|
(priorityDto.getSubjectivePriority() * weights.getSubjectivePriorityWeight());
|
|
}
|
|
}
|