其实在上一张已经提到过,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 { @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("==========================="); } }
③ 测试运行