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 bd427e32f2..77b67a339d 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 @@ -692,7 +692,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();