1,
Set<AuthResourcePO> authResourcePOSet = Sets.newHashSet();
Long dialogInitAuthResourceId = 387L;
//根据父权限id获取该权限以及该权限下所有权限的集合
authResourcePOSet = findChildAuthResource(authResourcePOSet, dialogInitAuthResourceId);
//根权限的id得到该权限ID以及该权限下所有子权限ID的集合
List<Long> authResourceIdList = authResourcePOSet.stream().map(AuthResourcePO::getAuthResourceId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
2,
private Set<AuthResourcePO> findChildAuthResource(Set<AuthResourcePO> authResourcePOSet, Long dialogInitAuthResourceId) {
AuthResourcePO authResourcePO = authResourceService.selectByKey(dialogInitAuthResourceId);
if (authResourcePO != null) {
authResourcePOSet.add(authResourcePO);
}
//查找子节点,递归算法一定要有一个退出条件
List<AuthResourcePO> authResourcePOS = authResourceService.selectByAuthResourceId(dialogInitAuthResourceId);
for (AuthResourcePO authResourceItem : authResourcePOS) {
findChildAuthResource(authResourcePOSet, authResourceItem.getAuthResourceId());
}
return authResourcePOSet;
}
热门评论
有没有更好的方案呢