From 2d08524f41a4c015ca3f140ce0a3d48ca920bb63 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 26 Jan 2026 19:15:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A2=84=E5=85=88?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E7=9A=84=E4=BB=BB=E5=8A=A1=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BF=9B=E5=BA=A6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题描述: - 预先指定设计师的任务(receiver_id已设置)但状态仍为pending - 设计师尝试更新进度时报错"只能更新进行中的子任务" - 因为设计师没有点击"接单"按钮将状态变为in_progress 解决方案: - 在updateProgress方法中检测到这种情况时 - 自动将子任务状态从pending变为in_progress - 同时计算deadline并更新主任务状态 - 让设计师可以直接更新进度,无需单独接单 --- .../designhub/service/TaskItemService.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/designhub/service/TaskItemService.java b/backend/src/main/java/com/designhub/service/TaskItemService.java index e49ebbc..29b86f8 100644 --- a/backend/src/main/java/com/designhub/service/TaskItemService.java +++ b/backend/src/main/java/com/designhub/service/TaskItemService.java @@ -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, "只能更新进行中的子任务"); }