From bd98e4a3abfa97f0d44c114c62aca0fd79343948 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 7 Jan 2026 16:43:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E5=AD=90=E4=BB=BB=E5=8A=A1=E5=AE=8C=E6=88=90=E5=90=8E?= =?UTF-8?q?=E6=9C=AA=E9=80=9A=E7=9F=A5=E4=B8=8B=E4=B8=80=E7=BB=84=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E8=B4=9F=E8=B4=A3=E4=BA=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 使用子任务的任务类型配置(allowed_dept_ids)获取目标部门 2. 递归向上查找父级类型的部门配置 3. 发送通知给所有相关部门负责人 --- .../designhub/service/TaskItemService.java | 83 +++++++++++++++---- 1 file changed, 65 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/com/designhub/service/TaskItemService.java b/backend/src/main/java/com/designhub/service/TaskItemService.java index 46554b0..aa24c58 100644 --- a/backend/src/main/java/com/designhub/service/TaskItemService.java +++ b/backend/src/main/java/com/designhub/service/TaskItemService.java @@ -37,6 +37,7 @@ public class TaskItemService { private final ConfigService configService; private final ExternalAssetService externalAssetService; private final SystemConfigService systemConfigService; + private final com.designhub.mapper.TaskTypeMapper taskTypeMapper; /** * 获取可接单的子任务列表 @@ -504,27 +505,38 @@ public class TaskItemService { result.put("unlockedCount", nextGroupItems.size()); // 发送通知给接单部门负责人 - if (mainTask.getReceiverDeptId() != null) { - com.designhub.entity.Department receiverDept = departmentMapper.selectById(mainTask.getReceiverDeptId()); - if (receiverDept != null && receiverDept.getLeaderId() != null) { - Notification notification = new Notification(); - notification.setReceiverId(receiverDept.getLeaderId()); - notification.setNotificationType("task_approval"); - notification.setTitle("新子任务组待审核"); - notification.setContent("任务《" + mainTask.getTitle() + "》第 " + nextGroupNo + " 组共 " + - nextGroupItems.size() + " 个子任务已解锁,请审核并分配!"); - notification.setRelatedId(item.getTaskId()); - notification.setRelatedType("task"); - notification.setPriority(2); // 重要 - notification.setPushDingtalk(1); // 推送到钉钉 - notificationService.sendNotification(notification); - - log.info("已通知接单部门负责人(ID: {})审核第 {} 组子任务", - receiverDept.getLeaderId(), nextGroupNo); + // 从子任务的任务类型配置中获取allowed_dept_ids + Set notifiedLeaderIds = new java.util.HashSet<>(); + for (TaskItem nextItem : nextGroupItems) { + 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() + "》第 " + nextGroupNo + " 组共 " + + nextGroupItems.size() + " 个子任务已解锁,请审核并分配!"); + notification.setRelatedId(item.getTaskId()); + notification.setRelatedType("task"); + notification.setPriority(2); // 重要 + notification.setPushDingtalk(1); // 推送到钉钉 + notificationService.sendNotification(notification); + + log.info("已通知接单部门负责人(部门: {}, 负责人ID: {})审核第 {} 组子任务", + receiverDept.getDeptName(), receiverDept.getLeaderId(), nextGroupNo); + } + } else { + log.warn("子任务 {} 的任务类型未配置接单部门", nextItem.getItemNo()); } } - log.info("第 {} 组 {} 个子任务已解锁,等待接单部门负责人审核", nextGroupNo, nextGroupItems.size()); + log.info("第 {} 组 {} 个子任务已解锁,等待接单部门负责人审核,已通知 {} 个部门负责人", + nextGroupNo, nextGroupItems.size(), notifiedLeaderIds.size()); } else { log.info("没有更多子任务组需要解锁"); } @@ -998,4 +1010,39 @@ public class TaskItemService { return new java.util.ArrayList<>(groupMap.values()); } + + /** + * 从任务类型配置中获取目标接单部门ID + * 如果当前类型未配置,则递归向上查找父级类型的配置 + */ + private Long getTargetDeptIdFromTaskType(Long taskTypeId) { + if (taskTypeId == null) { + return null; + } + + com.designhub.entity.TaskType taskType = taskTypeMapper.selectById(taskTypeId); + if (taskType == null) { + return null; + } + + // 如果当前类型配置了allowed_dept_ids,返回第一个部门ID + String allowedDeptIds = taskType.getAllowedDeptIds(); + if (allowedDeptIds != null && !allowedDeptIds.isEmpty()) { + try { + String[] deptIds = allowedDeptIds.split(","); + if (deptIds.length > 0) { + return Long.parseLong(deptIds[0].trim()); + } + } catch (NumberFormatException e) { + log.warn("解析allowed_dept_ids失败: {}", allowedDeptIds, e); + } + } + + // 如果当前类型未配置,递归查找父级 + if (taskType.getParentId() != null) { + return getTargetDeptIdFromTaskType(taskType.getParentId()); + } + + return null; + } }