diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index ec8113e..d32e033 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -267,13 +267,7 @@ public class SysDeptServiceImpl implements ISysDeptService { if (hasChild(list, tChild)) { - // 判断是否有子节点 - Iterator it = childList.iterator(); - while (it.hasNext()) - { - SysDept n = (SysDept) it.next(); - recursionFn(list, n); - } + recursionFn(list, tChild); } } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index d3fb074..51fb662 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -178,14 +178,19 @@ public class SysMenuServiceImpl implements ISysMenuService public List buildMenuTree(List menus) { List returnList = new ArrayList(); + List tempList = new ArrayList(); + for (SysMenu dept : menus) + { + tempList.add(dept.getMenuId()); + } for (Iterator iterator = menus.iterator(); iterator.hasNext();) { - SysMenu t = (SysMenu) iterator.next(); - // 根据传入的某个父节点ID,遍历该父节点的所有子节点 - if (t.getParentId() == 0) + SysMenu menu = (SysMenu) iterator.next(); + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(menu.getParentId())) { - recursionFn(menus, t); - returnList.add(t); + recursionFn(menus, menu); + returnList.add(menu); } } if (returnList.isEmpty()) @@ -406,13 +411,7 @@ public class SysMenuServiceImpl implements ISysMenuService { if (hasChild(list, tChild)) { - // 判断是否有子节点 - Iterator it = childList.iterator(); - while (it.hasNext()) - { - SysMenu n = (SysMenu) it.next(); - recursionFn(list, n); - } + recursionFn(list, tChild); } } }