|
@@ -6,6 +6,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import thyyxxk.webserver.entity.settings.IntergrationMenu;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* @description: 层级菜单工具
|
|
@@ -22,6 +24,28 @@ public class TreeUtil {
|
|
|
return ObjectTree(tempList, "id", "parentId", addCallback);
|
|
|
}
|
|
|
|
|
|
+ public static <T> List<T> ObjectSort(List<T> tempList, String sortName) {
|
|
|
+ String getSortName = "get" + StringUtil.getMethodName(sortName);
|
|
|
+ String getChildrenName = "get" + StringUtil.getMethodName("children");
|
|
|
+ String setChildrenName = "set" + StringUtil.getMethodName("children");
|
|
|
+ Stream<T> sorted = tempList
|
|
|
+ .stream()
|
|
|
+ .sorted((Comparator.comparing(a -> {
|
|
|
+ List<T> child = ReflectUtil.invoke(a, getChildrenName);
|
|
|
+ if (child != null && !child.isEmpty()) {
|
|
|
+ ReflectUtil.invoke(a, setChildrenName, ObjectSort(child, sortName));
|
|
|
+ }
|
|
|
+ Integer sort = ReflectUtil.invoke(a, getSortName);
|
|
|
+ if (sort == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return sort;
|
|
|
+ }
|
|
|
+ )));
|
|
|
+
|
|
|
+ return sorted.collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
public static <T> List<T> ObjectTree(List<T> tempList) {
|
|
|
return ObjectTree(tempList, "id", "parentId", null);
|
|
|
}
|