activiti网关分支设置
设置流程图的网关
-
流程图配置实现:在流程图属性栏设置Condition属性值为网关的执行条件,eg:${choose}
-
流程图xml文件配置实现:在流程图对应的xml文件指定网关的执行条件
<process id="myProcess_1" isClosed="false" isExecutable="true" processType="None"> <startEvent id="_2" name="StartEvent"/> <userTask activiti:exclusive="true" id="_3" name="员工"/> <endEvent id="_4" name="EndEvent"/> <sequenceFlow id="_5" sourceRef="_2" targetRef="_3"/> <userTask activiti:exclusive="true" id="_7" name="部长"/> <userTask activiti:exclusive="true" id="_8" name="经理"/> <sequenceFlow id="_12" sourceRef="_8" targetRef="_4"/> <exclusiveGateway gatewayDirection="Unspecified" id="_6" name="ExclusiveGateway"/> <sequenceFlow id="_9" sourceRef="_3" targetRef="_6"/> <sequenceFlow id="_10" sourceRef="_6" targetRef="_7"> <conditionExpression xsi:type="tFormalExpression"> <![CDATA[${choose}]]> </conditionExpression> </sequenceFlow> <sequenceFlow id="_11" sourceRef="_6" targetRef="_8"> <conditionExpression xsi:type="tFormalExpression"> <![CDATA[${!choose}]]> </conditionExpression> </sequenceFlow> <sequenceFlow id="_13" sourceRef="_7" targetRef="_4"/> </process>
-
示例
package com.yl; import org.activiti.engine.*; import org.activiti.engine.repository.Deployment; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.junit.Test; import java.util.HashMap; import java.util.Map; public class ActivitiTest { //创建工作流引擎 ProcessEngine processEngine= ProcessEngines.getDefaultProcessEngine(); //管理流程文件的对象 RepositoryService repositoryService=processEngine.getRepositoryService(); //管理流程实例的对象 RuntimeService runtimeService=processEngine.getRuntimeService(); //管理任务节点的对象 TaskService taskService=processEngine.getTaskService(); //流程实例id private String processInstanceId; /** * 部署流程文件 */ @Test public void deployment() { //部署bpmn文件到数据库表 Deployment deployment=repositoryService.createDeployment().addClasspathResource("hello.bpmn").deploy(); System.out.println("部署文件id="+deployment.getId()); } /** * 启动流程实例 */ @Test public void start(){ //启动流程实例 ProcessInstance processInstance=runtimeService.startProcessInstanceByKey("myProcess_1"); processInstanceId=processInstance.getId(); System.out.println("流程实例id="+processInstanceId); } /** * 获取当前任务节点对象及完成此任务节点 */ @Test public void complete(){ //获取任务节点对象 Task task= taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); //存储网关条件 /* Map<String,Object> variables=new HashMap<>(); variables.put("choose",true);*/ System.out.println("待办事务="+task.getName()); //完成此任务节点 taskService.complete(task.getId()); } }