From adc270d0ef02b0da455aed054cf7acd442b8e108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E7=8B=BC=E8=93=9D=E5=A4=A9?= Date: Fri, 1 Nov 2024 11:19:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=A0=B9=E6=8D=AE=E8=A7=92=E8=89=B2=E6=9D=83?= =?UTF-8?q?=E9=99=90=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../harmony/mapper/SystemMapper.java | 4 +- .../service/impl/SystemServiceImpl.java | 54 ++++--------------- 2 files changed, 13 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/guaiguailang/harmony/mapper/SystemMapper.java b/src/main/java/com/guaiguailang/harmony/mapper/SystemMapper.java index 84783fe..7ef67d4 100644 --- a/src/main/java/com/guaiguailang/harmony/mapper/SystemMapper.java +++ b/src/main/java/com/guaiguailang/harmony/mapper/SystemMapper.java @@ -10,6 +10,6 @@ import java.util.List; @Mapper public interface SystemMapper { List getAllMenus(); - @Select("SELECT * from menu_data_item") - List getMenus(); + @Select("SELECT * from menu_data_item where id in (select system_role_menu.menu_id from system_role_menu where role_id=#{roleId})") + List getMenus(String roleId); } diff --git a/src/main/java/com/guaiguailang/harmony/service/impl/SystemServiceImpl.java b/src/main/java/com/guaiguailang/harmony/service/impl/SystemServiceImpl.java index 6f0d3c3..18b085d 100644 --- a/src/main/java/com/guaiguailang/harmony/service/impl/SystemServiceImpl.java +++ b/src/main/java/com/guaiguailang/harmony/service/impl/SystemServiceImpl.java @@ -1,10 +1,13 @@ package com.guaiguailang.harmony.service.impl; +import cn.dev33.satoken.stp.StpUtil; import com.guaiguailang.harmony.domain.entity.MenuDataItem; import com.guaiguailang.harmony.domain.entity.SystemMenu; +import com.guaiguailang.harmony.domain.entity.UserInfo; import com.guaiguailang.harmony.domain.vo.MenuVO; import com.guaiguailang.harmony.domain.vo.ResponseResult; import com.guaiguailang.harmony.mapper.SystemMapper; +import com.guaiguailang.harmony.mapper.UserMapper; import com.guaiguailang.harmony.service.SystemService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; @@ -19,54 +22,19 @@ import java.util.stream.Collectors; public class SystemServiceImpl implements SystemService { private final SystemMapper systemMapper; + private final UserMapper userMapper; - public SystemServiceImpl(SystemMapper systemMapper) { + public SystemServiceImpl(SystemMapper systemMapper, UserMapper userMapper) { this.systemMapper = systemMapper; + this.userMapper = userMapper; } -// // 备份旧的方法 -// public ResponseResult getMenu() { -// // 获取所有激活的状态菜单 -// List menus = systemMapper.getAllMenus(); -// Map menuMap = new HashMap<>(); -// List rootMenus = new ArrayList<>(); -// // 第一步:将SystemMenu转换为MenuVO并存储在map中 -// for (SystemMenu menu : menus) { -// MenuVO menuVO = new MenuVO(); -// menuVO.setId(menu.getId()); -// menuVO.setTitle(menu.getTitle()); -// menuVO.setKey(menu.getKey()); -// menuVO.setName(menu.getName()); -// menuVO.setComponent(menu.getComponent()); -// menuVO.setRedirect(menu.getRedirect()); -// menuVO.setIcon(menu.getIcon()); -// menuVO.setStatus(menu.getStatus()); -// menuVO.setOrder(menu.getOrder()); -// menuVO.setParent(menu.getParent()); -// menuMap.put(menu.getName(), menuVO); -// } -// // 第二步:构建树形结构 -// for (MenuVO menuVO : menuMap.values()) { -// String parentId = menuVO.getParent(); -// if (parentId == null) { -// // 没有父菜单,即为根菜单 -// rootMenus.add(menuVO); -// } else { -// // 查找父菜单并添加到其子菜单列表中 -// MenuVO parentMenuVO = menuMap.get(parentId); -// if (parentMenuVO != null) { -// if (parentMenuVO.getChildren() == null) { -// parentMenuVO.setChildren(new ArrayList<>()); -// } -// parentMenuVO.getChildren().add(menuVO); -// } -// } -// } -// return ResponseResult.success(rootMenus); -// } - public ResponseResult getMenu() { + // 获取用户角色 + Long uid = Long.parseLong(StpUtil.getLoginId().toString()); + UserInfo userInfo = userMapper.getUserById(uid); // 获取所有激活的状态菜单 - List menus = systemMapper.getMenus(); + List menus = systemMapper.getMenus(userInfo.getRoleId()); + return ResponseResult.success(menus); }