From ae760ae09a7a4b932056f522af65361cfc68a23c Mon Sep 17 00:00:00 2001 From: stylefeng Date: Fri, 30 Aug 2024 14:21:43 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.3.0=E3=80=91=E3=80=90rule=E3=80=91?= =?UTF-8?q?=E6=9B=B4=E6=96=B0pids=E8=AE=A1=E7=AE=97=E7=9A=84=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rule/pidset/CalcParentIdListUtil.java | 45 +++++++++++++++++++ .../pidset/callback/PidGetterService.java | 21 +++++++++ .../rule/pidset/callback/PidSettable.java | 27 +++++++++++ .../rule/pidset/pojo/ParentIdInfoPojo.java | 28 ++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/CalcParentIdListUtil.java create mode 100644 kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidGetterService.java create mode 100644 kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidSettable.java create mode 100644 kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/pojo/ParentIdInfoPojo.java diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/CalcParentIdListUtil.java b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/CalcParentIdListUtil.java new file mode 100644 index 000000000..299e1cf29 --- /dev/null +++ b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/CalcParentIdListUtil.java @@ -0,0 +1,45 @@ +package cn.stylefeng.roses.kernel.rule.pidset; + +import cn.stylefeng.roses.kernel.rule.constants.SymbolConstant; +import cn.stylefeng.roses.kernel.rule.constants.TreeConstants; +import cn.stylefeng.roses.kernel.rule.pidset.callback.PidGetterService; +import cn.stylefeng.roses.kernel.rule.pidset.callback.PidSettable; +import cn.stylefeng.roses.kernel.rule.pidset.pojo.ParentIdInfoPojo; + +/** + * pid和pids的填充计算 + * + * @author fengshuonan + * @since 2024/8/30 13:45 + */ +public class CalcParentIdListUtil { + + /** + * 填充该节点的pIds + *

+ * 如果pid是顶级节点,pids就是 [-1], + *

+ * 如果pid不是顶级节点,pids就是父节点的pids + [pid] + , + * + * @author fengshuonan + * @since 2024/8/30 13:45 + */ + public static void fillParentIds(PidSettable pidSettable, PidGetterService pidGetterService) { + + // 如果父级是-1,则代表顶级节点 + if (TreeConstants.DEFAULT_PARENT_ID.equals(pidSettable.getParentId())) { + pidSettable.setParentIdListString(SymbolConstant.LEFT_SQUARE_BRACKETS + TreeConstants.DEFAULT_PARENT_ID + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA); + } + + // 如果不是顶级节点,则查询到父级的id集合,再拼接上级id即可 + else { + // 获取父级的节点信息 + ParentIdInfoPojo pointNodePidInfo = pidGetterService.getPointNodePidInfo(pidSettable.getParentId()); + + // 设置本节点的父ids为 (上一个节点的pids + (上级节点的id) ) + pidSettable.setParentIdListString(pointNodePidInfo.getParentIdListString() + SymbolConstant.LEFT_SQUARE_BRACKETS + pointNodePidInfo.getId() + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA); + } + + } + +} diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidGetterService.java b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidGetterService.java new file mode 100644 index 000000000..b3c874011 --- /dev/null +++ b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidGetterService.java @@ -0,0 +1,21 @@ +package cn.stylefeng.roses.kernel.rule.pidset.callback; + +import cn.stylefeng.roses.kernel.rule.pidset.pojo.ParentIdInfoPojo; + +/** + * 获取指定item的详情(详情包含父级的pids信息) + * + * @author fengshuonan + * @since 2024/8/30 13:50 + */ +public interface PidGetterService { + + /** + * 获取指定节点的pids信息 + * + * @author fengshuonan + * @since 2024/8/30 13:50 + */ + ParentIdInfoPojo getPointNodePidInfo(Long itemId); + +} diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidSettable.java b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidSettable.java new file mode 100644 index 000000000..8fc6697b6 --- /dev/null +++ b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidSettable.java @@ -0,0 +1,27 @@ +package cn.stylefeng.roses.kernel.rule.pidset.callback; + +/** + * pid string填充回调 + * + * @author fengshuonan + * @since 2024/8/30 13:46 + */ +public interface PidSettable { + + /** + * 获取当前节点的上级id + * + * @author fengshuonan + * @since 2024/8/30 13:51 + */ + Long getParentId(); + + /** + * 填充pid string的值 + * + * @author fengshuonan + * @since 2024/8/30 13:47 + */ + void setParentIdListString(String parentIdListString); + +} diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/pojo/ParentIdInfoPojo.java b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/pojo/ParentIdInfoPojo.java new file mode 100644 index 000000000..46a358cf0 --- /dev/null +++ b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/pojo/ParentIdInfoPojo.java @@ -0,0 +1,28 @@ +package cn.stylefeng.roses.kernel.rule.pidset.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 父级id信息的获取 + * + * @author fengshuonan + * @since 2024/8/30 13:54 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ParentIdInfoPojo { + + /** + * 指定节点的id + */ + private Long id; + + /** + * 指定节点的父级id集合 + */ + private String parentIdListString; + +}