@MetaData(title = "树形表格数据") public HttpHeaders treeGridData() { Map<String, Menu> menuDatas = Maps.newLinkedHashMap(); String nodeid = this.getParameter("nodeid"); if (StringUtils.isNotBlank(nodeid)) { Menu parent = menuService.findOne(nodeid); List<Menu> children = menuService.findChildren(parent); for (Menu menu : children) { menu.addExtraAttribute("level", menu.getLevel()); menu.addExtraAttribute("parent", nodeid); menu.addExtraAttribute( "isLeaf", CollectionUtils.isEmpty(menuService.findChildren(menu)) ? true : false); menu.addExtraAttribute("expanded", false); menu.addExtraAttribute("loaded", true); menuDatas.put(menu.getId(), menu); } } else { GroupPropertyFilter groupFilter = GroupPropertyFilter.buildGroupFilterFromHttpRequest(entityClass, getRequest()); if (groupFilter.isEmpty()) { groupFilter.and(new PropertyFilter(MatchType.NU, "parent", true)); } List<Menu> menus = menuService.findByFilters(groupFilter, new Sort(Direction.DESC, "parent", "orderRank")); for (Menu menu : menus) { loopTreeGridData(menuDatas, menu, false); } } setModel(menuDatas.values()); return buildDefaultHttpHeaders(); }
private void loopTreeGridData(Map<String, Menu> menuDatas, Menu menu, boolean expanded) { Menu parent = menu.getParent(); if (parent != null && !menuDatas.containsKey(parent.getId())) { loopTreeGridData(menuDatas, parent, true); } List<Menu> children = menuService.findChildren(menu); menu.addExtraAttribute("level", menu.getLevel()); menu.addExtraAttribute("parent", parent == null ? "" : parent.getId()); menu.addExtraAttribute("isLeaf", CollectionUtils.isEmpty(children) ? true : false); menu.addExtraAttribute("expanded", expanded); menu.addExtraAttribute("loaded", true); menuDatas.put(menu.getId(), menu); }