From afacb6534675ae008452e2362a365adf7bd20d25 Mon Sep 17 00:00:00 2001 From: little3201 Date: Wed, 21 Jul 2021 20:06:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC0.1.3?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=90=E8=8A=82=E7=82=B9=E6=9E=84=E9=80=A0?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++- pom.xml | 11 +++--- .../reactive/ReactiveTreeNodeAware.java | 21 +++++----- .../common/servlet/ServletTreeNodeAware.java | 39 ++++++++++--------- 4 files changed, 38 insertions(+), 38 deletions(-) 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..073e391 100644 --- a/pom.xml +++ b/pom.xml @@ -3,21 +3,22 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - top.leafage - leafage-starter-parent - 0.1.1 + org.springframework.boot + spring-boot-starter-parent + 2.4.6 + top.leafage leafage-common - 0.1.2 + 0.1.3 jar leafage-common common for leafage - 11 + 8 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(); } /** From 378112c7e231a910d095cdc3d0d1efca5054e60c Mon Sep 17 00:00:00 2001 From: little3201 Date: Wed, 21 Jul 2021 20:07:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=88=B0=200.1.3=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 073e391..4bb635e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,13 +3,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 2.4.6 + top.leafage + leafage-starter-parent + 0.1.1 - top.leafage leafage-common 0.1.3 jar @@ -18,7 +17,7 @@ common for leafage - 8 + 11