/** * Resource转Easy UI Menu * * @param resource * @param isCascade 是否递归遍历子节点 * @return * @throws DaoException * @throws SystemException * @throws ServiceException */ public Menu resourceToMenu(Resource resource, boolean isCascade) throws DaoException, SystemException, ServiceException { Assert.notNull(resource, "参数resource不能为空"); if (ResourceState.menu.getValue().equals(resource.getType())) { Menu menu = new Menu(); menu.setId(resource.getId().toString()); menu.setText(resource.getName()); menu.setHref(resource.getUrl()); if (isCascade) { List<Menu> childrenMenus = Lists.newArrayList(); for (Resource subResource : resource.getSubResources()) { if (ResourceState.menu.getValue().equals(subResource.getType())) { childrenMenus.add(resourceToMenu(subResource, true)); } } menu.setChildren(childrenMenus); } return menu; } return null; }
public List<Menu> getAppMenusByUserId(Long userId) { List<Menu> menus = Lists.newArrayList(); List<Resource> resources = Lists.newArrayList(); User user = userManager.loadById(userId); User superUser = userManager.getSuperUser(); if (user != null && superUser != null && user.getId() == superUser.getId()) { // 超级用户 resources = super.getAll(); } else if (user != null) { resources = getResourcesByUserId(userId); } for (Resource resource : resources) { if (StringUtils.isNotBlank(resource.getUrl())) { if (ResourceState.menu.getValue().equals(resource.getType())) { Menu menu = new Menu(); menu.setId(resource.getId().toString()); menu.setText(resource.getName()); menu.setHref(resource.getUrl()); menus.add(menu); } } } return menus; }