pref: 树状文件夹构造优化

This commit is contained in:
xiaozzzi 2024-03-14 15:52:19 +08:00
parent 3873322b83
commit 2ec331df72

View File

@ -1,7 +1,6 @@
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;
@ -10,11 +9,7 @@ import com.blossom.backend.server.folder.pojo.FolderEntity;
import com.blossom.common.base.enums.YesNo;
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.*;
import java.util.stream.Collectors;
/**
@ -37,14 +32,17 @@ public class DocUtil {
* @return 树状菜单对象
*/
public static List<DocTreeRes> treeWrap(List<DocTreeRes> list, boolean priorityType) {
// 将原始列表进行分组 并排序每个分组的列表
// 将原始列表进行分组, 并排序每个分组的列表
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()))){
if(item.getTy().equals(DocTypeEnum.A.getType())) {
return;
}
if (!CollUtil.isEmpty(pidMapping.get(item.getI()))){
item.setChildren(pidMapping.get(item.getI()));
}
});