From 068c3e6f0deb4a179a2535119df5f6fc0a6ad226 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 28 Aug 2020 10:14:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=92=E5=BD=92=E5=AD=90?= =?UTF-8?q?=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SysDeptServiceImpl.java | 8 +------ .../service/impl/SysMenuServiceImpl.java | 23 +++++++++---------- 2 files changed, 12 insertions(+), 19 deletions(-) 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 ec8113ec1..d32e033a9 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 d3fb074ba..51fb662fd 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); } } }