From fef2ce23b76b9cf84b4105669ad2ffa48741a573 Mon Sep 17 00:00:00 2001 From: stylefeng Date: Fri, 30 Aug 2024 11:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.3.0=E3=80=91=E3=80=90rule=E3=80=91?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=80=E4=B8=AApids=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rule/tree/buildpids/PidParseUtil.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 kernel-a-rule/src/main/java/cn/stylefeng/roses/kernel/rule/tree/buildpids/PidParseUtil.java 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; + } + +}