Search in sources :

Example 1 with MenuTree

use of com.albedo.java.modules.sys.domain.vo.MenuTree in project albedo by somowhere.

the class MenuServiceImpl method buildMenus.

/**
 * 两层循环实现建树
 *
 * @param menuTreeList 传入的树节点列表
 * @return
 */
public List<MenuTree> buildMenus(List<MenuTree> menuTreeList) {
    menuTreeList.forEach(menu -> {
        if (menu != null) {
            List<MenuTree> menuChildList = menu.getChildren();
            if (CollUtil.isNotEmpty(menuChildList)) {
                menu.setAlwaysShow(true);
                menu.setRedirect("noredirect");
                menu.setChildren(buildMenus(menuChildList));
            // 处理是一级菜单并且没有子菜单的情况
            } else if (TreeUtil.ROOT.equals(menu.getParentId())) {
                MenuTree menuVo = new MenuTree();
                menuVo.setMeta(menu.getMeta());
                // 非外链
                if (!CommonConstants.YES.equals(menu.getIframe())) {
                    menuVo.setPath("index");
                    menuVo.setName(menu.getName());
                    menuVo.setComponent(menu.getComponent());
                } else {
                    menuVo.setPath(menu.getPath());
                }
                menu.setName(null);
                menu.setMeta(null);
                menu.setComponent("Layout");
                menu.setChildren(Lists.newArrayList(menuVo));
            }
        }
    });
    return menuTreeList;
}
Also used : MenuTree(com.albedo.java.modules.sys.domain.vo.MenuTree)

Example 2 with MenuTree

use of com.albedo.java.modules.sys.domain.vo.MenuTree in project albedo by somowhere.

the class MenuServiceImpl method findTreeByUserId.

@Override
@Transactional(readOnly = true, rollbackFor = Exception.class)
public List<MenuTree> findTreeByUserId(Long userId) {
    CacheKey cacheKey = new MenuCacheKeyBuilder().key("findTreeByUserId", userId);
    return cacheOps.get(cacheKey, (k) -> {
        // 获取符合条件的菜单
        Set<MenuVo> all = new HashSet<>();
        roleRepository.findListByUserId(userId).forEach(role -> all.addAll(findListByRoleId(role.getId())));
        List<MenuTree> menuTreeList = all.stream().filter(menuVo -> !MenuDto.TYPE_BUTTON.equals(menuVo.getType())).sorted(Comparator.comparingInt(MenuVo::getSort)).map(MenuTree::new).collect(Collectors.toList());
        return buildMenus(Lists.newArrayList(TreeUtil.buildByLoopAutoRoot(menuTreeList)));
    });
}
Also used : MenuVo(com.albedo.java.modules.sys.domain.vo.MenuVo) MenuTree(com.albedo.java.modules.sys.domain.vo.MenuTree) MenuCacheKeyBuilder(com.albedo.java.modules.sys.cache.MenuCacheKeyBuilder) MenuSortDto(com.albedo.java.modules.sys.domain.dto.MenuSortDto) MenuRepository(com.albedo.java.modules.sys.repository.MenuRepository) ObjectUtil(com.albedo.java.common.core.util.ObjectUtil) ArgumentAssert(com.albedo.java.common.core.util.ArgumentAssert) GenSchemeDto(com.albedo.java.modules.sys.domain.dto.GenSchemeDto) CollUtil(com.albedo.java.common.core.util.CollUtil) EntityExistException(com.albedo.java.common.core.exception.EntityExistException) MenuDo(com.albedo.java.modules.sys.domain.MenuDo) SysCacheUtil(com.albedo.java.modules.sys.util.SysCacheUtil) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) CharUtil(cn.hutool.core.util.CharUtil) RoleMenuRepository(com.albedo.java.modules.sys.repository.RoleMenuRepository) RoleRepository(com.albedo.java.modules.sys.repository.RoleRepository) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo) Set(java.util.Set) MenuTree(com.albedo.java.modules.sys.domain.vo.MenuTree) CommonConstants(com.albedo.java.common.core.constant.CommonConstants) CacheKeyBuilder(com.albedo.java.common.core.cache.model.CacheKeyBuilder) StringUtil(com.albedo.java.common.core.util.StringUtil) Collectors(java.util.stream.Collectors) MenuVo(com.albedo.java.modules.sys.domain.vo.MenuVo) List(java.util.List) AbstractTreeCacheServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.AbstractTreeCacheServiceImpl) TreeUtil(com.albedo.java.common.core.util.tree.TreeUtil) BizException(com.albedo.java.common.core.exception.BizException) MenuDto(com.albedo.java.modules.sys.domain.dto.MenuDto) AllArgsConstructor(lombok.AllArgsConstructor) Comparator(java.util.Comparator) MenuService(com.albedo.java.modules.sys.service.MenuService) Transactional(org.springframework.transaction.annotation.Transactional) MenuCacheKeyBuilder(com.albedo.java.modules.sys.cache.MenuCacheKeyBuilder) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MenuTree (com.albedo.java.modules.sys.domain.vo.MenuTree)2 CharUtil (cn.hutool.core.util.CharUtil)1 CacheKey (com.albedo.java.common.core.cache.model.CacheKey)1 CacheKeyBuilder (com.albedo.java.common.core.cache.model.CacheKeyBuilder)1 CommonConstants (com.albedo.java.common.core.constant.CommonConstants)1 BizException (com.albedo.java.common.core.exception.BizException)1 EntityExistException (com.albedo.java.common.core.exception.EntityExistException)1 ArgumentAssert (com.albedo.java.common.core.util.ArgumentAssert)1 CollUtil (com.albedo.java.common.core.util.CollUtil)1 ObjectUtil (com.albedo.java.common.core.util.ObjectUtil)1 StringUtil (com.albedo.java.common.core.util.StringUtil)1 TreeUtil (com.albedo.java.common.core.util.tree.TreeUtil)1 MenuCacheKeyBuilder (com.albedo.java.modules.sys.cache.MenuCacheKeyBuilder)1 MenuDo (com.albedo.java.modules.sys.domain.MenuDo)1 RoleMenuDo (com.albedo.java.modules.sys.domain.RoleMenuDo)1 GenSchemeDto (com.albedo.java.modules.sys.domain.dto.GenSchemeDto)1 MenuDto (com.albedo.java.modules.sys.domain.dto.MenuDto)1 MenuSortDto (com.albedo.java.modules.sys.domain.dto.MenuSortDto)1 MenuVo (com.albedo.java.modules.sys.domain.vo.MenuVo)1 MenuRepository (com.albedo.java.modules.sys.repository.MenuRepository)1