From dda268997ca8f8a364f7c19b45d7a43a50a98efe Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期二, 25 十月 2022 18:00:11 +0800
Subject: [PATCH] changes
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/MenuService.java | 55 +++++++++++++++++++++++++++----------------------------
1 files changed, 27 insertions(+), 28 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 5bb34e4..4c16ac4 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
@@ -1,29 +1,24 @@
package com.sandu.ximon.admin.service;
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;
-import com.sandu.common.execption.EntityExistException;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.param.MenuParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.bo.MenuNode;
-import com.sandu.ximon.dao.domain.AdminRoleRelation;
import com.sandu.ximon.dao.domain.Menu;
import com.sandu.ximon.dao.domain.Role;
import com.sandu.ximon.dao.domain.RoleMenuRelation;
-import com.sandu.ximon.dao.mapper.AdminRoleRelationMapper;
import com.sandu.ximon.dao.mapper.MenuMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
-import java.util.Collections;
import java.util.List;
-import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -35,40 +30,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);
- menu.setPermission(param.getRouterName());
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();
@@ -86,6 +68,10 @@
throw new BusinessException("鎵句笉鍒拌彍鍗曚俊鎭�");
}
+ if (one.getPid() == 0 && param.getPid() != 0) {
+ throw new BusinessException("鐩綍宸叉槸鏈�椤跺眰鑿滃崟,鏃犳硶璁剧疆涓婄骇鐩綍 !");
+ }
+
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)) {
@@ -94,19 +80,18 @@
Menu menu = new Menu();
BeanUtils.copyProperties(param, menu);
- menu.setPermission(param.getRouterName());
+ 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());
}
-
- private MenuMapper menuMapper;
public boolean delMenu(Long menuId) {
Menu one = getById(menuId);
@@ -129,4 +114,18 @@
}
}
+
+ /**
+ * 閫氳繃鑿滃崟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