fix: 修复预先指定的任务无法更新进度的问题
问题描述: - 预先指定设计师的任务(receiver_id已设置)但状态仍为pending - 设计师尝试更新进度时报错"只能更新进行中的子任务" - 因为设计师没有点击"接单"按钮将状态变为in_progress 解决方案: - 在updateProgress方法中检测到这种情况时 - 自动将子任务状态从pending变为in_progress - 同时计算deadline并更新主任务状态 - 让设计师可以直接更新进度,无需单独接单
This commit is contained in:
parent
b49c9e411a
commit
2d08524f41
@ -465,8 +465,41 @@ public class TaskItemService {
|
||||
throw new BusinessException(ResultCode.FORBIDDEN, "无权更新该子任务");
|
||||
}
|
||||
|
||||
// 验证状态
|
||||
if (!"in_progress".equals(item.getStatus())) {
|
||||
// 🔥 修复:如果子任务是预先指定给该用户的(status=pending且receiverId=userId),自动转为进行中
|
||||
if ("pending".equals(item.getStatus())) {
|
||||
// 检查是否被锁定
|
||||
if (item.getIsLocked() != null && item.getIsLocked() == 1) {
|
||||
throw new BusinessException(ResultCode.TASK_STATUS_ERROR, "该子任务已被锁定,请等待前序任务完成");
|
||||
}
|
||||
|
||||
log.info("子任务 {} 是预先指定任务(status=pending, receiverId={}),自动转为进行中", itemId, userId);
|
||||
|
||||
// 计算deadline
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime deadline = null;
|
||||
if (item.getEstimatedHours() != null && item.getEstimatedHours().compareTo(java.math.BigDecimal.ZERO) > 0) {
|
||||
deadline = workHoursCalculator.calculateDeadline(now, item.getEstimatedHours());
|
||||
log.info("子任务deadline已计算:从当前时间 {} 开始,预估 {} 小时,截止时间 {}",
|
||||
now, item.getEstimatedHours(), deadline);
|
||||
}
|
||||
|
||||
// 更新子任务状态为进行中
|
||||
item.setStatus("in_progress");
|
||||
item.setClaimTime(now);
|
||||
if (deadline != null) {
|
||||
item.setDeadline(deadline);
|
||||
}
|
||||
|
||||
// 同步更新主任务状态
|
||||
Task mainTask = taskMapper.selectById(item.getTaskId());
|
||||
if (mainTask != null && "pending".equals(mainTask.getStatus())) {
|
||||
mainTask.setStatus("in_progress");
|
||||
mainTask.setStartTime(now);
|
||||
mainTask.setActualStartTime(now);
|
||||
taskMapper.updateById(mainTask);
|
||||
log.info("主任务 {} 状态已更新为 in_progress", mainTask.getId());
|
||||
}
|
||||
} else if (!"in_progress".equals(item.getStatus())) {
|
||||
throw new BusinessException(ResultCode.TASK_STATUS_ERROR, "只能更新进行中的子任务");
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user