提交 a28a9c97 编写于 作者: Tyl666's avatar Tyl666

角色查询父子关系算法优化

上级 99484a00
......@@ -3,6 +3,7 @@ package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.uaa.filter.SysRoleSearchContext;
import cn.ibizlab.core.uaa.service.impl.SysRoleServiceImpl;
import liquibase.util.StringUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.core.uaa.domain.SysRole;
import org.springframework.data.domain.Page;
......@@ -44,28 +45,34 @@ public class SysRoleExService extends SysRoleServiceImpl {
* 查询集合 数据查询
*/
@Override
@SneakyThrows
public Page<SysRole> searchNoRepeat(SysRoleSearchContext context) {
List<String> newResult = new CopyOnWriteArrayList<>();
String sysRoleid = (String) context.getParams().get("sys_roleid");
com.baomidou.mybatisplus.extension.plugins.pagination.Page<SysRole> pages=baseMapper.searchNoRepeat(context.getPages(),context,context.getSelectCond());
List<SysRole> sysRoles = new ArrayList<>();
SysRole currentSysRole = baseMapper.selectById(sysRoleid);
if(!ObjectUtils.isEmpty(currentSysRole)){
sysRoles.add(currentSysRole);
findSRelation(sysRoles);
findSRelation(result,pages.getRecords(),sysRoleid);
newResult.addAll(findPRelation(sysRoleid,new ArrayList<String>()));
newResult.addAll(result);
result.clear();
}
String noRepeat = String.join(";", newResult);
context.setN_sys_roleid_notin(noRepeat);
com.baomidou.mybatisplus.extension.plugins.pagination.Page<SysRole> pages=baseMapper.searchNoRepeat(context.getPages(),context,context.getSelectCond());
return new PageImpl<SysRole>(pages.getRecords(), context.getPageable(), pages.getTotal());
com.baomidou.mybatisplus.extension.plugins.pagination.Page<SysRole> newPages=baseMapper.searchNoRepeat(context.getPages(),context,context.getSelectCond());
return new PageImpl<SysRole>(newPages.getRecords(), context.getPageable(), newPages.getTotal());
}
/**
*
* @param contextId
* 递归获取某个子节点的所有父节点
* @param contextId 上下文中当前子节点id
* @param pList 父id集合
* @return
*/
private List<String> findPRelation(String contextId,List<String> pList){
......@@ -84,23 +91,20 @@ public class SysRoleExService extends SysRoleServiceImpl {
}
/**
* 获取某个父节点下面的所有子节点
* @return
* 递归获取某个父节点下的所有子节点
* @param childRole 返回的结果
* @param roleList 数据库查询出来的所有角色集合
* @param pId 父id
*/
public void findSRelation(List<SysRole> ids){
List<SysRole> temp= new ArrayList<SysRole>();
List<SysRole> sysEnterpriseOrgList = new ArrayList<SysRole>();
for (SysRole sRole :ids) {
sysEnterpriseOrgList = selectByProleid(sRole.getRoleid());
for (SysRole s:sysEnterpriseOrgList) {
temp.add(s);
result.add(s.getRoleid());
private void findSRelation(List<String> childRole,List<SysRole> roleList, String pId) {
for (SysRole role : roleList) {
if (!StringUtils.isEmpty(role.getProleid())) {
if (role.getProleid().equals(pId)) {
findSRelation(childRole,roleList, role.getRoleid());
result.add(role.getRoleid());
}
}
}
}
if(!ObjectUtils.isEmpty(temp)){
findSRelation(temp);
}
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册