change - 菜单处理

main
wenjy 3 years ago
parent a3ea0db193
commit 73cdf2fa6d

@ -3,6 +3,7 @@ package com.ruoyi.web.controller.system;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -52,9 +53,6 @@ public class SysIndexController extends BaseController
{ {
// 取身份信息 // 取身份信息
SysUser user = getSysUser(); SysUser user = getSysUser();
// 根据用户id取出菜单
List<SysMenu> menus = menuService.selectMenusByUser(user);
mmap.put("menus", menus);
mmap.put("user", user); mmap.put("user", user);
mmap.put("sideTheme", configService.selectConfigByKey("sys.index.sideTheme")); mmap.put("sideTheme", configService.selectConfigByKey("sys.index.sideTheme"));
mmap.put("skinName", configService.selectConfigByKey("sys.index.skinName")); mmap.put("skinName", configService.selectConfigByKey("sys.index.skinName"));
@ -88,14 +86,45 @@ public class SysIndexController extends BaseController
return webIndex; return webIndex;
} }
/**
*
* @author WenJY
* @date 2022/2/28 17:55
* @return com.ruoyi.web.controller.system.JsonRootBean
*/
public JsonRootBean menuInfo(){ public JsonRootBean menuInfo(){
List<SysMenu> menus = menuService.selectVisualMenusByUser(getSysUser());
List<SysMenu> firstMenu = menus.stream().filter(x->x.getParentId()==1112).collect(Collectors.toList());
JsonRootBean jsonResult = new JsonRootBean(); JsonRootBean jsonResult = new JsonRootBean();
List<List<String>> urlResult = new ArrayList<>(); List<List<String>> urlResult = new ArrayList<>();
List<MenuStr> menuStrList = new ArrayList<>(); List<MenuStr> menuStrList = new ArrayList<>();
urlResult.add(new ArrayList<String>(){{ for (SysMenu menu : firstMenu){
List<SysMenu> menuList = menus.stream().filter(x->x.getParentId().equals(menu.getMenuId()) && menu.getMenuId() != 1112).collect(Collectors.toList());
if(menuList.size() > 0){
List<String> menuNames = new ArrayList<String>();
urlResult.add(new ArrayList<String>(){{
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<String>(){{
this.add(menu.getUrl());
}});
menuStrList.add(new MenuStr(menu.getMenuName(),new ArrayList<String>()));
}
}
/*urlResult.add(new ArrayList<String>(){{
this.add("/iot/index"); this.add("/iot/index");
//this.add("/sections/substation");
}}); }});
urlResult.add(new ArrayList<String>(){{ urlResult.add(new ArrayList<String>(){{
this.add("/sections/substation"); 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/substation");
this.add("/sections/substation"); this.add("/sections/substation");
/*this.add("/sections/transformer-detail");
this.add("/iot/index");*/
}}); }});
urlResult.add(new ArrayList<String>(){{ urlResult.add(new ArrayList<String>(){{
this.add("/sections/transformer-detail"); this.add("/sections/transformer-detail");
@ -135,9 +162,10 @@ public class SysIndexController extends BaseController
this.add("电容电抗器设备"); this.add("电容电抗器设备");
this.add("避雷器设备"); this.add("避雷器设备");
}})); }}));
menuStrList.add(new MenuStr("传感器汇总",new ArrayList<String>())); menuStrList.add(new MenuStr("传感器汇总",new ArrayList<String>()));*/
jsonResult.setUrl(urlResult); jsonResult.setUrl(urlResult);
jsonResult.setMenuStr(menuStrList); jsonResult.setMenuStr(menuStrList);
System.out.println("测试:"+JSONArray.toJSONString(jsonResult));
return jsonResult; return jsonResult;
} }

