diff --git a/backend/src/main/java/com/designhub/service/TaskItemService.java b/backend/src/main/java/com/designhub/service/TaskItemService.java index 69f9f53..c224908 100644 --- a/backend/src/main/java/com/designhub/service/TaskItemService.java +++ b/backend/src/main/java/com/designhub/service/TaskItemService.java @@ -205,11 +205,11 @@ public class TaskItemService { throw new BusinessException(ResultCode.FORBIDDEN, "部门负责人不能接单,请分配给设计师"); } - // 检查4:验证部门是否允许接该任务类型(支持三级分类继承二级分类的配置) + // 检查4:验证部门是否允许接该任务类型(支持三级分类继承二级分类的配置,支持子部门继承父部门权限) if (item.getTaskTypeId() != null) { com.designhub.entity.DemandType demandType = configService.getDemandTypeById(item.getTaskTypeId()); if (demandType != null) { - // 获取允许的部门ID(支持继承) + // 获取允许的部门ID(支持任务类型继承) String allowedDeptIds = demandType.getAllowedDeptIds(); if ((allowedDeptIds == null || allowedDeptIds.isEmpty()) && demandType.getParentId() != null) { // 三级分类没有配置,尝试获取父级(二级分类)的配置 @@ -220,17 +220,36 @@ public class TaskItemService { } if (allowedDeptIds != null && !allowedDeptIds.isEmpty()) { - // 检查用户部门是否在允许列表中 + // 检查用户部门或其父部门是否在允许列表中(子部门继承父部门权限) String[] allowedIds = allowedDeptIds.split(","); - boolean isAllowed = false; - for (String allowedId : allowedIds) { - if (allowedId.trim().equals(String.valueOf(user.getDeptId()))) { - isAllowed = true; - break; + Set allowedDeptIdSet = new HashSet<>(); + for (String allowedId : allowedIds) { + try { + allowedDeptIdSet.add(Long.parseLong(allowedId.trim())); + } catch (NumberFormatException e) { + log.warn("解析允许部门ID失败: {}", allowedId); + } } - } - if (!isAllowed) { - throw new BusinessException(ResultCode.FORBIDDEN, "您的部门无权接收此类型的任务"); + + // 获取用户部门及其所有父部门ID + boolean isAllowed = false; + Long currentDeptId = user.getDeptId(); + while (currentDeptId != null) { + if (allowedDeptIdSet.contains(currentDeptId)) { + isAllowed = true; + break; + } + // 向上查找父部门 + com.designhub.entity.Department currentDept = departmentMapper.selectById(currentDeptId); + if (currentDept != null && currentDept.getParentId() != null) { + currentDeptId = currentDept.getParentId(); + } else { + break; + } + } + + if (!isAllowed) { + throw new BusinessException(ResultCode.FORBIDDEN, "您的部门无权接收此类型的任务"); } } }