zl程序教程

您现在的位置是:首页 >  其它

当前栏目

Camunda 创建 流程图回调 (三)

创建 回调 流程图
2023-09-11 14:21:21 时间

其实在上一张已经提到过,Camunda的回调方法。

这里在补充一下。

 

一 看一下流程图

 

二 设置回调

这里我们使用2种回调,来触发

1 审批:EventListener

2 审核:  JavaDelegate

 

I 使用EventListener:

① application.yml  中开启监听

camunda.bpm:
  #开启监听
  eventing:
    execution: true
    history: true
    task: true

② 代码实现

一个监听事件,有多种状态,

create
assigment
complete
delete
start
end

这里我们使用  delegateTask.eventName=='create'  ,

并且delegateTask.name=='审批'  就回调该方法。

@Component
public class AuditListener {
 
//使用#delegateTask.taskDefinitionKey=='Activity_053ns1t' 更靠谱,taskDefinitionKey就是审批节点的ID @EventListener(condition
= "#delegateTask.eventName=='create' && #delegateTask.name=='审批'") public void notity(DelegateTask delegateTask){ System.out.println("审核流程 - USER TASK - "+delegateTask.getEventName()); Object assignee=delegateTask.getAssignee(); System.out.println("审批人:"+ assignee); Object approve=delegateTask.getVariable("approve"); System.out.println("审批结果:"+ approve); System.out.println("==========================="); } }

至此,@EventListener就好了

 

③ 测试运行:

 

II 使用JavaDelegate

① 在审核节点,我们填写如下

 

 

② 代码:

public class AuditDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) throws Exception {
        System.out.println("审核流程 - SERVICE TASK - 回调");
        Object approved=execution.getVariable("approve");
        System.out.println("审批结果:"+ approved);
        Object amount=execution.getVariable("amount");
        System.out.println("审批金额:"+ amount);
        System.out.println("===========================");
    }
}

③ 测试运行