Pre Merge pull request !1270 from Lemon/feature/bpm-节点增强
This commit is contained in:
commit
866153ff73
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -692,7 +692,14 @@ public class SimpleModelUtils {
|
|||
List<String> 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();
|
||||
|
|
Loading…
Reference in New Issue