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); }