activiti5之学习之路,贵在坚持,activiti接收任务活动,说明全在代码里

ReceiveTask是没有当前状态任务的,在任务表里面没有的,下一步需要手动执行

<?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:xsd="http://www.w3.org/2001/XMLSchema" 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="receiveTask" 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="startevent1" targetRef="receivetask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="receivetask1" targetRef="receivetask2"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="receivetask2" targetRef="endevent1"></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="380.0" y="20.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="receivetask1" id="BPMNShape_receivetask1">
        <omgdc:Bounds height="55.0" width="105.0" x="345.0" y="120.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="receivetask2" id="BPMNShape_receivetask2">
        <omgdc:Bounds height="55.0" width="105.0" x="345.0" y="220.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="380.0" y="320.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="397.0" y="55.0"></omgdi:waypoint>
        <omgdi:waypoint x="397.0" y="120.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="397.0" y="175.0"></omgdi:waypoint>
        <omgdi:waypoint x="397.0" y="220.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="397.0" y="275.0"></omgdi:waypoint>
        <omgdi:waypoint x="397.0" y="320.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

 

package com.ljw.e_receiveTask;

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;

/**
 * 接收任务活动
 * 
 * @author lenovo
 *
 */
public class ReceiveTaskTest {
	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

	// 部署流程定义(classpath)
	@Test
	public void deploymentProcessDefinition_inputStream() {
		InputStream bpmn = this.getClass().getResourceAsStream("receiveTask.bpmn");
		InputStream png = this.getClass().getResourceAsStream("receiveTask.png");
		Deployment deployment = processEngine.getRepositoryService()// 与流程定义和部署对象相关的sevices
				.createDeployment()// 创建一个部署对象
				.name("接收任务活动")// 添加部署名称
				.addInputStream("receiveTask.bpmn", bpmn).addInputStream("receiveTask.png", png).deploy();
		System.out.println("部署ID:" + deployment.getId());
		System.out.println("部署名称:" + deployment.getName());

	}

	// 启动流程实例+设置流程变量+获取流程变量+向后执行一步
	@Test
	public void deploymentProcessInstance() {
		String key = "receiveTask";
		ProcessInstance pi = processEngine.getRuntimeService()// 与正在执行的流程是咧和执行对象相关的services
				.startProcessInstanceByKey(key);// 使用流程定义的key启动流程实例key对呀的helloworld.bnpm文件里的id的属性值
		System.out.println("流程实例ID:" + pi.getId());
		System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
		
		/**查询执行对象ID*/
		Execution execution = processEngine.getRuntimeService()
			.createExecutionQuery()//创建执行对象查询
			.processInstanceId(pi.getProcessInstanceId())//使用流程实例查询
			.activityId("receivetask1")//当前活动的ID,对应receiveTask.bpmn文件中的活动节点id的属性值
			.singleResult();
		System.out.println("executionId:"+execution.getId());
		/**使用流程变量来设置当日销售额,用来传递业务参数*/
		processEngine.getRuntimeService()
			.setVariable(execution.getId(), "汇总当日销售额", 21000);
		
		/**向后执行一步,如果流程处于等待状态,使得流程继续执行*/
		processEngine.getRuntimeService()
			.signal(execution.getId());
		
		
		/***************************实际业务中可能分多段执行*****************************************/
		
		/**查询执行对象ID*/
		Execution execution2 = processEngine.getRuntimeService()
			.createExecutionQuery()//创建执行对象查询
			.processInstanceId(pi.getProcessInstanceId())//使用流程实例查询
			.activityId("receivetask2")//当前活动的ID,对应receiveTask.bpmn文件中的活动节点id的属性值
			.singleResult();
		System.out.println("executionId:"+execution.getId());
		/**从流程变量中获取汇总当日销售额*/
		Integer val=(Integer)processEngine.getRuntimeService()
			.getVariable(execution2.getId(), "汇总当日销售额");
		System.out.println("给老板发送短信,金额是:"+val);	
		
		/**向后执行一步,如果流程处于等待状态,使得流程继续执行*/
		processEngine.getRuntimeService()
			.signal(execution.getId());
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值