diff --git a/src/com/engine/organization/util/tree/SearchTreeUtil.java b/src/com/engine/organization/util/tree/SearchTreeUtil.java index 3bc9891a..60b7ce31 100644 --- a/src/com/engine/organization/util/tree/SearchTreeUtil.java +++ b/src/com/engine/organization/util/tree/SearchTreeUtil.java @@ -35,7 +35,7 @@ public class SearchTreeUtil { // 排序,设置是否为叶子节点 List collect = treeList.stream().peek(item -> item.setIsParent(CollectionUtils.isNotEmpty(item.getSubs())) - ).sorted(Comparator.comparing(item -> Integer.parseInt(item.getId()))).collect(Collectors.toList()); + ).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(collect)) { treeDatas.addAll(collect); } @@ -87,14 +87,16 @@ public class SearchTreeUtil { * @return */ public static List builderTreeMode(List treeList) { - List sortedList = treeList.stream().sorted(Comparator.comparing(SearchTree::getOrderNum)).collect(Collectors.toList()); - Map> collects = sortedList.stream().collect(Collectors.groupingBy(TreeNode::getPid)); + Map> collects = treeList.stream().collect(Collectors.groupingBy(TreeNode::getPid)); Set leafIds = new HashSet<>(); - List collect = sortedList.stream().peek(e -> { - e.setSubs(collects.get(e.getId())); - leafIds.add(e.getId()); - if (CollectionUtils.isNotEmpty(e.getSubs())) { - e.setIsParent(true); + List collect = treeList.stream().peek(e -> { + if (null != collects && CollectionUtils.isNotEmpty(collects.get(e.getId()))) { + List nodes = collects.get(e.getId()).stream().sorted(Comparator.comparing(item -> null == item.getOrderNum() ? 0 : item.getOrderNum())).collect(Collectors.toList()); + e.setSubs(nodes); + leafIds.add(e.getId()); + if (CollectionUtils.isNotEmpty(e.getSubs())) { + e.setIsParent(true); + } } }).collect(Collectors.toList()); return collect.stream().filter(item -> !leafIds.contains(item.getPid())).collect(Collectors.toList()); @@ -113,17 +115,15 @@ public class SearchTreeUtil { boolean isAdd = !childMap.isEmpty(); Set leafIds = new HashSet<>(); List collect = treeList.stream().peek(e -> { - Set treeNodes = new HashSet<>(); + Set treeNodes = new LinkedHashSet<>(); + if (isAdd && CollectionUtils.isNotEmpty(childMap.get(e.getId()))) { + List searchTrees = childMap.get(e.getId()).stream().sorted(Comparator.comparing(SearchTree::getOrderNum)).collect(Collectors.toList()); + treeNodes.addAll(searchTrees); + } List nodes = parentMap.get(e.getId()); if (CollectionUtils.isNotEmpty(nodes)) { treeNodes.addAll(nodes); } - if (isAdd && CollectionUtils.isNotEmpty(childMap.get(e.getId()))) { - treeNodes.addAll(childMap.get(e.getId())); - } - if (CollectionUtils.isNotEmpty(e.getSubs())) { - treeNodes.addAll(e.getSubs()); - } e.setSubs(new ArrayList<>(treeNodes)); leafIds.add(e.getId()); }).collect(Collectors.toList()); @@ -153,4 +153,8 @@ public class SearchTreeUtil { public static boolean isTop(Long pid) { return null == pid; } + + public static boolean isTop(Integer pid) { + return null == pid; + } }