fix(task): allow dept-redirected item grabbing by target dept

This commit is contained in:
Your Name 2026-02-08 11:47:53 +08:00
parent f484e17e73
commit 1f4e312339

View File

@ -272,6 +272,28 @@ public class TaskItemService {
}
}
/**
* 判断用户部门是否属于目标部门(含目标部门的子部门)
*/
private boolean isDeptMatchedOrInherited(Long userDeptId, Long targetDeptId) {
if (userDeptId == null || targetDeptId == null) {
return false;
}
Long currentDeptId = userDeptId;
while (currentDeptId != null) {
if (targetDeptId.equals(currentDeptId)) {
return true;
}
com.designhub.entity.Department currentDept = departmentMapper.selectById(currentDeptId);
if (currentDept == null || currentDept.getParentId() == null
|| currentDeptId.equals(currentDept.getParentId())) {
break;
}
currentDeptId = currentDept.getParentId();
}
return false;
}
/**
* 获取进行中的子任务列表
* @param receiverId 接单人ID,null表示不按接单人过滤
@ -424,8 +446,14 @@ public class TaskItemService {
throw new BusinessException(ResultCode.FORBIDDEN, "部门负责人不能接单,请分配给设计师");
}
// 检查4:如果子任务已指定接单部门,则仅允许该部门(含子部门)成员接单
if (item.getReceiverDeptId() != null
&& !isDeptMatchedOrInherited(user.getDeptId(), item.getReceiverDeptId())) {
throw new BusinessException(ResultCode.FORBIDDEN, "该任务仅允许指定接单部门成员接单");
}
// 检查4:验证部门是否允许接该任务类型(支持三级分类继承二级分类的配置,支持子部门继承父部门权限)
if (item.getTaskTypeId() != null) {
if (item.getReceiverDeptId() == null && item.getTaskTypeId() != null) {
com.designhub.entity.DemandType demandType = configService.getDemandTypeById(item.getTaskTypeId());
if (demandType != null) {
// 获取允许的部门ID(支持任务类型继承)