fix: 子部门继承父部门的接单权限
This commit is contained in:
parent
dfa8ae63cb
commit
70bf51d9fd
@ -205,11 +205,11 @@ public class TaskItemService {
|
|||||||
throw new BusinessException(ResultCode.FORBIDDEN, "部门负责人不能接单,请分配给设计师");
|
throw new BusinessException(ResultCode.FORBIDDEN, "部门负责人不能接单,请分配给设计师");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查4:验证部门是否允许接该任务类型(支持三级分类继承二级分类的配置)
|
// 检查4:验证部门是否允许接该任务类型(支持三级分类继承二级分类的配置,支持子部门继承父部门权限)
|
||||||
if (item.getTaskTypeId() != null) {
|
if (item.getTaskTypeId() != null) {
|
||||||
com.designhub.entity.DemandType demandType = configService.getDemandTypeById(item.getTaskTypeId());
|
com.designhub.entity.DemandType demandType = configService.getDemandTypeById(item.getTaskTypeId());
|
||||||
if (demandType != null) {
|
if (demandType != null) {
|
||||||
// 获取允许的部门ID(支持继承)
|
// 获取允许的部门ID(支持任务类型继承)
|
||||||
String allowedDeptIds = demandType.getAllowedDeptIds();
|
String allowedDeptIds = demandType.getAllowedDeptIds();
|
||||||
if ((allowedDeptIds == null || allowedDeptIds.isEmpty()) && demandType.getParentId() != null) {
|
if ((allowedDeptIds == null || allowedDeptIds.isEmpty()) && demandType.getParentId() != null) {
|
||||||
// 三级分类没有配置,尝试获取父级(二级分类)的配置
|
// 三级分类没有配置,尝试获取父级(二级分类)的配置
|
||||||
@ -220,17 +220,36 @@ public class TaskItemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (allowedDeptIds != null && !allowedDeptIds.isEmpty()) {
|
if (allowedDeptIds != null && !allowedDeptIds.isEmpty()) {
|
||||||
// 检查用户部门是否在允许列表中
|
// 检查用户部门或其父部门是否在允许列表中(子部门继承父部门权限)
|
||||||
String[] allowedIds = allowedDeptIds.split(",");
|
String[] allowedIds = allowedDeptIds.split(",");
|
||||||
boolean isAllowed = false;
|
Set<Long> allowedDeptIdSet = new HashSet<>();
|
||||||
for (String allowedId : allowedIds) {
|
for (String allowedId : allowedIds) {
|
||||||
if (allowedId.trim().equals(String.valueOf(user.getDeptId()))) {
|
try {
|
||||||
isAllowed = true;
|
allowedDeptIdSet.add(Long.parseLong(allowedId.trim()));
|
||||||
break;
|
} catch (NumberFormatException e) {
|
||||||
|
log.warn("解析允许部门ID失败: {}", allowedId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!isAllowed) {
|
// 获取用户部门及其所有父部门ID
|
||||||
throw new BusinessException(ResultCode.FORBIDDEN, "您的部门无权接收此类型的任务");
|
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, "您的部门无权接收此类型的任务");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user