activiti学习--11接受任务活动

来源:互联网 发布:服装店记账软件手机 编辑:程序博客网 时间:2024/06/05 17:41

receiveTask.bpmn

这里写图片描述

<?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="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="350.0" y="50.0"></omgdc:Bounds>      </bpmndi:BPMNShape>      <bpmndi:BPMNShape bpmnElement="receivetask1" id="BPMNShape_receivetask1">        <omgdc:Bounds height="55.0" width="105.0" x="315.0" y="150.0"></omgdc:Bounds>      </bpmndi:BPMNShape>      <bpmndi:BPMNShape bpmnElement="receivetask2" id="BPMNShape_receivetask2">        <omgdc:Bounds height="55.0" width="105.0" x="315.0" y="260.0"></omgdc:Bounds>      </bpmndi:BPMNShape>      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">        <omgdc:Bounds height="35.0" width="35.0" x="350.0" y="380.0"></omgdc:Bounds>      </bpmndi:BPMNShape>      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">        <omgdi:waypoint x="367.0" y="315.0"></omgdi:waypoint>        <omgdi:waypoint x="367.0" y="380.0"></omgdi:waypoint>      </bpmndi:BPMNEdge>      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">        <omgdi:waypoint x="367.0" y="85.0"></omgdi:waypoint>        <omgdi:waypoint x="367.0" y="150.0"></omgdi:waypoint>      </bpmndi:BPMNEdge>      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">        <omgdi:waypoint x="367.0" y="205.0"></omgdi:waypoint>        <omgdi:waypoint x="367.0" y="260.0"></omgdi:waypoint>      </bpmndi:BPMNEdge>    </bpmndi:BPMNPlane>  </bpmndi:BPMNDiagram></definitions>
  /** 部署流程定义(从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());//        System.out.println("部署时间:" + deployment.getDeploymentTime());        // 部署ID:3801        // 部署名称:接收活动任务        // 部署时间:Thu Sep 07 13:52:56 CST 2017    }    /** 启动流程实例+设置流程变量+向后执行一步+获取流程变量+向后执行一步 */    @Test    public void startProcessInstance() {        // 流程定义的key.,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动        String processDefinitionKey = "receiveTask";        ProcessInstance pi = processEngine.getRuntimeService()// 与正在执行的流程实例和执行对象相关的Service                .startProcessInstanceByKey(processDefinitionKey);// 使用流程定义的key启动流程实例,        System.out.println("流程实例ID:" + pi.getId());//        System.out.println("流程定义ID:" + pi.getProcessDefinitionId());//        // 流程实例ID:4001        // 流程定义ID:receiveTask:1:3804        /** 查询执行对象ID 关联表ACT_RU_EXECUTION */        Execution execution1 = processEngine.getRuntimeService()//                .createExecutionQuery()// 创建执行对象查询                .processInstanceId(pi.getId())// 使用流程实例ID查询                .activityId("receivetask1")// 当前活动的id,对应receiveTask.bpmn文件中的活动节点id的属性值                .singleResult();        // execution1:ProcessInstance[4001]        /** 使用流程变量设置财务报告金额,用来传递业务参数 */        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);        // 总裁收到的金额是:21000        /** 向后执行一步,如果流程处于等待状态,使得流程继续执行 */        processEngine.getRuntimeService().signal(execution2.getId());    }

解析:
1开启流程实例
2节点到财务报告,这里设置财务金额变量,并执行下一步
3节点到发送给总裁,获取变量的内容,执行下一步
4节点到结束
变化的表:
ACT_HI_ACTINST
这里写图片描述
ACT_HI_VARINST
这里写图片描述

阅读全文
0 0