From 6ef29b05c5ad809130986e5fcd204f9194eb950c Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Wed, 8 Jan 2025 10:39:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9B=91=E5=90=AC=E5=99=A8?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=EF=BC=8C=E7=A7=BB=E9=99=A4=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E6=B5=81=E7=A8=8B=E5=A7=8B=E6=9C=AB=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flowable/jpa/SimpleListener.java | 10 -------- .../core/manager/FlowableManager.java | 25 +++++++++---------- .../flowable/core/model/FlowableListener.java | 12 --------- .../flowable/test/SimpleListener.java | 10 -------- 4 files changed, 12 insertions(+), 45 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 b4bc79b..d134f30 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 @@ -19,16 +19,6 @@ public class SimpleListener implements FlowableListener { @Resource private FlowableManager flowableManager; - @Override - public void onFlowStart(FlowableInstance instance, FlowableNode node) { - log.info("onFlowStart with spring: {}", flowableManager.listNodes()); - } - - @Override - public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) { - log.info("onFlowEnd with spring: {}", flowableManager.listNodes()); - } - @Override public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("onActionStart 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 583712f..f2ad222 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 @@ -93,9 +93,8 @@ public abstract class FlowableManager { .extra(extra) .build(); repository.saveInstance(instance); - callListeners(node.getListeners(), listener -> listener.onFlowStart(instance, node)); if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) { - automaticAction(instance, node); + automaticAction(instance); } return instance.getInstanceId(); } @@ -141,15 +140,15 @@ public abstract class FlowableManager { if (MapHelper.isNotEmpty(metadata)) { instance.getMetadata().putAll(metadata); } + action(instance, action, comment); + } + + private void automaticAction(FlowableInstance instance) { + action(instance, null, "系统自动执行"); + } + + private void action(FlowableInstance instance, final FlowableAction inputAction, String comment) { FlowableNode node = repository.getNode(instance.getCurrentNodeId()); - action(instance, node, action, comment); - } - - private void automaticAction(FlowableInstance instance, FlowableNode node) { - action(instance, node, null, "系统自动执行"); - } - - private void action(FlowableInstance instance, FlowableNode node, final FlowableAction inputAction, String comment) { String handlerClass = node.getHandler(); if (StringHelper.isBlank(handlerClass)) { throw new IllegalArgumentException("节点执行器为空"); @@ -185,14 +184,14 @@ public abstract class FlowableManager { if (FlowableAction.TERMINAL.equals(action)) { saveInstance(instance, FlowableInstance.Status.TERMINAL, action, comment); - callListeners(node.getListeners(), listener -> listener.onFlowEnd(instance, node, action)); + callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action)); return; } if (Objects.isNull(node.getTargets()) || !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, action)); + callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action)); return; } String nextNodeId = node.getTargets().get(action); @@ -202,7 +201,7 @@ public abstract class FlowableManager { callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action)); if (FlowableNode.Type.AUTOMATIC.equals(nextNode.getType())) { - automaticAction(instance, nextNode); + automaticAction(instance); } } 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 a881cd0..972b1ea 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 @@ -7,10 +7,6 @@ package com.lanyuanxiaoyao.flowable.core.model; * @version 20241231 */ public interface FlowableListener { - void onFlowStart(FlowableInstance instance, FlowableNode node); - - void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action); - void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action); void onAction(FlowableInstance instance, FlowableNode node, FlowableAction action); @@ -18,14 +14,6 @@ public interface FlowableListener { void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action); abstract class AbstractFlowableListener implements FlowableListener { - @Override - public void onFlowStart(FlowableInstance instance, FlowableNode node) { - } - - @Override - public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) { - } - @Override public void onActionStart(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 e8f929c..02be691 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 @@ -12,16 +12,6 @@ import lombok.extern.slf4j.Slf4j; */ @Slf4j public class SimpleListener implements FlowableListener { - @Override - public void onFlowStart(FlowableInstance instance, FlowableNode node) { - log.info("onFlowStart"); - } - - @Override - public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) { - log.info("onFlowEnd"); - } - @Override public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("onActionStart");