From 140be610032a7b92ac0a7627d10353dca81ac608 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 8 Feb 2020 14:49:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=94=A8=E6=88=B7=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=8A=A0=E8=BD=BD=E8=8F=9C=E5=8D=95=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=A0=91=E5=BD=A2=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/SysMenuController.java | 16 +++++++++++++--- .../project/system/mapper/SysMenuMapper.java | 8 ++++++++ .../project/system/service/ISysMenuService.java | 5 +++-- .../system/service/impl/SysMenuServiceImpl.java | 15 +++++++++++++-- .../resources/mybatis/system/SysMenuMapper.xml | 16 ++++++++++++++++ 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java b/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java index 47634f5a..1e6ce5ef 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java @@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; +import com.ruoyi.framework.security.LoginUser; +import com.ruoyi.framework.security.service.TokenService; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.project.system.domain.SysMenu; @@ -33,6 +36,9 @@ public class SysMenuController extends BaseController @Autowired private ISysMenuService menuService; + @Autowired + private TokenService tokenService; + /** * 获取菜单列表 */ @@ -40,7 +46,9 @@ public class SysMenuController extends BaseController @GetMapping("/list") public AjaxResult list(SysMenu menu) { - List menus = menuService.selectMenuList(menu); + LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + Long userId = loginUser.getUser().getUserId(); + List menus = menuService.selectMenuList(menu, userId); return AjaxResult.success(menuService.buildMenuTree(menus)); } @@ -58,9 +66,11 @@ public class SysMenuController extends BaseController * 获取菜单下拉树列表 */ @GetMapping("/treeselect") - public AjaxResult treeselect(SysMenu dept) + public AjaxResult treeselect(SysMenu menu) { - List menus = menuService.selectMenuList(dept); + LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + Long userId = loginUser.getUser().getUserId(); + List menus = menuService.selectMenuList(menu, userId); return AjaxResult.success(menuService.buildMenuTreeSelect(menus)); } diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysMenuMapper.java b/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysMenuMapper.java index d52a0879..fc460852 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysMenuMapper.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysMenuMapper.java @@ -26,6 +26,14 @@ public interface SysMenuMapper */ public List selectMenuPerms(); + /** + * 根据用户查询系统菜单列表 + * + * @param menu 菜单信息 + * @return 菜单列表 + */ + public List selectMenuListByUserId(SysMenu menu); + /** * 根据用户ID查询权限 * diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysMenuService.java b/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysMenuService.java index 8460554d..cb4d7b72 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysMenuService.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysMenuService.java @@ -14,12 +14,13 @@ import com.ruoyi.project.system.domain.vo.RouterVo; public interface ISysMenuService { /** - * 查询系统菜单列表 + * 根据用户查询系统菜单列表 * * @param menu 菜单信息 + * @param userId 用户ID * @return 菜单列表 */ - public List selectMenuList(SysMenu menu); + public List selectMenuList(SysMenu menu, Long userId); /** * 根据用户ID查询权限 diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java b/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java index 2b195463..b8d86032 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java @@ -15,6 +15,7 @@ import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.web.domain.TreeSelect; import com.ruoyi.project.system.domain.SysMenu; +import com.ruoyi.project.system.domain.SysUser; import com.ruoyi.project.system.domain.vo.MetaVo; import com.ruoyi.project.system.domain.vo.RouterVo; import com.ruoyi.project.system.mapper.SysMenuMapper; @@ -44,9 +45,19 @@ public class SysMenuServiceImpl implements ISysMenuService * @return 菜单列表 */ @Override - public List selectMenuList(SysMenu menu) + public List selectMenuList(SysMenu menu, Long userId) { - List menuList = menuMapper.selectMenuList(menu); + List menuList = null; + // 管理员显示所有菜单信息 + if (SysUser.isAdmin(userId)) + { + menuList = menuMapper.selectMenuList(menu); + } + else + { + menu.getParams().put("userId", userId); + menuList = menuMapper.selectMenuListByUserId(menu); + } return menuList; } diff --git a/ruoyi/src/main/resources/mybatis/system/SysMenuMapper.xml b/ruoyi/src/main/resources/mybatis/system/SysMenuMapper.xml index d233602a..98aee20f 100644 --- a/ruoyi/src/main/resources/mybatis/system/SysMenuMapper.xml +++ b/ruoyi/src/main/resources/mybatis/system/SysMenuMapper.xml @@ -47,6 +47,22 @@ from sys_menu m where m.menu_type in ('M', 'C') and m.visible = 0 order by m.parent_id, m.order_num + +