feat: saasRoleVo添加接口
添加基于单位I与工作台ID获取匹配菜单的接口
This commit is contained in:
parent
10e237551c
commit
000af3f456
@ -1,13 +1,20 @@
|
||||
package cn.axzo.tyr.client.model.vo;
|
||||
|
||||
import cn.axzo.trade.datasecurity.core.annotation.control.DisableCrypt;
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointTreeNode;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@ -16,47 +23,118 @@ import java.util.stream.Collectors;
|
||||
@Builder
|
||||
public class SaasRoleVO {
|
||||
|
||||
private Long id;
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 角色类型: init 标准 common 自定义角色 admin管理员 super_admin 超管
|
||||
*/
|
||||
private String roleType;
|
||||
/**
|
||||
* 角色类型: init 标准 common 自定义角色 admin管理员 super_admin 超管
|
||||
*/
|
||||
private String roleType;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private Long createBy;
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private Long updateBy;
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private Long updateBy;
|
||||
|
||||
/**
|
||||
* 权限组
|
||||
*/
|
||||
private List<SaasPermissionGroupVO> permissionGroup;
|
||||
/**
|
||||
* 权限组
|
||||
*/
|
||||
private List<SaasPermissionGroupVO> permissionGroup;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Long isDelete;
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Long isDelete;
|
||||
|
||||
private Date createAt;
|
||||
private Date createAt;
|
||||
|
||||
private Date updateAt;
|
||||
private Date updateAt;
|
||||
|
||||
/**
|
||||
* 获取角色对应所用的权限
|
||||
* @return
|
||||
*/
|
||||
public List<PermissionPointTreeNode> getFeature(){
|
||||
return this.permissionGroup.stream().map(SaasPermissionGroupVO::getFeature).flatMap(List::stream).distinct().collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* 获取角色对应所用的菜单,不管例外
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<PermissionPointTreeNode> getFeature() {
|
||||
return this.permissionGroup.stream().map(SaasPermissionGroupVO::getFeature).flatMap(List::stream).distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色基于单位ID和工作台ID所匹配的所以菜单(包括通用和例外)
|
||||
* @param workspaceId
|
||||
* @param ouId
|
||||
* @return
|
||||
*/
|
||||
public List<PermissionPointTreeNode> getMatchFeature (Long workspaceId, Long ouId) {
|
||||
Set<PermissionPointTreeNode> permissionPoint = new HashSet<>();
|
||||
//例外
|
||||
group:
|
||||
for (SaasPermissionGroupVO permissionGroupVO : permissionGroup) {
|
||||
// 通用权限
|
||||
if (CollectionUtil.isEmpty(permissionGroupVO.getScopes())) {
|
||||
permissionPoint.addAll(permissionGroupVO.getFeature());
|
||||
}
|
||||
List<SaasRolePermissionScopeVO> scopes = permissionGroupVO.getScopes();
|
||||
|
||||
scope:
|
||||
for (SaasRolePermissionScopeVO scope : scopes) {
|
||||
//正选
|
||||
if (Objects.equals(scope.getType(), 1)) {
|
||||
|
||||
// 判断是否与当前工作台或者单位ID匹配
|
||||
if (scope.getScopeType().equals("workspace")
|
||||
&& match(true, permissionPoint, permissionGroupVO.getFeature(), scope.getScopeId(), workspaceId)) {
|
||||
continue group;
|
||||
}
|
||||
|
||||
if (scope.getScopeType().equals("ou")
|
||||
&& match(true, permissionPoint, permissionGroupVO.getFeature(), scope.getScopeId(), ouId)
|
||||
) {
|
||||
continue group;
|
||||
}
|
||||
|
||||
//反选
|
||||
} else if (Objects.equals(scope.getType(), 2)) {
|
||||
|
||||
// 判断是否与当前工作台或者单位ID匹配
|
||||
if (scope.getScopeType().equals("workspace")
|
||||
&& match(false, permissionPoint, permissionGroupVO.getFeature(), scope.getScopeId(), workspaceId)
|
||||
/* && !Objects.equals(scope.getScopeId(), workspaceId)
|
||||
&& permissionPoint.addAll(permissionGroupVO.getFeature())*/) {
|
||||
continue group;
|
||||
}
|
||||
|
||||
if (scope.getScopeType().equals("ou")
|
||||
&& match(false, permissionPoint, permissionGroupVO.getFeature(), scope.getScopeId(), ouId)
|
||||
/* && !Objects.equals(scope.getScopeId(), ouId)
|
||||
&& permissionPoint.addAll(permissionGroupVO.getFeature())*/) {
|
||||
continue group;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return new ArrayList<>((Collection) permissionPoint);
|
||||
}
|
||||
|
||||
private boolean match(boolean isMatch, Set<PermissionPointTreeNode> source, Collection<PermissionPointTreeNode> target, Long scopeId, Long workspaceId) {
|
||||
if (isMatch && scopeId.equals(workspaceId)) {
|
||||
source.addAll(target);
|
||||
return true;
|
||||
} else if (!isMatch && !Objects.equals(scopeId, workspaceId)) {
|
||||
source.addAll(target);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user