提交 28d6b2d2 编写于 作者: tangyaologin's avatar tangyaologin

角色查询父子关系代码优化

上级 3587aec3
......@@ -2,6 +2,7 @@ package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.uaa.filter.SysRoleSearchContext;
import cn.ibizlab.core.uaa.service.impl.SysRoleServiceImpl;
import liquibase.pro.packaged.S;
import liquibase.util.StringUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
......@@ -14,6 +15,7 @@ import org.springframework.context.annotation.Primary;
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* 实体[系统角色] 自定义服务对象
......@@ -22,7 +24,6 @@ import java.util.*;
@Primary
@Service("SysRoleExService")
public class SysRoleExService extends SysRoleServiceImpl {
List<SysRole> result = new ArrayList<>();
@Override
protected Class currentModelClass() {
......@@ -51,14 +52,20 @@ public class SysRoleExService extends SysRoleServiceImpl {
com.baomidou.mybatisplus.extension.plugins.pagination.Page<SysRole> pages = baseMapper.searchNoRepeat(context.getPages(),context,context.getSelectCond());
if(!ObjectUtils.isEmpty(sysRoleId)){
findSRelation(pages.getRecords(),sysRoleId);
List<SysRole> childRole = new ArrayList<>();
List<SysRole> grandSonRole = new ArrayList<>();
findSRelation(childRole,pages.getRecords(),sysRoleId);
grandSonRole.addAll(childRole);
for (SysRole sr : grandSonRole){
findSRelation(childRole,pages.getRecords(),sr.getRoleid());
}
newResult.addAll(childRole);
newResult.addAll(findPRelation(sysRoleId,new ArrayList<>()));
newResult.addAll(result);
result.clear();
newResult = newResult.stream().distinct().collect(Collectors.toList());
}
for (SysRole sysRole : newResult) {
for (int j = 0; j < pages.getRecords().size(); j++) {
if (pages.getRecords().get(j).getRoleid().equals(sysRole.getRoleid())) {
for (int i = 0 ;i < newResult.size();i++){
for (int j = 0;j < pages.getRecords().size();j++){
if(pages.getRecords().get(j).getRoleid().equals(newResult.get(i).getRoleid())){
pages.getRecords().remove(j);
}
}
......@@ -88,15 +95,16 @@ public class SysRoleExService extends SysRoleServiceImpl {
/**
* 递归获取某个父节点下的所有子节点
* @param childRole 返回的结果
* @param roleList 数据库查询出来的所有角色集合
* @param pId 父id
*/
private void findSRelation(List<SysRole> roleList, String pId) {
private void findSRelation(List<SysRole> childRole,List<SysRole> roleList, String pId) {
for (SysRole role : roleList) {
if (!StringUtils.isEmpty(role.getProleid())) {
if (role.getProleid().equals(pId)) {
findSRelation(roleList, role.getRoleid());
result.add(role);
findSRelation(childRole,roleList,role.getRoleid());
childRole.add(role);
}
}
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册