diff --git a/backend/src/main/java/com/designhub/service/TaskItemService.java b/backend/src/main/java/com/designhub/service/TaskItemService.java index 40fdb36..288c164 100644 --- a/backend/src/main/java/com/designhub/service/TaskItemService.java +++ b/backend/src/main/java/com/designhub/service/TaskItemService.java @@ -678,54 +678,109 @@ public class TaskItemService { .collect(java.util.stream.Collectors.toList()); if (!nextDeptItems.isEmpty()) { - // 批量解锁下一个部门的所有子任务,状态设为待审核,并传递前置环节的下载链接 + // 🔥 分类处理:已预先指定设计师的 vs 未指定的 + List preAssignedItems = new ArrayList<>(); // 已预先指定设计师的子任务 + List unassignedItems = new ArrayList<>(); // 未指定的子任务 + for (TaskItem nextItem : nextDeptItems) { - nextItem.setStatus("pending_approval"); // 待接单部门负责人审核 + if (nextItem.getReceiverId() != null) { + preAssignedItems.add(nextItem); + } else { + unassignedItems.add(nextItem); + } + } + + LocalDateTime now = LocalDateTime.now(); + + // 🔥 处理已预先指定设计师的子任务:直接设为待接单状态,并通知设计师 + Set notifiedDesignerIds = new HashSet<>(); + for (TaskItem nextItem : preAssignedItems) { + nextItem.setStatus("pending"); // 待接单(设计师需要点击接单确认) nextItem.setIsLocked(0); - nextItem.setPrevDownloadUrl(prevDownloadUrlStr); // 🔥 传递前置环节的下载链接 - nextItem.setUpdateTime(LocalDateTime.now()); + nextItem.setPrevDownloadUrl(prevDownloadUrlStr); + nextItem.setUpdateTime(now); taskItemMapper.updateById(nextItem); - log.info("✅ 解锁子任务: {} (部门序号: {}, ID: {}),待接单部门负责人审核,已传递前置素材链接", + log.info("✅ 解锁预先指定的子任务: {} -> 设计师 {} (ID: {}),状态设为待接单", + nextItem.getItemNo(), nextItem.getReceiverName(), nextItem.getReceiverId()); + + // 通知预先指定的设计师 + if (!notifiedDesignerIds.contains(nextItem.getReceiverId())) { + notifiedDesignerIds.add(nextItem.getReceiverId()); + + Notification notification = new Notification(); + notification.setReceiverId(nextItem.getReceiverId()); + notification.setNotificationType("task"); + notification.setTitle("指派任务已解锁"); + notification.setContent("任务《" + mainTask.getTitle() + "》的子任务 " + nextItem.getItemNo() + + " 已解锁,请尽快接单处理!"); + notification.setRelatedId(nextItem.getId()); + notification.setRelatedType("task_item"); + notification.setPriority(2); // 重要 + notification.setPushDingtalk(1); // 推送到钉钉 + notificationService.sendNotification(notification); + + log.info("已通知预先指定的设计师 {} (ID: {}) 子任务已解锁", + nextItem.getReceiverName(), nextItem.getReceiverId()); + } + } + + // 🔥 处理未指定设计师的子任务:设为待审核,通知接单部门负责人 + for (TaskItem nextItem : unassignedItems) { + nextItem.setStatus("pending_approval"); // 待接单部门负责人审核 + nextItem.setIsLocked(0); + nextItem.setPrevDownloadUrl(prevDownloadUrlStr); + nextItem.setUpdateTime(now); + taskItemMapper.updateById(nextItem); + + log.info("✅ 解锁未指定的子任务: {} (部门序号: {}, ID: {}),待接单部门负责人审核", nextItem.getItemNo(), nextDeptIndex, nextItem.getId()); } result.put("unlockedDeptIndex", nextDeptIndex); result.put("unlockedCount", nextDeptItems.size()); + result.put("preAssignedCount", preAssignedItems.size()); + result.put("unassignedCount", unassignedItems.size()); - // 发送通知给接单部门负责人 - // 从子任务的任务类型配置中获取allowed_dept_ids - Set notifiedLeaderIds = new HashSet<>(); - for (TaskItem nextItem : nextDeptItems) { - Long targetDeptId = getTargetDeptIdFromTaskType(nextItem.getTaskTypeId()); - if (targetDeptId != null) { - com.designhub.entity.Department receiverDept = departmentMapper.selectById(targetDeptId); - if (receiverDept != null && receiverDept.getLeaderId() != null - && !notifiedLeaderIds.contains(receiverDept.getLeaderId())) { - notifiedLeaderIds.add(receiverDept.getLeaderId()); - - Notification notification = new Notification(); - notification.setReceiverId(receiverDept.getLeaderId()); - notification.setNotificationType("task_approval"); - notification.setTitle("新子任务组待审核"); - notification.setContent("任务《" + mainTask.getTitle() + "》第 " + nextDeptIndex + " 个部门共 " + - nextDeptItems.size() + " 个子任务已解锁,请审核并分配!"); - notification.setRelatedId(item.getTaskId()); - notification.setRelatedType("task"); - notification.setPriority(2); // 重要 - notification.setPushDingtalk(1); // 推送到钉钉 - notificationService.sendNotification(notification); - - log.info("已通知接单部门负责人(部门: {}, 负责人ID: {})审核第 {} 个部门子任务", - receiverDept.getDeptName(), receiverDept.getLeaderId(), nextDeptIndex); + // 只有未指定设计师的子任务才需要通知接单部门负责人审核 + if (!unassignedItems.isEmpty()) { + Set notifiedLeaderIds = new HashSet<>(); + for (TaskItem nextItem : unassignedItems) { + Long targetDeptId = getTargetDeptIdFromTaskType(nextItem.getTaskTypeId()); + if (targetDeptId != null) { + com.designhub.entity.Department receiverDept = departmentMapper.selectById(targetDeptId); + if (receiverDept != null && receiverDept.getLeaderId() != null + && !notifiedLeaderIds.contains(receiverDept.getLeaderId())) { + notifiedLeaderIds.add(receiverDept.getLeaderId()); + + Notification notification = new Notification(); + notification.setReceiverId(receiverDept.getLeaderId()); + notification.setNotificationType("task_approval"); + notification.setTitle("新子任务组待审核"); + notification.setContent("任务《" + mainTask.getTitle() + "》第 " + nextDeptIndex + " 个部门共 " + + unassignedItems.size() + " 个子任务已解锁,请审核并分配!"); + notification.setRelatedId(item.getTaskId()); + notification.setRelatedType("task"); + notification.setPriority(2); // 重要 + notification.setPushDingtalk(1); // 推送到钉钉 + notificationService.sendNotification(notification); + + log.info("已通知接单部门负责人(部门: {}, 负责人ID: {})审核第 {} 个部门子任务", + receiverDept.getDeptName(), receiverDept.getLeaderId(), nextDeptIndex); + } + } else { + log.warn("子任务 {} 的任务类型未配置接单部门", nextItem.getItemNo()); } - } else { - log.warn("子任务 {} 的任务类型未配置接单部门", nextItem.getItemNo()); } + + log.info("第 {} 个部门 {} 个未指定子任务已解锁,等待接单部门负责人审核,已通知 {} 个部门负责人", + nextDeptIndex, unassignedItems.size(), notifiedLeaderIds.size()); } - log.info("第 {} 个部门 {} 个子任务已解锁,等待接单部门负责人审核,已通知 {} 个部门负责人", - nextDeptIndex, nextDeptItems.size(), notifiedLeaderIds.size()); + if (!preAssignedItems.isEmpty()) { + log.info("第 {} 个部门 {} 个预先指定的子任务已解锁,已通知 {} 个设计师", + nextDeptIndex, preAssignedItems.size(), notifiedDesignerIds.size()); + } } else { log.info("没有更多部门的子任务需要解锁"); }