Java Activiti(8)--監聽器

一、執行監聽器

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入門

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章