mirror of https://gitee.com/stylefeng/roses
【8.3.0】【tree】更新pids计算,填充子节点的方法
parent
116476a873
commit
1d51be9bf8
|
@ -0,0 +1 @@
|
||||||
|
## 树组件的操作
|
|
@ -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>
|
|
@ -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 {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测是否变化了parentId,如果变化了parentId则需要更新子节点的子节点的pids
|
||||||
|
* <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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将字符串类型的pid结构,解析成Long类型List
|
* 将字符串类型的pid结构,解析成Long类型List
|
|
@ -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();
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue