feat(优先级):维度权重可配置并即时重算
- 新表 user_priority_weights(每用户一行,默认 0.35/0.25/0.20/0.10/0.10) - PriorityWeightsService:读取/保存权重,权重和必须为 1,保存后重算全部任务 - TaskController:GET/PUT /tasks/priority-weights - CalculatedPriorityTool 支持自定义权重 - 修复 updateTask 不重算优先级的问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.guo.learningprogresstracker.utils;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.PriorityDto;
|
||||
import com.guo.learningprogresstracker.entity.UserPriorityWeightsEntity;
|
||||
|
||||
/**
|
||||
* 加权优先级计算工具
|
||||
@@ -8,31 +9,21 @@ import com.guo.learningprogresstracker.dto.PriorityDto;
|
||||
public class CalculatedPriorityTool {
|
||||
|
||||
/**
|
||||
* 通过用户选择的5个选项,结合定义的权重计算任务的加权优先级。
|
||||
* 急迫性 (Urgency)
|
||||
* 急迫性代表任务的紧急程度。权重:0.35
|
||||
* <p>
|
||||
* 重要性 (Importance)
|
||||
* 重要性指示任务的重要程度。权重:0.25
|
||||
* <p>
|
||||
* 内容难度 (Content Difficulty)
|
||||
* 内容难度衡量任务内容的复杂性。权重:0.20
|
||||
* <p>
|
||||
* 未来价值 (Future Value)
|
||||
* 未来价值估计完成任务的长期价值。权重:0.10
|
||||
* <p>
|
||||
* 主观优先级 (Subjective Priority)
|
||||
* 主观优先级是用户对任务优先级的个人评估。权重:0.10
|
||||
*
|
||||
* @param priorityDto
|
||||
* @return
|
||||
* 使用系统默认权重计算加权优先级。
|
||||
* 急迫性 0.35 / 重要性 0.25 / 内容难度 0.20 / 未来价值 0.10 / 主观优先级 0.10
|
||||
*/
|
||||
public static Double calculatedPriority(PriorityDto priorityDto) {
|
||||
// 暂时写死权重,也许可以考虑让用户自行配置权重
|
||||
return (priorityDto.getUrgency() * 0.35) +
|
||||
(priorityDto.getImportance() * 0.25) +
|
||||
(priorityDto.getContentDifficulty() * 0.20) +
|
||||
(priorityDto.getFutureValue() * 0.10) +
|
||||
(priorityDto.getSubjectivePriority() * 0.10);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user