首先推荐这篇博客,刚接触工作流的时候也是依据这个“分享牛”写的文章来实现一些基本功能。
链接:https://blog.csdn.net/qq_30739519/article/details/51258447
从 activiti监听器的使用范围来看,大致分为三种:
1.全局的监听器。 全局监听器主要使用的场景就是监控这个流程的启动和结束。 全局监听器实现的接口是org.activiti.engine.delegate.ExecutionListener
2.连线的监听器。 当节点结束的时候,经过连线的时候,我们可以在线上定义类,实现自己的业务逻辑。
3.节点的监听器。 任务节点的监听只要实现TaskListener接口即可。 DelegateTask类
首先以连线监听为例。
在开始事件和用户事件之间的连线添加监听事件 连线id是flow3
直接上代码吧
@Component
public class RawMatOutRepplyListener implements ExecutionListener, TaskListener {
public RawMatOutRepplyListener() {
}
//流程监听器
@Override
public void notify(DelegateExecution execution) throws Exception {
String eventName = execution.getEventName();
String processBusinessKey = execution.getProcessBusinessKey();
String str = processBusinessKey.substring(processBusinessKey.indexOf(":") + 1);
//使用JAVA配置的老方法,手动从容器中取出Bean
MatOperationMainService matOperationMainService = SpringUtils.getBean(MatOperationMainService.class);
if ("end".equals(eventName)) {
System.out.println("end==========");
} else if ("take".equals(eventName)) {
System.out.println("take=========");
matOperationMainService.outrepply(str);
} else if ("start".equals(eventName)) {
System.out.println("start=========");
}
}
//任务监听器
@Override
public void notify(DelegateTask delegateTask) {
String eventName = delegateTask.getEventName();
MatOperationMainService matOperationMainService = SpringUtils.getBean(MatOperationMainService.class);
String tableInfoId = delegateTask.getExecution().getProcessBusinessKey();
String str = tableInfoId.substring(tableInfoId.indexOf(":")+1);
//使用JAVA配置的老方法,手动从容器中取出Bean
if ("create".equals(eventName)) {
System.out.println("create==========");
// matOperationMainService.outrepply(str);
}else if ("assignment".endsWith(eventName)) {
System.out.println("assignment========");
}else if ("complete".endsWith(eventName)) {
System.out.println("complete===========");
}else if ("delete".endsWith(eventName)) {
System.out.println("delete=============");
}
}
}