feat: REQ-1650 角色名称校验
This commit is contained in:
parent
5d8db627d0
commit
1e5991c88a
@ -38,9 +38,12 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.codehaus.groovy.runtime.DefaultGroovyMethods.collect;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*
|
||||
@ -262,19 +265,52 @@ public class RoleServiceImpl implements RoleService {
|
||||
}
|
||||
|
||||
private void validRoleName(SaveOrUpdateRoleVO saveOrUpdateRole) {
|
||||
List<SaveOrUpdateRoleVO.GroupInfoVO> groupTrees = saveOrUpdateRole.getGroupTree();
|
||||
if (CollectionUtil.isEmpty(groupTrees)) {
|
||||
return;
|
||||
}
|
||||
String currentWorkspaceCode = groupTrees.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());
|
||||
if (CollectionUtil.isEmpty(roleGroupIds)) {
|
||||
return;
|
||||
}
|
||||
List<SaasRoleGroupRelation> roleGroupRelations = roleGroupRelationDao.lambdaQuery()
|
||||
.in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroupIds)
|
||||
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
if (CollectionUtil.isNotEmpty(roleGroupRelations)) {
|
||||
List<Long> saasRoleIds = roleGroupRelations.stream().map(SaasRoleGroupRelation::getRoleId).collect(Collectors.toList());
|
||||
//确保这些角色id 都是正常使用的
|
||||
List<SaasRole> roles = saasRoleDao.lambdaQuery()
|
||||
.eq(SaasRole::getWorkspaceId, saveOrUpdateRole.getWorkspaceId())
|
||||
.eq(SaasRole::getId, saasRoleIds)
|
||||
.eq(SaasRole::getName, saveOrUpdateRole.getName())
|
||||
.eq(SaasRole::getOwnerOuId, saveOrUpdateRole.getOwnerOuId())
|
||||
.eq(SaasRole::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
if (CollectionUtils.isNotEmpty(roles)) {
|
||||
Optional<SaasRole> repeatGroupName = roles.stream()
|
||||
.filter(g -> !Objects.equals(g.getId(), saveOrUpdateRole.getId()) && StringUtils.equalsIgnoreCase(g.getName(), saveOrUpdateRole.getName())).findFirst();
|
||||
if (repeatGroupName.isPresent()) {
|
||||
throw new ServiceException("同一个单位、同一工作台类型内,角色名称不能重复!");
|
||||
if (CollectionUtil.isNotEmpty(roles)) {
|
||||
//新增角色 判断角色名称重复
|
||||
if (Objects.isNull(saveOrUpdateRole.getId())) {
|
||||
throw new ServiceException("同一企业单位、同一工作台类型,角色名称不能重复!");
|
||||
} else {
|
||||
//如果是更新角色,必须是当前角色
|
||||
if (!(roles.size() == 1 && (roles.get(0).getId().equals(saveOrUpdateRole.getId())))) {
|
||||
throw new ServiceException("同一企业单位、同一工作台类型,角色名称不能重复!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Optional<SaasRole> repeatGroupName = roles.stream()
|
||||
// .filter(g -> !Objects.equals(g.getId(), saveOrUpdateRole.getId()) && StringUtils.equalsIgnoreCase(g.getName(), saveOrUpdateRole.getName())).findFirst();
|
||||
// if (repeatGroupName.isPresent()) {
|
||||
// throw new ServiceException("同一个单位、同一工作台类型内,角色名称不能重复!");
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IsSuperAdminRes> isSuperAdmin(List<QueryByIdentityIdTypeReq> req) {
|
||||
List<IsSuperAdminRes> result = new ArrayList<>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user