diff --git a/util/blueprint/exec.go b/util/blueprint/exec.go index 3ba6be4..2d37f61 100644 --- a/util/blueprint/exec.go +++ b/util/blueprint/exec.go @@ -22,6 +22,8 @@ type IInnerExecNode interface { GetInPort(index int) IPort GetOutPort(index int) IPort + + GetOutPortParamStartIndex() int } type IExecNode interface { @@ -40,8 +42,10 @@ type innerExecNode struct { Package string Description string - inPort []IPort - outPort []IPort + inPort []IPort // 下标即为portId + outPort []IPort // 下标即为portId + + outPortParamStartIndex int // 输出参数的起始索引,用于排除执行出口 IExecNode } @@ -139,21 +143,27 @@ func (em *innerExecNode) SetOutPortById(id int, port IPort) bool { return false } em.outPort[id] = port + + // 分析执行的 + em.outPortParamStartIndex = -1 + for i := range em.outPort { + if em.outPort[i] == nil { + continue + } + + // 遇到非Exec结点,即为输出参数开始位置 + if !em.outPort[i].IsPortExec() { + em.outPortParamStartIndex = i + break + } + } + return true } -// -//func (em *innerExecNode) AppendOutPort(port ...IPort) { -// if len(em.outPort) == 0 { -// em.outPortParamStartIndex = -1 -// } -// for i := 0; i < len(port); i++ { -// if !port[i].IsPortExec() && em.outPortParamStartIndex < 0 { -// em.outPortParamStartIndex = len(em.outPort) -// } -// em.outPort = append(em.outPort, port[i]) -// } -//} +func (em *innerExecNode) GetOutPortParamStartIndex() int { + return em.outPortParamStartIndex +} func (em *innerExecNode) GetName() string { return em.Name @@ -166,6 +176,10 @@ func (em *innerExecNode) SetExec(exec IExecNode) { func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) { inPorts := make([]IPort, 0, 2) for _, port := range em.inPort { + if port == nil { + inPorts = append(inPorts, nil) + } + if port.IsPortExec() { // 执行入口, 不需要克隆,占位处理 inPorts = append(inPorts, nil) @@ -177,6 +191,10 @@ func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) { outPorts := make([]IPort, 0, 2) for _, port := range em.outPort { + if port == nil { + outPorts = append(outPorts, nil) + } + if port.IsPortExec() { outPorts = append(outPorts, nil) continue diff --git a/util/blueprint/execpool.go b/util/blueprint/execpool.go index 1ff76ed..25fa4d7 100644 --- a/util/blueprint/execpool.go +++ b/util/blueprint/execpool.go @@ -7,6 +7,7 @@ import ( "path/filepath" "strconv" "strings" + "sort" ) // 格式说明Entrance_ID @@ -83,6 +84,15 @@ func (em *ExecPool) processJSONFile(filePath string) error { } for i := range baseExecConfig { + // 排序 + sort.Slice(baseExecConfig[i].Inputs, func(left, right int) bool { + return baseExecConfig[i].Inputs[left].PortId < baseExecConfig[i].Inputs[right].PortId + }) + + sort.Slice(baseExecConfig[i].Outputs, func(left, right int) bool { + return baseExecConfig[i].Outputs[left].PortId < baseExecConfig[i].Outputs[right].PortId + }) + exec, err := em.createExecFromJSON(baseExecConfig[i]) if err != nil { return err diff --git a/util/blueprint/graphpool.go b/util/blueprint/graphpool.go index 3e08777..112bff8 100644 --- a/util/blueprint/graphpool.go +++ b/util/blueprint/graphpool.go @@ -263,7 +263,7 @@ func (gp *GraphPool) findPreInPortNode(mapNodes map[string]*execNode, nodeExec * var preNode prePortNode preNode.node = srcNode - preNode.outPortIndex = edge.SourcePortId + preNode.outPortId = edge.SourcePortId return &preNode } diff --git a/util/blueprint/node.go b/util/blueprint/node.go index 43bca69..f26ed79 100644 --- a/util/blueprint/node.go +++ b/util/blueprint/node.go @@ -5,8 +5,8 @@ import ( ) type prePortNode struct { - node *execNode // 上个结点 - outPortIndex int // 对应上一个结点的OutPort索引 + node *execNode // 上个结点 + outPortId int // 对应上一个结点的OutPortId } type execNode struct { @@ -142,9 +142,9 @@ func (en *execNode) doSetInPort(gr *Graph, index int, inPort IPort) error { // 判断上一个结点是否已经执行过 if _, ok := gr.context[preNode.node.Id]; ok { - outPort := gr.GetNodeOutPortValue(preNode.node.Id, preNode.outPortIndex) + outPort := gr.GetNodeOutPortValue(preNode.node.Id, preNode.outPortId) if outPort == nil { - return fmt.Errorf("pre node %s out port index %d not found", preNode.node.Id, preNode.outPortIndex) + return fmt.Errorf("pre node %s out port index %d not found", preNode.node.Id, preNode.outPortId) } inPort.SetValue(outPort) @@ -175,12 +175,12 @@ func (en *execNode) Do(gr *Graph, outPortArgs ...any) error { // 处理InPort结点值 var err error - for index := range inPorts { - if en.execNode.IsInPortExec(index) { + for portId := range inPorts { + if en.execNode.IsInPortExec(portId) { continue } - err = en.doSetInPort(gr, index, inPorts[index]) + err = en.doSetInPort(gr, portId, inPorts[portId]) if err != nil { return err }