优化递归子节点
This commit is contained in:
parent
dd6640086e
commit
068c3e6f0d
@ -267,13 +267,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||||||
{
|
{
|
||||||
if (hasChild(list, tChild))
|
if (hasChild(list, tChild))
|
||||||
{
|
{
|
||||||
// 判断是否有子节点
|
recursionFn(list, tChild);
|
||||||
Iterator<SysDept> it = childList.iterator();
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
SysDept n = (SysDept) it.next();
|
|
||||||
recursionFn(list, n);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,14 +178,19 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|||||||
public List<SysMenu> buildMenuTree(List<SysMenu> menus)
|
public List<SysMenu> buildMenuTree(List<SysMenu> menus)
|
||||||
{
|
{
|
||||||
List<SysMenu> returnList = new ArrayList<SysMenu>();
|
List<SysMenu> returnList = new ArrayList<SysMenu>();
|
||||||
|
List<Long> tempList = new ArrayList<Long>();
|
||||||
|
for (SysMenu dept : menus)
|
||||||
|
{
|
||||||
|
tempList.add(dept.getMenuId());
|
||||||
|
}
|
||||||
for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext();)
|
for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext();)
|
||||||
{
|
{
|
||||||
SysMenu t = (SysMenu) iterator.next();
|
SysMenu menu = (SysMenu) iterator.next();
|
||||||
// 根据传入的某个父节点ID,遍历该父节点的所有子节点
|
// 如果是顶级节点, 遍历该父节点的所有子节点
|
||||||
if (t.getParentId() == 0)
|
if (!tempList.contains(menu.getParentId()))
|
||||||
{
|
{
|
||||||
recursionFn(menus, t);
|
recursionFn(menus, menu);
|
||||||
returnList.add(t);
|
returnList.add(menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (returnList.isEmpty())
|
if (returnList.isEmpty())
|
||||||
@ -406,13 +411,7 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|||||||
{
|
{
|
||||||
if (hasChild(list, tChild))
|
if (hasChild(list, tChild))
|
||||||
{
|
{
|
||||||
// 判断是否有子节点
|
recursionFn(list, tChild);
|
||||||
Iterator<SysMenu> it = childList.iterator();
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
SysMenu n = (SysMenu) it.next();
|
|
||||||
recursionFn(list, n);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user