角色新增或保存
This commit is contained in:
parent
5a49466f0d
commit
e666e5c2bc
@ -5,6 +5,7 @@ import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
|
||||
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
|
||||
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -26,7 +27,7 @@ public interface TyrSaasRoleApi {
|
||||
* 如果权限列表不为空则创建通用权限
|
||||
*/
|
||||
@PostMapping("/api/saasRole/saveOrUpdate")
|
||||
ApiResult saveOrUpdate(@RequestBody SaasRoleVO req);
|
||||
ApiResult<Long> saveOrUpdate(@RequestBody SaveOrUpdateRoleVO saveOrUpdateRole);
|
||||
|
||||
/**
|
||||
* 根据id查询详情
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
package cn.axzo.tyr.client.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SaveOrUpdateRoleVO {
|
||||
|
||||
/**
|
||||
* 角色id(编辑时有效)
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
@NotBlank(message = "角色名称不能为空")
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 角色类型:init 业务角色 admin管理员 common 自定义
|
||||
*/
|
||||
@NotBlank(message = "角色类型不能为空")
|
||||
private String roleType;
|
||||
|
||||
private Long workspaceId;
|
||||
|
||||
private Integer workspaceType;
|
||||
|
||||
private Long ownerOuId;
|
||||
|
||||
private Long operatorId;
|
||||
|
||||
private String operatorName;
|
||||
/**
|
||||
* 角色分组
|
||||
*/
|
||||
@NotEmpty
|
||||
@Valid
|
||||
private List<GroupInfoVO> groupTree;
|
||||
|
||||
/**
|
||||
* 通用权限集id(编辑时有效)
|
||||
*/
|
||||
private Long permissionGroupId;
|
||||
|
||||
private String permissionGroupName;
|
||||
|
||||
private String permissionGroupDescription;
|
||||
|
||||
/**
|
||||
* 权限集类型:feature data
|
||||
*/
|
||||
private String permissionGroupType;
|
||||
|
||||
/**
|
||||
* 选中的权限点id
|
||||
*/
|
||||
@NotNull
|
||||
private List<Long> selectedPPIds;
|
||||
|
||||
@Data
|
||||
public static class GroupInfoVO {
|
||||
|
||||
/**
|
||||
* 角色分组id
|
||||
*/
|
||||
@NotNull
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 项目部类型字典code
|
||||
*/
|
||||
@NotNull
|
||||
private Long workspaceTypeCode;
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,7 @@ import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
|
||||
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
|
||||
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
|
||||
import cn.axzo.tyr.server.service.RoleService;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -34,8 +35,8 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
RoleService roleService;
|
||||
|
||||
@Override
|
||||
public ApiResult saveOrUpdate(SaasRoleVO req) {
|
||||
return null;
|
||||
public ApiResult<Long> saveOrUpdate(SaveOrUpdateRoleVO saveOrUpdateRole) {
|
||||
return ApiResult.ok(roleService.saveOrUpdate(saveOrUpdateRole));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -8,6 +8,7 @@ import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 权限集功能中间表(SaasPgroupPermissionRelation)表实体类
|
||||
@ -52,5 +53,14 @@ public class SaasPgroupPermissionRelation extends BaseEntity<SaasPgroupPermissio
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
SaasPgroupPermissionRelation that = (SaasPgroupPermissionRelation) o;
|
||||
return Objects.equals(groupId, that.groupId) && Objects.equals(featureId, that.featureId) && Objects.equals(isDelete, that.isDelete);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 角色分组关联表
|
||||
@ -44,5 +45,14 @@ public class SaasRoleGroupRelation extends BaseEntity<SaasRoleGroupRelation> imp
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
SaasRoleGroupRelation that = (SaasRoleGroupRelation) o;
|
||||
return Objects.equals(roleId, that.roleId) && Objects.equals(saasRoleGroupId, that.saasRoleGroupId) && Objects.equals(isDelete, that.isDelete);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,13 +3,14 @@ package cn.axzo.tyr.server.repository.service;
|
||||
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
|
||||
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPgroupPermissionRelation;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasRole;
|
||||
import cn.axzo.tyr.server.repository.mapper.SaasPgroupPermissionRelationMapper;
|
||||
import cn.axzo.tyr.server.repository.mapper.SaasRoleMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@ -27,5 +28,15 @@ public class SaasPgroupPermissionRelationDao extends ServiceImpl<SaasPgroupPermi
|
||||
.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeByIds(Collection<? extends Serializable> idList) {
|
||||
if (CollectionUtils.isEmpty(idList)) {
|
||||
return false;
|
||||
}
|
||||
return lambdaUpdate()
|
||||
.in(SaasPgroupPermissionRelation::getId,idList)
|
||||
.set(BaseEntity::getIsDelete, TableIsDeleteEnum.DELETE.value)
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,13 +2,14 @@ package cn.axzo.tyr.server.repository.service;
|
||||
|
||||
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
|
||||
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPermissionGroup;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPgroupRoleRelation;
|
||||
import cn.axzo.tyr.server.repository.mapper.SaasPermissionGroupMapper;
|
||||
import cn.axzo.tyr.server.repository.mapper.SaasPgroupRoleRelationMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@ -21,5 +22,15 @@ public class SaasPgroupRoleRelationDao extends ServiceImpl<SaasPgroupRoleRelatio
|
||||
.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeByIds(Collection<? extends Serializable> idList) {
|
||||
if (CollectionUtils.isEmpty(idList)) {
|
||||
return false;
|
||||
}
|
||||
return lambdaUpdate()
|
||||
.in(SaasPgroupRoleRelation::getId,idList)
|
||||
.set(BaseEntity::getIsDelete, TableIsDeleteEnum.DELETE.value)
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,18 +1,28 @@
|
||||
package cn.axzo.tyr.server.repository.service;
|
||||
|
||||
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
|
||||
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasRole;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasRoleGroup;
|
||||
import cn.axzo.tyr.server.repository.mapper.SaasRoleGroupMapper;
|
||||
import cn.axzo.tyr.server.repository.mapper.SaasRoleMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class SaasRoleDao extends ServiceImpl<SaasRoleMapper, SaasRole> {
|
||||
|
||||
@Override
|
||||
public SaasRole getById(Serializable id) {
|
||||
List<SaasRole> roles = lambdaQuery().eq(SaasRole::getId, id).eq(SaasRole::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
if (CollectionUtils.isEmpty(roles)) {
|
||||
return null;
|
||||
}
|
||||
return roles.get(0);
|
||||
}
|
||||
|
||||
public void delete(List<Long> id) {
|
||||
lambdaUpdate()
|
||||
.in(BaseEntity::getId,id)
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
|
||||
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
|
||||
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -23,4 +24,6 @@ public interface RoleService {
|
||||
List<SaasRoleVO> query(QuerySaasRoleReq req);
|
||||
|
||||
List<QueryBatchByIdentityIdTypeRes> queryBatchByIdentityIdType(List<QueryByIdentityIdTypeReq> req);
|
||||
|
||||
Long saveOrUpdate(SaveOrUpdateRoleVO saveOrUpdateRole);
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
package cn.axzo.tyr.server.service;
|
||||
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPgroupPermissionRelation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SaasPgroupPermissionRelationService {
|
||||
void saveOrUpdate(List<SaasPgroupPermissionRelation> relations);
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package cn.axzo.tyr.server.service;
|
||||
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPgroupRoleRelation;
|
||||
|
||||
public interface SaasPgroupRoleRelationService {
|
||||
/**
|
||||
* 处理通用权限集
|
||||
* @param commonRelation
|
||||
*/
|
||||
void saveOrUpdateCommon(SaasPgroupRoleRelation commonRelation);
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package cn.axzo.tyr.server.service;
|
||||
|
||||
import cn.axzo.tyr.server.repository.entity.SaasRoleGroupRelation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SaasRoleGroupRelationService {
|
||||
void saveOrUpdate(List<SaasRoleGroupRelation> relations);
|
||||
}
|
||||
@ -1,7 +1,10 @@
|
||||
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.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import cn.axzo.tyr.client.model.enums.PermissionGroupType;
|
||||
import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasPermissionGroupReq;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
|
||||
@ -9,10 +12,10 @@ import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
|
||||
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
|
||||
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
|
||||
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
|
||||
import cn.axzo.tyr.server.repository.entity.*;
|
||||
import cn.axzo.tyr.server.repository.service.*;
|
||||
import cn.axzo.tyr.server.service.PermissionGroupService;
|
||||
import cn.axzo.tyr.server.service.RoleService;
|
||||
import cn.axzo.tyr.server.service.*;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -20,8 +23,10 @@ import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -48,6 +53,16 @@ public class RoleServiceImpl implements RoleService {
|
||||
SaasRoleGroupDao saasRoleGroupDao;
|
||||
@Autowired
|
||||
SaasRoleGroupRelationDao roleGroupRelationDao;
|
||||
@Autowired
|
||||
SaasPermissionGroupDao saasPermissionGroupDao;
|
||||
@Autowired
|
||||
SaasRoleGroupRelationService saasRoleGroupRelationService;
|
||||
@Autowired
|
||||
SaasFeatureDao saasFeatureDao;
|
||||
@Autowired
|
||||
SaasPgroupRoleRelationService saasPgroupRoleRelationService;
|
||||
@Autowired
|
||||
SaasPgroupPermissionRelationService saasPgroupPermissionRelationService;
|
||||
|
||||
@Override
|
||||
public List<SaasRoleVO> queryByIdentityIdType(Long identityId, Integer identityType, Long workspaceId, Long ouId) {
|
||||
@ -176,6 +191,131 @@ public class RoleServiceImpl implements RoleService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long saveOrUpdate(SaveOrUpdateRoleVO saveOrUpdateRole) {
|
||||
// 新增OR修改角色
|
||||
SaasRole saasRole;
|
||||
Date now = new Date();
|
||||
boolean save = Objects.isNull(saveOrUpdateRole.getId());
|
||||
if (!save) {
|
||||
saasRole = saasRoleDao.getById(saveOrUpdateRole.getId());
|
||||
if (Objects.isNull(saasRole)) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "角色不存在");
|
||||
}
|
||||
} else {
|
||||
saasRole = new SaasRole();
|
||||
saasRole.setCreateBy(saveOrUpdateRole.getOperatorId());
|
||||
saasRole.setCreateAt(now);
|
||||
}
|
||||
List<SaveOrUpdateRoleVO.GroupInfoVO> groupTrees = saveOrUpdateRole.getGroupTree();
|
||||
// 验证角色分组信息
|
||||
validRoleGroup(groupTrees);
|
||||
//验证权限集信息
|
||||
SaasPermissionGroup saasPermissionGroup = validPermissionGroupCommon(saveOrUpdateRole);
|
||||
validFeature(saveOrUpdateRole.getSelectedPPIds());
|
||||
saasRole.setId(saveOrUpdateRole.getId());
|
||||
saasRole.setName(saveOrUpdateRole.getName());
|
||||
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);
|
||||
saasRoleDao.saveOrUpdate(saasRole);
|
||||
// 新增或者保存分组和角色映射关系
|
||||
saasRoleGroupRelationService.saveOrUpdate(groupTrees.stream().map(g -> {
|
||||
SaasRoleGroupRelation roleGroupRelation = new SaasRoleGroupRelation();
|
||||
roleGroupRelation.setRoleId(saasRole.getId());
|
||||
roleGroupRelation.setSaasRoleGroupId(g.getId());
|
||||
roleGroupRelation.setCreateAt(now);
|
||||
roleGroupRelation.setUpdateAt(now);
|
||||
return roleGroupRelation;
|
||||
}).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.setCreateAt(now);
|
||||
pgrr.setUpdateAt(now);
|
||||
// 新增或保存角色通用权限映射
|
||||
saasPgroupRoleRelationService.saveOrUpdateCommon(pgrr);
|
||||
// 保存权限集和权限点映射关系
|
||||
List<SaasPgroupPermissionRelation> pgpRelations = Optional.ofNullable(saveOrUpdateRole.getSelectedPPIds()).orElse(new ArrayList<>()).stream().map(ppId -> {
|
||||
SaasPgroupPermissionRelation target = new SaasPgroupPermissionRelation();
|
||||
target.setGroupId(saasPermissionGroup.getId());
|
||||
target.setFeatureId(ppId);
|
||||
target.setCreateBy(saveOrUpdateRole.getOperatorId());
|
||||
target.setUpdateBy(saveOrUpdateRole.getOperatorId());
|
||||
return target;
|
||||
}).collect(Collectors.toList());
|
||||
saasPgroupPermissionRelationService.saveOrUpdate(pgpRelations);
|
||||
return saasRole.getId();
|
||||
}
|
||||
|
||||
private void validFeature(List<Long> featureIds) {
|
||||
if (CollectionUtils.isEmpty(featureIds)) {
|
||||
return;
|
||||
}
|
||||
List<SaasFeature> saasFeatures = saasFeatureDao.lambdaQuery().in(SaasFeature::getId, featureIds)
|
||||
.eq(SaasFeature::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
Map<Long, SaasFeature> featureMap = saasFeatures.stream().collect(Collectors.toMap(SaasFeature::getId, Function.identity()));
|
||||
List<Long> invalidFeatues = featureIds.stream().filter(rg -> {
|
||||
SaasFeature target = featureMap.get(rg);
|
||||
return Objects.isNull(target);
|
||||
}).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(invalidFeatues)) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "权限点信息错误");
|
||||
}
|
||||
}
|
||||
|
||||
private SaasPermissionGroup validPermissionGroupCommon(SaveOrUpdateRoleVO saveOrUpdateRole) {
|
||||
SaasPermissionGroup saasPermissionGroup;
|
||||
if (Objects.isNull(saveOrUpdateRole.getPermissionGroupId())) {
|
||||
saasPermissionGroup = new SaasPermissionGroup();
|
||||
saasPermissionGroup.setIsCommon(PermissionGroupType.COMMON.getCode());
|
||||
saasPermissionGroup.setCreateBy(saveOrUpdateRole.getOperatorId());
|
||||
saasPermissionGroup.setCreatorName(saveOrUpdateRole.getOperatorName());
|
||||
} else {
|
||||
List<SaasPermissionGroup> groups = saasPermissionGroupDao.lambdaQuery()
|
||||
.eq(SaasPermissionGroup::getId, saveOrUpdateRole.getPermissionGroupId())
|
||||
.eq(SaasPermissionGroup::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
if (CollectionUtils.isEmpty(groups)) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "权限集不存在");
|
||||
}
|
||||
saasPermissionGroup = groups.get(0);
|
||||
if (!Objects.equals(saasPermissionGroup.getIsCommon(), PermissionGroupType.COMMON.getCode())) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "权限集不是通用权限集");
|
||||
}
|
||||
}
|
||||
saasPermissionGroup.setName(saveOrUpdateRole.getPermissionGroupName());
|
||||
saasPermissionGroup.setDescription(saveOrUpdateRole.getPermissionGroupDescription());
|
||||
saasPermissionGroup.setUpdateBy(saveOrUpdateRole.getOperatorId());
|
||||
saasPermissionGroup.setUpdatorName(saveOrUpdateRole.getOperatorName());
|
||||
saasPermissionGroup.setType(saveOrUpdateRole.getPermissionGroupType());
|
||||
return saasPermissionGroup;
|
||||
}
|
||||
|
||||
private void validRoleGroup(List<SaveOrUpdateRoleVO.GroupInfoVO> groupTrees) {
|
||||
if (CollectionUtils.isEmpty(groupTrees)) {
|
||||
return;
|
||||
}
|
||||
List<SaasRoleGroup> groups = saasRoleGroupDao.lambdaQuery()
|
||||
.in(SaasRoleGroup::getId, groupTrees.stream().map(SaveOrUpdateRoleVO.GroupInfoVO::getId).collect(Collectors.toList()))
|
||||
.eq(SaasRoleGroup::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
|
||||
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());
|
||||
}).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(invalidRoleGroups)) {
|
||||
throw new BizException(BaseCode.BAD_REQUEST, "角色分组信息错误");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色id查询权限集关联关系
|
||||
*/
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
package cn.axzo.tyr.server.service.impl;
|
||||
|
||||
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasPgroupPermissionRelation;
|
||||
import cn.axzo.tyr.server.repository.service.SaasPgroupPermissionRelationDao;
|
||||
import cn.axzo.tyr.server.service.SaasPgroupPermissionRelationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SaasPgroupPermissionRelationServiceImpl implements SaasPgroupPermissionRelationService {
|
||||
private final SaasPgroupPermissionRelationDao saasPgroupPermissionRelationDao;
|
||||
|
||||
@Override
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package cn.axzo.tyr.server.service.impl;
|
||||
|
||||
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
|
||||
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.service.SaasPermissionGroupDao;
|
||||
import cn.axzo.tyr.server.repository.service.SaasPgroupRoleRelationDao;
|
||||
import cn.axzo.tyr.server.service.SaasPgroupRoleRelationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SaasPgroupRoleRelationServiceImpl implements SaasPgroupRoleRelationService {
|
||||
private final SaasPgroupRoleRelationDao saasPgroupRoleRelationDao;
|
||||
private final SaasPermissionGroupDao saasPermissionGroupDao;
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package cn.axzo.tyr.server.service.impl;
|
||||
|
||||
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasRoleGroupRelation;
|
||||
import cn.axzo.tyr.server.repository.service.SaasRoleGroupRelationDao;
|
||||
import cn.axzo.tyr.server.service.SaasRoleGroupRelationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SaasRoleGroupRelationServiceImpl implements SaasRoleGroupRelationService {
|
||||
private final SaasRoleGroupRelationDao saasRoleGroupRelationDao;
|
||||
@Override
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user