一 代码
/**
* Copyright (C), 2020-2020, 软件公司
* FileName: Trigger.java
* Author: cakin
* Date: 2020/4/23
* Description: receiveTask流程执行
*/
package com.syc.activiti.chapter9;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
/**
* @className: Trigger
* @description: receiveTask流程执行
* @date: 2020/4/23
* @author: cakin
*/
public class Trigger {
public static void main( String[] args ) {
// 创建流程引擎
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
// 得到流程存储服务实例
RepositoryService repositoryService = engine.getRepositoryService();
// 得到运行时服务组件
RuntimeService runtimeService = engine.getRuntimeService();
// 部署流程描述文件
repositoryService.createDeployment()
.addClasspathResource("bpmn/chapter9/trigger.bpmn").deploy();
// 开始流程
ProcessInstance pi = runtimeService
.startProcessInstanceByKey("vacationRequest");
// 查找执行流(当前只有一个执行流)
Execution exe = runtimeService.createExecutionQuery().activityId("receivetask1").singleResult();
if (exe != null) {
/***************************************************************************
mysql> select ID_, REV_,PROC_INST_ID_ ,BUSINESS_KEY_ ,PARENT_ID_ ,PROC_DEF_ID_ ,SUPER_EXEC_,ROOT_PROC_INST_ID_ ,ACT_ID_ from act_ru_execution;
+--------+------+---------------+---------------+------------+---------------------------+-------------+--------------------+--------------+
| ID_ | REV_ | PROC_INST_ID_ | BUSINESS_KEY_ | PARENT_ID_ | PROC_DEF_ID_ | SUPER_EXEC_ | ROOT_PROC_INST_ID_ | ACT_ID_ |
+--------+------+---------------+---------------+------------+---------------------------+-------------+--------------------+--------------+
| 190005 | 1 | 190005 | NULL | NULL | vacationRequest:10:190004 | NULL | 190005 | NULL |
| 190006 | 1 | 190005 | NULL | 190005 | vacationRequest:10:190004 | NULL | 190005 | receivetask1 |
+--------+------+---------------+---------------+------------+---------------------------+-------------+--------------------+--------------+
2 rows in set (0.00 sec)
****************************************************************************/
System.out.println("当前流程节点为: receivetask1");
}
// 触发等待节点
runtimeService.trigger(exe.getId());
// 查询当前的流程节点
exe = runtimeService.createExecutionQuery().activityId("usertask1").singleResult();
if (exe != null) {
/***************************************************************************
mysql> select ID_, REV_,PROC_INST_ID_ ,BUSINESS_KEY_ ,PARENT_ID_ ,PROC_DEF_ID_ ,SUPER_EXEC_,ROOT_PROC_INST_ID_ ,ACT_ID_ from act_ru_execution;
+--------+------+---------------+---------------+------------+---------------------------+-------------+--------------------+-----------+
| ID_ | REV_ | PROC_INST_ID_ | BUSINESS_KEY_ | PARENT_ID_ | PROC_DEF_ID_ | SUPER_EXEC_ | ROOT_PROC_INST_ID_ | ACT_ID_ |
+--------+------+---------------+---------------+------------+---------------------------+-------------+--------------------+-----------+
| 190005 | 1 | 190005 | NULL | NULL | vacationRequest:10:190004 | NULL | 190005 | NULL |
| 190006 | 2 | 190005 | NULL | 190005 | vacationRequest:10:190004 | NULL | 190005 | usertask1 |
+--------+------+---------------+---------------+------------+---------------------------+-------------+--------------------+-----------+
mysql> select ID_ ,REV_, EXECUTION_ID_, PROC_INST_ID_ , PROC_DEF_ID_, NAME_ , PARENT_TASK_ID_ , DESCRIPTION_ , TASK_DEF_KEY_ , OWNER_, ASSIGNEE_ from act_ru_task;
+--------+------+---------------+---------------+---------------------------+---------------+-----------------+--------------+---------------+--------+-----------+
| ID_ | REV_ | EXECUTION_ID_ | PROC_INST_ID_ | PROC_DEF_ID_ | NAME_ | PARENT_TASK_ID_ | DESCRIPTION_ | TASK_DEF_KEY_ | OWNER_ | ASSIGNEE_ |
+--------+------+---------------+---------------+---------------------------+---------------+-----------------+--------------+---------------+--------+-----------+
| 190010 | 1 | 190006 | 190005 | vacationRequest:10:190004 | Complete Task | NULL | NULL | usertask1 | NULL | NULL |
+--------+------+---------------+---------------+---------------------------+---------------+-----------------+--------------+---------------+--------+-----------+
1 row in set (0.00 sec)
****************************************************************************/
System.out.println("当前流程节点为: usertask1");
}
}
}
二 流程文件
<?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="Examples">
<process id="vacationRequest" name="vacationRequest" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<endEvent id="endevent1" name="End"></endEvent>
<receiveTask id="receivetask1" name="Receive Task"></receiveTask>
<userTask id="usertask1" name="Complete Task"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="receivetask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="receivetask1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
</definitions>
三 运行结果
当前流程节点为: receivetask 1190006
当前流程节点为: usertask 1190006
来源:oschina
链接:https://my.oschina.net/u/4301811/blog/3652294