From 4459e2a1721f9d5a3129f9af0ecaa9b625d2fc8b Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期二, 05 七月 2022 15:18:02 +0800
Subject: [PATCH] fix
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/MenuService.java | 62 +++++++++++++++++++------------
1 files changed, 38 insertions(+), 24 deletions(-)
diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/MenuService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/MenuService.java
index 5516885..02994a6 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/MenuService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/MenuService.java
@@ -2,6 +2,7 @@
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.enums.RoleLevelStatus;
import com.sandu.common.execption.BusinessException;
@@ -35,38 +36,27 @@
public class MenuService extends BaseServiceImpl<MenuMapper, Menu> {
private final RoleMenuRelationService roleMenuRelationService;
+ private MenuMapper menuMapper;
+
/**
* 鑾峰彇瑙掕壊涓嬬殑鑿滃崟
*/
public List<Menu> listByRoleIds(List<Long> roleIdList) {
- List<Long> menuIdList = roleMenuRelationService.list(Wrappers.lambdaQuery(RoleMenuRelation.class).in(RoleMenuRelation::getRoleId, roleIdList).select(RoleMenuRelation::getMenuId))
+ List<Long> menuIdList = roleMenuRelationService.list(Wrappers.lambdaQuery(RoleMenuRelation.class)
+ .in(RoleMenuRelation::getRoleId, roleIdList).select(RoleMenuRelation::getMenuId))
.stream().map(RoleMenuRelation::getMenuId).distinct().collect(Collectors.toList());
if (CollectionUtil.isEmpty(menuIdList)) {
return null;
}
- return listByIds(menuIdList);
+
+ return menuMapper.listMenuById(menuIdList);
}
public boolean addMenu(MenuParam param) {
Menu menu = new Menu();
- BeanUtils.copyProperties(param,menu);
+ BeanUtils.copyProperties(param, menu);
return save(menu);
}
-
-// public Set<Menu> listMenuByRoles(Set<Role> roles) {
-// List<Long> roleIds = roles.stream().map(Role::getId).collect(Collectors.toList());
-// Set<Menu> menus = menuDao.listMenuByRoleIds(roleIds);
-// return menus;
-// }
-//
-// /**
-// * 鎶婅彍鍗曡浆鎴愭爲褰㈢粨鏋�
-// */
-// public List<MenuNode> buildTree(List<Menu> menuList) {
-// return menuList.stream()
-// .filter(menu -> menu.getPid().equals(0L))
-// .map(menu -> covertMenuNode(menu, menuList)).collect(Collectors.toList());
-// }
private MenuNode covertMenuNode(Menu menu, List<Menu> menuList) {
MenuNode node = new MenuNode();
@@ -78,7 +68,7 @@
return node;
}
- public boolean updateMenu(Long menuId,MenuParam param) {
+ public boolean updateMenu(Long menuId, MenuParam param) {
Menu one = getById(menuId);
if (one == null) {
throw new BusinessException("鎵句笉鍒拌彍鍗曚俊鎭�");
@@ -86,18 +76,20 @@
List<Role> roles = SpringContextHolder.getBean(RoleService.class).listByAdminId(SecurityUtils.getUserId());
Integer roleLevel = roles.stream().map(Role::getLevel).min(Integer::compareTo).orElse(RoleLevelStatus.COMMON.getCode());
- if(!RoleLevelStatus.SUPER.getCode().equals(roleLevel)){
+ if (!RoleLevelStatus.SUPER.getCode().equals(roleLevel)) {
throw new BusinessException("瓒呯骇绠$悊鍛樻墠鍙互缂栬緫鑿滃崟");
}
Menu menu = new Menu();
- BeanUtils.copyProperties(param,menu);
+ BeanUtils.copyProperties(param, menu);
+ menu.setType(one.getType());
menu.setId(menuId);
return updateById(menu);
}
public List<MenuNode> treeList() {
- List<Menu> list = list();
+ LambdaQueryWrapper<Menu> menuLambdaQueryWrapper = Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSeq);
+ List<Menu> list = list(menuLambdaQueryWrapper);
return list.stream()
.filter(menu -> menu.getPid().equals(0L))
.map(menu -> covertMenuNode(menu, list)).collect(Collectors.toList());
@@ -111,9 +103,31 @@
List<Role> roles = SpringContextHolder.getBean(RoleService.class).listByAdminId(SecurityUtils.getUserId());
Integer roleLevel = roles.stream().map(Role::getLevel).min(Integer::compareTo).orElse(RoleLevelStatus.COMMON.getCode());
- if(!RoleLevelStatus.SUPER.getCode().equals(roleLevel)){
+ if (!RoleLevelStatus.SUPER.getCode().equals(roleLevel)) {
throw new BusinessException("瓒呯骇绠$悊鍛樻墠鍙互鍒犻櫎鑿滃崟");
}
- return removeById(menuId);
+ List<Long> list = menuMapper.listMenuIfBinding(menuId);
+ List<Long> list1 = menuMapper.listMenuIfBinding1(menuId);
+
+ if (list.size() == 0 && list1.size() == 0) {
+ return removeById(menuId);
+ } else {
+ throw new BusinessException("鑿滃崟姝e湪浣跨敤锛岃鍕垮垹闄�");
+ }
+
+ }
+
+ /**
+ * 閫氳繃鑿滃崟ID闆嗗悎鑾峰彇鑿滃崟瀹炰綋鍒楄〃
+ *
+ * @param menuIds 鑿滃崟ID闆嗗悎
+ */
+ public List<MenuNode> getUserPermissionListById(List<Long> menuIds) {
+ List<Menu> menuList = menuMapper.getUserPermissionListById(menuIds);
+
+ List<MenuNode> resultList = menuList.stream()
+ .filter(menu -> menu.getPid().equals(0L))
+ .map(menu -> covertMenuNode(menu, menuList)).collect(Collectors.toList());
+ return resultList;
}
}
--
Gitblit v1.9.3