1
0

优化监听器事件,移除错误的流程始末事件

This commit is contained in:
2025-01-08 10:39:42 +08:00
parent 96dfcea7b8
commit 6ef29b05c5
4 changed files with 12 additions and 45 deletions

View File

@@ -19,16 +19,6 @@ public class SimpleListener implements FlowableListener {
@Resource @Resource
private FlowableManager flowableManager; 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 @Override
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) { public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onActionStart with spring: {}", flowableManager.listNodes()); log.info("onActionStart with spring: {}", flowableManager.listNodes());

View File

@@ -93,9 +93,8 @@ public abstract class FlowableManager {
.extra(extra) .extra(extra)
.build(); .build();
repository.saveInstance(instance); repository.saveInstance(instance);
callListeners(node.getListeners(), listener -> listener.onFlowStart(instance, node));
if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) { if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) {
automaticAction(instance, node); automaticAction(instance);
} }
return instance.getInstanceId(); return instance.getInstanceId();
} }
@@ -141,15 +140,15 @@ public abstract class FlowableManager {
if (MapHelper.isNotEmpty(metadata)) { if (MapHelper.isNotEmpty(metadata)) {
instance.getMetadata().putAll(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()); 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(); String handlerClass = node.getHandler();
if (StringHelper.isBlank(handlerClass)) { if (StringHelper.isBlank(handlerClass)) {
throw new IllegalArgumentException("节点执行器为空"); throw new IllegalArgumentException("节点执行器为空");
@@ -185,14 +184,14 @@ public abstract class FlowableManager {
if (FlowableAction.TERMINAL.equals(action)) { if (FlowableAction.TERMINAL.equals(action)) {
saveInstance(instance, FlowableInstance.Status.TERMINAL, action, comment); 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; return;
} }
if (Objects.isNull(node.getTargets()) if (Objects.isNull(node.getTargets())
|| !node.getTargets().containsKey(action) || !node.getTargets().containsKey(action)
|| StringHelper.isBlank(node.getTargets().get(action))) { || StringHelper.isBlank(node.getTargets().get(action))) {
saveInstance(instance, FlowableInstance.Status.COMPLETED, action, comment); 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; return;
} }
String nextNodeId = node.getTargets().get(action); String nextNodeId = node.getTargets().get(action);
@@ -202,7 +201,7 @@ public abstract class FlowableManager {
callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action)); callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action));
if (FlowableNode.Type.AUTOMATIC.equals(nextNode.getType())) { if (FlowableNode.Type.AUTOMATIC.equals(nextNode.getType())) {
automaticAction(instance, nextNode); automaticAction(instance);
} }
} }

View File

@@ -7,10 +7,6 @@ package com.lanyuanxiaoyao.flowable.core.model;
* @version 20241231 * @version 20241231
*/ */
public interface FlowableListener { 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 onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action);
void onAction(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); void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action);
abstract class AbstractFlowableListener implements FlowableListener { abstract class AbstractFlowableListener implements FlowableListener {
@Override
public void onFlowStart(FlowableInstance instance, FlowableNode node) {
}
@Override
public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) {
}
@Override @Override
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) { public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
} }

View File

@@ -12,16 +12,6 @@ import lombok.extern.slf4j.Slf4j;
*/ */
@Slf4j @Slf4j
public class SimpleListener implements FlowableListener { 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 @Override
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) { public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onActionStart"); log.info("onActionStart");