code review add comment refect

This commit is contained in:
陈维伟 2023-09-14 17:57:44 +08:00
parent b219f788aa
commit e0501daf68
6 changed files with 71 additions and 76 deletions

View File

@ -79,6 +79,6 @@ public class SaveOrUpdateRoleVO {
* 项目部类型字典code * 项目部类型字典code
*/ */
@NotNull @NotNull
private Long workspaceTypeCode; private String workspaceTypeCode;
} }
} }

View File

@ -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) {

View File

@ -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, "角色分组信息错误");

View File

@ -35,7 +35,7 @@ public class SaasPgroupPermissionRelationServiceImpl implements SaasPgroupPermis
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()));
} }
} }
} }

View File

@ -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;
@ -23,7 +26,6 @@ import java.util.stream.Collectors;
@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)
@ -38,16 +40,8 @@ public class SaasPgroupRoleRelationServiceImpl implements SaasPgroupRoleRelation
if (CollectionUtils.isNotEmpty(prr)) { if (CollectionUtils.isNotEmpty(prr)) {
// 通用权限集已经 存在 // 通用权限集已经 存在
return; return;
}else {
throw new BizException(BaseCode.BAD_REQUEST,"传入的权限集id与已存在的通用权限集id不一致 req{}", JSONUtil.toJsonStr(commonRelation));
} }
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);
} }
} }

View File

@ -19,6 +19,7 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public class SaasRoleGroupRelationServiceImpl implements SaasRoleGroupRelationService { public class SaasRoleGroupRelationServiceImpl implements SaasRoleGroupRelationService {
private final SaasRoleGroupRelationDao saasRoleGroupRelationDao; private final SaasRoleGroupRelationDao saasRoleGroupRelationDao;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(List<SaasRoleGroupRelation> relations) { public void saveOrUpdate(List<SaasRoleGroupRelation> relations) {
@ -38,7 +39,7 @@ public class SaasRoleGroupRelationServiceImpl implements SaasRoleGroupRelationSe
saasRoleGroupRelationDao.saveBatch(insertList); saasRoleGroupRelationDao.saveBatch(insertList);
} }
if (CollectionUtils.isNotEmpty(deleteList)) { if (CollectionUtils.isNotEmpty(deleteList)) {
saasRoleGroupRelationDao.removeByIds(deleteList.stream().map(SaasRoleGroupRelation::getId).sorted().collect(Collectors.toList())); saasRoleGroupRelationDao.removeByIds(deleteList.stream().map(SaasRoleGroupRelation::getId).collect(Collectors.toList()));
} }
} }
} }