refactor(权限点): 增加通过ID过滤树

This commit is contained in:
zhansihu 2023-09-12 14:41:07 +08:00
parent 26e1438414
commit 50a4d12540
2 changed files with 9 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package cn.axzo.tyr.client.model.permission;
import lombok.Data;
import java.util.List;
import java.util.Set;
/**
* 权限点树形查询请求参数
@ -27,7 +28,7 @@ public class PermissionPointTreeQueryReq {
private List<String> terminalList;
/** 权限点ID列表 **/
private List<Long> ids;
private Set<Long> ids;
/** 权限点terminal对应workspaceType **/
private List<String> workspaceType;

View File

@ -140,7 +140,8 @@ public class PermissionPointServiceImpl implements PermissionPointService {
private List<PermissionPointTreeNode> filterTreeNode(PermissionPointTreeQueryReq request, List<PermissionPointTreeNode> treeList) {
//过滤条件
boolean needFilter = StrUtil.isNotBlank(request.getKeyword())
|| request.getDelegateType() != 0;
|| request.getDelegateType() != 0
|| CollectionUtil.isNotEmpty(request.getIds());
if (needFilter) {
return treeList.stream().filter(x -> this.recursionFilter(request, x)).collect(Collectors.toList());
@ -149,14 +150,17 @@ public class PermissionPointServiceImpl implements PermissionPointService {
}
private boolean recursionFilter(PermissionPointTreeQueryReq request, PermissionPointTreeNode node) {
// 过滤参数为空时 认为匹配成功
//条件匹配 - 关键字
boolean matchKeyword = request.getKeyword() == null || node.getPermissionName().contains(request.getKeyword());
//条件匹配 - 授权策略类型
boolean matchDelegateType = request.getDelegateType() == 0 || Objects.equals(request.getDelegateType(), node.getDelegatedType());
if (matchKeyword && matchDelegateType) {
//条件匹配 - ID
boolean matchId = CollectionUtil.isEmpty(request.getIds()) || request.getIds().contains(node.getPermissionPointId());
if (matchKeyword && matchDelegateType && matchId) {
//如果匹配直接返回否则过滤子节点
return true;
}