From d8f58ea2b5a7d5b00b6c64788b052bef16455d89 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Tue, 7 Jan 2025 14:50:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4Listener=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flowable/jpa/SimpleListener.java | 8 ++--- .../core/manager/FlowableManager.java | 31 +++++++++---------- .../flowable/core/model/FlowableListener.java | 8 ++--- .../flowable/test/SimpleListener.java | 8 ++--- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/adapter/flowable-spring-boot-jpa-starter/src/test/java/com/lanyuanxiaoyao/flowable/jpa/SimpleListener.java b/adapter/flowable-spring-boot-jpa-starter/src/test/java/com/lanyuanxiaoyao/flowable/jpa/SimpleListener.java index 6a7b5f1..b4bc79b 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/test/java/com/lanyuanxiaoyao/flowable/jpa/SimpleListener.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/test/java/com/lanyuanxiaoyao/flowable/jpa/SimpleListener.java @@ -25,22 +25,22 @@ public class SimpleListener implements FlowableListener { } @Override - public void onFlowEnd(FlowableInstance instance, FlowableNode node) { + public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("onFlowEnd with spring: {}", flowableManager.listNodes()); } @Override - public void onActionStart(FlowableInstance instance, FlowableNode node) { + public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("onActionStart with spring: {}", flowableManager.listNodes()); } @Override - public void onAction(FlowableInstance instance, FlowableAction action) { + public void onAction(FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("onAction with spring: {}", flowableManager.listNodes()); } @Override - public void onActionComplete(FlowableInstance instance, FlowableNode node) { + public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("onActionComplete with spring: {}", flowableManager.listNodes()); } } diff --git a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/manager/FlowableManager.java b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/manager/FlowableManager.java index 6e51cae..47c10b8 100644 --- a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/manager/FlowableManager.java +++ b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/manager/FlowableManager.java @@ -144,8 +144,18 @@ public abstract class FlowableManager { action(instance, node, null, "系统自动执行"); } - private void action(FlowableInstance instance, FlowableNode node, FlowableAction action, String comment) { - callListeners(node.getListeners(), listener -> listener.onActionStart(instance, node)); + private void action(FlowableInstance instance, FlowableNode node, final FlowableAction inputAction, String comment) { + String handlerClass = node.getHandler(); + if (StringHelper.isBlank(handlerClass)) { + throw new IllegalArgumentException("节点执行器为空"); + } + FlowableHandler handler = createBean(handlerClass); + final FlowableAction action = handler.handle(configuration, instance, node, inputAction); + if (Objects.isNull(action)) { + throw new IllegalArgumentException("节点执行结果不能为空"); + } + + callListeners(node.getListeners(), listener -> listener.onActionStart(instance, node, action)); if (FlowableInstance.Status.COMPLETED.equals(instance.getStatus()) || FlowableInstance.Status.TERMINAL.equals(instance.getStatus())) { throw new IllegalArgumentException("ID为" + instance.getInstanceId() + "的流程已结束,无法操作"); @@ -160,18 +170,7 @@ public abstract class FlowableManager { throw new IllegalArgumentException("权限校验不通过"); } - String handlerClass = node.getHandler(); - if (StringHelper.isBlank(handlerClass)) { - throw new IllegalArgumentException("节点执行器为空"); - } - FlowableHandler handler = createBean(handlerClass); - action = handler.handle(configuration, instance, node, action); - if (Objects.isNull(action)) { - throw new IllegalArgumentException("节点执行结果不能为空"); - } - - FlowableAction tempAction = action; - callListeners(node.getListeners(), listener -> listener.onAction(instance, tempAction)); + callListeners(node.getListeners(), listener -> listener.onAction(instance, node, action)); // 如果是挂起操作,就直接返回,不做操作 if (FlowableAction.SUSPEND.equals(action)) { @@ -187,7 +186,7 @@ public abstract class FlowableManager { || !node.getTargets().containsKey(action) || StringHelper.isBlank(node.getTargets().get(action))) { saveInstance(instance, FlowableInstance.Status.COMPLETED, action, comment); - callListeners(node.getListeners(), listener -> listener.onFlowEnd(instance, node)); + callListeners(node.getListeners(), listener -> listener.onFlowEnd(instance, node, action)); return; } String nextNodeId = node.getTargets().get(action); @@ -195,7 +194,7 @@ public abstract class FlowableManager { instance.setCurrentNodeId(nextNode.getNodeId()); saveInstance(instance, FlowableInstance.Status.RUNNING, action, comment); - callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node)); + callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action)); if (FlowableNode.Type.AUTOMATIC.equals(nextNode.getType())) { automaticAction(instance, node); } diff --git a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableListener.java b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableListener.java index 261fae0..e22a8d5 100644 --- a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableListener.java +++ b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableListener.java @@ -9,11 +9,11 @@ package com.lanyuanxiaoyao.flowable.core.model; public interface FlowableListener { void onFlowStart(FlowableInstance instance, FlowableNode node); - void onFlowEnd(FlowableInstance instance, FlowableNode node); + void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action); - void onActionStart(FlowableInstance instance, FlowableNode node); + void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action); - void onAction(FlowableInstance instance, FlowableAction action); + void onAction(FlowableInstance instance, FlowableNode node, FlowableAction action); - void onActionComplete(FlowableInstance instance, FlowableNode node); + void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action); } diff --git a/flowable-example/src/test/java/com/lanyuanxiaoyao/flowable/test/SimpleListener.java b/flowable-example/src/test/java/com/lanyuanxiaoyao/flowable/test/SimpleListener.java index 32c5fbb..e8f929c 100644 --- a/flowable-example/src/test/java/com/lanyuanxiaoyao/flowable/test/SimpleListener.java +++ b/flowable-example/src/test/java/com/lanyuanxiaoyao/flowable/test/SimpleListener.java @@ -18,22 +18,22 @@ public class SimpleListener implements FlowableListener { } @Override - public void onFlowEnd(FlowableInstance instance, FlowableNode node) { + public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("onFlowEnd"); } @Override - public void onActionStart(FlowableInstance instance, FlowableNode node) { + public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("onActionStart"); } @Override - public void onAction(FlowableInstance instance, FlowableAction action) { + public void onAction(FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("onAction"); } @Override - public void onActionComplete(FlowableInstance instance, FlowableNode node) { + public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("onActionComplete"); } }