From d62137b7fcb7170da9445d412c5085736948d87d Mon Sep 17 00:00:00 2001 From: Lemon <1599456917@qq.com> Date: Mon, 3 Mar 2025 16:42:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=A2=9E=E5=BC=BA=E5=8C=85?= =?UTF-8?q?=E5=90=AB=20=E4=B8=8D=E5=8C=85=E5=90=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/el/ContainsExpressionFunction.java | 46 +++++++++++++++++++ .../flowable/core/util/SimpleModelUtils.java | 9 +++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/el/ContainsExpressionFunction.java diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/el/ContainsExpressionFunction.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/el/ContainsExpressionFunction.java new file mode 100644 index 0000000000..f343336fbd --- /dev/null +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/el/ContainsExpressionFunction.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.bpm.framework.flowable.core.el; + +import org.flowable.common.engine.api.variable.VariableContainer; +import org.flowable.common.engine.impl.el.function.AbstractFlowableVariableExpressionFunction; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class ContainsExpressionFunction extends AbstractFlowableVariableExpressionFunction { + + public ContainsExpressionFunction() { + super("contains"); + } + + public static boolean contains(VariableContainer variableContainer, String variableName, Object paramValue) { + Object variable = variableContainer.getVariable(variableName); + if (variable instanceof List list) { + Object convertedValue = convertParamValue(list, paramValue); + return list.contains(convertedValue); + } + return false; + } + + private static Object convertParamValue(List list, Object paramValue) { + if (list.isEmpty()) { + return paramValue; + } + Object firstElement = list.get(0); + if (firstElement instanceof String) { + return paramValue.toString(); + } else if (firstElement instanceof Number) { + try { + if (firstElement instanceof Integer) { + return Integer.parseInt(paramValue.toString()); + } else if (firstElement instanceof Long) { + return Long.parseLong(paramValue.toString()); + } + // 其他数值类型处理... + } catch (NumberFormatException e) { + return paramValue; // 转换失败,保持原样 + } + } + return paramValue; + } +} \ No newline at end of file diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java index e32d93ceb0..2d783e0063 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java @@ -671,7 +671,14 @@ public class SimpleModelUtils { List list = CollectionUtils.convertList(item.getRules(), (rule) -> { String rightSide = NumberUtil.isNumber(rule.getRightSide()) ? rule.getRightSide() : "\"" + rule.getRightSide() + "\""; // 如果非数值类型加引号 - return String.format(" %s %s var:convertByType(%s,%s)", rule.getLeftSide(), rule.getOpCode(), rule.getLeftSide(), rightSide); + System.out.println(rule.getOpCode()); + if ("contains".equals(rule.getOpCode())) { + return String.format("var:contains(%s, %s)", rule.getLeftSide(), rightSide); + } else if ("notContains".equals(rule.getOpCode())) { + return String.format("!var:contains(%s, %s)", rule.getLeftSide(), rightSide); + } else { + return String.format(" %s %s var:convertByType(%s,%s)", rule.getLeftSide(), rule.getOpCode(), rule.getLeftSide(), rightSide); + } }); // 构造条件组的表达式 Boolean and = item.getAnd();