|
@@ -1,6 +1,5 @@
|
|
|
package org.hswebframework.web.crud.service;
|
|
|
|
|
|
-import org.hswebframework.ezorm.core.param.QueryParam;
|
|
|
import org.hswebframework.ezorm.rdb.mapping.defaults.SaveResult;
|
|
|
import org.hswebframework.utils.RandomUtil;
|
|
|
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
|
|
@@ -13,6 +12,8 @@ import reactor.core.publisher.Flux;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -30,13 +31,17 @@ public interface ReactiveTreeSortEntityService<E extends TreeSortSupportEntity<K
|
|
|
default Mono<List<E>> queryResultToTree(QueryParamEntity paramEntity) {
|
|
|
return query(paramEntity)
|
|
|
.collectList()
|
|
|
- .map(list -> TreeSupportEntity.list2tree(list, this::setChildren, this::isRootNode));
|
|
|
+ .map(list -> TreeSupportEntity.list2tree(list,
|
|
|
+ this::setChildren,
|
|
|
+ this::createRootNodePredicate));
|
|
|
}
|
|
|
|
|
|
default Mono<List<E>> queryIncludeChildrenTree(QueryParamEntity paramEntity) {
|
|
|
return queryIncludeChildren(paramEntity)
|
|
|
.collectList()
|
|
|
- .map(list -> TreeSupportEntity.list2tree(list, this::setChildren, this::isRootNode));
|
|
|
+ .map(list -> TreeSupportEntity.list2tree(list,
|
|
|
+ this::setChildren,
|
|
|
+ this::createRootNodePredicate));
|
|
|
}
|
|
|
|
|
|
default Flux<E> queryIncludeChildren(Collection<K> idList) {
|
|
@@ -115,6 +120,19 @@ public interface ReactiveTreeSortEntityService<E extends TreeSortSupportEntity<K
|
|
|
return entity.getChildren();
|
|
|
}
|
|
|
|
|
|
+ default Predicate<E> createRootNodePredicate(TreeSupportEntity.TreeHelper<E, K> helper) {
|
|
|
+ return node -> {
|
|
|
+ if (isRootNode(node)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ //有父节点,但是父节点不存在
|
|
|
+ if (!StringUtils.isEmpty(node.getParentId())) {
|
|
|
+ return helper.getNode(node.getParentId()) == null;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
default boolean isRootNode(E entity) {
|
|
|
return StringUtils.isEmpty(entity.getParentId()) || "-1".equals(String.valueOf(entity.getParentId()));
|
|
|
}
|