1. 流程
2. 设置,路径表达式
3.xml
<process id="sequenceFlow" name="sequenceFlowProcess" isExecutable="true"> <startEvent id="startevent1" name="Start"></startEvent> <userTask id="usertask1" name="审批【部门经理】" activiti:assignee="赵六"></userTask> <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow> <userTask id="usertask2" name="审批【总经理】" activiti:assignee="田七"></userTask> <sequenceFlow id="flow2" name="重要" sourceRef="usertask1" targetRef="usertask2"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${message=='重要'}]]></conditionExpression> </sequenceFlow> <endEvent id="endevent1" name="End"></endEvent> <sequenceFlow id="flow3" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow> <sequenceFlow id="flow4" name="不重要" sourceRef="usertask1" targetRef="endevent1"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${message=='不重要'}]]></conditionExpression> </sequenceFlow> </process>
4. 代码
public class SequenceFlowTest { ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); /**部署流程定义(从inputStream)*/ @Test public void deploymentProcessDefinition_inputStream(){ InputStream inputStreamBpmn = this.getClass().getResourceAsStream("sequenceFlow.bpmn"); InputStream inputStreamPng = this.getClass().getResourceAsStream("sequenceFlow.png"); Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service .createDeployment()//建立一个部署对象 .name("连线")//添加部署的名称 .addInputStream("sequenceFlow.bpmn", inputStreamBpmn)// .addInputStream("sequenceFlow.png", inputStreamPng)// .deploy();//完成部署 System.out.println("部署ID:"+deployment.getId());// System.out.println("部署名称:"+deployment.getName());// } /**启动流程实例*/ @Test public void startProcessInstance(){ //流程定义的key String processDefinitionKey = "sequenceFlow"; ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service .startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动 System.out.println("流程实例ID:"+pi.getId());//流程实例ID 101 System.out.println("流程定义ID:"+pi.getProcessDefinitionId());//流程定义ID helloworld:1:4 /* 流程实例ID:17501 流程定义ID:sequenceFlow:1:15004 */ } /**查询当前人的我的任务*/ @Test public void findMyPersonalTask(){ String assignee = "赵六"; List<Task> list = processEngine.getTaskService()//与正在执行的任务管理相关的Service .createTaskQuery()//建立任务查询对象 /**查询条件(where部分)*/ .taskAssignee(assignee)//指定我的任务查询,指定办理人 // .taskCandidateUser(candidateUser)//组任务的办理人查询 // .processDefinitionId(processDefinitionId)//使用流程定义ID查询 // .processInstanceId(processInstanceId)//使用流程实例ID查询 // .executionId(executionId)//使用执行对象ID查询 /**排序*/ .orderByTaskCreateTime().asc()//使用建立时间的升序排列 /**返回结果集*/ // .singleResult()//返回唯一结果集 // .count()//返回结果集的数量 // .listPage(firstResult, maxResults);//分页查询 .list();//返回列表 if(list!=null && list.size()>0){ for(Task task:list){ System.out.println("任务ID:"+task.getId()); System.out.println("任务名称:"+task.getName()); System.out.println("任务的建立时间:"+task.getCreateTime()); System.out.println("任务的办理人:"+task.getAssignee()); System.out.println("流程实例ID:"+task.getProcessInstanceId()); System.out.println("执行对象ID:"+task.getExecutionId()); System.out.println("流程定义ID:"+task.getProcessDefinitionId()); System.out.println("########################################################"); } } /* 任务ID:17504 任务名称:审批【部门经理】 任务的建立时间:Tue Jan 10 12:55:16 CST 2017 任务的办理人:赵六 流程实例ID:17501 执行对象ID:17501 流程定义ID:sequenceFlow:1:15004 ######################################################## */ } /**完成个人任务*/ @Test public void completeMyPersonalTask(){ //任务ID String taskId = "17504"; //完成任务的同时,设置流程变量,使用流程变量用来指定完成任务后,下一个连线,对应sequenceFlow.bpmn文件中${message=='不重要'} Map<String, Object> variables = new HashMap<String, Object>(); variables.put("message", "重要"); processEngine.getTaskService()//与正在执行的任务管理相关的Service .complete(taskId,variables); System.out.println("完成任务:任务ID:"+taskId); } }