Skip to content

Commit

Permalink
Merge pull request #25 from little3201/develop
Browse files Browse the repository at this point in the history
更新版本:0.1.9;
  • Loading branch information
little3201 authored Nov 9, 2022
2 parents 1383c58 + c45e4a1 commit c8b7b97
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 71 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>top.leafage</groupId>
<artifactId>leafage-starter-parent</artifactId>
<version>0.1.3</version>
<version>0.1.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<artifactId>leafage-common</artifactId>
<version>0.1.8</version>
<version>0.1.9</version>
<packaging>jar</packaging>

<name>leafage-common</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.status.StatusLogger;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -29,20 +30,20 @@ public abstract class AbstractTreeNodeService<T> extends AbstractBasicService {
/**
* 构造 TreeNode 对象
*
* @param superiorCode superior code
* @param t 实例数据
* @param expand 扩展字段
* @param t 实例数据
* @param expand 扩展字段
* @return TreeNode 对象
* @since 0.1.7
*/
protected TreeNode construct(Object superiorCode, T t, Set<String> expand) {
protected TreeNode construct(T t, Set<String> expand) {
Class<?> childClass = t.getClass();
Object code = this.getCode(t, childClass);
Object name = this.getName(t, childClass);
Object superior = this.getSuperior(t, childClass);

TreeNode treeNode = new TreeNode(Objects.nonNull(code) ? String.valueOf(code) : null,
Objects.nonNull(name) ? String.valueOf(name) : null);
treeNode.setSuperior(Objects.nonNull(superiorCode) ? String.valueOf(superiorCode) : null);
treeNode.setSuperior(Objects.nonNull(superior) ? String.valueOf(superior) : null);

// deal expand
this.expand(treeNode, childClass, t, expand);
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/top/leafage/common/basic/AbstractVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,29 @@
* @author liwenqiang 2020-10-06 22:09
* @since 0.1.6
*/
public abstract class AbstractVO<C> {

/**
* 代码
*/
private C code;
public abstract class AbstractVO<C> extends BasicVO<C> {

/**
* 修改时间
*/
private LocalDateTime modifyTime;

public C getCode() {
return code;
}

public void setCode(C code) {
this.code = code;
}

/**
* modify time getter
*
* @return modify time
*/
public LocalDateTime getModifyTime() {
return modifyTime;
}

/**
* modify time setter
*
* @param modifyTime modify time
*/
public void setModifyTime(LocalDateTime modifyTime) {
this.modifyTime = modifyTime;
}

}
57 changes: 57 additions & 0 deletions src/main/java/top/leafage/common/basic/BasicVO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package top.leafage.common.basic;

/**
* 基础VO类
*
* @author liwenqiang 2022/7/23 10:04
* @since 0.1.9
**/
public class BasicVO<C> {


/**
* 代码
*/
private C code;

/**
* 名称
*/
private String name;

/**
* code getter
*
* @return C
*/
public C getCode() {
return code;
}

/**
* code setter
*
* @param code code of model
*/
public void setCode(C code) {
this.code = code;
}

/**
* name getter
*
* @return name
*/
public String getName() {
return name;
}

/**
* name setter
*
* @param name name of model
*/
public void setName(String name) {
this.name = name;
}
}
94 changes: 77 additions & 17 deletions src/main/java/top/leafage/common/basic/TreeNode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package top.leafage.common.basic;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
Expand All @@ -11,6 +12,7 @@
*/
public class TreeNode implements Serializable {

@Serial
private static final long serialVersionUID = 3977470984616592112L;

/**
Expand All @@ -29,50 +31,108 @@ public class TreeNode implements Serializable {
* 扩展属性
*/
private Map<String, Object> expand;

/**
* 子节点
*/
private List<TreeNode> children;

/**
* 构造方法
*
* @param code code
* @param name name
*/
public TreeNode(String code, String name) {
this.code = code;
this.name = name;
}

/**
* code getter
*
* @return code
*/
public String getCode() {
return code;
}

public String getName() {
return name;
}

public String getSuperior() {
return superior;
}

public Map<String, Object> getExpand() {
return expand;
}

public List<TreeNode> getChildren() {
return children;
}

/**
* code setter
*
* @param code code
*/
public void setCode(String code) {
this.code = code;
}

/**
* name getter
*
* @return name
*/
public String getName() {
return name;
}

/**
* name setter
*
* @param name name
*/
public void setName(String name) {
this.name = name;
}

/**
* superior getter
*
* @return superior
*/
public String getSuperior() {
return superior;
}

/**
* superior setter
*
* @param superior superior
*/
public void setSuperior(String superior) {
this.superior = superior;
}

/**
* expand getter
*
* @return expand
*/
public Map<String, Object> getExpand() {
return expand;
}

/**
* expand setter
*
* @param expand expand
*/
public void setExpand(Map<String, Object> expand) {
this.expand = expand;
}

/**
* children getter
*
* @return children
*/
public List<TreeNode> getChildren() {
return children;
}

/**
* children setter
*
* @param children children
*/
public void setChildren(List<TreeNode> children) {
this.children = children;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/top/leafage/common/basic/ValidMessage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package top.leafage.common.basic;

import java.io.Serial;
import java.io.Serializable;

/**
Expand All @@ -10,6 +11,7 @@
**/
public class ValidMessage implements Serializable {

@Serial
private static final long serialVersionUID = 3385684846039604779L;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package top.leafage.common.reactive;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import top.leafage.common.basic.AbstractTreeNodeService;
import top.leafage.common.basic.TreeNode;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
* For reactive to construct tree
Expand All @@ -16,36 +22,32 @@ public abstract class ReactiveAbstractTreeNodeService<T> extends AbstractTreeNod
/**
* 处理子节点
*
* @param superior 上级数据
* @param children 子节点
* @return 树节点数据集
* @since 0.1.9
*/
protected Flux<TreeNode> children(T superior, Flux<T> children) {
return this.children(superior, children, null);
protected Flux<TreeNode> convert(Flux<T> children) {
return this.convert(children, null);
}

/**
* 处理子节点
*
* @param superior 上级数据
* @param children 子节点
* @param expand 扩展属性
* @return 树节点数据集
* @since 0.1.9
*/
protected Flux<TreeNode> children(T superior, Flux<T> children, Set<String> expand) {
Class<?> aClass = superior.getClass();
// ID是集成基础父类的,所以要通过superClass获取
Object superiorId = this.getId(superior, aClass);
Object superiorCode = this.getCode(superior, aClass);

return children.filter(child -> this.check(superiorId, child)).flatMap(child -> {
TreeNode treeNode = this.construct(superiorCode, child, expand);
protected Flux<TreeNode> convert(Flux<T> children, Set<String> expand) {
Flux<TreeNode> nodesFlux = children.map(child -> this.construct(child, expand));
Mono<Map<String, List<TreeNode>>> mapMono = nodesFlux.filter(node -> Objects.nonNull(node.getSuperior()) &&
!"0".equals(node.getSuperior()))
.collect(Collectors.groupingBy(TreeNode::getSuperior));

return this.children(child, children, expand).collectList().map(treeNodes -> {
treeNode.setChildren(treeNodes);
return treeNode;
});
});
return nodesFlux.zipWith(mapMono, (node, map) -> {
node.setChildren(map.get(node.getCode()));
return node;
}).filter(node -> Objects.isNull(node.getSuperior()) || "0".equals(node.getSuperior()));
}

}
Loading

0 comments on commit c8b7b97

Please sign in to comment.