From d6c81f1fdc3b8479766d005d470c7d1e16bade81 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 4 Jan 2026 08:39:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=AE=A1=E7=90=86=E5=91=98=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=8A=A2=E5=8D=95=EF=BC=8C=E6=8B=A5=E6=9C=89=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 管理员可以抢单主任务(绕过部门类型、部门负责人限制) - 管理员可以抢单子任务(绕过所有限制) - 管理员拥有:发起任务、审核任务、指定任务、抢单、交付等完整权限 --- .../designhub/service/TaskItemService.java | 82 ++++++++++--------- .../com/designhub/service/TaskService.java | 63 ++++++++------ 2 files changed, 81 insertions(+), 64 deletions(-) diff --git a/backend/src/main/java/com/designhub/service/TaskItemService.java b/backend/src/main/java/com/designhub/service/TaskItemService.java index 518d1d9..d0eb888 100644 --- a/backend/src/main/java/com/designhub/service/TaskItemService.java +++ b/backend/src/main/java/com/designhub/service/TaskItemService.java @@ -112,48 +112,56 @@ public class TaskItemService { throw new BusinessException(ResultCode.NOT_FOUND, "子任务不存在"); } - // 验证用户部门权限 - if (user.getDeptId() == null) { - throw new BusinessException(ResultCode.FORBIDDEN, "您未分配部门,无法接单"); - } + // 检查是否是管理员(管理员可以抢单,绕过所有限制) + boolean isAdmin = user.getIsAdmin() != null && user.getIsAdmin() == 1; - com.designhub.entity.Department department = departmentMapper.selectById(user.getDeptId()); - if (department == null) { - throw new BusinessException(ResultCode.FORBIDDEN, "未找到用户所属部门,请联系管理员"); - } - - // 检查1:需求部门不能抢单 - if ("demand".equals(department.getDeptType())) { - throw new BusinessException(ResultCode.FORBIDDEN, "需求部门成员不能接单,只能发起需求"); - } - - // 检查2:接单部门类型验证 - if (!"receiving".equals(department.getDeptType())) { - throw new BusinessException(ResultCode.FORBIDDEN, "只有接单部门成员可以接收任务"); - } - - // 检查3:部门负责人不能抢单 - if (department.getLeaderId() != null && department.getLeaderId().equals(userId)) { - throw new BusinessException(ResultCode.FORBIDDEN, "部门负责人不能接单,请分配给设计师"); - } + // 非管理员需要进行权限验证 + if (!isAdmin) { + // 验证用户部门权限 + if (user.getDeptId() == null) { + throw new BusinessException(ResultCode.FORBIDDEN, "您未分配部门,无法接单"); + } + + com.designhub.entity.Department department = departmentMapper.selectById(user.getDeptId()); + if (department == null) { + throw new BusinessException(ResultCode.FORBIDDEN, "未找到用户所属部门,请联系管理员"); + } + + // 检查1:需求部门不能抢单 + if ("demand".equals(department.getDeptType())) { + throw new BusinessException(ResultCode.FORBIDDEN, "需求部门成员不能接单,只能发起需求"); + } + + // 检查2:接单部门类型验证 + if (!"receiving".equals(department.getDeptType())) { + throw new BusinessException(ResultCode.FORBIDDEN, "只有接单部门成员可以接收任务"); + } + + // 检查3:部门负责人不能抢单 + if (department.getLeaderId() != null && department.getLeaderId().equals(userId)) { + throw new BusinessException(ResultCode.FORBIDDEN, "部门负责人不能接单,请分配给设计师"); + } - // 检查4:验证部门是否允许接该任务类型 - if (item.getTaskTypeId() != null) { - com.designhub.entity.DemandType demandType = configService.getDemandTypeById(item.getTaskTypeId()); - if (demandType != null && demandType.getAllowedDeptIds() != null && !demandType.getAllowedDeptIds().isEmpty()) { - // 检查用户部门是否在允许列表中 - String[] allowedIds = demandType.getAllowedDeptIds().split(","); - boolean isAllowed = false; - for (String allowedId : allowedIds) { - if (allowedId.trim().equals(String.valueOf(user.getDeptId()))) { - isAllowed = true; - break; + // 检查4:验证部门是否允许接该任务类型 + if (item.getTaskTypeId() != null) { + com.designhub.entity.DemandType demandType = configService.getDemandTypeById(item.getTaskTypeId()); + if (demandType != null && demandType.getAllowedDeptIds() != null && !demandType.getAllowedDeptIds().isEmpty()) { + // 检查用户部门是否在允许列表中 + String[] allowedIds = demandType.getAllowedDeptIds().split(","); + boolean isAllowed = false; + for (String allowedId : allowedIds) { + if (allowedId.trim().equals(String.valueOf(user.getDeptId()))) { + isAllowed = true; + break; + } + } + if (!isAllowed) { + throw new BusinessException(ResultCode.FORBIDDEN, "您的部门无权接收此类型的任务"); } } - if (!isAllowed) { - throw new BusinessException(ResultCode.FORBIDDEN, "您的部门无权接收此类型的任务"); - } } + } else { + log.info("管理员 {} 抢单子任务 {}", user.getRealName(), itemId); } // 验证状态 diff --git a/backend/src/main/java/com/designhub/service/TaskService.java b/backend/src/main/java/com/designhub/service/TaskService.java index 8a2cd17..2292872 100644 --- a/backend/src/main/java/com/designhub/service/TaskService.java +++ b/backend/src/main/java/com/designhub/service/TaskService.java @@ -753,35 +753,44 @@ public class TaskService { throw new BusinessException(ResultCode.FORBIDDEN, "用户不存在"); } + // 检查是否是管理员(管理员可以抢单,绕过所有限制) + boolean isAdmin = isAdminUser(userId); + Long deptId = user.getDeptId(); - if (deptId == null) { - throw new BusinessException(ResultCode.FORBIDDEN, "您未分配部门,无法接单"); - } - // 获取用户所属部门 - Department department = departmentService.getDepartmentById(deptId); - if (department == null) { - throw new BusinessException(ResultCode.FORBIDDEN, "未找到用户所属部门,请联系管理员"); - } - - // 检查1:需求部门不能抢单 - if ("demand".equals(department.getDeptType())) { - throw new BusinessException(ResultCode.FORBIDDEN, "需求部门成员不能接单,只能发起需求"); - } - - // 检查2:接单部门类型验证 - if (!"receiving".equals(department.getDeptType())) { - throw new BusinessException(ResultCode.FORBIDDEN, "只有接单部门成员可以接收任务"); - } - - // 检查3:部门负责人不能抢单 - if (department.getLeaderId() != null && department.getLeaderId().equals(userId)) { - throw new BusinessException(ResultCode.FORBIDDEN, "部门负责人不能接单,请分配给设计师"); - } - - // 检查4:验证部门是否允许接该需求类型 - if (task.getDemandTypeId() != null) { - validateAllowedDemandTypes(department, task.getDemandTypeId()); + // 非管理员需要进行权限验证 + if (!isAdmin) { + if (deptId == null) { + throw new BusinessException(ResultCode.FORBIDDEN, "您未分配部门,无法接单"); + } + + // 获取用户所属部门 + Department department = departmentService.getDepartmentById(deptId); + if (department == null) { + throw new BusinessException(ResultCode.FORBIDDEN, "未找到用户所属部门,请联系管理员"); + } + + // 检查1:需求部门不能抢单 + if ("demand".equals(department.getDeptType())) { + throw new BusinessException(ResultCode.FORBIDDEN, "需求部门成员不能接单,只能发起需求"); + } + + // 检查2:接单部门类型验证 + if (!"receiving".equals(department.getDeptType())) { + throw new BusinessException(ResultCode.FORBIDDEN, "只有接单部门成员可以接收任务"); + } + + // 检查3:部门负责人不能抢单 + if (department.getLeaderId() != null && department.getLeaderId().equals(userId)) { + throw new BusinessException(ResultCode.FORBIDDEN, "部门负责人不能接单,请分配给设计师"); + } + + // 检查4:验证部门是否允许接该需求类型 + if (task.getDemandTypeId() != null) { + validateAllowedDemandTypes(department, task.getDemandTypeId()); + } + } else { + log.info("管理员 {} 抢单任务 {}", user.getRealName(), taskId); } LocalDateTime now = LocalDateTime.now();