diff --git a/backend/src/main/java/com/designhub/dto/PipelineTaskDTO.java b/backend/src/main/java/com/designhub/dto/PipelineTaskDTO.java index d482b69..e1f5002 100644 --- a/backend/src/main/java/com/designhub/dto/PipelineTaskDTO.java +++ b/backend/src/main/java/com/designhub/dto/PipelineTaskDTO.java @@ -81,5 +81,10 @@ public class PipelineTaskDTO { * 指定接收人ID */ private Long receiverId; + + /** + * 用户选择的接单部门ID(当任务类型配置多个部门时使用) + */ + private Long selectedDeptId; } } diff --git a/backend/src/main/java/com/designhub/service/TaskService.java b/backend/src/main/java/com/designhub/service/TaskService.java index d55d5d1..2fbfa49 100644 --- a/backend/src/main/java/com/designhub/service/TaskService.java +++ b/backend/src/main/java/com/designhub/service/TaskService.java @@ -350,34 +350,42 @@ public class TaskService { // **步骤1:按接单部门自动分组** // 遍历任务类型列表,根据接单部门分组 int currentGroupNo = 1; - String lastAllowedDeptIds = null; + String lastDeptKey = null; for (int i = 0; i < dto.getItems().size(); i++) { com.designhub.dto.PipelineTaskDTO.TaskItemDTO itemDto = dto.getItems().get(i); var demandType = configService.getDemandTypeById(itemDto.getTaskTypeId()); - // 获取当前任务类型的接单部门配置(支持三级分类继承二级分类的配置) - String currentAllowedDeptIds = demandType.getAllowedDeptIds(); - if (currentAllowedDeptIds == null && demandType.getParentId() != null) { - // 如果当前类型没有配置,尝试获取父级的配置 - var parentType = configService.getDemandTypeById(demandType.getParentId()); - if (parentType != null) { - currentAllowedDeptIds = parentType.getAllowedDeptIds(); - log.info("三级分类 {} 继承父级 {} 的接单部门配置: {}", - demandType.getName(), parentType.getName(), currentAllowedDeptIds); + // 获取当前任务类型的接单部门配置 + String currentDeptKey; + + // 🔥 优先使用用户选择的接单部门 + if (itemDto.getSelectedDeptId() != null) { + currentDeptKey = String.valueOf(itemDto.getSelectedDeptId()); + log.info("任务类型 {} 使用用户选择的接单部门: {}", demandType.getName(), currentDeptKey); + } else { + // 否则使用任务类型配置的 allowedDeptIds(支持三级分类继承二级分类的配置) + currentDeptKey = demandType.getAllowedDeptIds(); + if (currentDeptKey == null && demandType.getParentId() != null) { + // 如果当前类型没有配置,尝试获取父级的配置 + var parentType = configService.getDemandTypeById(demandType.getParentId()); + if (parentType != null) { + currentDeptKey = parentType.getAllowedDeptIds(); + log.info("三级分类 {} 继承父级 {} 的接单部门配置: {}", + demandType.getName(), parentType.getName(), currentDeptKey); + } } } // 判断是否需要创建新分组 boolean needNewGroup = false; if (i > 0) { - // 如果当前或上一个的 allowed_dept_ids 为 null,则必须分组 - // 因为 null 表示所有部门可接单,无法确定具体接单部门 - if (currentAllowedDeptIds == null || lastAllowedDeptIds == null) { + // 如果当前或上一个的部门配置为 null,则必须分组 + if (currentDeptKey == null || lastDeptKey == null) { needNewGroup = true; } // 如果两者都不为 null,则比较是否相同 - else if (!currentAllowedDeptIds.equals(lastAllowedDeptIds)) { + else if (!currentDeptKey.equals(lastDeptKey)) { needNewGroup = true; } } @@ -385,12 +393,12 @@ public class TaskService { if (needNewGroup) { currentGroupNo++; log.info("检测到接单部门变化,创建新分组: groupNo={}, 前一部门={}, 当前部门={}", - currentGroupNo, lastAllowedDeptIds, currentAllowedDeptIds); + currentGroupNo, lastDeptKey, currentDeptKey); } // 记录当前分组号(临时存储在sortOrder字段,稍后会恢复) itemDto.setSortOrder(currentGroupNo * 1000 + i); // 高位存group_no,低位存原始顺序 - lastAllowedDeptIds = currentAllowedDeptIds; + lastDeptKey = currentDeptKey; } log.info("分组完成,共 {} 个子任务组", currentGroupNo); diff --git a/frontend/src/views/CreateTask.vue b/frontend/src/views/CreateTask.vue index 0c6d89c..0131291 100644 --- a/frontend/src/views/CreateTask.vue +++ b/frontend/src/views/CreateTask.vue @@ -106,6 +106,25 @@ /> + +