From 5a3951654c9a74cfbf31a617ef6eb6ac1c0da719 Mon Sep 17 00:00:00 2001 From: liwenqiang Date: Sat, 20 Aug 2022 10:00:06 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1BasicVO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../top/leafage/common/basic/AbstractVO.java | 39 ------------- .../top/leafage/common/basic/BasicVO.java | 57 ------------------- 2 files changed, 96 deletions(-) delete mode 100644 src/main/java/top/leafage/common/basic/AbstractVO.java delete mode 100644 src/main/java/top/leafage/common/basic/BasicVO.java diff --git a/src/main/java/top/leafage/common/basic/AbstractVO.java b/src/main/java/top/leafage/common/basic/AbstractVO.java deleted file mode 100644 index 5aadb68..0000000 --- a/src/main/java/top/leafage/common/basic/AbstractVO.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 extends BasicVO { - - /** - * 修改时间 - */ - private LocalDateTime modifyTime; - - /** - * 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; - } - -} diff --git a/src/main/java/top/leafage/common/basic/BasicVO.java b/src/main/java/top/leafage/common/basic/BasicVO.java deleted file mode 100644 index 846a802..0000000 --- a/src/main/java/top/leafage/common/basic/BasicVO.java +++ /dev/null @@ -1,57 +0,0 @@ -package top.leafage.common.basic; - -/** - * 基础VO类 - * - * @author liwenqiang 2022/7/23 10:04 - * @since 0.1.9 - **/ -public class BasicVO { - - - /** - * 代码 - */ - 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; - } -} From 3aaa257e764853997d9ce694104e5227044a539c Mon Sep 17 00:00:00 2001 From: liwenqiang Date: Fri, 9 Dec 2022 23:14:32 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20getSuperior()=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ++-- .../java/top/leafage/common/ExcelReader.java | 4 +-- .../common/basic/AbstractTreeNodeService.java | 31 ++++++------------- .../top/leafage/common/basic/TreeNode.java | 7 +---- .../leafage/common/basic/ValidMessage.java | 29 ++++++----------- .../common/reactive/ReactiveBasicService.java | 1 + .../ServletAbstractTreeNodeService.java | 12 +++---- 7 files changed, 31 insertions(+), 59 deletions(-) diff --git a/pom.xml b/pom.xml index 5266ee6..68f3714 100644 --- a/pom.xml +++ b/pom.xml @@ -5,19 +5,19 @@ top.leafage leafage-starter-parent - 0.1.6 + 0.1.7 leafage-common - 0.1.9 + 0.1.10 jar leafage-common common for leafage - 5.2.2 + 5.2.3 diff --git a/src/main/java/top/leafage/common/ExcelReader.java b/src/main/java/top/leafage/common/ExcelReader.java index c2dd0bf..5aea3d2 100644 --- a/src/main/java/top/leafage/common/ExcelReader.java +++ b/src/main/java/top/leafage/common/ExcelReader.java @@ -1,6 +1,5 @@ package top.leafage.common; - import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.status.StatusLogger; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -9,6 +8,7 @@ import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; + import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; import java.io.File; @@ -150,7 +150,7 @@ private static T mapping(Row row, Class clazz) { writeData(t, cell, descriptor); } } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | - IntrospectionException e) { + IntrospectionException e) { log.error("对象映射异常!", e); return null; } diff --git a/src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java b/src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java index 8a3e8f3..02fb563 100644 --- a/src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java +++ b/src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java @@ -20,7 +20,6 @@ */ public abstract class AbstractTreeNodeService extends AbstractBasicService { - private static final String ID = "id"; private static final String NAME = "name"; private static final String CODE = "code"; private static final String SUPERIOR = "superior"; @@ -75,25 +74,6 @@ private void expand(TreeNode treeNode, Class clazz, T t, Set expand) } } - /** - * 获取ID - * - * @param t 对象 - * @param clazz 类型 - * @return ID - */ - protected Object getId(T t, Class clazz) { - Object superiorId = null; - try { - // ID是集成基础父类的,所以要通过superClass获取 - PropertyDescriptor superIdDescriptor = new PropertyDescriptor(ID, clazz.getSuperclass()); - superiorId = superIdDescriptor.getReadMethod().invoke(t); - } catch (IntrospectionException | IllegalAccessException | InvocationTargetException e) { - log.error("get id error.", e); - } - return superiorId; - } - /** * 获取name * @@ -140,8 +120,15 @@ protected Object getCode(T t, Class clazz) { private Object getSuperior(T t, Class clazz) { Object superior = null; try { - PropertyDescriptor superIdDescriptor = new PropertyDescriptor(SUPERIOR, clazz); - superior = superIdDescriptor.getReadMethod().invoke(t); + PropertyDescriptor superDescriptor = new PropertyDescriptor(SUPERIOR, clazz); + superior = superDescriptor.getReadMethod().invoke(t); + // superior code + if (Objects.nonNull(superior)) { + Class aClass = superior.getClass(); + PropertyDescriptor superCodeDescriptor = new PropertyDescriptor(CODE, aClass); + superior = superCodeDescriptor.getReadMethod().invoke(t); + } + } catch (IntrospectionException | IllegalAccessException | InvocationTargetException e) { log.error("get superior error.", e); } diff --git a/src/main/java/top/leafage/common/basic/TreeNode.java b/src/main/java/top/leafage/common/basic/TreeNode.java index 8ba9817..21eb335 100644 --- a/src/main/java/top/leafage/common/basic/TreeNode.java +++ b/src/main/java/top/leafage/common/basic/TreeNode.java @@ -1,7 +1,5 @@ package top.leafage.common.basic; -import java.io.Serial; -import java.io.Serializable; import java.util.List; import java.util.Map; @@ -10,10 +8,7 @@ * * @author liwenqiang 2021-07-02 17:18 */ -public class TreeNode implements Serializable { - - @Serial - private static final long serialVersionUID = 3977470984616592112L; +public class TreeNode { /** * 代码 diff --git a/src/main/java/top/leafage/common/basic/ValidMessage.java b/src/main/java/top/leafage/common/basic/ValidMessage.java index d840c08..5245f65 100644 --- a/src/main/java/top/leafage/common/basic/ValidMessage.java +++ b/src/main/java/top/leafage/common/basic/ValidMessage.java @@ -1,18 +1,12 @@ package top.leafage.common.basic; -import java.io.Serial; -import java.io.Serializable; - /** * 参数校验信息 * * @author liwenqiang 2022/4/13 17:13 * @since 0.1.8 **/ -public class ValidMessage implements Serializable { - - @Serial - private static final long serialVersionUID = 3385684846039604779L; +public abstract class ValidMessage { /** * code @@ -33,29 +27,24 @@ public class ValidMessage implements Serializable { * 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; + /** + * non null + */ + private static final String NON_NULL = " must not be null."; + /** + * code must not be null + */ + public static final String CODE_NOT_NULL = CODE + NON_NULL; } diff --git a/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java b/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java index 35cde22..2aa0ebc 100644 --- a/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java +++ b/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java @@ -2,6 +2,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; + import java.util.List; /** diff --git a/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java b/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java index 8f5f5c5..b313525 100644 --- a/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java +++ b/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java @@ -8,7 +8,6 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * For servlet to construct tree @@ -38,13 +37,14 @@ protected List convert(List children) { * @since 0.1.9 */ protected List convert(List children, Set expand) { - Stream stream = children.stream().map(child -> this.construct(child, expand)); - Map> listMap = stream.filter(node -> Objects.nonNull(node.getSuperior()) && + List nodeList = children.stream().map(child -> this.construct(child, expand)).toList(); + // group by node + Map> listMap = nodeList.stream().filter(node -> Objects.nonNull(node.getSuperior()) && !"0".equals(node.getSuperior())) .collect(Collectors.groupingBy(TreeNode::getSuperior)); - - stream.forEach(node -> node.setChildren(listMap.get(node.getCode()))); - return stream.filter(node -> Objects.isNull(node.getSuperior()) || "0".equals(node.getSuperior())) + // get children from grouped map + nodeList.forEach(node -> node.setChildren(listMap.get(node.getCode()))); + return nodeList.stream().filter(node -> Objects.isNull(node.getSuperior()) || "0".equals(node.getSuperior())) .collect(Collectors.toList()); } From 32416e890fd93cc59273680597ecef592a0b3eff Mon Sep 17 00:00:00 2001 From: liwenqiang Date: Thu, 22 Dec 2022 09:41:39 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E7=A7=BB=E9=99=A4package-info.java=20?= =?UTF-8?q?=E8=A1=A5=E5=85=85copyright?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 21 +++++++++++-- .../{basic => }/AbstractBasicService.java | 19 +++++++++++- .../{basic => }/AbstractTreeNodeService.java | 30 +++++++++++-------- .../java/top/leafage/common/ExcelReader.java | 17 +++++++++++ .../leafage/common/{basic => }/TreeNode.java | 19 +++++++++++- .../common/{basic => }/ValidMessage.java | 19 +++++++++++- .../java/top/leafage/common/package-info.java | 6 ---- .../ReactiveAbstractTreeNodeService.java | 21 +++++++++++-- .../common/reactive/ReactiveBasicService.java | 17 +++++++++++ .../ServletAbstractTreeNodeService.java | 21 +++++++++++-- .../common/servlet/ServletBasicService.java | 18 +++++++++-- 11 files changed, 178 insertions(+), 30 deletions(-) rename src/main/java/top/leafage/common/{basic => }/AbstractBasicService.java (69%) rename src/main/java/top/leafage/common/{basic => }/AbstractTreeNodeService.java (86%) rename src/main/java/top/leafage/common/{basic => }/TreeNode.java (75%) rename src/main/java/top/leafage/common/{basic => }/ValidMessage.java (60%) delete mode 100644 src/main/java/top/leafage/common/package-info.java diff --git a/pom.xml b/pom.xml index 68f3714..4b46cd0 100644 --- a/pom.xml +++ b/pom.xml @@ -1,16 +1,33 @@ + + 4.0.0 top.leafage leafage-starter-parent - 0.1.7 + 0.2.0 leafage-common - 0.1.10 + 0.2.0 jar leafage-common diff --git a/src/main/java/top/leafage/common/basic/AbstractBasicService.java b/src/main/java/top/leafage/common/AbstractBasicService.java similarity index 69% rename from src/main/java/top/leafage/common/basic/AbstractBasicService.java rename to src/main/java/top/leafage/common/AbstractBasicService.java index 9c1e262..b214fd7 100644 --- a/src/main/java/top/leafage/common/basic/AbstractBasicService.java +++ b/src/main/java/top/leafage/common/AbstractBasicService.java @@ -1,4 +1,21 @@ -package top.leafage.common.basic; +/* + * Copyright 2018-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package top.leafage.common; import java.security.SecureRandom; import java.time.LocalDate; diff --git a/src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java b/src/main/java/top/leafage/common/AbstractTreeNodeService.java similarity index 86% rename from src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java rename to src/main/java/top/leafage/common/AbstractTreeNodeService.java index 02fb563..dc8b0f0 100644 --- a/src/main/java/top/leafage/common/basic/AbstractTreeNodeService.java +++ b/src/main/java/top/leafage/common/AbstractTreeNodeService.java @@ -1,5 +1,21 @@ -package top.leafage.common.basic; +/* + * Copyright 2018-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package top.leafage.common; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.status.StatusLogger; @@ -134,16 +150,4 @@ private Object getSuperior(T t, Class clazz) { } return superior; } - - /** - * 检查是否上下级节点 - * - * @param superiorId 上级节点ID - * @param child 对象实例 - * @return true-是,false-否 - */ - protected boolean check(Object superiorId, T child) { - Object superior = this.getSuperior(child, child.getClass()); - return superiorId.equals(superior); - } } diff --git a/src/main/java/top/leafage/common/ExcelReader.java b/src/main/java/top/leafage/common/ExcelReader.java index 5aea3d2..9994b25 100644 --- a/src/main/java/top/leafage/common/ExcelReader.java +++ b/src/main/java/top/leafage/common/ExcelReader.java @@ -1,3 +1,20 @@ +/* + * Copyright 2018-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package top.leafage.common; import org.apache.logging.log4j.Logger; diff --git a/src/main/java/top/leafage/common/basic/TreeNode.java b/src/main/java/top/leafage/common/TreeNode.java similarity index 75% rename from src/main/java/top/leafage/common/basic/TreeNode.java rename to src/main/java/top/leafage/common/TreeNode.java index 21eb335..d2206a6 100644 --- a/src/main/java/top/leafage/common/basic/TreeNode.java +++ b/src/main/java/top/leafage/common/TreeNode.java @@ -1,4 +1,21 @@ -package top.leafage.common.basic; +/* + * Copyright 2018-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package top.leafage.common; import java.util.List; import java.util.Map; diff --git a/src/main/java/top/leafage/common/basic/ValidMessage.java b/src/main/java/top/leafage/common/ValidMessage.java similarity index 60% rename from src/main/java/top/leafage/common/basic/ValidMessage.java rename to src/main/java/top/leafage/common/ValidMessage.java index 5245f65..dcce0b1 100644 --- a/src/main/java/top/leafage/common/basic/ValidMessage.java +++ b/src/main/java/top/leafage/common/ValidMessage.java @@ -1,4 +1,21 @@ -package top.leafage.common.basic; +/* + * Copyright 2018-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package top.leafage.common; /** * 参数校验信息 diff --git a/src/main/java/top/leafage/common/package-info.java b/src/main/java/top/leafage/common/package-info.java deleted file mode 100644 index e53b4aa..0000000 --- a/src/main/java/top/leafage/common/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * common interfaces or methods with webmvc and webflux - * - * @author liwenqiang 2019/10/23 9:51 - **/ -package top.leafage.common; \ No newline at end of file diff --git a/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java b/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java index 610b6e3..b935f55 100644 --- a/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java +++ b/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java @@ -1,9 +1,26 @@ +/* + * Copyright 2018-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + 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 top.leafage.common.AbstractTreeNodeService; +import top.leafage.common.TreeNode; import java.util.List; import java.util.Map; diff --git a/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java b/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java index 2aa0ebc..b92113a 100644 --- a/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java +++ b/src/main/java/top/leafage/common/reactive/ReactiveBasicService.java @@ -1,3 +1,20 @@ +/* + * Copyright 2018-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package top.leafage.common.reactive; import reactor.core.publisher.Flux; diff --git a/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java b/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java index b313525..cafc174 100644 --- a/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java +++ b/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java @@ -1,7 +1,24 @@ +/* + * Copyright 2018-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package top.leafage.common.servlet; -import top.leafage.common.basic.AbstractTreeNodeService; -import top.leafage.common.basic.TreeNode; +import top.leafage.common.AbstractTreeNodeService; +import top.leafage.common.TreeNode; import java.util.List; import java.util.Map; diff --git a/src/main/java/top/leafage/common/servlet/ServletBasicService.java b/src/main/java/top/leafage/common/servlet/ServletBasicService.java index 8b7d92f..d3c9f5b 100644 --- a/src/main/java/top/leafage/common/servlet/ServletBasicService.java +++ b/src/main/java/top/leafage/common/servlet/ServletBasicService.java @@ -1,6 +1,20 @@ /* - * Copyright (c) 2019. Abeille All Right Reserved. + * Copyright 2018-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * */ + package top.leafage.common.servlet; import java.util.Collections; @@ -87,7 +101,7 @@ default V modify(C code, D d) { * 批量保存 * * @param dList 实例集合 - * @return an array containing the elements of this list + * @return an list containing the elements of this list */ default List saveAll(List dList) { return Collections.emptyList(); From 6e932964e4cb6bac7a913e1b4be8ca4f2a2e5eaa Mon Sep 17 00:00:00 2001 From: liwenqiang Date: Wed, 4 Jan 2023 21:05:15 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20convert()=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/AbstractTreeNodeService.java | 20 +++++++++++----- .../ReactiveAbstractTreeNodeService.java | 23 ++++++------------- .../ServletAbstractTreeNodeService.java | 20 ++++------------ 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/main/java/top/leafage/common/AbstractTreeNodeService.java b/src/main/java/top/leafage/common/AbstractTreeNodeService.java index dc8b0f0..3cd69c3 100644 --- a/src/main/java/top/leafage/common/AbstractTreeNodeService.java +++ b/src/main/java/top/leafage/common/AbstractTreeNodeService.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,8 @@ 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; +import java.util.*; +import java.util.stream.Collectors; /** * Construct tree @@ -50,7 +48,7 @@ public abstract class AbstractTreeNodeService extends AbstractBasicService { * @return TreeNode 对象 * @since 0.1.7 */ - protected TreeNode construct(T t, Set expand) { + protected TreeNode node(T t, Set expand) { Class childClass = t.getClass(); Object code = this.getCode(t, childClass); Object name = this.getName(t, childClass); @@ -65,6 +63,16 @@ protected TreeNode construct(T t, Set expand) { return treeNode; } + protected List nodes(List treeNodes) { + Map> listMap = treeNodes.stream().filter(node -> Objects.nonNull(node.getSuperior()) && + !"0".equals(node.getSuperior())) + .collect(Collectors.groupingBy(TreeNode::getSuperior)); + // get children from grouped map + treeNodes.forEach(node -> node.setChildren(listMap.get(node.getCode()))); + return treeNodes.stream().filter(node -> Objects.isNull(node.getSuperior()) || "0".equals(node.getSuperior())) + .collect(Collectors.toList()); + } + /** * 扩展数据 * diff --git a/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java b/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java index b935f55..b457882 100644 --- a/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java +++ b/src/main/java/top/leafage/common/reactive/ReactiveAbstractTreeNodeService.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,7 @@ import top.leafage.common.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 @@ -41,9 +38,9 @@ public abstract class ReactiveAbstractTreeNodeService extends AbstractTreeNod * * @param children 子节点 * @return 树节点数据集 - * @since 0.1.9 + * @since 0.2.0 */ - protected Flux convert(Flux children) { + protected Mono> convert(Flux children) { return this.convert(children, null); } @@ -53,18 +50,12 @@ protected Flux convert(Flux children) { * @param children 子节点 * @param expand 扩展属性 * @return 树节点数据集 - * @since 0.1.9 + * @since 0.2.0 */ - protected Flux convert(Flux children, Set expand) { - Flux nodesFlux = children.map(child -> this.construct(child, expand)); - Mono>> mapMono = nodesFlux.filter(node -> Objects.nonNull(node.getSuperior()) && - !"0".equals(node.getSuperior())) - .collect(Collectors.groupingBy(TreeNode::getSuperior)); + protected Mono> convert(Flux children, Set expand) { + Flux nodesFlux = children.map(child -> this.node(child, expand)); - return nodesFlux.zipWith(mapMono, (node, map) -> { - node.setChildren(map.get(node.getCode())); - return node; - }).filter(node -> Objects.isNull(node.getSuperior()) || "0".equals(node.getSuperior())); + return nodesFlux.collectList().map(this::nodes); } } diff --git a/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java b/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java index cafc174..b3b4918 100644 --- a/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java +++ b/src/main/java/top/leafage/common/servlet/ServletAbstractTreeNodeService.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,7 @@ import top.leafage.common.TreeNode; import java.util.List; -import java.util.Map; -import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; /** * For servlet to construct tree @@ -39,7 +36,7 @@ public abstract class ServletAbstractTreeNodeService extends AbstractTreeNode * * @param children 子节点 * @return 树节点数据集 - * @since 0.1.9 + * @since 0.2.0 */ protected List convert(List children) { return this.convert(children, null); @@ -51,18 +48,11 @@ protected List convert(List children) { * @param children 子节点 * @param expand 扩展属性 * @return 树节点数据集 - * @since 0.1.9 + * @since 0.2.0 */ protected List convert(List children, Set expand) { - List nodeList = children.stream().map(child -> this.construct(child, expand)).toList(); - // group by node - Map> listMap = nodeList.stream().filter(node -> Objects.nonNull(node.getSuperior()) && - !"0".equals(node.getSuperior())) - .collect(Collectors.groupingBy(TreeNode::getSuperior)); - // get children from grouped map - nodeList.forEach(node -> node.setChildren(listMap.get(node.getCode()))); - return nodeList.stream().filter(node -> Objects.isNull(node.getSuperior()) || "0".equals(node.getSuperior())) - .collect(Collectors.toList()); + List treeNodes = children.stream().map(child -> this.node(child, expand)).toList(); + return this.nodes(treeNodes); } } From 8099959c1fd1e4df80e83f8503f1e09f60969d6f Mon Sep 17 00:00:00 2001 From: liwenqiang Date: Wed, 4 Jan 2023 21:06:58 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/top/leafage/common/AbstractTreeNodeService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/top/leafage/common/AbstractTreeNodeService.java b/src/main/java/top/leafage/common/AbstractTreeNodeService.java index 3cd69c3..3f9abe7 100644 --- a/src/main/java/top/leafage/common/AbstractTreeNodeService.java +++ b/src/main/java/top/leafage/common/AbstractTreeNodeService.java @@ -46,7 +46,7 @@ public abstract class AbstractTreeNodeService extends AbstractBasicService { * @param t 实例数据 * @param expand 扩展字段 * @return TreeNode 对象 - * @since 0.1.7 + * @since 0.2.0 */ protected TreeNode node(T t, Set expand) { Class childClass = t.getClass(); @@ -63,6 +63,13 @@ protected TreeNode node(T t, Set expand) { return treeNode; } + /** + * 转换并设置 TreeNode + * + * @param treeNodes TreeNode 对象 + * @return TreeNode 对象集合 + * @since 0.2.0 + */ protected List nodes(List treeNodes) { Map> listMap = treeNodes.stream().filter(node -> Objects.nonNull(node.getSuperior()) && !"0".equals(node.getSuperior())) From 241f9ba02dec2ddc0f625c74a27be3b4ffddf568 Mon Sep 17 00:00:00 2001 From: liwenqiang Date: Wed, 4 Jan 2023 22:18:33 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20getSuperior()=20?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../top/leafage/common/AbstractTreeNodeService.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/top/leafage/common/AbstractTreeNodeService.java b/src/main/java/top/leafage/common/AbstractTreeNodeService.java index 3f9abe7..0a47a6a 100644 --- a/src/main/java/top/leafage/common/AbstractTreeNodeService.java +++ b/src/main/java/top/leafage/common/AbstractTreeNodeService.java @@ -126,15 +126,15 @@ protected Object getName(T t, Class clazz) { /** * 获取code * - * @param t 对象 + * @param obj 实例 * @param clazz 类型 * @return code */ - protected Object getCode(T t, Class clazz) { + protected Object getCode(Object obj, Class clazz) { Object code = null; try { PropertyDescriptor superIdDescriptor = new PropertyDescriptor(CODE, clazz); - code = superIdDescriptor.getReadMethod().invoke(t); + code = superIdDescriptor.getReadMethod().invoke(obj); } catch (IntrospectionException | IllegalAccessException | InvocationTargetException e) { log.error("get code error.", e); } @@ -155,9 +155,7 @@ private Object getSuperior(T t, Class clazz) { superior = superDescriptor.getReadMethod().invoke(t); // superior code if (Objects.nonNull(superior)) { - Class aClass = superior.getClass(); - PropertyDescriptor superCodeDescriptor = new PropertyDescriptor(CODE, aClass); - superior = superCodeDescriptor.getReadMethod().invoke(t); + superior = this.getCode(superior, superior.getClass()); } } catch (IntrospectionException | IllegalAccessException | InvocationTargetException e) {