mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
新增结点实现
This commit is contained in:
3
go.mod
3
go.mod
@@ -6,8 +6,10 @@ toolchain go1.22.7
|
||||
|
||||
require (
|
||||
github.com/IBM/sarama v1.43.3
|
||||
github.com/duanhf2012/rotatelogs v0.0.0-20250124024205-39765c212d8a
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/goccy/go-json v0.10.2
|
||||
github.com/gomodule/redigo v1.8.8
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
@@ -43,7 +45,6 @@ require (
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
||||
github.com/go-stack/stack v1.8.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -20,6 +20,8 @@ github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/duanhf2012/rotatelogs v0.0.0-20250124024205-39765c212d8a h1:BVmZrOSKTg9ry1YjqY6IjVXmBDsFdX/W+pnvO5cPUDc=
|
||||
github.com/duanhf2012/rotatelogs v0.0.0-20250124024205-39765c212d8a/go.mod h1:S/NNkpdnXps6VXaYVVDFtqQAm/NKayHxxOAhsrFnCgg=
|
||||
github.com/eapache/go-resiliency v1.7.0 h1:n3NRTnBn5N0Cbi/IeOHuQn9s2UwVUH7Ga0ZWcP+9JTA=
|
||||
github.com/eapache/go-resiliency v1.7.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws=
|
||||
|
||||
@@ -5,15 +5,14 @@ import (
|
||||
)
|
||||
|
||||
func TestExecMgr(t *testing.T) {
|
||||
|
||||
var bp Blueprint
|
||||
err := bp.Init("D:\\Develop\\OriginNodeEditor\\json", "D:\\Develop\\OriginNodeEditor\\vgf")
|
||||
if err != nil {
|
||||
t.Fatalf("init failed,err:%v", err)
|
||||
}
|
||||
|
||||
graphTest1 := bp.Create("testArray")
|
||||
err = graphTest1.Do(EntranceID_ArrayParam, 1, []int64{10, 11, 12})
|
||||
graphTest1 := bp.Create("testMath")
|
||||
err = graphTest1.Do(EntranceID_IntParam, 1, 2, 3)
|
||||
if err != nil {
|
||||
t.Fatalf("Do EntranceID_IntParam failed,err:%v", err)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import "fmt"
|
||||
type IBaseExecNode interface {
|
||||
initInnerExecNode(innerNode *innerExecNode)
|
||||
initExecNode(gr *Graph, en *execNode) error
|
||||
GetPorts() ([]IPort, []IPort)
|
||||
}
|
||||
|
||||
type IInnerExecNode interface {
|
||||
@@ -147,6 +148,7 @@ func (em *innerExecNode) IsInPortExec(index int) bool {
|
||||
|
||||
return em.inPort[index].IsPortExec()
|
||||
}
|
||||
|
||||
func (em *innerExecNode) IsOutPortExec(index int) bool {
|
||||
if index >= len(em.outPort) || index < 0 {
|
||||
return false
|
||||
@@ -201,6 +203,10 @@ func (en *BaseExecNode) initExecNode(gr *Graph, node *execNode) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (en *BaseExecNode) GetPorts() ([]IPort, []IPort) {
|
||||
return en.InputPorts, en.OutputPorts
|
||||
}
|
||||
|
||||
func (en *BaseExecNode) GetInPort(index int) IPort {
|
||||
if en.InputPorts == nil {
|
||||
return nil
|
||||
@@ -481,6 +487,10 @@ func (en *BaseExecNode) DoNext(index int) error {
|
||||
return fmt.Errorf("next index %d not found", index)
|
||||
}
|
||||
|
||||
if en.execNode.nextNode[index] == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return en.execNode.nextNode[index].Do(en.gr)
|
||||
}
|
||||
|
||||
|
||||
@@ -179,15 +179,17 @@ func (gp *GraphPool) prepareOneNode(mapNodeExec map[string]*execNode, nodeExec *
|
||||
for ; nodeExec.execNode.IsOutPortExec(idx) && idx < nodeExec.execNode.GetOutPortCount(); idx++ {
|
||||
// 找到出口结点
|
||||
nextExecNode := gp.findOutNextNode(graphConfig, mapNodeExec, nodeExec.Id, idx)
|
||||
if nextExecNode == nil {
|
||||
continue
|
||||
}
|
||||
nextExecNode.beConnect = true
|
||||
nodeExec.nextNode = append(nodeExec.nextNode, nextExecNode)
|
||||
if nextExecNode != nil {
|
||||
nextExecNode.beConnect = true
|
||||
}
|
||||
}
|
||||
|
||||
// 将所有的next填充next
|
||||
for _, nextOne := range nodeExec.nextNode {
|
||||
if nextOne == nil {
|
||||
continue
|
||||
}
|
||||
// 对出口进行预处理
|
||||
err := gp.prepareOneNode(mapNodeExec, nextOne, graphConfig, recursion)
|
||||
if err != nil {
|
||||
|
||||
237
util/blueprint/mathnode.go
Normal file
237
util/blueprint/mathnode.go
Normal file
@@ -0,0 +1,237 @@
|
||||
package blueprint
|
||||
|
||||
import "fmt"
|
||||
|
||||
func init() {
|
||||
RegExecNode(&AddInt{})
|
||||
RegExecNode(&SubInt{})
|
||||
RegExecNode(&MulInt{})
|
||||
RegExecNode(&DivInt{})
|
||||
RegExecNode(&ModInt{})
|
||||
}
|
||||
|
||||
type AddInt struct {
|
||||
BaseExecNode
|
||||
}
|
||||
|
||||
func (em *AddInt) GetName() string {
|
||||
return "AddInt"
|
||||
}
|
||||
|
||||
func (em *AddInt) Exec() (int, error) {
|
||||
inPortA := em.GetInPort(0)
|
||||
if inPortA == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 1 not found")
|
||||
}
|
||||
|
||||
inPortB := em.GetInPort(1)
|
||||
if inPortB == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
|
||||
outPortRet := em.GetOutPort(0)
|
||||
if outPortRet == nil {
|
||||
return -1, fmt.Errorf("AddInt outParam not found")
|
||||
}
|
||||
|
||||
inA, ok := inPortA.GetInt()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 1 not found")
|
||||
}
|
||||
inB, ok := inPortB.GetInt()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
ret := inA + inB
|
||||
outPortRet.SetInt(ret)
|
||||
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
type SubInt struct {
|
||||
BaseExecNode
|
||||
}
|
||||
|
||||
func (em *SubInt) GetName() string {
|
||||
return "SubInt"
|
||||
}
|
||||
|
||||
func (em *SubInt) Exec() (int, error) {
|
||||
inPortA := em.GetInPort(0)
|
||||
if inPortA == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 1 not found")
|
||||
}
|
||||
|
||||
inPortB := em.GetInPort(1)
|
||||
if inPortB == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
|
||||
inPortAbs := em.GetInPort(2)
|
||||
if inPortAbs == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
|
||||
outPortRet := em.GetOutPort(0)
|
||||
if outPortRet == nil {
|
||||
return -1, fmt.Errorf("AddInt outParam not found")
|
||||
}
|
||||
|
||||
inA, ok := inPortA.GetInt()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 1 not found")
|
||||
}
|
||||
inB, ok := inPortB.GetInt()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
isAbs, ok := inPortAbs.GetBool()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
ret := inA - inB
|
||||
if isAbs && ret < 0 {
|
||||
ret *= -1
|
||||
}
|
||||
|
||||
outPortRet.SetInt(ret)
|
||||
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
type MulInt struct {
|
||||
BaseExecNode
|
||||
}
|
||||
|
||||
func (em *MulInt) GetName() string {
|
||||
return "MulInt"
|
||||
}
|
||||
|
||||
func (em *MulInt) Exec() (int, error) {
|
||||
inPortA := em.GetInPort(0)
|
||||
if inPortA == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 1 not found")
|
||||
}
|
||||
|
||||
inPortB := em.GetInPort(1)
|
||||
if inPortB == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
|
||||
outPortRet := em.GetOutPort(0)
|
||||
if outPortRet == nil {
|
||||
return -1, fmt.Errorf("AddInt outParam not found")
|
||||
}
|
||||
|
||||
inA, ok := inPortA.GetInt()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 1 not found")
|
||||
}
|
||||
inB, ok := inPortB.GetInt()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
|
||||
outPortRet.SetInt(inA * inB)
|
||||
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
type DivInt struct {
|
||||
BaseExecNode
|
||||
}
|
||||
|
||||
func (em *DivInt) GetName() string {
|
||||
return "DivInt"
|
||||
}
|
||||
|
||||
func (em *DivInt) Exec() (int, error) {
|
||||
inPortA := em.GetInPort(0)
|
||||
if inPortA == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 1 not found")
|
||||
}
|
||||
|
||||
inPortB := em.GetInPort(1)
|
||||
if inPortB == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
|
||||
inPortRound := em.GetInPort(2)
|
||||
if inPortRound == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
|
||||
outPortRet := em.GetOutPort(0)
|
||||
if outPortRet == nil {
|
||||
return -1, fmt.Errorf("AddInt outParam not found")
|
||||
}
|
||||
|
||||
inA, ok := inPortA.GetInt()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 1 not found")
|
||||
}
|
||||
inB, ok := inPortB.GetInt()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
isRound, ok := inPortRound.GetBool()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
|
||||
if inB == 0 {
|
||||
return -1, fmt.Errorf("div zero error")
|
||||
}
|
||||
|
||||
var ret int64
|
||||
if isRound {
|
||||
ret = (inA + inB/2) / inB
|
||||
} else {
|
||||
ret = inA / inB
|
||||
}
|
||||
|
||||
outPortRet.SetInt(ret)
|
||||
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
type ModInt struct {
|
||||
BaseExecNode
|
||||
}
|
||||
|
||||
func (em *ModInt) GetName() string {
|
||||
return "ModInt"
|
||||
}
|
||||
|
||||
func (em *ModInt) Exec() (int, error) {
|
||||
inPortA := em.GetInPort(0)
|
||||
if inPortA == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 1 not found")
|
||||
}
|
||||
|
||||
inPortB := em.GetInPort(1)
|
||||
if inPortB == nil {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
|
||||
outPortRet := em.GetOutPort(0)
|
||||
if outPortRet == nil {
|
||||
return -1, fmt.Errorf("AddInt outParam not found")
|
||||
}
|
||||
|
||||
inA, ok := inPortA.GetInt()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 1 not found")
|
||||
}
|
||||
inB, ok := inPortB.GetInt()
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("AddInt inParam 2 not found")
|
||||
}
|
||||
if inB == 0 {
|
||||
return -1, fmt.Errorf("mod zero error")
|
||||
}
|
||||
|
||||
outPortRet.SetInt(inA % inB)
|
||||
|
||||
return -1, nil
|
||||
}
|
||||
@@ -71,7 +71,20 @@ func (en *execNode) exec(gr *Graph) (int, error) {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
//log.Debug("exec node %s", en.execNode.GetName())
|
||||
defer func() {
|
||||
inPort, outPort := node.GetPorts()
|
||||
debugString := "inPort:"
|
||||
for i := 0; i < len(inPort); i++ {
|
||||
debugString += fmt.Sprintf("%+v,", inPort[i])
|
||||
}
|
||||
debugString += " outPort:"
|
||||
for i := 0; i < len(outPort); i++ {
|
||||
debugString += fmt.Sprintf("%+v,", outPort[i])
|
||||
}
|
||||
|
||||
fmt.Printf("exec node %s,%s\n", en.execNode.GetName(), debugString)
|
||||
}()
|
||||
|
||||
return e.Exec()
|
||||
}
|
||||
|
||||
@@ -158,5 +171,8 @@ func (en *execNode) Do(gr *Graph, outPortArgs ...any) error {
|
||||
return fmt.Errorf("next index %d not found", nextIndex)
|
||||
}
|
||||
|
||||
if en.nextNode[nextIndex] == nil {
|
||||
return nil
|
||||
}
|
||||
return en.nextNode[nextIndex].Do(gr)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
// 系统入口ID定义,1000以内
|
||||
const (
|
||||
EntranceID_ArrayParam = 2
|
||||
EntranceID_IntParam = 3
|
||||
EntranceID_IntParam = 1
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -60,7 +60,7 @@ func (em *Output) Exec() (int, error) {
|
||||
return 0, fmt.Errorf("Output Exec inParam not found")
|
||||
}
|
||||
|
||||
fmt.Printf("Output Exec inParam %d", val)
|
||||
fmt.Printf("Output Exec inParam %d\n", val)
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user