【8.3.0】【tree】更新pids计算,填充子节点的方法

master
stylefeng 2024-08-30 18:33:55 +08:00
parent 116476a873
commit 1d51be9bf8
8 changed files with 137 additions and 41 deletions

1
kernel-d-tree/README.md Normal file
View File

@ -0,0 +1 @@
## 树组件的操作

39
kernel-d-tree/pom.xml Normal file
View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.javaguns.roses</groupId>
<artifactId>roses-kernel</artifactId>
<version>8.3.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>kernel-d-tree</artifactId>
<packaging>jar</packaging>
<dependencies>
<!-- 基础依赖 -->
<dependency>
<groupId>com.javaguns.roses</groupId>
<artifactId>kernel-a-rule</artifactId>
<version>${roses.version}</version>
</dependency>
<!-- 数据库操作依赖,需要更新树节点的子节点 -->
<dependency>
<groupId>com.javaguns.roses</groupId>
<artifactId>db-api</artifactId>
<version>${roses.version}</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
</build>
</project>

View File

@ -1,5 +1,7 @@
package cn.stylefeng.roses.kernel.rule.pidset; 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.SymbolConstant;
import cn.stylefeng.roses.kernel.rule.constants.TreeConstants; 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.PidGetterService;
@ -42,4 +44,39 @@ public class CalcParentIdListUtil {
} }
/**
* parentIdparentIdpids
* <p>
* 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);
}
} }

View File

@ -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.convert.Convert;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -12,7 +12,7 @@ import java.util.List;
* @author fengshuonan * @author fengshuonan
* @since 2024/8/30 11:10 * @since 2024/8/30 11:10
*/ */
public class PidParseUtil { public class ParentIdParseUtil {
/** /**
* pidLongList * pidLongList

View File

@ -8,6 +8,14 @@ package cn.stylefeng.roses.kernel.rule.pidset.callback;
*/ */
public interface PidSettable { public interface PidSettable {
/**
* id
*
* @author fengshuonan
* @since 2024/8/30 17:16
*/
Long getCurrentId();
/** /**
* id * id
* *
@ -17,11 +25,19 @@ public interface PidSettable {
Long getParentId(); Long getParentId();
/** /**
* pid string * pids
* *
* @author fengshuonan * @author fengshuonan
* @since 2024/8/30 13:47 * @since 2024/8/30 13:47
*/ */
void setParentIdListString(String parentIdListString); void setParentIdListString(String parentIdListString);
/**
* pids
*
* @author fengshuonan
* @since 2024/8/30 17:14
*/
String getParentIdListString();
} }

View File

@ -76,6 +76,9 @@
<!--定时任务模块--> <!--定时任务模块-->
<module>kernel-d-timer</module> <module>kernel-d-timer</module>
<!--树节点操作-->
<module>kernel-d-tree</module>
<!--参数校验模块--> <!--参数校验模块-->
<module>kernel-d-validator</module> <module>kernel-d-validator</module>