diff --git a/kernel-d-tree/README.md b/kernel-d-tree/README.md new file mode 100644 index 000000000..2fe2e6be5 --- /dev/null +++ b/kernel-d-tree/README.md @@ -0,0 +1 @@ +## 树组件的操作 \ No newline at end of file diff --git a/kernel-d-tree/pom.xml b/kernel-d-tree/pom.xml new file mode 100644 index 000000000..7e36d44c6 --- /dev/null +++ b/kernel-d-tree/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + + com.javaguns.roses + roses-kernel + 8.3.0 + ../pom.xml + + + kernel-d-tree + + jar + + + + + + com.javaguns.roses + kernel-a-rule + ${roses.version} + + + + + com.javaguns.roses + db-api + ${roses.version} + + + + + + ${project.artifactId} + + diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/CalcParentIdListUtil.java b/kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/CalcParentIdListUtil.java similarity index 52% rename from kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/CalcParentIdListUtil.java rename to kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/CalcParentIdListUtil.java index 299e1cf29..e5a791a21 100644 --- a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/CalcParentIdListUtil.java +++ b/kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/CalcParentIdListUtil.java @@ -1,5 +1,7 @@ package cn.stylefeng.roses.kernel.rule.pidset; +import cn.hutool.extra.spring.SpringUtil; +import cn.stylefeng.roses.kernel.db.api.DbOperatorApi; 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; @@ -42,4 +44,39 @@ public class CalcParentIdListUtil { } + /** + * 检测是否变化了parentId,如果变化了parentId则需要更新子节点的子节点的pids + *

+ * 更新节点的所有子节点的pid_list_string集合 + * + * @author fengshuonan + * @since 2024/8/30 17:03 + */ + public static void updateParentIdStringList(String tableName, String pidsFieldName, + PidSettable oldItem, PidSettable newItem, PidGetterService pidGetterService) { + + if (oldItem == null || newItem == null) { + return; + } + + // 如果新旧pid都一样,则不需要更新 + if (oldItem.getParentId().equals(newItem.getParentId())) { + return; + } + + // 计算出来新的parentIdListString,并填充到新Item上 + fillParentIds(newItem, pidGetterService); + + // 计算出被更新的pids + String oldPids = oldItem.getParentIdListString(); + oldPids = oldPids + SymbolConstant.COMMA + SymbolConstant.LEFT_SQUARE_BRACKETS + oldItem.getCurrentId() + SymbolConstant.RIGHT_SQUARE_BRACKETS; + + // 将pids更改为新的pids + String newParentIds = newItem.getParentIdListString() + SymbolConstant.COMMA + SymbolConstant.LEFT_SQUARE_BRACKETS + newItem.getCurrentId() + SymbolConstant.RIGHT_SQUARE_BRACKETS; + + // 更新pids结构 + DbOperatorApi dbOperatorApi = SpringUtil.getBean(DbOperatorApi.class); + dbOperatorApi.updateSubParentIdListString(tableName, pidsFieldName, oldPids, newParentIds); + } + } diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/tree/buildpids/PidParseUtil.java b/kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/ParentIdParseUtil.java similarity index 92% rename from kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/tree/buildpids/PidParseUtil.java rename to kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/ParentIdParseUtil.java index f83c03540..09f8bb738 100644 --- a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/tree/buildpids/PidParseUtil.java +++ b/kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/ParentIdParseUtil.java @@ -1,4 +1,4 @@ -package cn.stylefeng.roses.kernel.rule.tree.buildpids; +package cn.stylefeng.roses.kernel.rule.pidset; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.StrUtil; @@ -12,7 +12,7 @@ import java.util.List; * @author fengshuonan * @since 2024/8/30 11:10 */ -public class PidParseUtil { +public class ParentIdParseUtil { /** * 将字符串类型的pid结构,解析成Long类型List diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidGetterService.java b/kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidGetterService.java similarity index 100% rename from kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidGetterService.java rename to kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidGetterService.java diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidSettable.java b/kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidSettable.java similarity index 58% rename from kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidSettable.java rename to kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidSettable.java index 8fc6697b6..9b1af9701 100644 --- a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidSettable.java +++ b/kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/callback/PidSettable.java @@ -8,6 +8,14 @@ package cn.stylefeng.roses.kernel.rule.pidset.callback; */ public interface PidSettable { + /** + * 获取当前节点的本身的id + * + * @author fengshuonan + * @since 2024/8/30 17:16 + */ + Long getCurrentId(); + /** * 获取当前节点的上级id * @@ -17,11 +25,19 @@ public interface PidSettable { Long getParentId(); /** - * 填充pid string的值 + * 填充pids的值 * * @author fengshuonan * @since 2024/8/30 13:47 */ void setParentIdListString(String parentIdListString); + /** + * 获取当前节点的pids值 + * + * @author fengshuonan + * @since 2024/8/30 17:14 + */ + String getParentIdListString(); + } diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/pojo/ParentIdInfoPojo.java b/kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/pojo/ParentIdInfoPojo.java similarity index 100% rename from kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/pojo/ParentIdInfoPojo.java rename to kernel-d-tree/src/main/java/cn/stylefeng/roses/kernel/rule/pidset/pojo/ParentIdInfoPojo.java diff --git a/pom.xml b/pom.xml index e0569475f..46c340fd6 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,9 @@ kernel-d-timer + + kernel-d-tree + kernel-d-validator @@ -318,48 +321,48 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + +