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