diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java index 9ab14d2ab..944cf6f00 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java @@ -1,6 +1,8 @@ package com.ruoyi.web.controller.system; import java.util.List; + +import com.ruoyi.common.core.page.TableDataInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; @@ -44,6 +46,18 @@ public class SysMenuController extends BaseController return AjaxResult.success(menus); } + /** + * 分页获取菜单列表 + */ + @PreAuthorize("@ss.hasPermi('system:menu:list')") + @GetMapping("/listTreeByPage") + public TableDataInfo listTreeByPage(SysMenu menu) + { + startPage(); + List menus = menuService.selectTreeByPage(menu, getUserId()); + return getDataTable(menus); + } + /** * 根据菜单编号获取详细信息 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java index 59009be01..2f54bd41f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java @@ -133,4 +133,13 @@ public interface ISysMenuService * @return 结果 */ public String checkMenuNameUnique(SysMenu menu); + + /** + * 分页查询菜单树 + * + * @param menu + * @param userId + * @return + */ + public List selectTreeByPage(SysMenu menu, Long userId); } 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 37dcc1977..3cf892140 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 @@ -79,6 +79,60 @@ public class SysMenuServiceImpl implements ISysMenuService return menuList; } + /** + * 分页查询菜单树 + * + * @param menu + * @param userId + * @return + */ + @Override + public List selectTreeByPage(SysMenu menu, Long userId) + { + List menuList = null; + menu.setParentId(0L); + + // 管理员显示所有菜单信息 + if (SysUser.isAdmin(userId)) { + menuList = menuMapper.selectMenuList(menu); + } + else + { + menu.getParams().put("userId", userId); + menuList = menuMapper.selectMenuListByUserId(menu); + } + return findChildren(menuList, userId); + } + + public List findChildren(List sysMenuList, Long userId) + { + List children = null; + SysMenu menu = new SysMenu(); + + for (SysMenu sysMenu : sysMenuList) + { + menu.setParentId(sysMenu.getMenuId()); + + // 管理员显示所有菜单信息 + if (SysUser.isAdmin(userId)) + { + children = menuMapper.selectMenuList(menu); + } + else + { + menu.getParams().put("userId", userId); + children = menuMapper.selectMenuListByUserId(menu); + } + + if (StringUtils.isNotNull(children) && children.size() > 0) + { + findChildren(children, userId); + sysMenu.setChildren(children); + } + } + return sysMenuList; + } + /** * 根据用户ID查询权限 * diff --git a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml index f11402c7f..c20fa9cd7 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml @@ -35,6 +35,9 @@