code review add comment refect
This commit is contained in:
parent
b219f788aa
commit
e0501daf68
@ -79,6 +79,6 @@ public class SaveOrUpdateRoleVO {
|
||||
* 项目部类型字典code
|
||||
*/
|
||||
@NotNull
|
||||
private Long workspaceTypeCode;
|
||||
private String workspaceTypeCode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,10 +357,11 @@ public class PermissionGroupImpl implements PermissionGroupService {
|
||||
private void validSaasPermissionGroup(SaveOrUpdatePermissionGroupVO permissionGroup) {
|
||||
SaasRole saasRole = saasRoleDao.getById(permissionGroup.getRoleId());
|
||||
if (Objects.isNull(saasRole)) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "角色不存在");
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "权限集不存在");
|
||||
}
|
||||
if (Objects.nonNull(permissionGroup.getId())) {
|
||||
int relationCount = roleRelationDao.lambdaQuery().eq(SaasPgroupRoleRelation::getRoleId, permissionGroup.getRoleId())
|
||||
int relationCount = roleRelationDao.lambdaQuery()
|
||||
.eq(SaasPgroupRoleRelation::getRoleId, permissionGroup.getRoleId())
|
||||
.eq(SaasPgroupRoleRelation::getGroupId, permissionGroup.getId())
|
||||
.eq(SaasPgroupRoleRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).count();
|
||||
if (relationCount == 0) {
|
||||
|
||||
@ -225,7 +225,6 @@ public class RoleServiceImpl implements RoleService {
|
||||
saasRole.setDescription(saasRole.getDescription());
|
||||
saasRole.setRoleType(saveOrUpdateRole.getRoleType());
|
||||
saasRole.setWorkspaceId(saveOrUpdateRole.getWorkspaceId());
|
||||
// saasRole.setWorkspaceType(saveOrUpdateRole.getWorkspaceType());
|
||||
saasRole.setOwnerOuId(saveOrUpdateRole.getOwnerOuId());
|
||||
saasRole.setUpdateBy(saveOrUpdateRole.getOperatorId());
|
||||
saasRole.setUpdateAt(now);
|
||||
@ -241,10 +240,10 @@ public class RoleServiceImpl implements RoleService {
|
||||
}).collect(Collectors.toList()));
|
||||
saasPermissionGroupDao.saveOrUpdate(saasPermissionGroup);
|
||||
SaasPgroupRoleRelation pgrr = new SaasPgroupRoleRelation();
|
||||
pgrr.setCreateBy(saveOrUpdateRole.getOperatorId());
|
||||
pgrr.setRoleId(saasRole.getId());
|
||||
pgrr.setUpdateBy(saveOrUpdateRole.getOperatorId());
|
||||
pgrr.setGroupId(saasPermissionGroup.getId());
|
||||
pgrr.setCreateBy(saveOrUpdateRole.getOperatorId());
|
||||
pgrr.setUpdateBy(saveOrUpdateRole.getOperatorId());
|
||||
pgrr.setCreateAt(now);
|
||||
pgrr.setUpdateAt(now);
|
||||
// 新增或保存角色通用权限映射
|
||||
@ -306,7 +305,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
Map<Long, SaasRoleGroup> roleGroupMap = groups.stream().collect(Collectors.toMap(SaasRoleGroup::getId, Function.identity()));
|
||||
List<SaveOrUpdateRoleVO.GroupInfoVO> invalidRoleGroups = groupTrees.stream().filter(rg -> {
|
||||
SaasRoleGroup target = roleGroupMap.get(rg.getId());
|
||||
return Objects.isNull(target) || !Objects.equals(target.getWorkspaceTypeCode(), rg.getWorkspaceTypeCode().toString());
|
||||
return Objects.isNull(target) || !Objects.equals(target.getWorkspaceTypeCode(), rg.getWorkspaceTypeCode());
|
||||
}).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(invalidRoleGroups)) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "角色分组信息错误");
|
||||
|
||||
@ -18,24 +18,24 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SaasPgroupPermissionRelationServiceImpl implements SaasPgroupPermissionRelationService {
|
||||
private final SaasPgroupPermissionRelationDao saasPgroupPermissionRelationDao;
|
||||
private final SaasPgroupPermissionRelationDao saasPgroupPermissionRelationDao;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdate(List<SaasPgroupPermissionRelation> relations) {
|
||||
if (CollectionUtils.isNotEmpty(relations)) {
|
||||
return;
|
||||
}
|
||||
List<SaasPgroupPermissionRelation> exists = saasPgroupPermissionRelationDao.lambdaQuery()
|
||||
.in(SaasPgroupPermissionRelation::getGroupId, relations.stream().map(SaasPgroupPermissionRelation::getGroupId).distinct().sorted().collect(Collectors.toList()))
|
||||
.eq(SaasPgroupPermissionRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
Collection<SaasPgroupPermissionRelation> insertList = CollectionUtils.subtract(relations, exists);
|
||||
Collection<SaasPgroupPermissionRelation> deleteList = CollectionUtils.subtract(exists, relations);
|
||||
if (CollectionUtils.isNotEmpty(insertList)) {
|
||||
saasPgroupPermissionRelationDao.saveBatch(insertList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(deleteList)) {
|
||||
saasPgroupPermissionRelationDao.removeByIds(deleteList.stream().map(SaasPgroupPermissionRelation::getId).sorted().collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdate(List<SaasPgroupPermissionRelation> relations) {
|
||||
if (CollectionUtils.isNotEmpty(relations)) {
|
||||
return;
|
||||
}
|
||||
List<SaasPgroupPermissionRelation> exists = saasPgroupPermissionRelationDao.lambdaQuery()
|
||||
.in(SaasPgroupPermissionRelation::getGroupId, relations.stream().map(SaasPgroupPermissionRelation::getGroupId).distinct().sorted().collect(Collectors.toList()))
|
||||
.eq(SaasPgroupPermissionRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
Collection<SaasPgroupPermissionRelation> insertList = CollectionUtils.subtract(relations, exists);
|
||||
Collection<SaasPgroupPermissionRelation> deleteList = CollectionUtils.subtract(exists, relations);
|
||||
if (CollectionUtils.isNotEmpty(insertList)) {
|
||||
saasPgroupPermissionRelationDao.saveBatch(insertList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(deleteList)) {
|
||||
saasPgroupPermissionRelationDao.removeByIds(deleteList.stream().map(SaasPgroupPermissionRelation::getId).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
package cn.axzo.tyr.server.service.impl;
|
||||
|
||||
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
|
||||
import cn.axzo.framework.domain.web.BizException;
|
||||
import cn.axzo.framework.domain.web.code.BaseCode;
|
||||
import cn.axzo.tyr.client.model.enums.PermissionGroupType;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPermissionGroup;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPgroupRoleRelation;
|
||||
import cn.axzo.tyr.server.repository.dao.SaasPermissionGroupDao;
|
||||
import cn.axzo.tyr.server.repository.dao.SaasPgroupRoleRelationDao;
|
||||
import cn.axzo.tyr.server.service.SaasPgroupRoleRelationService;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
@ -22,32 +25,23 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SaasPgroupRoleRelationServiceImpl implements SaasPgroupRoleRelationService {
|
||||
private final SaasPgroupRoleRelationDao saasPgroupRoleRelationDao;
|
||||
private final SaasPermissionGroupDao saasPermissionGroupDao;
|
||||
private final SaasPgroupRoleRelationDao saasPgroupRoleRelationDao;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdateCommon(SaasPgroupRoleRelation commonRelation) {
|
||||
List<SaasPgroupRoleRelation> relations = saasPgroupRoleRelationDao.lambdaQuery().eq(SaasPgroupRoleRelation::getRoleId, commonRelation.getRoleId())
|
||||
.eq(SaasPgroupRoleRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
if (CollectionUtils.isEmpty(relations)) {
|
||||
saasPgroupRoleRelationDao.save(commonRelation);
|
||||
return;
|
||||
}
|
||||
List<SaasPgroupRoleRelation> prr = relations.stream().filter(e -> Objects.equals(commonRelation.getGroupId(), e.getGroupId())).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(prr)) {
|
||||
// 通用权限集已经 存在
|
||||
return;
|
||||
}
|
||||
List<Long> permissionGroupIds = relations.stream().map(SaasPgroupRoleRelation::getGroupId).sorted().collect(Collectors.toList());
|
||||
List<SaasPermissionGroup> commonGroups = saasPermissionGroupDao.lambdaQuery().in(SaasPermissionGroup::getId, permissionGroupIds)
|
||||
.eq(SaasPermissionGroup::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.eq(SaasPermissionGroup::getIsCommon, PermissionGroupType.COMMON.getCode()).list();
|
||||
if (CollectionUtils.isNotEmpty(commonGroups)) {
|
||||
Set<Long> commonGroupIds = commonGroups.stream().map(SaasPermissionGroup::getId).collect(Collectors.toSet());
|
||||
// 移除以前的通用权限集
|
||||
saasPgroupRoleRelationDao.removeByIds(relations.stream().filter(e -> commonGroupIds.contains(e.getGroupId())).collect(Collectors.toList()));
|
||||
}
|
||||
saasPgroupRoleRelationDao.save(commonRelation);
|
||||
}
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdateCommon(SaasPgroupRoleRelation commonRelation) {
|
||||
List<SaasPgroupRoleRelation> relations = saasPgroupRoleRelationDao.lambdaQuery().eq(SaasPgroupRoleRelation::getRoleId, commonRelation.getRoleId())
|
||||
.eq(SaasPgroupRoleRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
if (CollectionUtils.isEmpty(relations)) {
|
||||
saasPgroupRoleRelationDao.save(commonRelation);
|
||||
return;
|
||||
}
|
||||
List<SaasPgroupRoleRelation> prr = relations.stream().filter(e -> Objects.equals(commonRelation.getGroupId(), e.getGroupId())).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(prr)) {
|
||||
// 通用权限集已经 存在
|
||||
return;
|
||||
}else {
|
||||
throw new BizException(BaseCode.BAD_REQUEST,"传入的权限集id与已存在的通用权限集id不一致 req{}", JSONUtil.toJsonStr(commonRelation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,27 +18,28 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SaasRoleGroupRelationServiceImpl implements SaasRoleGroupRelationService {
|
||||
private final SaasRoleGroupRelationDao saasRoleGroupRelationDao;
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdate(List<SaasRoleGroupRelation> relations) {
|
||||
if (CollectionUtils.isEmpty(relations)) {
|
||||
return;
|
||||
}
|
||||
List<SaasRoleGroupRelation> exists = saasRoleGroupRelationDao.lambdaQuery()
|
||||
.in(SaasRoleGroupRelation::getRoleId, relations.stream().map(SaasRoleGroupRelation::getRoleId).distinct().sorted().collect(Collectors.toList()))
|
||||
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
if (CollectionUtils.isEmpty(exists)) {
|
||||
saasRoleGroupRelationDao.saveBatch(relations);
|
||||
return;
|
||||
}
|
||||
Collection<SaasRoleGroupRelation> insertList = CollectionUtils.subtract(relations, exists);
|
||||
Collection<SaasRoleGroupRelation> deleteList = CollectionUtils.subtract(exists, relations);
|
||||
if (CollectionUtils.isNotEmpty(insertList)) {
|
||||
saasRoleGroupRelationDao.saveBatch(insertList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(deleteList)) {
|
||||
saasRoleGroupRelationDao.removeByIds(deleteList.stream().map(SaasRoleGroupRelation::getId).sorted().collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
private final SaasRoleGroupRelationDao saasRoleGroupRelationDao;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdate(List<SaasRoleGroupRelation> relations) {
|
||||
if (CollectionUtils.isEmpty(relations)) {
|
||||
return;
|
||||
}
|
||||
List<SaasRoleGroupRelation> exists = saasRoleGroupRelationDao.lambdaQuery()
|
||||
.in(SaasRoleGroupRelation::getRoleId, relations.stream().map(SaasRoleGroupRelation::getRoleId).distinct().sorted().collect(Collectors.toList()))
|
||||
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
if (CollectionUtils.isEmpty(exists)) {
|
||||
saasRoleGroupRelationDao.saveBatch(relations);
|
||||
return;
|
||||
}
|
||||
Collection<SaasRoleGroupRelation> insertList = CollectionUtils.subtract(relations, exists);
|
||||
Collection<SaasRoleGroupRelation> deleteList = CollectionUtils.subtract(exists, relations);
|
||||
if (CollectionUtils.isNotEmpty(insertList)) {
|
||||
saasRoleGroupRelationDao.saveBatch(insertList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(deleteList)) {
|
||||
saasRoleGroupRelationDao.removeByIds(deleteList.stream().map(SaasRoleGroupRelation::getId).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user