工作流activiti 6 学习笔记七 中间事件

举报
lu_zhishen 发表于 2021/09/26 16:25:12 2021/09/26
【摘要】 中间事件分以下6类,他们有抛出事件也有捕获事件,根据事件名称可以判断。catch 就是捕获,throwing 就是抛出第一类中间事件,定时捕获中间事件bpmn文件<process id="myProcess" name="My process" isExecutable="true"> <startEvent id="startevent1" name="Start"></startE...

中间事件分以下6类,他们有抛出事件也有捕获事件,根据事件名称可以判断。catch 就是捕获,throwing 就是抛出

第一类中间事件,定时捕获中间事件

bpmn文件

<process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="task1"></userTask>
    <userTask id="usertask2" name="task2"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <intermediateCatchEvent id="timerintermediatecatchevent1" name="TimerCatchEvent">
      <timerEventDefinition><timeDuration>PT1M</timeDuration></timerEventDefinition>
    </intermediateCatchEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="timerintermediatecatchevent1"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="timerintermediatecatchevent1" targetRef="usertask2"></sequenceFlow>
  </process>

Java代码

// 部署流程
		Deployment deploye = rs.createDeployment().addClasspathResource("timerIntermediate.bpmn").deploy();
		
		ProcessDefinition  pdf = rs.createProcessDefinitionQuery().deploymentId(deploye.getId()).singleResult();
		
		ProcessInstance  pi = runS.startProcessInstanceById(pdf.getId());
		System.out.println(pi.getId());
		Task task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
		System.out.println("当前节点的名字"+task.getName());
		
		ts.complete(task.getId());
		
		task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
		System.out.println("当前节点的名字"+task);// 此处获取不到中间中间节点,
		
		Thread.sleep(70*1000);// 等待70s,流程自动跳转到task2
		
		task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
		System.out.println("当前节点的名字"+task.getName());

代码运行结果;

195005
当前节点的名字task1
当前节点的名字null
当前节点的名字task2

代码解释:

使用场景,严格按照时间进行审批的流控制的节点。比如生产企业,工艺流程的控制。

第二类:信号抛出事件和信号捕获事件,此处同时展示这两个时间

bpmn文件

<signal id="sinalId" name="signalName"></signal>
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway>
    <userTask id="usertask1" name="task1"></userTask>
    <intermediateCatchEvent id="signalintermediatecatchevent1" name="SignalCatchEvent">
      <signalEventDefinition signalRef="sinalId"></signalEventDefinition>
    </intermediateCatchEvent>
    <intermediateCatchEvent id="signalintermediatecatchevent2" name="SignalCatchEvent">
      <signalEventDefinition signalRef="sinalId"></signalEventDefinition>
    </intermediateCatchEvent>
    <intermediateThrowEvent id="signalintermediatethrowevent1" name="SignalThrowEvent">
      <signalEventDefinition signalRef="sinalId" ></signalEventDefinition>
    </intermediateThrowEvent>
    <userTask id="usertask2" name="task2"></userTask>
    <userTask id="usertask3" name="task3"></userTask>
    <parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="parallelgateway1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="parallelgateway1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="parallelgateway1" targetRef="signalintermediatecatchevent1"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="parallelgateway1" targetRef="signalintermediatecatchevent2"></sequenceFlow>
    <sequenceFlow id="flow5" sourceRef="usertask1" targetRef="signalintermediatethrowevent1"></sequenceFlow>
    <sequenceFlow id="flow6" sourceRef="signalintermediatethrowevent1" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow7" sourceRef="signalintermediatecatchevent1" targetRef="usertask2"></sequenceFlow>
    <sequenceFlow id="flow8" sourceRef="usertask2" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow9" sourceRef="parallelgateway2" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow10" sourceRef="usertask3" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow11" sourceRef="signalintermediatecatchevent2" targetRef="usertask3"></sequenceFlow>
  </process>

java代码

// 部署流程
		Deployment deploye = rs.createDeployment().addClasspathResource("signalIntermediate2.bpmn").deploy();
		
		ProcessDefinition  pdf = rs.createProcessDefinitionQuery().deploymentId(deploye.getId()).singleResult();
		
		ProcessInstance  pi = runS.startProcessInstanceById(pdf.getId());
		System.out.println(pi.getId());
		List<Task> tasks = ts.createTaskQuery().processInstanceId(pi.getId()).list();
		System.out.println("当前节点的个数"+tasks.size());
		
		
		for(Task task:tasks) {
			System.out.println("当前节点的名字"+task.getName());
			ts.complete(task.getId());// 审批完成自动触发抛出事件
		}
		
		tasks = ts.createTaskQuery().processInstanceId(pi.getId()).list();
		System.out.println("当前节点的个数"+tasks.size());
		
		for(Task task:tasks) {
			System.out.println("当前节点名称:"+task.getName());
		}

代码运行结果:

222505
当前节点的个数1
当前节点的名字task1
当前节点的个数2
当前节点名称:task2
当前节点名称:task3

代码解释:

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。