流程中往往需要特定人接受任务并进行一定操作才能继续进行下去。

  代码如下

import java.io.InputStream;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;
public class ReceiveTaskTest { ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); /**部署流程定义(从inputStream)*/
@Test
public void deploymentProcessDefinition_inputStream(){
InputStream inputStreamBpmn = this.getClass().getResourceAsStream("receiveTask.bpmn");
InputStream inputStreamPng = this.getClass().getResourceAsStream("receiveTask.png");
Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service
.createDeployment()//创建一个部署对象
.name("接收活动任务")//添加部署的名称
.addInputStream("receiveTask.bpmn", inputStreamBpmn)//
.addInputStream("receiveTask.png", inputStreamPng)//
.deploy();//完成部署
System.out.println("部署ID:"+deployment.getId());//
System.out.println("部署名称:"+deployment.getName());//
} /**启动流程实例+设置流程变量+获取流程变量+向后执行一步*/
@Test
public void startProcessInstance(){
//流程定义的key
String processDefinitionKey = "receiveTask";
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*/
Execution execution1 = processEngine.getRuntimeService()//
.createExecutionQuery()//创建执行对象查询
.processInstanceId(pi.getId())//使用流程实例ID查询
.activityId("receivetask1")//当前活动的id,对应receiveTask.bpmn文件中的活动节点id的属性值
.singleResult(); /**使用流程变量设置当日销售额**/
processEngine.getRuntimeService().setVariable(execution1.getId(), "汇总当日销售额", 21000); /**向后执行一步,如果流程处于等待状态,使得流程继续执行*/
processEngine.getRuntimeService()
.signal(execution1.getId());
/**查询执行对象ID*/
Execution execution2 = processEngine.getRuntimeService()//
.createExecutionQuery()//创建执行对象查询
.processInstanceId(pi.getId())//使用流程实例ID查询
.activityId("receivetask2")//当前活动的id,对应receiveTask.bpmn文件中的活动节点id的属性值
.singleResult();
/**从流程变量中获取汇总当日销售额的值*/
Integer value = (Integer)processEngine.getRuntimeService()//
.getVariable(execution2.getId(), "汇总当日销售额");
System.out.println("给老板发送短信:金额是:"+value);
/**向后执行一步,如果流程处于等待状态,使得流程继续执行*/
processEngine.getRuntimeService()
.signal(execution2.getId());
}
}

  由于没有任务id,因此只能由流程进行操作,所以使用getRuntimeService()方法。先由流程实例编号查询流程1,并进行汇总销售操作然后进行到下一个流程。同样,由流程实例编号查询流程2,汇报给老板并进行到下一步完成整个流程

  bpnm文件如下

  

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="receiveTask" name="receiveTaskProcess" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<receiveTask id="receivetask1" name="汇总当日销售额"></receiveTask>
<receiveTask id="receivetask2" name="给老板发送信息"></receiveTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="receivetask2" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="startevent1" targetRef="receivetask1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="receivetask1" targetRef="receivetask2"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_receiveTask">
<bpmndi:BPMNPlane bpmnElement="receiveTask" id="BPMNPlane_receiveTask">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="360.0" y="20.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="receivetask1" id="BPMNShape_receivetask1">
<omgdc:Bounds height="55.0" width="105.0" x="325.0" y="120.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="receivetask2" id="BPMNShape_receivetask2">
<omgdc:Bounds height="55.0" width="105.0" x="325.0" y="250.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="360.0" y="360.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="377.0" y="305.0"></omgdi:waypoint>
<omgdi:waypoint x="377.0" y="360.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="377.0" y="55.0"></omgdi:waypoint>
<omgdi:waypoint x="377.0" y="120.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="377.0" y="175.0"></omgdi:waypoint>
<omgdi:waypoint x="377.0" y="250.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>

最新文章

  1. 易用BPM时代,软件开发者缘何选择H3?
  2. Java Thread 的使用
  3. Microsoft Azure Project Oxford 体验
  4. 如何做出header,footer固定定位后让main主体部分可以滑动,在微信浏览器中滑动到最后不出现黑边的情况
  5. HP的笔记本经常蓝屏崩溃 -------athr.sys
  6. 游戏全区全服和分区分服 QQ斗地主的设计
  7. mysql 数据库磁盘占用量统计
  8. docker版本升级
  9. Arduino+Avr libc制作Badusb原理及示例讲解
  10. day 08 函数
  11. np.random.rand均匀分布随机数和np.random.randn正态分布随机数函数使用方法
  12. [整理]x=x++和x=++x
  13. shell编程快速入门及实战
  14. Head内常用标签
  15. HTML5 五大特性
  16. AX5511 Boost Converter
  17. DirectShow控制台输出和保存视频设备名称
  18. 【Prism】MEF版HelloWorld
  19. 多线程-Thread-Runnable
  20. 人生苦短之Python文件的IO操作

热门文章

  1. mysql 远程连接报错
  2. CF930E Coins Exhibition
  3. Java 基础 - 原生类型
  4. 【JZOJ6367】工厂(factory)
  5. The Preliminary Contest for ICPC Asia Nanjing 2019 C. Tsy&#39;s number 5
  6. linux下phpstudy安装
  7. Linux 后台运行python .sh等程序,以及查看和关闭后台运行程序操作
  8. js比较常用的
  9. low版九九乘法表
  10. 关于ueditor 文本框