Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
xiaozzzi 2023-12-19 15:38:28 +08:00
commit 67b7e4e301

View File

@ -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,23 +37,32 @@ public class DocUtil {
* @return 树状菜单对象
*/
public static List<DocTreeRes> treeWrap(List<DocTreeRes> list, boolean priorityType) {
final List<DocTreeRes> allList = list;
//查询根菜单
List<DocTreeRes> rootLevel =
allList.stream()
.filter(p -> p.getP().equals(ROOT_FOLDER_ID))
.sorted(Comparator.comparing(DocTreeRes::getS))
.sorted((d1, d2) -> {
if (priorityType) {
if (d2.getTy().equals(d1.getTy())) {
return d1.getS() - d2.getS();
}
return d2.getTy() - d1.getTy();
}
return SortUtil.intSort.compare(d1.getS(), d2.getS());
})
.collect(Collectors.toList());
rootLevel.parallelStream().forEach(item -> setChild(item, allList));
// 将原始列表进行分组 并排序每个分组的列表
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) -> {
if (priorityType) {
if (d2.getTy().equals(d1.getTy())) {
return d1.getS() - d2.getS();
}
return d2.getTy() - d1.getTy();
}
return SortUtil.intSort.compare(d1.getS(), d2.getS());
})
.collect(Collectors.toList());
return rootLevel;
}