From 73cdf2fa6df85933fdead468401a18cbac5a3641 Mon Sep 17 00:00:00 2001 From: wenjy Date: Mon, 28 Feb 2022 17:56:34 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E8=8F=9C=E5=8D=95=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysIndexController.java | 44 +++++++++++++++---- .../ruoyi/system/mapper/SysMenuMapper.java | 16 +++++++ .../ruoyi/system/service/ISysMenuService.java | 8 ++++ .../service/impl/SysMenuServiceImpl.java | 35 +++++++++++++++ .../resources/mapper/system/SysMenuMapper.xml | 14 ++++++ 5 files changed, 109 insertions(+), 8 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java index 68c7405..6767417 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java @@ -3,6 +3,7 @@ package com.ruoyi.web.controller.system; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; @@ -52,9 +53,6 @@ public class SysIndexController extends BaseController { // 取身份信息 SysUser user = getSysUser(); - // 根据用户id取出菜单 - List menus = menuService.selectMenusByUser(user); - mmap.put("menus", menus); mmap.put("user", user); mmap.put("sideTheme", configService.selectConfigByKey("sys.index.sideTheme")); mmap.put("skinName", configService.selectConfigByKey("sys.index.skinName")); @@ -88,14 +86,45 @@ public class SysIndexController extends BaseController return webIndex; } + /** + * 筛选可视化界面菜单 + * @author WenJY + * @date 2022/2/28 17:55 + * @return com.ruoyi.web.controller.system.JsonRootBean + */ public JsonRootBean menuInfo(){ + + List menus = menuService.selectVisualMenusByUser(getSysUser()); + + List firstMenu = menus.stream().filter(x->x.getParentId()==1112).collect(Collectors.toList()); + JsonRootBean jsonResult = new JsonRootBean(); List> urlResult = new ArrayList<>(); List menuStrList = new ArrayList<>(); - urlResult.add(new ArrayList(){{ + for (SysMenu menu : firstMenu){ + List menuList = menus.stream().filter(x->x.getParentId().equals(menu.getMenuId()) && menu.getMenuId() != 1112).collect(Collectors.toList()); + if(menuList.size() > 0){ + List menuNames = new ArrayList(); + urlResult.add(new ArrayList(){{ + menuList.forEach(x->{ + if (x.getUrl() != "#"){ + this.add(x.getUrl()); + menuNames.add(x.getMenuName()); + } + }); + }}); + menuStrList.add(new MenuStr(menu.getMenuName(),menuNames)); + }else{ + urlResult.add(new ArrayList(){{ + this.add(menu.getUrl()); + }}); + menuStrList.add(new MenuStr(menu.getMenuName(),new ArrayList())); + } + } + + /*urlResult.add(new ArrayList(){{ this.add("/iot/index"); - //this.add("/sections/substation"); }}); urlResult.add(new ArrayList(){{ this.add("/sections/substation"); @@ -104,8 +133,6 @@ public class SysIndexController extends BaseController this.add("/sections/substation"); this.add("/sections/substation"); this.add("/sections/substation"); - /*this.add("/sections/transformer-detail"); - this.add("/iot/index");*/ }}); urlResult.add(new ArrayList(){{ this.add("/sections/transformer-detail"); @@ -135,9 +162,10 @@ public class SysIndexController extends BaseController this.add("电容电抗器设备"); this.add("避雷器设备"); }})); - menuStrList.add(new MenuStr("传感器汇总",new ArrayList())); + menuStrList.add(new MenuStr("传感器汇总",new ArrayList()));*/ jsonResult.setUrl(urlResult); jsonResult.setMenuStr(menuStrList); + System.out.println("测试:"+JSONArray.toJSONString(jsonResult)); return jsonResult; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java index 62361f7..fcd2896 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java @@ -18,6 +18,14 @@ public interface SysMenuMapper */ public List selectMenuAll(); + /** + * 查询所有可视化菜单 + * @author WenJY + * @date 2022/2/28 17:22 + * @return java.util.List + */ + public List selectVisualMenuAll(); + /** * 根据用户ID查询菜单 * @@ -26,6 +34,14 @@ public interface SysMenuMapper */ public List selectMenuAllByUserId(Long userId); + /** + * 根据用户Id查询可视化菜单 + * @author WenJY + * @date 2022/2/28 17:22 + * @return java.util.List + */ + public List selectVisualMenuAllByUserId(Long userId); + /** * 查询系统正常显示菜单(不含按钮) * 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 237d06f..d311cca 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 @@ -23,6 +23,14 @@ public interface ISysMenuService */ public List selectMenusByUser(SysUser user); + /** + * 根据用户ID查询可视化菜单 + * + * @param user 用户信息 + * @return 菜单列表 + */ + public List selectVisualMenusByUser(SysUser user); + /** * 查询系统菜单列表 * 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 a8c5b1d..66064c9 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 @@ -9,6 +9,8 @@ import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.common.constant.UserConstants; @@ -56,9 +58,42 @@ public class SysMenuServiceImpl implements ISysMenuService { menus = menuMapper.selectMenusByUserId(user.getUserId()); } + + //清除前端可视化界面 + List info = new LinkedList(); + List menuList = menus.stream().filter(x->x.getParentId() == 1112 || x.getMenuId() == 1112 ).collect(Collectors.toList()); + info.addAll(menuList); + for (SysMenu menu : menuList){ + info.addAll(menus.stream().filter(x->x.getParentId().equals(menu.getMenuId()) && menu.getParentId() != 0).collect(Collectors.toList())); + } + menus.removeAll(info); + return getChildPerms(menus, 0); } + /** + * 根据用户查询可视化菜单 + * + * @param user 用户信息 + * @return 菜单列表 + */ + @Override + public List selectVisualMenusByUser(SysUser user) + { + List menus = new LinkedList(); + // 管理员显示所有菜单信息 + if (user.isAdmin()) + { + menus = menuMapper.selectVisualMenuAll(); + } + else + { + menus = menuMapper.selectVisualMenuAllByUserId(user.getUserId()); + } + + return menus.stream().filter(x->x.getParentId()!=0).collect(Collectors.toList()); + } + /** * 查询菜单集合 * diff --git a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml index f9af0dc..6d4132b 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml @@ -51,6 +51,10 @@ order by parent_id, order_num + + + +