修改 获取菜单根据角色权限获取
This commit is contained in:
parent
b87db3cef4
commit
adc270d0ef
@ -10,6 +10,6 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface SystemMapper {
|
||||
List<SystemMenu> getAllMenus();
|
||||
@Select("SELECT * from menu_data_item")
|
||||
List<MenuDataItem> 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<MenuDataItem> getMenus(String roleId);
|
||||
}
|
||||
|
@ -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<SystemMenu> menus = systemMapper.getAllMenus();
|
||||
// Map<String, MenuVO> menuMap = new HashMap<>();
|
||||
// List<MenuVO> 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<MenuDataItem> menus = systemMapper.getMenus();
|
||||
List<MenuDataItem> menus = systemMapper.getMenus(userInfo.getRoleId());
|
||||
|
||||
return ResponseResult.success(menus);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user