From 2a12d40f7ab0dc0e48e6647d98c2eb155464e6ed Mon Sep 17 00:00:00 2001 From: boyce <6549168@qq.com> Date: Tue, 23 Sep 2025 15:06:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/blueprint/blueprint_test.go | 3 ++- util/blueprint/exec.go | 40 ++++++++++++++++++++++++++++++-- util/blueprint/node.go | 3 ++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/util/blueprint/blueprint_test.go b/util/blueprint/blueprint_test.go index d424600..88c87bc 100644 --- a/util/blueprint/blueprint_test.go +++ b/util/blueprint/blueprint_test.go @@ -24,8 +24,9 @@ type Output struct { func (em *Output) GetName() string { return "Output" } + func (em *Output) Exec() (int, error) { - val, ok := em.GetInPortInt(0) + val, ok := em.GetInPortInt(1) if !ok { return 0, fmt.Errorf("Output Exec inParam not found") } diff --git a/util/blueprint/exec.go b/util/blueprint/exec.go index b2f8860..2637fca 100644 --- a/util/blueprint/exec.go +++ b/util/blueprint/exec.go @@ -18,6 +18,9 @@ type IInnerExecNode interface { GetInPort(index int) IPort GetOutPort(index int) IPort + + GetInPortParamStartIndex() int + GetOutPortParamStartIndex() int } type IExecNode interface { @@ -36,6 +39,9 @@ type innerExecNode struct { InPort []IPort OutPort []IPort + + inPortParamStartIndex int // 输入参数的起始索引,用于排除执行入口 + outPortParamStartIndex int // 输出参数的起始索引,用于排除执行出口 IExecNode } @@ -74,11 +80,29 @@ type BaseExecConfig struct { } func (em *innerExecNode) AppendInPort(port ...IPort) { - em.InPort = append(em.InPort, port...) + if len(em.InPort) == 0 { + em.inPortParamStartIndex = -1 + } + + for i := 0; i < len(port); i++ { + if !port[i].IsPortExec() && em.inPortParamStartIndex < 0 { + em.inPortParamStartIndex = len(em.InPort) + } + + em.InPort = append(em.InPort, port[i]) + } } func (em *innerExecNode) AppendOutPort(port ...IPort) { - em.OutPort = append(em.OutPort, port...) + 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) GetName() string { @@ -93,6 +117,8 @@ func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) { inPorts := make([]IPort, 0, 2) for _, port := range em.InPort { if port.IsPortExec() { + // 执行入口, 不需要克隆,占位处理 + inPorts = append(inPorts, nil) continue } @@ -102,6 +128,7 @@ func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) { for _, port := range em.OutPort { if port.IsPortExec() { + outPorts = append(outPorts, nil) continue } outPorts = append(outPorts, port.Clone()) @@ -147,6 +174,14 @@ func (em *innerExecNode) GetOutPort(index int) IPort { return em.OutPort[index] } +func (em *innerExecNode) GetInPortParamStartIndex() int { + return em.inPortParamStartIndex +} + +func (em *innerExecNode) GetOutPortParamStartIndex() int { + return em.outPortParamStartIndex +} + func (en *BaseExecNode) initInnerExecNode(innerNode *innerExecNode) { en.innerExecNode = innerNode } @@ -197,6 +232,7 @@ func (en *BaseExecNode) GetInPortInt(index int) (Port_Int, bool) { if port == nil { return 0, false } + return port.GetInt() } diff --git a/util/blueprint/node.go b/util/blueprint/node.go index aa53089..9d08a79 100644 --- a/util/blueprint/node.go +++ b/util/blueprint/node.go @@ -90,12 +90,13 @@ func (en *execNode) Do(gr *Graph, outPortArgs ...any) error { OutputPorts: outPorts, } + startOutIdx := en.execNode.GetOutPortParamStartIndex() for i := 0; i < len(outPortArgs); i++ { if i >= len(outPorts) { return fmt.Errorf("args %d not found in node %s", i, en.execNode.GetName()) } - if err := outPorts[i].setAnyVale(outPortArgs[i]); err != nil { + if err := outPorts[i+startOutIdx].setAnyVale(outPortArgs[i]); err != nil { return fmt.Errorf("args %d set value error: %w", i, err) } }