1
0

统一自动节点和手动节点的逻辑

This commit is contained in:
2025-01-03 10:34:25 +08:00
parent 07ee530b79
commit 7885f8e87a
10 changed files with 70 additions and 42 deletions

View File

@@ -26,15 +26,14 @@ public class SpringFlowableManager extends FlowableManager {
@Override
protected <T> T createBean(String classpath) {
Class<?> clazz = Class.forName(classpath);
T targetObject = null;
T targetObject;
try {
targetObject = (T) applicationContext.getBean(clazz);
} catch (Exception springException) {
log.warn("{} not found in spring context", springException);
try {
targetObject = (T) clazz.newInstance();
} catch (Exception javaException) {
throw new IllegalArgumentException(javaException);
throw new IllegalArgumentException(javaException.initCause(springException));
}
}
return targetObject;

View File

@@ -47,12 +47,12 @@ public class JpaFlowableNode {
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private FlowableNode.Type type;
private String automaticAction;
private String handler;
@ElementCollection(fetch = javax.persistence.FetchType.EAGER)
@MapKeyColumn(name = "action")
@Column(name = "nodeId")
@CollectionTable(name = "flowable_node_manual_actions", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Map<FlowableAction, String> manualActions;
@CollectionTable(name = "flowable_node_targets", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Map<FlowableAction, String> targets;
@CreatedDate
private LocalDateTime createdTime;
@@ -64,12 +64,12 @@ public class JpaFlowableNode {
this.name = node.getName();
this.description = node.getDescription();
this.type = node.getType();
this.automaticAction = node.getAutomaticAction();
this.manualActions = node.getManualActions();
this.handler = node.getHandler();
this.targets = node.getTargets();
}
public FlowableNode toFlowableNode() {
FlowableNode node = new FlowableNode(nodeId, name, description, type, automaticAction, manualActions, null, createdTime);
FlowableNode node = new FlowableNode(nodeId, name, description, type, handler, targets, null, createdTime);
node.setUpdatedTime(updateTime);
return node;
}

View File

@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.flowable.jpa;
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
import java.util.Map;
@@ -13,12 +14,12 @@ import lombok.extern.slf4j.Slf4j;
* @version 20250102
*/
@Slf4j
public class SimpleAutoAction implements FlowableNode.AutoAction {
public class SimpleAutoAction implements FlowableHandler {
@Resource
private FlowableManager flowableManager;
@Override
public FlowableAction action(FlowableInstance instance, FlowableNode node, Map<String, Object> metadata) {
public FlowableAction handle(FlowableAction action, FlowableInstance instance, FlowableNode node, Map<String, Object> metadata) {
log.info("Initial with spring: {}", flowableManager.listNodes());
return FlowableAction.APPROVE;
}

View File

@@ -1,6 +1,7 @@
package com.lanyuanxiaoyao.flowable.jpa;
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
import com.lanyuanxiaoyao.flowable.test.TestFlowableManager;
import javax.annotation.Resource;
import org.springframework.boot.test.context.SpringBootTest;
@@ -20,7 +21,7 @@ public class TestSpringFlowableManager extends TestFlowableManager {
}
@Override
protected Class<?> getAutomaticNodeClass() {
protected Class<? extends FlowableHandler> getAutomaticNodeClass() {
return SimpleAutoAction.class;
}
}