Java Activiti(8)--监听器

来源:互联网 发布:算法工程师jd 编辑:程序博客网 时间:2024/06/03 20:04

一、执行监听器

1、创建监听

/** * 执行监听器 * Created by Administrator on 2017/10/12. */public class MyExecutionListener implements ExecutionListener {    @Override    public void notify(DelegateExecution execution) {        System.out.println("notify====getEventName=====" + execution.getEventName());    }}

2、创建流程:
这里写图片描述

3、在start处添加监听
这里写图片描述

4、生成三个文件
这里写图片描述

5、部署流程

 @Test    public void deployLeave() throws Exception {        DeploymentBuilder builder = processEngine.getRepositoryService().createDeployment();        builder.addClasspathResource("flow/executionListener.bpmn");        builder.addClasspathResource("flow/executionListener.png");        builder.name("执行监听器报销流程部署");        Deployment deploy = builder.deploy();        System.out.println("deploy.getId()==" + deploy.getId());    }

6、启动流程实例时,添加变量

@Test    public void startProcessInstanceByKey() throws Exception {        //String processDefinitionKey = "grouptask";        String processInstanceId = "72501";        Map<String, Object> variable = new HashMap<String, Object>();        variable.put("amount", "300元");        variable.put("reason", "出差");        ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processInstanceId,variable);        System.out.println("processInstance.getId()===" + processInstance.getId());        System.out.println("processInstance.getProcessDefinitionId()===" + processInstance.getProcessDefinitionId());    }

7、完成任务

@Test    public void dealPersonalTask() throws Exception {        String taskId = "75011";        processEngine.getTaskService().complete(taskId);    }

注:在提交任务与完成任务时,都会触发监听事件

二、任务监听器

1、创建监听器

public class MyTaskListener1 implements TaskListener {    @Override    public void notify(DelegateTask delegateTask) {        System.out.println(delegateTask.getExecutionId());        Map<String, Object> variables = delegateTask.getVariables();        Set<String> variableNames = delegateTask.getVariableNames();        for(String key : variableNames){            System.out.println(key +":" + delegateTask.getVariable(key));        }        System.out.println("一个任务由" + delegateTask.getName() + "创建了,下一步由" + delegateTask.getAssignee() + "负责办理");    }}

2、添加create监听器

这里写图片描述

—————————————————————————————————————————————————–

java架构师项目实战,高并发集群分布式,大数据高可用视频教程,共760G

下载地址:

https://item.taobao.com/item.htm?id=555888526201

01.高级架构师四十二个阶段高
02.Java高级系统培训架构课程148课时
03.Java高级互联网架构师课程
04.Java互联网架构Netty、Nio、Mina等-视频教程
05.Java高级架构设计2016整理-视频教程
06.架构师基础、高级片
07.Java架构师必修linux运维系列课程
08.Java高级系统培训架构课程116课时
+
hadoop系列教程,java设计模式与数据结构, Spring Cloud微服务, SpringBoot入门

—————————————————————————————————————————————————–

原创粉丝点击