feat: 管理员可以抢单,拥有完整权限

- 管理员可以抢单主任务(绕过部门类型、部门负责人限制)
- 管理员可以抢单子任务(绕过所有限制)
- 管理员拥有:发起任务、审核任务、指定任务、抢单、交付等完整权限
This commit is contained in:
Your Name 2026-01-04 08:39:52 +08:00
parent 07ce2e5613
commit d6c81f1fdc
2 changed files with 81 additions and 64 deletions

View File

@ -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);
}
// 验证状态

View File

@ -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();