This commit is contained in:
zhangchenbiao
2023-06-29 10:27:33 +08:00
parent 21ed32a2b4
commit 573d60e97e
2 changed files with 16 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
@@ -21,6 +22,7 @@ import java.util.stream.Collectors;
*/
@Data
@ApiModel
@Slf4j
public class OpenAreaTreeVO {
@@ -48,6 +50,7 @@ public class OpenAreaTreeVO {
public static List<OpenAreaTreeVO> convertTree(List<HyOpenAreaInfoDO> allOpenArea, String keyword){
long startTime = System.currentTimeMillis();
List<HyOpenAreaInfoDO> firstArea = allOpenArea.stream().filter(o -> Objects.isNull(o.getParentId())).collect(Collectors.toList());
Map<Long, List<HyOpenAreaInfoDO>> openAreaParentMap = allOpenArea.stream().filter(o->Objects.nonNull(o.getParentId())).collect(Collectors.groupingBy(k -> k.getParentId()));
List<OpenAreaTreeVO> allTree = new ArrayList<>();
@@ -57,6 +60,7 @@ public class OpenAreaTreeVO {
node.setChildNode(childList);
allTree.add(node);
}
log.info("1#耗时:{}", System.currentTimeMillis() - startTime);
Map<Long, List<OpenAreaTreeVO>> childMap = allTree.stream().collect(Collectors.toMap(k -> k.getId(), v -> v.getChildNode()));
List<HyOpenAreaInfoDO> filterList = allOpenArea.stream().filter(o -> o.getAreaPath().contains(keyword)).collect(Collectors.toList());
Map<Long, HyOpenAreaInfoDO> openAreaMap = allOpenArea.stream().collect(Collectors.toMap(k -> k.getId(), Function.identity()));
@@ -72,6 +76,7 @@ public class OpenAreaTreeVO {
list.add(openAreaInfo);
}
}
log.info("2#耗时:{}", System.currentTimeMillis() - startTime);
List<OpenAreaTreeVO> resultList = new ArrayList<>();
List<HyOpenAreaInfoDO> filterFirstArea = list.stream().filter(o -> Objects.isNull(o.getParentId())).distinct().collect(Collectors.toList());
Map<Long, List<HyOpenAreaInfoDO>> filterOpenAreaParentMap = list.stream().filter(Objects::nonNull).filter(o->Objects.nonNull(o.getParentId())).collect(Collectors.groupingBy(k -> k.getParentId()));
@@ -84,6 +89,7 @@ public class OpenAreaTreeVO {
node.setChildNode(childList);
resultList.add(node);
}
log.info("2#耗时:{}", System.currentTimeMillis() - startTime);
return resultList;
}