feat: REQ-1650 角色名称校验

This commit is contained in:
zuoqinbo 2023-12-06 17:39:40 +08:00
parent 1e5991c88a
commit 0037e2e8e8

View File

@ -223,7 +223,7 @@ public class RoleServiceImpl implements RoleService {
List<SaveOrUpdateRoleVO.GroupInfoVO> groupTrees = saveOrUpdateRole.getGroupTree(); List<SaveOrUpdateRoleVO.GroupInfoVO> groupTrees = saveOrUpdateRole.getGroupTree();
// 验证角色分组信息 // 验证角色分组信息
validRoleGroup(groupTrees); validRoleGroup(groupTrees);
validRoleName(saveOrUpdateRole); //validRoleName(saveOrUpdateRole);
SaasRole saasRole = validAndBuildRole(saveOrUpdateRole, now); SaasRole saasRole = validAndBuildRole(saveOrUpdateRole, now);
//验证权限集信息 //验证权限集信息
SaasPermissionGroup saasPermissionGroup = validPermissionGroupCommon(saveOrUpdateRole); SaasPermissionGroup saasPermissionGroup = validPermissionGroupCommon(saveOrUpdateRole);
@ -369,9 +369,17 @@ public class RoleServiceImpl implements RoleService {
saasRole.setUpdateBy(saveOrUpdateRole.getOperatorId()); saasRole.setUpdateBy(saveOrUpdateRole.getOperatorId());
saasRole.setUpdateAt(now); saasRole.setUpdateAt(now);
// 不可能为空 // 不可能为空
List<Long> groupIds = saveOrUpdateRole.getGroupTree().stream().map(SaveOrUpdateRoleVO.GroupInfoVO::getId).sorted().collect(Collectors.toList()); //List<Long> groupIds = saveOrUpdateRole.getGroupTree().stream().map(SaveOrUpdateRoleVO.GroupInfoVO::getId).sorted().collect(Collectors.toList());
//同分组内角色名称不能重复 //TODO // 同一个企业单位 同一个工作台 角色名称不能为空
List<SaasRoleGroupRelation> relations = roleGroupRelationDao.lambdaQuery().in(SaasRoleGroupRelation::getSaasRoleGroupId, groupIds) String currentWorkspaceCode = saveOrUpdateRole.getGroupTree().get(0).getWorkspaceTypeCode();
List<SaasRoleGroup> roleGroups = saasRoleGroupDao.lambdaQuery()
.in(SaasRoleGroup::getWorkspaceTypeCode, currentWorkspaceCode)
.eq(SaasRoleGroup::getWorkspaceId, saveOrUpdateRole.getWorkspaceId())
.eq(SaasRoleGroup::getOuId, saveOrUpdateRole.getOwnerOuId())
.eq(SaasRoleGroup::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
List<Long> roleGroupIds = roleGroups.stream().map(SaasRoleGroup::getId).collect(Collectors.toList());
//同分组内角色名称不能重复 --->> 同一个企业单位 同一个工作台 角色名称不能为空 by zuoqinbo
List<SaasRoleGroupRelation> relations = roleGroupRelationDao.lambdaQuery().in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroupIds)
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list(); .eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
if (CollectionUtils.isNotEmpty(relations)) { if (CollectionUtils.isNotEmpty(relations)) {
@ -384,7 +392,7 @@ public class RoleServiceImpl implements RoleService {
.filter(e -> Objects.nonNull(e) && !Objects.equals(e.getId(), saveOrUpdateRole.getId()) && StringUtils.equalsIgnoreCase(e.getName(), saasRole.getName())) .filter(e -> Objects.nonNull(e) && !Objects.equals(e.getId(), saveOrUpdateRole.getId()) && StringUtils.equalsIgnoreCase(e.getName(), saasRole.getName()))
.findFirst(); .findFirst();
if (repeatNameRole.isPresent()) { if (repeatNameRole.isPresent()) {
throw new ServiceException("分组内角色名称不能重复"); throw new ServiceException("一个企业单位,同一个工作台,角色名称不能重复!!");
} }
}); });
} }