1
0

调整Listener参数

This commit is contained in:
2025-01-07 14:50:02 +08:00
parent bf0e7e47be
commit d8f58ea2b5
4 changed files with 27 additions and 28 deletions

View File

@@ -25,22 +25,22 @@ public class SimpleListener implements FlowableListener {
} }
@Override @Override
public void onFlowEnd(FlowableInstance instance, FlowableNode node) { public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onFlowEnd with spring: {}", flowableManager.listNodes()); log.info("onFlowEnd with spring: {}", flowableManager.listNodes());
} }
@Override @Override
public void onActionStart(FlowableInstance instance, FlowableNode node) { public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onActionStart with spring: {}", flowableManager.listNodes()); log.info("onActionStart with spring: {}", flowableManager.listNodes());
} }
@Override @Override
public void onAction(FlowableInstance instance, FlowableAction action) { public void onAction(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onAction with spring: {}", flowableManager.listNodes()); log.info("onAction with spring: {}", flowableManager.listNodes());
} }
@Override @Override
public void onActionComplete(FlowableInstance instance, FlowableNode node) { public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onActionComplete with spring: {}", flowableManager.listNodes()); log.info("onActionComplete with spring: {}", flowableManager.listNodes());
} }
} }

View File

@@ -144,8 +144,18 @@ public abstract class FlowableManager {
action(instance, node, null, "系统自动执行"); action(instance, node, null, "系统自动执行");
} }
private void action(FlowableInstance instance, FlowableNode node, FlowableAction action, String comment) { private void action(FlowableInstance instance, FlowableNode node, final FlowableAction inputAction, String comment) {
callListeners(node.getListeners(), listener -> listener.onActionStart(instance, node)); 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())) { if (FlowableInstance.Status.COMPLETED.equals(instance.getStatus()) || FlowableInstance.Status.TERMINAL.equals(instance.getStatus())) {
throw new IllegalArgumentException("ID为" + instance.getInstanceId() + "的流程已结束,无法操作"); throw new IllegalArgumentException("ID为" + instance.getInstanceId() + "的流程已结束,无法操作");
@@ -160,18 +170,7 @@ public abstract class FlowableManager {
throw new IllegalArgumentException("权限校验不通过"); throw new IllegalArgumentException("权限校验不通过");
} }
String handlerClass = node.getHandler(); callListeners(node.getListeners(), listener -> listener.onAction(instance, node, action));
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));
// 如果是挂起操作,就直接返回,不做操作 // 如果是挂起操作,就直接返回,不做操作
if (FlowableAction.SUSPEND.equals(action)) { if (FlowableAction.SUSPEND.equals(action)) {
@@ -187,7 +186,7 @@ public abstract class FlowableManager {
|| !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)); callListeners(node.getListeners(), listener -> listener.onFlowEnd(instance, node, action));
return; return;
} }
String nextNodeId = node.getTargets().get(action); String nextNodeId = node.getTargets().get(action);
@@ -195,7 +194,7 @@ public abstract class FlowableManager {
instance.setCurrentNodeId(nextNode.getNodeId()); instance.setCurrentNodeId(nextNode.getNodeId());
saveInstance(instance, FlowableInstance.Status.RUNNING, action, comment); 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())) { if (FlowableNode.Type.AUTOMATIC.equals(nextNode.getType())) {
automaticAction(instance, node); automaticAction(instance, node);
} }

View File

@@ -9,11 +9,11 @@ package com.lanyuanxiaoyao.flowable.core.model;
public interface FlowableListener { public interface FlowableListener {
void onFlowStart(FlowableInstance instance, FlowableNode node); 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);
} }

View File

@@ -18,22 +18,22 @@ public class SimpleListener implements FlowableListener {
} }
@Override @Override
public void onFlowEnd(FlowableInstance instance, FlowableNode node) { public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onFlowEnd"); log.info("onFlowEnd");
} }
@Override @Override
public void onActionStart(FlowableInstance instance, FlowableNode node) { public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onActionStart"); log.info("onActionStart");
} }
@Override @Override
public void onAction(FlowableInstance instance, FlowableAction action) { public void onAction(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onAction"); log.info("onAction");
} }
@Override @Override
public void onActionComplete(FlowableInstance instance, FlowableNode node) { public void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onActionComplete"); log.info("onActionComplete");
} }
} }