| | |
| | | |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | 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(); |
| | |
| | | |
| | | Menu menu = new 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()); |
| | | } |
| | | |
| | | private MenuMapper menuMapper; |
| | | |
| | | public boolean delMenu(Long menuId) { |
| | | Menu one = getById(menuId); |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 通过菜单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; |
| | | } |
| | | } |