diff --git a/README.md b/README.md index b73bc0d..ba2d0e6 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ leafage 开源项目的公共模块,提供通用工具和抽象接口; leafage-basic下 assets 和 hypervisor 两个服务必须的依赖项目, 提供: -- BasicService: 基础业务接口; +- BasicService, ReactiveBasicService: 基础业务接口; - AbstractBasicService: 抽象接口,提供随机代码生成逻辑方法; -- FileBasicUtils: 文件操作工具类; \ No newline at end of file +- FileBasicUtils: 文件操作工具类; +- TreeNode, ServletTreeNodeAware, ReactiveTreeNodeAware操作接口; \ No newline at end of file diff --git a/pom.xml b/pom.xml index f6fcc4f..4bb635e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ leafage-common - 0.1.2 + 0.1.3 jar leafage-common diff --git a/src/main/java/top/leafage/common/reactive/ReactiveTreeNodeAware.java b/src/main/java/top/leafage/common/reactive/ReactiveTreeNodeAware.java index 8572d85..0cc9b0e 100644 --- a/src/main/java/top/leafage/common/reactive/ReactiveTreeNodeAware.java +++ b/src/main/java/top/leafage/common/reactive/ReactiveTreeNodeAware.java @@ -33,34 +33,31 @@ default Flux children(T superior, Flux children, Set expand try { Object superiorId = aClass.getSuperclass().getMethod("getId").invoke(superior); Object superiorName = aClass.getMethod("getName").invoke(superior); - return children.filter(child -> this.check(superiorId, child)).flatMap(child -> { Class childClass = child.getClass(); try { - String code = childClass.getMethod("getCode").invoke(child).toString(); + Object code = childClass.getMethod("getCode").invoke(child); Object name = childClass.getMethod("getName").invoke(child); - TreeNode treeNode = new TreeNode(code, name != null ? name.toString() : null); + TreeNode treeNode = new TreeNode(code != null ? code.toString() : null, + name != null ? name.toString() : null); treeNode.setSuperior(superiorName != null ? superiorName.toString() : null); - this.children(child, children, expand).collectList().map(treeNodes -> { + // deal expand + this.expand(treeNode, childClass, child, expand); + + return this.children(child, children, expand).collectList().map(treeNodes -> { treeNode.setChildren(treeNodes); return treeNode; }); - // deal expand - this.expand(treeNode, childClass, child, expand); - - return Mono.just(treeNode); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); + return Mono.empty(); } - return Mono.empty(); }); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); + return Flux.empty(); } - return Flux.empty(); } /** diff --git a/src/main/java/top/leafage/common/servlet/ServletTreeNodeAware.java b/src/main/java/top/leafage/common/servlet/ServletTreeNodeAware.java index b40cf0f..ea69a14 100644 --- a/src/main/java/top/leafage/common/servlet/ServletTreeNodeAware.java +++ b/src/main/java/top/leafage/common/servlet/ServletTreeNodeAware.java @@ -33,32 +33,33 @@ default List children(T superior, List children, Set expand Class aClass = superior.getClass(); try { Long superiorId = (Long) aClass.getSuperclass().getMethod("getId").invoke(superior); - String superiorName = aClass.getMethod("getName").invoke(superior).toString(); + Object superiorName = aClass.getMethod("getName").invoke(superior); - return children.stream().filter(child -> this.check(superiorId, child)) - .map(child -> { - Class childClass = child.getClass(); - try { - String name = childClass.getMethod("getName").invoke(child).toString(); - String code = childClass.getMethod("getCode").invoke(child).toString(); + return children.stream().filter(child -> this.check(superiorId, child)).map(child -> { + Class childClass = child.getClass(); + try { + Object name = childClass.getMethod("getName").invoke(child); + Object code = childClass.getMethod("getCode").invoke(child); - TreeNode servletTreeNode = new TreeNode(code, name); - servletTreeNode.setSuperior(superiorName); - servletTreeNode.setChildren(this.children(child, children)); + TreeNode treeNode = new TreeNode(code == null ? null : code.toString(), + name == null ? null : name.toString()); + treeNode.setSuperior(superiorName == null ? null : superiorName.toString()); - // deal expand - this.expand(servletTreeNode, childClass, child, expand); + // deal expand + this.expand(treeNode, childClass, child, expand); - return servletTreeNode; - } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - } - return null; - }).collect(Collectors.toList()); + treeNode.setChildren(this.children(child, children, expand)); + + return treeNode; + } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { + e.printStackTrace(); + return null; + } + }).collect(Collectors.toList()); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { e.printStackTrace(); + return Collections.emptyList(); } - return Collections.emptyList(); } /**