Skip to content

Commit

Permalink
Merge pull request #19 from little3201/develop
Browse files Browse the repository at this point in the history
升级版本0.1.3, 优化子节点构造逻辑;
  • Loading branch information
little3201 authored Jul 22, 2021
2 parents df94de9 + 378112c commit fc8c8ac
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ leafage 开源项目的公共模块,提供通用工具和抽象接口;

leafage-basic下 assets 和 hypervisor 两个服务必须的依赖项目, 提供:

- BasicService: 基础业务接口;
- BasicService, ReactiveBasicService: 基础业务接口;
- AbstractBasicService: 抽象接口,提供随机代码生成逻辑方法;
- FileBasicUtils: 文件操作工具类;
- FileBasicUtils: 文件操作工具类;
- TreeNode, ServletTreeNodeAware, ReactiveTreeNodeAware操作接口;
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>leafage-common</artifactId>
<version>0.1.2</version>
<version>0.1.3</version>
<packaging>jar</packaging>

<name>leafage-common</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,31 @@ default Flux<TreeNode> children(T superior, Flux<T> children, Set<String> 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();
}

/**
Expand Down
39 changes: 20 additions & 19 deletions src/main/java/top/leafage/common/servlet/ServletTreeNodeAware.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,33 @@ default List<TreeNode> children(T superior, List<T> children, Set<String> 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();
}

/**
Expand Down

0 comments on commit fc8c8ac

Please sign in to comment.