当前位置:网站首页>Call activity of Activiti7 sub-process

Call activity of Activiti7 sub-process

2022-08-10 23:49:00 keep-go-on

Call activity (子流程)

BPMN2.0There are regular subprocesses(Sub-Process)and calling the subprocess(call activity).Both are calling subprocesses.不用于Sub-process,call activityThe invoked subprocess does not need to be nested within the original process.
当流程执行到Call ActivityWhen calling the activity,A new process instance will be created,When the sub-process is executed, the original process will continue to be executed.

Process flow diagram schematic

子流程

Main process definition

<?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/processdef">
  <process id="process_call_activiti" name="callActiviti" isExecutable="true">
    <startEvent id="sid-16DBFA1E-35E2-47E3-AFAF-474794A484EF"></startEvent>
    <callActivity id="sid-A18F2859-7517-4FE3-9492-E1D554D67E08" name="子流程" calledElement="process_demo" activiti:inheritVariables="false"></callActivity>
    <userTask id="sid-36AE98BA-7D81-4CCD-9361-46A4C651A227" name="主任务"></userTask>
    <sequenceFlow id="sid-6DD89223-E3B4-49DF-BAD1-3BD5C635BCEA" sourceRef="sid-A18F2859-7517-4FE3-9492-E1D554D67E08" targetRef="sid-36AE98BA-7D81-4CCD-9361-46A4C651A227"></sequenceFlow>
    <endEvent id="sid-7B73BC3A-08CA-47F8-B054-13B71285FEFE"></endEvent>
    <sequenceFlow id="sid-BBB8A48C-463D-4D32-BA11-225756DAB95B" sourceRef="sid-36AE98BA-7D81-4CCD-9361-46A4C651A227" targetRef="sid-7B73BC3A-08CA-47F8-B054-13B71285FEFE"></sequenceFlow>
    <userTask id="sid-D94522CB-6251-4DC6-877C-6B113FE73E93" name="主任务开始"></userTask>
    <sequenceFlow id="sid-8FE8E385-8901-42EE-B216-13A9AA7E9EFB" sourceRef="sid-16DBFA1E-35E2-47E3-AFAF-474794A484EF" targetRef="sid-D94522CB-6251-4DC6-877C-6B113FE73E93"></sequenceFlow>
    <sequenceFlow id="sid-92753CF7-25F9-4FD3-83DD-A905EDA6CFF0" sourceRef="sid-D94522CB-6251-4DC6-877C-6B113FE73E93" targetRef="sid-A18F2859-7517-4FE3-9492-E1D554D67E08"></sequenceFlow>
  </process>
</definitions>

其中 The sub-process is defined as follows :

  <callActivity id="sid-A18F2859-7517-4FE3-9492-E1D554D67E08" name="子流程" calledElement="process_demo" activiti:inheritVariables="false"></callActivity>
属性简介
idSubprocess definitionID
nameSubprocess name
calledElementThe process definition of the called subprocessKey

Subprocess definition

<?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/processdef">
  <process id="process_demo" name="Simple one-line process" isExecutable="true">
    <startEvent id="sid-49B8F59F-916D-4470-B47D-E102F46402B3"></startEvent>
    <userTask id="sid-3D5E6338-B2EF-4235-AC08-63E311EEF45E" name="任务1"></userTask>
    <sequenceFlow id="sid-28BF011E-A3F1-48EC-91C3-F187D84FCC67" sourceRef="sid-49B8F59F-916D-4470-B47D-E102F46402B3" targetRef="sid-3D5E6338-B2EF-4235-AC08-63E311EEF45E"></sequenceFlow>
    <userTask id="sid-C8ED4D8D-8C94-4BA2-BFE7-6B315DC03518" name="任务2"></userTask>
    <sequenceFlow id="sid-D1065EBF-AA27-4C1D-BE35-064EBFD839C1" sourceRef="sid-3D5E6338-B2EF-4235-AC08-63E311EEF45E" targetRef="sid-C8ED4D8D-8C94-4BA2-BFE7-6B315DC03518"></sequenceFlow>
    <endEvent id="sid-AAD9DA48-D9DC-4CC2-8F77-D602D787D894" name="结束"></endEvent>
    <sequenceFlow id="sid-538E7A61-32DB-48C6-8A67-599F7E97562D" sourceRef="sid-C8ED4D8D-8C94-4BA2-BFE7-6B315DC03518" targetRef="sid-AAD9DA48-D9DC-4CC2-8F77-D602D787D894"></sequenceFlow>
  </process>
</definitions>

查询Call Activity

由于CallActivity并未继承Task类,所以使用 historyService.createHistoricTaskInstanceQuery()无法查询到CallActivity.

CallActivity继承关系如下 :
在这里插入图片描述

It can be seen from the inheritance relationshipCallActivity继承了Activity对象,因此可以使用 historyService.createHistoricActivityInstanceQuery()进行查询.

查询实例如下 :

  List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery()
                .processInstanceId(processInstanceId).list();
        for (HistoricActivityInstance activityInstance : list) {
    
          log.info("【流程实例】 实例名称 :[ {} ] 实例类型[ {} ] ID[ {} ] callInstanceId[ {} ]"
                  ,activityInstance.getActivityName(),activityInstance.getActivityType(),
                  activityInstance.getId(),activityInstance.getCalledProcessInstanceId());
        }

查询结果如下 :

[ 21:32:39.976 ] INFO | ActivitiTestController :: allTask | -  【流程实例】 实例名称 :[ null ] 实例类型[ startEvent ] ID[ 62f1ddd2e073d82423e53d98 ] callInstanceId[ null ] 
[ 21:32:39.976 ] INFO | ActivitiTestController :: allTask | -  【流程实例】 实例名称 :[ 主任务开始 ] 实例类型[ userTask ] ID[ 62f1ddd2e073d82423e53d99 ] callInstanceId[ null ] 
[ 21:32:39.976 ] INFO | ActivitiTestController :: allTask | -  【流程实例】 实例名称 :[ 子流程 ] 实例类型[ callActivity ] ID[ 62f1de08e073d82423e53d9b ] callInstanceId[ 62f1de08e073d82423e53d9c ] 
[ 21:32:39.977 ] INFO | ActivitiTestController :: allTask | -  【流程实例】 实例名称 :[ 主任务 ] 实例类型[ userTask ] ID[ 62f1e09ce073d82423e53da4 ] callInstanceId[ null ] 

传递变量

activiti Support for passing variables to subprocesses when calling them,It also supports passing variables to the main process when the subprocess ends.

<callActivity id="callSubProcess" calledElement="checkCreditProcess" >
  <extensionElements>
	  <activiti:in source="someVariableInMainProcess" target="nameOfVariableInSubProcess" />
	  <activiti:out source="someVariableInSubProcess" target="nameOfVariableInMainProcess" />
  </extensionElements>
</callActivity>
属性简介
sourceMain process variable name
targetSubprocess variable name

Except for variable passing,activitiAlso supports formulas.

<callActivity id="callSubProcess" calledElement="checkCreditProcess" >
	<extensionElements>
	  <activiti:in sourceExpression="${x+5}" target="y" />
	  <activiti:out source="${y+5}" target="z" />
	</extensionElements>
</callActivity>

z = y+5 = x+5+5

原网站

版权声明
本文为[keep-go-on]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208102331190124.html