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