mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
调整node实例id的生成时机
This commit is contained in:
@@ -2,6 +2,8 @@ package com.yomahub.liteflow.builder.el;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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.ObjectMapper;
|
||||
import com.ql.util.express.DefaultContext;
|
||||
@@ -215,6 +217,12 @@ public class LiteFlowChainELBuilder {
|
||||
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加入
|
||||
this.conditionList.add(condition);
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public abstract class NodeComponent{
|
||||
Slot slot = this.getSlot();
|
||||
|
||||
// 在元数据里加入step信息
|
||||
CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE, generateInstanceId());
|
||||
CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE, instanceId);
|
||||
cmpStep.setTag(this.getTag());
|
||||
cmpStep.setInstance(this);
|
||||
cmpStep.setRefNode(this.getRefNode());
|
||||
@@ -157,7 +157,7 @@ public abstract class NodeComponent{
|
||||
return;
|
||||
}
|
||||
|
||||
CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE, generateInstanceId());
|
||||
CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE, instanceId);
|
||||
cmpStep.setTag(this.getTag());
|
||||
cmpStep.setInstance(this);
|
||||
cmpStep.setRefNode(this.getRefNode());
|
||||
@@ -241,21 +241,6 @@ public abstract class NodeComponent{
|
||||
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() {
|
||||
return this.getRefNode().getSlotIndex();
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ public class Node implements Executable, Cloneable, Rollbackable{
|
||||
|
||||
private String id;
|
||||
|
||||
private String instanceId;
|
||||
|
||||
private String name;
|
||||
|
||||
private String clazz;
|
||||
@@ -95,6 +97,14 @@ public class Node implements Executable, Cloneable, Rollbackable{
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getInstanceId() {
|
||||
return instanceId;
|
||||
}
|
||||
|
||||
public void setInstanceId(String instanceId) {
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
@@ -146,6 +156,7 @@ public class Node implements Executable, Cloneable, Rollbackable{
|
||||
// 把线程属性赋值给组件对象
|
||||
this.setSlotIndex(slotIndex);
|
||||
instance.setRefNode(this);
|
||||
instance.setInstanceId(this.instanceId);
|
||||
|
||||
// 判断是否可执行,所以isAccess经常作为一个组件进入的实际判断要素,用作检查slot里的参数的完备性
|
||||
if (getAccessResult() || instance.isAccess()) {
|
||||
|
||||
Reference in New Issue
Block a user