1
0

调整核心类的创建方式

This commit is contained in:
2025-01-03 16:10:37 +08:00
parent 45ce5a2615
commit 743e2db17d
8 changed files with 76 additions and 91 deletions

View File

@@ -25,7 +25,7 @@ public class MapHelper {
return map;
}
public static Map<String, Object> empty() {
public static <K, V> Map<K, V> empty() {
return new HashMap<>(0);
}

View File

@@ -3,6 +3,7 @@ package com.lanyuanxiaoyao.flowable.core.manager;
import com.lanyuanxiaoyao.flowable.core.helper.ListHelper;
import com.lanyuanxiaoyao.flowable.core.helper.MapHelper;
import com.lanyuanxiaoyao.flowable.core.helper.StringHelper;
import com.lanyuanxiaoyao.flowable.core.model.FlowableAccessor;
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
import com.lanyuanxiaoyao.flowable.core.model.FlowableHistory;
@@ -68,7 +69,11 @@ public abstract class FlowableManager {
public String start(String nodeId, Map<String, Object> metadata) {
FlowableNode node = repository.getNode(nodeId);
FlowableInstance instance = new FlowableInstance(createId(), node.getNodeId(), new FlowableMetadata(metadata));
FlowableInstance instance = FlowableInstance.builder()
.instanceId(createId())
.currentNodeId(node.getNodeId())
.metadata(new FlowableMetadata(metadata))
.build();
repository.saveInstance(instance);
if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) {

View File

@@ -1,6 +1,8 @@
package com.lanyuanxiaoyao.flowable.core.model;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
/**
@@ -8,6 +10,8 @@ import lombok.Data;
* @version 20241231
*/
@Data
@AllArgsConstructor
@Builder
public class FlowableHistory {
private final String historyId;
private final String instanceId;
@@ -18,12 +22,4 @@ public class FlowableHistory {
public FlowableHistory(String historyId, String instanceId, FlowableAction action, String comment) {
this(historyId, instanceId, action, comment, LocalDateTime.now());
}
public FlowableHistory(String historyId, String instanceId, FlowableAction action, String comment, LocalDateTime createdTime) {
this.historyId = historyId;
this.instanceId = instanceId;
this.action = action;
this.comment = comment;
this.createdTime = createdTime;
}
}

View File

@@ -2,6 +2,8 @@ package com.lanyuanxiaoyao.flowable.core.model;
import java.time.LocalDateTime;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
/**
@@ -9,31 +11,20 @@ import lombok.Data;
* @version 20241231
*/
@Data
@AllArgsConstructor
@Builder
public class FlowableInstance {
private final String instanceId;
private final FlowableMetadata metadata;
private final LocalDateTime createdTime;
@Builder.Default
private final FlowableMetadata metadata = new FlowableMetadata();
@Builder.Default
private final LocalDateTime createdTime = LocalDateTime.now();
private String currentNodeId;
private Status status;
private LocalDateTime updatedTime;
public FlowableInstance(String instanceId, String currentNodeId) {
this(instanceId, currentNodeId, new FlowableMetadata(), Status.RUNNING, LocalDateTime.now(), LocalDateTime.now());
}
public FlowableInstance(String instanceId, String currentNodeId, FlowableMetadata metadata) {
this(instanceId, currentNodeId, metadata, Status.RUNNING, LocalDateTime.now(), LocalDateTime.now());
}
public FlowableInstance(String instanceId, String currentNodeId, FlowableMetadata metadata, Status status, LocalDateTime createdTime, LocalDateTime updatedTime) {
this.instanceId = instanceId;
this.metadata = metadata;
this.createdTime = createdTime;
this.currentNodeId = currentNodeId;
this.status = status;
this.updatedTime = updatedTime;
}
@Builder.Default
private Status status = Status.RUNNING;
@Builder.Default
private LocalDateTime updatedTime = LocalDateTime.now();
public void addMetadata(Map<String, Object> metadata) {
this.metadata.putAll(metadata);

View File

@@ -1,9 +1,11 @@
package com.lanyuanxiaoyao.flowable.core.model;
import com.lanyuanxiaoyao.flowable.core.helper.ListHelper;
import com.lanyuanxiaoyao.flowable.core.helper.MapHelper;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
/**
@@ -13,43 +15,29 @@ import lombok.Data;
* @version 20241231
*/
@Data
@AllArgsConstructor
@Builder
public class FlowableNode {
private final String nodeId;
private final String name;
private final String description;
private final Type type;
private final String handler;
private final Map<FlowableAction, String> targets;
@Builder.Default
private final Type type = Type.MANUAL;
@Builder.Default
private final String handler = FlowableHandler.DefaultFlowableHandler.class.getName();
@Builder.Default
private final Map<FlowableAction, String> targets = MapHelper.empty();
@Builder.Default
private final String accessor = FlowableAccessor.DefaultFlowableAccessor.class.getName();
private final List<String> listeners;
private final LocalDateTime createdTime;
@Builder.Default
private final LocalDateTime createdTime = LocalDateTime.now();
@Builder.Default
private LocalDateTime updatedTime = LocalDateTime.now();
public FlowableNode(String nodeId, String name, String description, Map<FlowableAction, String> targets) {
this(nodeId, name, description, Type.MANUAL, FlowableHandler.DefaultFlowableHandler.class, targets);
}
public FlowableNode(String nodeId, String name, String description, Class<? extends FlowableHandler> actionClass, Map<FlowableAction, String> targets) {
this(nodeId, name, description, Type.AUTOMATIC, actionClass, targets);
}
public FlowableNode(String nodeId, String name, String description, Type type, Class<? extends FlowableHandler> actionClass, Map<FlowableAction, String> targets) {
this(nodeId, name, description, type, actionClass.getName(), targets, ListHelper.empty(), LocalDateTime.now());
}
public FlowableNode(String nodeId, String name, String description, Type type, String handler, Map<FlowableAction, String> targets, List<String> listeners, LocalDateTime createdTime) {
this.nodeId = nodeId;
this.name = name;
this.description = description;
this.type = type;
this.handler = handler;
this.targets = targets;
this.listeners = listeners;
this.createdTime = createdTime;
}
public enum Type {
AUTOMATIC,
MANUAL,