mirror of https://gitee.com/stylefeng/roses
【8.3.0】【rule】更新pids计算的工具
parent
fef2ce23b7
commit
ae760ae09a
|
@ -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
|
||||
* <p>
|
||||
* 如果pid是顶级节点,pids就是 [-1],
|
||||
* <p>
|
||||
* 如果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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
Loading…
Reference in New Issue