@ -18,6 +18,14 @@ public interface SysMenuMapper
*/ */
public List<SysMenu> selectMenuAll(); public List<SysMenu> selectMenuAll();
/**
*
* @author WenJY
* @date 2022/2/28 17:22
* @return java.util.List<com.ruoyi.common.core.domain.entity.SysMenu>
*/
public List<SysMenu> selectVisualMenuAll();
/** /**
* ID * ID
* *
@ -26,6 +34,14 @@ public interface SysMenuMapper
*/ */
public List<SysMenu> selectMenuAllByUserId(Long userId); public List<SysMenu> selectMenuAllByUserId(Long userId);
/**
* Id
* @author WenJY
* @date 2022/2/28 17:22
* @return java.util.List<com.ruoyi.common.core.domain.entity.SysMenu>
*/
public List<SysMenu> selectVisualMenuAllByUserId(Long userId);
/** /**
* *
* *

@ -23,6 +23,14 @@ public interface ISysMenuService
*/ */
public List<SysMenu> selectMenusByUser(SysUser user); public List<SysMenu> selectMenusByUser(SysUser user);
/**
* ID
*
* @param user
* @return
*/
public List<SysMenu> selectVisualMenusByUser(SysUser user);
/** /**
* *
* *

@ -9,6 +9,8 @@ import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.constant.UserConstants;
@ -56,9 +58,42 @@ public class SysMenuServiceImpl implements ISysMenuService
{ {
menus = menuMapper.selectMenusByUserId(user.getUserId()); menus = menuMapper.selectMenusByUserId(user.getUserId());
} }
//清除前端可视化界面
List<SysMenu> info = new LinkedList<SysMenu>();
List<SysMenu> 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); return getChildPerms(menus, 0);
} }
/**
*
*
* @param user
* @return
*/
@Override
public List<SysMenu> selectVisualMenusByUser(SysUser user)
{
List<SysMenu> menus = new LinkedList<SysMenu>();
// 管理员显示所有菜单信息
if (user.isAdmin())
{
menus = menuMapper.selectVisualMenuAll();
}
else
{
menus = menuMapper.selectVisualMenuAllByUserId(user.getUserId());
}
return menus.stream().filter(x->x.getParentId()!=0).collect(Collectors.toList());
}
/** /**
* *
* *

@ -51,6 +51,10 @@
order by parent_id, order_num order by parent_id, order_num
</select> </select>
<select id="selectVisualMenuAll" resultMap="SysMenuResult">
SELECT * FROM sys_menu WHERE FIND_IN_SET(menu_id,queryChildrenAreaInfo(1112)) order by parent_id, order_num
</select>
<select id="selectMenuAllByUserId" parameterType="Long" resultMap="SysMenuResult"> <select id="selectMenuAllByUserId" parameterType="Long" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.url, m.visible, m.is_refresh, ifnull(m.perms,'') as perms, m.target, m.menu_type, m.icon, m.order_num, m.create_time select distinct m.menu_id, m.parent_id, m.menu_name, m.url, m.visible, m.is_refresh, ifnull(m.perms,'') as perms, m.target, m.menu_type, m.icon, m.order_num, m.create_time
from sys_menu m from sys_menu m
@ -61,6 +65,16 @@
order by m.parent_id, m.order_num order by m.parent_id, m.order_num
</select> </select>
<select id="selectVisualMenuAllByUserId" parameterType="Long" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.url, m.visible, m.is_refresh, ifnull(m.perms,'') as perms, m.target, m.menu_type, m.icon, m.order_num, m.create_time
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
left join sys_user_role ur on rm.role_id = ur.role_id
LEFT JOIN sys_role ro on ur.role_id = ro.role_id
where FIND_IN_SET(m.menu_id,queryChildrenAreaInfo(1112)) and ur.user_id = #{userId}
order by m.parent_id, m.order_num
</select>
<select id="selectPermsByUserId" parameterType="Long" resultType="String"> <select id="selectPermsByUserId" parameterType="Long" resultType="String">
select distinct m.perms select distinct m.perms
from sys_menu m from sys_menu m

Loading…
Cancel
Save