From 7a34fafdc8f0e8d343e36ed9087ff9808c6df87a Mon Sep 17 00:00:00 2001 From: boyce <6549168@qq.com> Date: Tue, 7 Oct 2025 22:06:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=95=B0=E7=BB=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/blueprint/blueprint_test.go | 4 +- util/blueprint/graph.go | 7 +- util/blueprint/port.go | 11 ++- util/blueprint/sysnodes.go | 137 +++++++++++++++++++++++++++++++ util/blueprint/variables.go | 1 - 5 files changed, 154 insertions(+), 6 deletions(-) diff --git a/util/blueprint/blueprint_test.go b/util/blueprint/blueprint_test.go index 0aa2bcc..dcaae70 100644 --- a/util/blueprint/blueprint_test.go +++ b/util/blueprint/blueprint_test.go @@ -11,12 +11,12 @@ func TestExecMgr(t *testing.T) { t.Fatalf("init failed,err:%v", err) } - graphTest1 := bp.Create("testSwitch") + graphTest1 := bp.Create("testArrayOperator") err = graphTest1.Do(EntranceID_IntParam, 20, 1, 3) if err != nil { t.Fatalf("Do EntranceID_IntParam failed,err:%v", err) } - + graphTest1.Release() //graphTest2 := bp.Create("testForeach") //err = graphTest2.Do(EntranceID_IntParam, 1, 2, 3) //if err != nil { diff --git a/util/blueprint/graph.go b/util/blueprint/graph.go index 83b58aa..27818e7 100644 --- a/util/blueprint/graph.go +++ b/util/blueprint/graph.go @@ -42,7 +42,7 @@ type edgeConfig struct { } type MultiTypeValue struct { - Value interface{} + Value any } // 实现json.Unmarshaler接口,自定义解码逻辑 @@ -75,6 +75,11 @@ func (v *MultiTypeValue) UnmarshalJSON(data []byte) error { return nil } + var arrayVal []any + if err := json.Unmarshal(data, &arrayVal); err == nil { + v.Value = arrayVal + return nil + } // 如果都失败,返回错误 return fmt.Errorf("cannot unmarshal JSON value: %s", string(data)) } diff --git a/util/blueprint/port.go b/util/blueprint/port.go index 964b7b7..2a58759 100644 --- a/util/blueprint/port.go +++ b/util/blueprint/port.go @@ -22,9 +22,16 @@ type Port[T iPortType] struct { } func (em *Port[T]) Clone() IPort { - return &Port[T]{ - PortVal: em.PortVal, + arrayData, ok := any(em.PortVal).(Port_Array) + if !ok { + return &Port[T]{ + PortVal: em.PortVal, + } } + + portArray := Port[Port_Array]{} + portArray.PortVal = append(portArray.PortVal, arrayData...) + return &portArray } func (em *Port[T]) Reset() { diff --git a/util/blueprint/sysnodes.go b/util/blueprint/sysnodes.go index a7453b3..bf99e44 100644 --- a/util/blueprint/sysnodes.go +++ b/util/blueprint/sysnodes.go @@ -21,6 +21,10 @@ func init() { RegExecNode(&GetArrayInt{}) RegExecNode(&GetArrayString{}) RegExecNode(&GetArrayLen{}) + RegExecNode(&CreateIntArray{}) + RegExecNode(&CreateStringArray{}) + RegExecNode(&AppendIntegerToArray{}) + RegExecNode(&AppendStringToArray{}) RegExecNode(&BoolIf{}) RegExecNode(&GreaterThanInteger{}) @@ -458,3 +462,136 @@ func (em *Probability) Exec() (int, error) { return 0, nil } + +// CreateIntArray 创建整型数组 +type CreateIntArray struct { + BaseExecNode +} + +func (em *CreateIntArray) GetName() string { + return "CreateIntArray" +} + +func (em *CreateIntArray) Exec() (int, error) { + intArray := em.execNode.GetInPortDefaultIntArrayValue(0) + if intArray == nil { + return -1, fmt.Errorf("CreateIntArray inParam 0 not found") + } + + outPort := em.GetOutPort(0) + if outPort == nil { + return -1, fmt.Errorf("GetArrayInt outParam 0 not found") + } + + for _, v := range intArray { + outPort.AppendArrayValInt(v) + } + + return -1, nil +} + +// CreateStringArray 创建字符串数组 +type CreateStringArray struct { + BaseExecNode +} + +func (em *CreateStringArray) GetName() string { + return "CreateStringArray" +} + +func (em *CreateStringArray) Exec() (int, error) { + intArray := em.execNode.GetInPortDefaultStringArrayValue(0) + if intArray == nil { + return -1, fmt.Errorf("CreateIntArray inParam 0 not found") + } + + outPort := em.GetOutPort(0) + if outPort == nil { + return -1, fmt.Errorf("GetArrayInt outParam 0 not found") + } + + for _, v := range intArray { + outPort.AppendArrayValStr(v) + } + + return -1, nil +} + +// AppendIntegerToArray 数组追加整型 +type AppendIntegerToArray struct { + BaseExecNode +} + +func (em *AppendIntegerToArray) GetName() string { + return "AppendIntegerToArray" +} + +func (em *AppendIntegerToArray) Exec() (int, error) { + inPortArray := em.GetInPort(0) + if inPortArray == nil { + return -1, fmt.Errorf("AppendIntegerToArray inParam 0 not found") + } + + inPortVal := em.GetInPort(1) + if inPortVal == nil { + return -1, fmt.Errorf("AppendIntegerToArray inParam 1 not found") + } + + outPort := em.GetOutPort(0) + if outPort == nil { + return -1, fmt.Errorf("AppendIntegerToArray outParam 0 not found") + } + + intArray, ok := inPortArray.GetArray() + if !ok { + return -1, fmt.Errorf("AppendIntegerToArray inParam 0 error") + } + + intVal, ok := inPortVal.GetInt() + if !ok { + return -1, fmt.Errorf("AppendIntegerToArray inParam 1 error") + } + + for i := range intArray { + outPort.AppendArrayValInt(intArray[i].IntVal) + } + outPort.AppendArrayValInt(intVal) + return -1, nil +} + +// AppendStringToArray 数组追加字符串 +type AppendStringToArray struct { + BaseExecNode +} + +func (em *AppendStringToArray) GetName() string { + return "AppendStringToArray" +} + +func (em *AppendStringToArray) Exec() (int, error) { + inPortArray := em.GetInPort(0) + if inPortArray == nil { + return -1, fmt.Errorf("AppendStringToArray inParam 0 not found") + } + + inPortVal := em.GetInPort(1) + if inPortVal == nil { + return -1, fmt.Errorf("AppendStringToArray inParam 1 not found") + } + + outPort := em.GetOutPort(0) + if outPort == nil { + return -1, fmt.Errorf("AppendStringToArray outParam 0 not found") + } + + intArray, ok := inPortArray.GetArray() + if !ok { + return -1, fmt.Errorf("AppendStringToArray inParam 0 error") + } + + for i := range intArray { + outPort.AppendArrayValStr(intArray[i].StrVal) + } + + return -1, nil +} diff --git a/util/blueprint/variables.go b/util/blueprint/variables.go index 0df672a..40194ef 100644 --- a/util/blueprint/variables.go +++ b/util/blueprint/variables.go @@ -60,7 +60,6 @@ func (g *SetVariablesNode) Exec() (int, error) { } varPort := port.Clone() - varPort.SetValue(port) if strings.HasPrefix(g.varName, globalVariablesPrefix) { g.gr.globalVariables[g.varName] = varPort } else {