工作流activiti 6 学习笔记十四 多流程实例
【摘要】 多流程实例是指一个任务节点被执行多次,用户任务服务任务都可以。本示例展示以下四种场景:直接指定执行次数,根据参数限制执行次数,获取参数值,提前结束。第一种:直接指定执行次数此示例指定一个服务任务执行两次bpmn文件<process id="myProcess" name="My process" isExecutable="true"> <startEvent id="starteve...
多流程实例是指一个任务节点被执行多次,用户任务服务任务都可以。本示例展示以下四种场景:直接指定执行次数,根据参数限制执行次数,获取参数值,提前结束。
第一种:直接指定执行次数
此示例指定一个服务任务执行两次
bpmn文件
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow3" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
<serviceTask id="servicetask1" name="Service Task" activiti:class="org.scf.act.api.task.multi.ServiceDelegate">
<multiInstanceLoopCharacteristics isSequential="false">
<loopCardinality>2</loopCardinality>
</multiInstanceLoopCharacteristics>
</serviceTask>
<sequenceFlow id="flow4" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="servicetask1" targetRef="usertask1"></sequenceFlow>
</process>
java 代码,
// 部署流程
Deployment deploye = rs.createDeployment().addClasspathResource("multiTask.bpmn").deploy();
ProcessDefinition pdf = rs.createProcessDefinitionQuery().deploymentId(deploye.getId()).singleResult();
ProcessInstance pi = runS.startProcessInstanceById(pdf.getId());
System.out.println(pi.getId());
运行结果
这是一个服务任务
这是一个服务任务
465005
第二种 :根据参数限制执行次数
设定一个list,放两个值,启动流程后会根据这两个值限制执行次数
bpmn文件
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow3" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
<serviceTask id="servicetask1" name="Service Task" activiti:class="org.scf.act.api.task.multi.ServiceDelegate">
<multiInstanceLoopCharacteristics isSequential="false">
<!-- <loopCardinality>2</loopCardinality> --><!-- 执行两次 -->
<loopDataInputRef>datas1</loopDataInputRef>
</multiInstanceLoopCharacteristics>
</serviceTask>
<sequenceFlow id="flow4" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="servicetask1" targetRef="usertask1"></sequenceFlow>
</process>
java代码
// 部署流程
Deployment deploye = rs.createDeployment().addClasspathResource("multiTask.bpmn").deploy();
ProcessDefinition pdf = rs.createProcessDefinitionQuery().deploymentId(deploye.getId()).singleResult();
List<String> datas1 = new ArrayList<String>();
datas1.add("a");
datas1.add("b");
Map<String,Object> map = new HashMap<String,Object>();
map.put("datas1", datas1);
ProcessInstance pi = runS.startProcessInstanceById(pdf.getId(),map);
System.out.println(pi.getId());
运行结果
这是一个服务任务
这是一个服务任务
467505
第三种:获取参数值
对以上示例进行打印list值
bpmn 文件
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow3" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
<serviceTask id="servicetask1" name="Service Task" activiti:class="org.scf.act.api.task.multi.ServiceDelegate">
<multiInstanceLoopCharacteristics isSequential="false" activiti:collection="${datas1}" activiti:elementVariable="data">
<!-- <loopCardinality>2</loopCardinality> --><!-- 执行两次 -->
<!-- <loopDataInputRef>datas1</loopDataInputRef> --><!-- 根据list个数设定执行次数 -->
</multiInstanceLoopCharacteristics>
</serviceTask>
<sequenceFlow id="flow4" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="servicetask1" targetRef="usertask1"></sequenceFlow>
</process>
java 代码同上
服务任务代码如下
package org.scf.act.api.task.multi;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
public class ServiceDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
System.out.println("这是一个服务任务"+execution.getVariable("data"));
}
}
运行结果
这是一个服务任务a
这是一个服务任务b
470005
第四种:提前结束
list 设置4个值,bpmn文件里面限定两次结束
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow3" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
<serviceTask id="servicetask1" name="Service Task" activiti:class="org.scf.act.api.task.multi.ServiceDelegate">
<multiInstanceLoopCharacteristics isSequential="false" activiti:collection="${datas1}" activiti:elementVariable="data">
<!-- <loopCardinality>2</loopCardinality> --><!-- 执行两次 -->
<!-- <loopDataInputRef>datas1</loopDataInputRef> --><!-- 根据list个数设定执行次数 -->
<completionCondition>${nrOfCompletedInstances >=2 }</completionCondition>
</multiInstanceLoopCharacteristics>
</serviceTask>
<sequenceFlow id="flow4" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="servicetask1" targetRef="usertask1"></sequenceFlow>
</process>
java 代码
// 部署流程
Deployment deploye = rs.createDeployment().addClasspathResource("multiTask.bpmn").deploy();
ProcessDefinition pdf = rs.createProcessDefinitionQuery().deploymentId(deploye.getId()).singleResult();
List<String> datas1 = new ArrayList<String>();
datas1.add("a");
datas1.add("b");
datas1.add("c");
datas1.add("d");
Map<String,Object> map = new HashMap<String,Object>();
map.put("datas1", datas1);
ProcessInstance pi = runS.startProcessInstanceById(pdf.getId(),map);
System.out.println(pi.getId());
运行结果
这是一个服务任务a
这是一个服务任务b
477505
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)