mirror of
https://github.com/blossom-editor/blossom
synced 2024-11-17 22:48:03 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
67b7e4e301
@ -1,6 +1,7 @@
|
||||
package com.blossom.backend.server.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.blossom.backend.server.article.draft.pojo.ArticleEntity;
|
||||
import com.blossom.backend.server.doc.DocTypeEnum;
|
||||
@ -11,7 +12,9 @@ import com.blossom.common.base.util.SortUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -34,10 +37,19 @@ public class DocUtil {
|
||||
* @return 树状菜单对象
|
||||
*/
|
||||
public static List<DocTreeRes> treeWrap(List<DocTreeRes> list, boolean priorityType) {
|
||||
final List<DocTreeRes> allList = list;
|
||||
//查询根菜单
|
||||
List<DocTreeRes> rootLevel =
|
||||
allList.stream()
|
||||
// 将原始列表进行分组, 并排序每个分组的列表
|
||||
Map<Long, List<DocTreeRes>> pidMapping = list.stream().collect(
|
||||
Collectors.groupingBy(DocTreeRes::getP, HashMap::new,
|
||||
Collectors.collectingAndThen(Collectors.toList(),
|
||||
item -> item.stream().sorted(Comparator.comparingInt(DocTreeRes::getS)).collect(Collectors.toList()))));
|
||||
// 免递归方式赋值子菜单
|
||||
list.parallelStream().forEach(item -> {
|
||||
if (!CollectionUtil.isEmpty(pidMapping.get(item.getI()))){
|
||||
item.setChildren(pidMapping.get(item.getI()));
|
||||
}
|
||||
});
|
||||
// 查询根菜单
|
||||
List<DocTreeRes> rootLevel = list.stream()
|
||||
.filter(p -> p.getP().equals(ROOT_FOLDER_ID))
|
||||
.sorted(Comparator.comparing(DocTreeRes::getS))
|
||||
.sorted((d1, d2) -> {
|
||||
@ -50,7 +62,7 @@ public class DocUtil {
|
||||
return SortUtil.intSort.compare(d1.getS(), d2.getS());
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
rootLevel.parallelStream().forEach(item -> setChild(item, allList));
|
||||
|
||||
return rootLevel;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user