feat: 优化任务时效计算逻辑 - 从接单时开始计算

问题:
- 任务时效(deadline)应该从设计师接单时开始计算
- 而不是从任务创建或审核通过时计算

修改内容:

1. TaskService.grabTask()
   - 无论任务之前是否有deadline
   - 抢单时都重新计算deadline
   - 从接单时间(now)开始 + estimatedHours
   - 添加详细日志记录

2. TaskApprovalService.approveReceivingLevel()
   - 接单部门负责人指定设计师时
   - 重新计算deadline
   - 从指定时间(now)开始 + estimatedHours
   - 添加详细日志记录

3. TaskApprovalService.approveDemandLevel()
   - assigned模式下已有正确逻辑
   - 从分配时间开始计算deadline
   - 保持不变

计算逻辑:
- deadline = 接单时间 + estimatedHours(小时)
- 如果estimatedHours为空或0,不设置deadline
- 记录详细日志便于排查

影响范围:
- 设计师抢单:✅ 重新计算
- 负责人指派:✅ 重新计算
- 需求部门指定:✅ 已有逻辑
- 发布到大厅:❌ 不设置(等待接单后计算)

示例:
- 任务预估8小时
- 设计师12:00接单
- deadline = 12:00 + 8小时 = 20:00
This commit is contained in:
Your Name 2026-01-03 11:54:59 +08:00
parent a241730633
commit fac68333a7
2 changed files with 18 additions and 4 deletions

View File

@ -226,8 +226,19 @@ public class TaskApprovalService {
// 普通任务:根据是否指定接收人设置状态
if (assignedReceiverId != null) {
task.setStatus("in_progress"); // 指定接单直接进入进行中状态
task.setStartTime(LocalDateTime.now());
task.setActualStartTime(LocalDateTime.now());
LocalDateTime now = LocalDateTime.now();
task.setStartTime(now);
task.setActualStartTime(now);
// 重新计算deadline:从指定接单时间开始计算
if (task.getEstimatedHours() != null) {
int hours = task.getEstimatedHours().intValue();
if (hours > 0) {
task.setDeadline(now.plusHours(hours));
log.info("任务deadline已重新计算:从指定接单时间 {} 开始,预估 {} 小时,截止时间 {}",
now, hours, task.getDeadline());
}
}
} else {
task.setStatus("pending"); // 未指定则发布到大厅
}

View File

@ -767,11 +767,14 @@ public class TaskService {
}
LocalDateTime now = LocalDateTime.now();
LocalDateTime deadline = task.getDeadline();
if (deadline == null && task.getEstimatedHours() != null) {
// 重新计算deadline:从接单时间开始计算,无论之前是否有deadline
LocalDateTime deadline = null;
if (task.getEstimatedHours() != null) {
int hours = task.getEstimatedHours().intValue();
if (hours > 0) {
deadline = now.plusHours(hours);
log.info("任务deadline已重新计算:从接单时间 {} 开始,预估 {} 小时,截止时间 {}",
now, hours, deadline);
}
}