diff --git a/pom.xml b/pom.xml
index e0a8c1b..479b308 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,20 +5,19 @@
top.leafage
leafage-starter-parent
- 0.1.1
+ 0.1.3
leafage-common
- 0.1.5
+ 0.1.8
jar
leafage-common
common for leafage
- 11
- 5.0.0
+ 5.2.2
diff --git a/src/main/java/top/leafage/common/ExcelReader.java b/src/main/java/top/leafage/common/ExcelReader.java
index aca7864..c2dd0bf 100644
--- a/src/main/java/top/leafage/common/ExcelReader.java
+++ b/src/main/java/top/leafage/common/ExcelReader.java
@@ -1,14 +1,14 @@
package top.leafage.common;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.status.StatusLogger;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.io.File;
@@ -26,17 +26,18 @@
* 读取excel文件,并解析为指定类型的对象
*
* @author liwenqiang 2021/8/26 9:37
+ * @since 0.1.4
*/
public class ExcelReader {
- private ExcelReader() {
- }
-
- private static final Logger log = LoggerFactory.getLogger(ExcelReader.class);
+ private static final Logger log = StatusLogger.getLogger();
private static final String XLS = ".xls";
private static final String XLSX = ".xlsx";
+ private ExcelReader() {
+ }
+
/**
* 根据文件后缀名类型获取对应的工作簿对象
*
@@ -167,6 +168,9 @@ private static T mapping(Row row, Class clazz) {
private static void writeData(T t, Cell cell, PropertyDescriptor descriptor) {
try {
switch (cell.getCellType()) {
+ case BLANK: // 空字符串
+ case _NONE: // null
+ break;
case NUMERIC: // 数字
descriptor.getWriteMethod().invoke(t, cell.getNumericCellValue());
break;
diff --git a/src/main/java/top/leafage/common/basic/AbstractBasicService.java b/src/main/java/top/leafage/common/basic/AbstractBasicService.java
index 9a35d2a..9c1e262 100644
--- a/src/main/java/top/leafage/common/basic/AbstractBasicService.java
+++ b/src/main/java/top/leafage/common/basic/AbstractBasicService.java
@@ -6,6 +6,12 @@
import java.util.Collections;
import java.util.List;
+/**
+ * Product random code
+ *
+ * @author liwenqiang 2020-10-06 22:09
+ * @since 0.1.0
+ */
public abstract class AbstractBasicService {
private static final List SEED_LIST = Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
diff --git a/src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java b/src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java
index e455936..a04a8a9 100644
--- a/src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java
+++ b/src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java
@@ -1,14 +1,22 @@
package top.leafage.common.basic;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+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;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
+/**
+ * Construct tree
+ *
+ * @author liwenqiang 2021-07-21 20:08
+ * @since 0.1.3
+ */
public abstract class AbstractTreeNodeService extends AbstractBasicService {
private static final String ID = "id";
@@ -16,7 +24,30 @@ public abstract class AbstractTreeNodeService extends AbstractBasicService {
private static final String CODE = "code";
private static final String SUPERIOR = "superior";
- private static final Logger log = LoggerFactory.getLogger(AbstractTreeNodeService.class);
+ private static final Logger log = StatusLogger.getLogger();
+
+ /**
+ * 构造 TreeNode 对象
+ *
+ * @param superiorCode superior code
+ * @param t 实例数据
+ * @param expand 扩展字段
+ * @return TreeNode 对象
+ * @since 0.1.7
+ */
+ protected TreeNode construct(Object superiorCode, T t, Set expand) {
+ Class> childClass = t.getClass();
+ Object code = this.getCode(t, childClass);
+ Object name = this.getName(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);
+
+ // deal expand
+ this.expand(treeNode, childClass, t, expand);
+ return treeNode;
+ }
/**
* 扩展数据
@@ -26,15 +57,15 @@ public abstract class AbstractTreeNodeService extends AbstractBasicService {
* @param t 数据实例
* @param expand 扩展字段
*/
- protected void expand(TreeNode treeNode, Class> clazz, T t, Set expand) {
+ private void expand(TreeNode treeNode, Class> clazz, T t, Set expand) {
if (expand != null && !expand.isEmpty()) {
- Map map = new HashMap<>(expand.size());
+ Map map = new HashMap<>(expand.size());
expand.forEach(filed -> {
try {
PropertyDescriptor superIdDescriptor = new PropertyDescriptor(filed, clazz);
Object value = superIdDescriptor.getReadMethod().invoke(t);
- map.put(filed, value != null ? value.toString() : null);
+ map.put(filed, value);
} catch (IllegalAccessException | InvocationTargetException | IntrospectionException e) {
log.error("expand data error.", e);
}
diff --git a/src/main/java/top/leafage/common/basic/AbstractVO.java b/src/main/java/top/leafage/common/basic/AbstractVO.java
new file mode 100644
index 0000000..66eb4f1
--- /dev/null
+++ b/src/main/java/top/leafage/common/basic/AbstractVO.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2021. Leafage All Right Reserved.
+ */
+package top.leafage.common.basic;
+
+import java.time.LocalDateTime;
+
+/**
+ * Abstract vo
+ *
+ * @author liwenqiang 2020-10-06 22:09
+ * @since 0.1.6
+ */
+public abstract class AbstractVO {
+
+ /**
+ * 代码
+ */
+ private C code;
+
+ /**
+ * 修改时间
+ */
+ private LocalDateTime modifyTime;
+
+ public C getCode() {
+ return code;
+ }
+
+ public void setCode(C code) {
+ this.code = code;
+ }
+
+ public LocalDateTime getModifyTime() {
+ return modifyTime;
+ }
+
+ public void setModifyTime(LocalDateTime modifyTime) {
+ this.modifyTime = modifyTime;
+ }
+}
diff --git a/src/main/java/top/leafage/common/basic/TreeNode.java b/src/main/java/top/leafage/common/basic/TreeNode.java
index c1c9f83..79dc2b6 100644
--- a/src/main/java/top/leafage/common/basic/TreeNode.java
+++ b/src/main/java/top/leafage/common/basic/TreeNode.java
@@ -1,9 +1,17 @@
package top.leafage.common.basic;
+import java.io.Serializable;
import java.util.List;
import java.util.Map;
-public class TreeNode {
+/**
+ * Tree node
+ *
+ * @author liwenqiang 2021-07-02 17:18
+ */
+public class TreeNode implements Serializable {
+
+ private static final long serialVersionUID = 3977470984616592112L;
/**
* 代码
@@ -20,7 +28,7 @@ public class TreeNode {
/**
* 扩展属性
*/
- private Map expand;
+ private Map expand;
private List children;
@@ -41,7 +49,7 @@ public String getSuperior() {
return superior;
}
- public Map getExpand() {
+ public Map getExpand() {
return expand;
}
@@ -61,7 +69,7 @@ public void setSuperior(String superior) {
this.superior = superior;
}
- public void setExpand(Map expand) {
+ public void setExpand(Map expand) {
this.expand = expand;
}
diff --git a/src/main/java/top/leafage/common/basic/ValidMessage.java b/src/main/java/top/leafage/common/basic/ValidMessage.java
new file mode 100644
index 0000000..c52e68e
--- /dev/null
+++ b/src/main/java/top/leafage/common/basic/ValidMessage.java
@@ -0,0 +1,59 @@
+package top.leafage.common.basic;
+
+import java.io.Serializable;
+
+/**
+ * 参数校验信息
+ *
+ * @author liwenqiang 2022/4/13 17:13
+ * @since 0.1.8
+ **/
+public class ValidMessage implements Serializable {
+
+ private static final long serialVersionUID = 3385684846039604779L;
+
+ /**
+ * code
+ */
+ private static final String CODE = "code";
+
+ /**
+ * name
+ */
+ private static final String NAME = "name";
+
+ /**
+ * username
+ */
+ private static final String USERNAME = "username";
+
+ /**
+ * not blank
+ */
+ private static final String NOT_BLANK = " must not be blank.";
+
+ /**
+ * non null
+ */
+ private static final String NON_NULL = " must not be null.";
+
+ /**
+ * code must not be blank
+ */
+ public static final String CODE_NOT_BLANK = CODE + NOT_BLANK;
+
+ /**
+ * code must not be null
+ */
+ public static final String CODE_NOT_NULL = CODE + NON_NULL;
+
+ /**
+ * name must not be blank
+ */
+ public static final String NAME_NOT_BLANK = NAME + NOT_BLANK;
+
+ /**
+ * username must not be blank
+ */
+ public static final String USERNAME_NOT_BLANK = USERNAME + NOT_BLANK;
+}
diff --git a/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java b/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java
index 1b78511..6ae1dbe 100644
--- a/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java
+++ b/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java
@@ -5,6 +5,12 @@
import top.leafage.common.basic.TreeNode;
import java.util.Set;
+/**
+ * For reactive to construct tree
+ *
+ * @author liwenqiang 2021-07-21 20:08
+ * @since 0.1.3
+ */
public abstract class ReactiveAbstractTreeNodeService extends AbstractTreeNodeService {
/**
@@ -30,19 +36,10 @@ protected Flux children(T superior, Flux children, Set expa
Class> aClass = superior.getClass();
// ID是集成基础父类的,所以要通过superClass获取
Object superiorId = this.getId(superior, aClass);
- Object superiorName = this.getName(superior, aClass);
+ Object superiorCode = this.getCode(superior, aClass);
return children.filter(child -> this.check(superiorId, child)).flatMap(child -> {
- Class> childClass = child.getClass();
- Object code = this.getCode(child, childClass);
- Object name = this.getName(child, childClass);
-
- TreeNode treeNode = new TreeNode(code != null ? code.toString() : null,
- name != null ? name.toString() : null);
- treeNode.setSuperior(superiorName != null ? superiorName.toString() : null);
-
- // deal expand
- this.expand(treeNode, childClass, child, expand);
+ TreeNode treeNode = this.construct(superiorCode, child, expand);
return this.children(child, children, expand).collectList().map(treeNodes -> {
treeNode.setChildren(treeNodes);
diff --git a/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java b/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java
index 55c4807..35cde22 100644
--- a/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java
+++ b/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java
@@ -10,7 +10,8 @@
* V —— VO
* C —— code type
*
- * @author liwenqiang 2021/7/27 23:14
+ * @author liwenqiang 2021/7/20 23:14
+ * @since 0.1.2
**/
public interface ReactiveBasicService {
@@ -24,40 +25,7 @@ default Flux retrieve() {
}
/**
- * 分页获取entities
- *
- * @param page 页码
- * @param size 分页大小
- * @return a flux containing the elements of this list
- */
- default Flux retrieve(int page, int size) {
- return Flux.empty();
- }
-
- /**
- * 分页获取排序后的entities
- *
- * @param page 页码
- * @param size 分页大小
- * @param sort 排序字段
- * @return a flux containing the elements of this list
- */
- default Flux retrieve(int page, int size, String sort) {
- return Flux.empty();
- }
-
- /**
- * 名称是否存在
- *
- * @param name 名称
- * @return true-exist, false-not exist
- */
- default Mono exist(String name) {
- return Mono.empty();
- }
-
- /**
- * 根据code获取entity
+ * 根据code查询
*
* @param code 代码
* @return a element instanceof vo
@@ -67,16 +35,17 @@ default Mono fetch(C code) {
}
/**
- * 统计记录数
+ * 是否存在
*
- * @return the count of elements
+ * @param param 属性
+ * @return true-exist, false-not exist
*/
- default Mono count() {
+ default Mono exist(String param) {
return Mono.empty();
}
/**
- * 根据code删除entity
+ * 删除
*
* @param code 代码
* @return Void no return
@@ -96,7 +65,7 @@ default Mono removeAll(List dList) {
}
/**
- * 新增entity
+ * 添加
*
* @param d 实例
* @return a element instanceof vo
@@ -106,7 +75,7 @@ default Mono create(D d) {
}
/**
- * 编辑entity
+ * 修改
*
* @param code 代码
* @param d 实例
diff --git a/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java b/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java
index 563a7aa..364ce6d 100644
--- a/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java
+++ b/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java
@@ -6,6 +6,12 @@
import java.util.Set;
import java.util.stream.Collectors;
+/**
+ * For servlet to construct tree
+ *
+ * @author liwenqiang 2021-07-21 20:08
+ * @since 0.1.3
+ */
public abstract class ServletAbstractTreeNodeService extends AbstractTreeNodeService {
/**
@@ -30,19 +36,10 @@ protected List children(T superior, List children) {
protected List children(T superior, List children, Set expand) {
Class> aClass = superior.getClass();
Object superiorId = this.getId(superior, aClass);
- Object superiorName = this.getName(superior, aClass);
+ Object superiorCode = this.getCode(superior, aClass);
return children.stream().filter(child -> this.check(superiorId, child)).map(child -> {
- Class> childClass = child.getClass();
- Object code = this.getCode(child, childClass);
- Object name = this.getName(child, childClass);
-
- 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(treeNode, childClass, child, expand);
+ TreeNode treeNode = this.construct(superiorCode, child, expand);
treeNode.setChildren(this.children(child, children, expand));
diff --git a/src/main/java/top/leafage/common/servlet/ServletBasicService.java b/src/main/java/top/leafage/common/servlet/ServletBasicService.java
index bafa441..8b7d92f 100644
--- a/src/main/java/top/leafage/common/servlet/ServletBasicService.java
+++ b/src/main/java/top/leafage/common/servlet/ServletBasicService.java
@@ -12,7 +12,8 @@
* V —— VO
* C —— code type
*
- * @author liwenqiang 2018/7/27 23:14
+ * @author liwenqiang 2021/7/20 23:14
+ * @since 0.1.2
**/
public interface ServletBasicService {
@@ -26,7 +27,7 @@ default List retrieve() {
}
/**
- * 根据唯一标识获取
+ * 根据code查询
*
* @param code 代码
* @return a element instanceof vo
@@ -36,17 +37,17 @@ default V fetch(C code) {
}
/**
- * 名称是否存在
+ * 是否存在
*
- * @param name 名称
+ * @param param 名称
* @return true-exist, false-not exist
*/
- default boolean exist(String name) {
+ default boolean exist(String param) {
return false;
}
/**
- * 根据唯一标识删除entity
+ * 删除
*
* @param code 代码
*/
@@ -62,7 +63,7 @@ default void removeAll(List dList) {
}
/**
- * 添加对象
+ * 添加
*
* @param d 入参
* @return a element instanceof vo
@@ -72,7 +73,7 @@ default V create(D d) {
}
/**
- * 修改对象
+ * 修改
*
* @param code 唯一标识
* @param d 入参