diff --git a/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/tree/buildpids/PidParseUtil.java b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/tree/buildpids/PidParseUtil.java new file mode 100644 index 000000000..f83c03540 --- /dev/null +++ b/kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/tree/buildpids/PidParseUtil.java @@ -0,0 +1,46 @@ +package cn.stylefeng.roses.kernel.rule.tree.buildpids; + +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.StrUtil; + +import java.util.ArrayList; +import java.util.List; + +/** + * 解析pids这种树形结构 + * + * @author fengshuonan + * @since 2024/8/30 11:10 + */ +public class PidParseUtil { + + /** + * 将字符串类型的pid结构,解析成Long类型List + * + * @author fengshuonan + * @since 2024/8/30 11:12 + */ + public static List parseToPidList(String pidListString) { + + List result = new ArrayList<>(); + + if (StrUtil.isBlank(pidListString)) { + return result; + } + + // 去掉中括号符号 + pidListString = pidListString.replaceAll("\\[", ""); + pidListString = pidListString.replaceAll("]", ""); + + // 解析出来所有的id列表 + String[] pidStringList = pidListString.split(","); + + // 查找到缺失的父级id + for (String idString : pidStringList) { + result.add(Convert.toLong(idString)); + } + + return result; + } + +}