Browse Source

调整node实例id的生成时机

jay li 7 months ago
parent
commit
3abca48b2f

+ 23 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java

@@ -2,6 +2,8 @@ package com.yomahub.liteflow.builder.el;
 
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.*;
 import cn.hutool.core.util.*;
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.digest.Digester;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.ql.util.express.DefaultContext;
 import com.ql.util.express.DefaultContext;
@@ -215,6 +217,12 @@ public class LiteFlowChainELBuilder {
 				throw new QLException(StrUtil.format("parse el fail,el:[{}]", elStr));
 				throw new QLException(StrUtil.format("parse el fail,el:[{}]", elStr));
 			}
 			}
 
 
+			condition.getExecutableGroup().forEach((s, executables) -> executables.forEach(executable -> {
+				if (executable instanceof Node) {
+					((Node) executable).setInstanceId(generateInstanceId(executable.getId()));
+				}
+			}));
+
 			// 把主要的condition加入
 			// 把主要的condition加入
 			this.conditionList.add(condition);
 			this.conditionList.add(condition);
 			return this;
 			return this;
@@ -438,4 +446,19 @@ public class LiteFlowChainELBuilder {
 		}
 		}
 	}
 	}
 
 
+	private String generateInstanceId(String nodeId) {
+		Digester sha256 = SecureUtil.sha256();
+		byte[] hashBytes = sha256.digest(nodeId + System.nanoTime());
+
+		StringBuilder sb = new StringBuilder();
+		for (byte b : hashBytes) {
+			if (sb.length() >= 8) {
+				break;
+			}
+			sb.append(String.format("%02x", b));
+		}
+
+		return sb.toString();
+	}
+
 }
 }

+ 2 - 17
liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java

@@ -89,7 +89,7 @@ public abstract class NodeComponent{
 		Slot slot = this.getSlot();
 		Slot slot = this.getSlot();
 
 
 		// 在元数据里加入step信息
 		// 在元数据里加入step信息
-		CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE, generateInstanceId());
+		CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE, instanceId);
 		cmpStep.setTag(this.getTag());
 		cmpStep.setTag(this.getTag());
 		cmpStep.setInstance(this);
 		cmpStep.setInstance(this);
 		cmpStep.setRefNode(this.getRefNode());
 		cmpStep.setRefNode(this.getRefNode());
@@ -157,7 +157,7 @@ public abstract class NodeComponent{
 			return;
 			return;
 		}
 		}
 
 
-		CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE, generateInstanceId());
+		CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE, instanceId);
 		cmpStep.setTag(this.getTag());
 		cmpStep.setTag(this.getTag());
 		cmpStep.setInstance(this);
 		cmpStep.setInstance(this);
 		cmpStep.setRefNode(this.getRefNode());
 		cmpStep.setRefNode(this.getRefNode());
@@ -241,21 +241,6 @@ public abstract class NodeComponent{
 		this.getRefNode().setIsContinueOnErrorResult(isContinueOnError);
 		this.getRefNode().setIsContinueOnErrorResult(isContinueOnError);
 	}
 	}
 
 
-	public String generateInstanceId() {
-		Digester sha256 = SecureUtil.sha256();
-		byte[] hashBytes = sha256.digest(this.getNodeId() + System.nanoTime());
-
-		StringBuilder sb = new StringBuilder();
-		for (byte b : hashBytes) {
-			if (sb.length() >= 6) {
-				break;
-			}
-			sb.append(String.format("%02x", b));
-		}
-
-		return sb.toString();
-	}
-
 	public Integer getSlotIndex() {
 	public Integer getSlotIndex() {
 		return this.getRefNode().getSlotIndex();
 		return this.getRefNode().getSlotIndex();
 	}
 	}

+ 11 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Node.java

@@ -40,6 +40,8 @@ public class Node implements Executable, Cloneable, Rollbackable{
 
 
 	private String id;
 	private String id;
 
 
+	private String instanceId;
+
 	private String name;
 	private String name;
 
 
 	private String clazz;
 	private String clazz;
@@ -95,6 +97,14 @@ public class Node implements Executable, Cloneable, Rollbackable{
 		return id;
 		return id;
 	}
 	}
 
 
+	public String getInstanceId() {
+		return instanceId;
+	}
+
+	public void setInstanceId(String instanceId) {
+		this.instanceId = instanceId;
+	}
+
 	@Override
 	@Override
 	public void setId(String id) {
 	public void setId(String id) {
 		this.id = id;
 		this.id = id;
@@ -146,6 +156,7 @@ public class Node implements Executable, Cloneable, Rollbackable{
 			// 把线程属性赋值给组件对象
 			// 把线程属性赋值给组件对象
 			this.setSlotIndex(slotIndex);
 			this.setSlotIndex(slotIndex);
 			instance.setRefNode(this);
 			instance.setRefNode(this);
+			instance.setInstanceId(this.instanceId);
 
 
 			// 判断是否可执行,所以isAccess经常作为一个组件进入的实际判断要素,用作检查slot里的参数的完备性
 			// 判断是否可执行,所以isAccess经常作为一个组件进入的实际判断要素,用作检查slot里的参数的完备性
 			if (getAccessResult() || instance.isAccess()) {
 			if (getAccessResult() || instance.isAccess()) {