UEL表达式:
Flowable使用UEL进行表达式解析。UEL代表Unified Expression Language,是EE6规范的一部分。它是一种占位符,让我们可以在代码中动态的给它赋值。它可以用于Java服务任务(Java Service task)、执行监听器(Execution Listener)、任务监听器(Task Listener) 与 条件顺序流(Conditional sequence flow)等。
UEL表达式有两种方式:UEL-value和UEL-method.
UEL-value:解析为一个值
`
参数可以在流程实例开启时传入,也可以在流程流转过程中传入
HashMap<String, Object> map = new HashMap<>();
map.put("userId", userId);
map.put("amount", amount);
ProcessInstance instance =runtimeService.startProcessInstanceByKey("reimbursement", map);
Map<String, Object> variables = new HashMap<>();
variables.put("approved", passed);
taskService.complete(task.getId(), variables);
UEL-method:调用一个方法
在使用UEL-method时,需要先将method注册到流程引擎配置的beans中,ProcessEngineConfiguration中的beans参数是一个map。当配置这个参数时,只有在这个map中声明的bean可以在表达式与脚本中使用。bean会使用你在map中指定的名字暴露。
使用
先创建一个类,定义表达式中需要用的方法
package com.example.demo.function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FunctionService {
private static final Logger log = LoggerFactory.getLogger(FunctionService.class);
public String getAssignee(String value){
return "哈哈";
}
public boolean isNeedExtraExamine(String amount){
return Integer.parseInt(amount)>500;
}
public void taskComplate(){
log.info("任务完成");
}
}
将该类注册到ProcessEngineConfiguration
package com.example.demo.config;
import com.example.demo.function.FunctionService;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {
@Override
public void configure(SpringProcessEngineConfiguration engineConfiguration) {
Map map=new HashMap();
map.put("khl_test", new FunctionService());
engineConfiguration.setBeans(map);
}
}
在表达式中使用
注意:
如果UEL表达式中的流程变量名不存在则报错。
如果UEL表达式中的流程变量值为空null,流程不按UEL表达式去执行,而是流程结束。
如果UEL表达式都不符合条件,流程结束
如果连线不设置条件,会走flow序号小的那条线,将bpmn文件后缀名改成xml就可以看到flow的序号了