From 6b258281132ed5e8c987cc8825c3b10187bdc32e Mon Sep 17 00:00:00 2001 From: RuoYi Date: Mon, 31 Aug 2020 23:23:08 +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 --- .../system/service/impl/SysDeptServiceImpl.java | 8 +------- .../system/service/impl/SysMenuServiceImpl.java | 23 +++++++++++----------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index ed8b74c..6197c93 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -269,13 +269,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-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index cc01468..afe94f1 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-modules/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); } } }