规则链

This commit is contained in:
XM-GO
2023-04-17 17:18:15 +08:00
10 changed files with 138 additions and 68 deletions

9
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,9 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
./idea

View File

@@ -2,10 +2,12 @@ package rule_engine
import ( import (
"context" "context"
"fmt"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"pandax/pkg/rule_engine/manifest" "pandax/pkg/rule_engine/manifest"
"pandax/pkg/rule_engine/message" "pandax/pkg/rule_engine/message"
"pandax/pkg/rule_engine/nodes" "pandax/pkg/rule_engine/nodes"
"strings"
) )
// ruleChainInstance is rulechain's runtime instance that manage all nodes in this chain, // ruleChainInstance is rulechain's runtime instance that manage all nodes in this chain,
@@ -38,6 +40,30 @@ func newInstanceWithManifest(m *manifest.Manifest) (*ruleChainInstance, []error)
firstRuleNodeId: m.FirstRuleNodeId, firstRuleNodeId: m.FirstRuleNodeId,
nodes: nodes, nodes: nodes,
} }
for _, edge := range m.Edges {
originalNode, found := r.nodes[edge.SourceNodeId]
if !found {
err := fmt.Errorf("original node '%s' no exist in", originalNode.Name())
errs = append(errs, err)
continue
}
targetNode, found := r.nodes[edge.TargetNodeId]
if !found {
err := fmt.Errorf("target node '%s' no exist in rulechain", targetNode.Name())
errs = append(errs, err)
continue
}
types := make([]string, 0)
if _, ok := edge.Properties["lineType"]; !ok {
types = append(types, "True")
} else {
types = strings.Split(edge.Properties["lineType"].(string), "/")
}
for _, ty := range types {
originalNode.AddLinkedNode(ty, targetNode)
}
}
return r, errs return r, errs
} }

View File

@@ -1,125 +1,129 @@
{ {
"nodes": [ "nodes": [
{ {
"id": "3b6b8df4-445f-4e70-9674-f7aa486b3d81", "id": "d2cc123c-d0d7-4830-8547-21d5e52b4011",
"type": "InputNode", "type": "InputNode",
"x": 280, "x": 120,
"y": 280, "y": 340,
"properties": { "properties": {
"icon": "/src/assets/icon_module/svg/start.svg", "debugMode": false,
"debugMode": false "status": false
}, },
"zIndex": 1002, "zIndex": 1013,
"text": { "text": {
"x": 290, "x": 130,
"y": 280, "y": 340,
"value": "输入" "value": "输入"
} }
}, },
{ {
"id": "45afb241-1977-4cbf-8af3-c12844d5666b", "id": "6c497a23-ece2-41fa-927d-9e2e9a1c7316",
"type": "DelayNode", "type": "MyNode",
"x": 600, "x": 400,
"y": 160, "y": 340,
"properties": { "properties": {
"icon": "/src/assets/icon_module/svg/function.svg", "debugMode": false,
"debugMode": false "status": false
}, },
"zIndex": 1004, "zIndex": 1002,
"text": { "text": {
"x": 610, "x": 410,
"y": 160, "y": 340,
"value": "延迟" "value": "测试节点"
} }
}, },
{ {
"id": "95047b03-e966-4685-b625-3cea27415706", "id": "7235c088-73e0-4683-982a-77b0fd31313d",
"type": "SwitchNode", "type": "MyNode",
"x": 600, "x": 660,
"y": 460, "y": 340,
"properties": { "properties": {
"icon": "/src/assets/icon_module/svg/switch.svg",
"debugMode": false, "debugMode": false,
"scripts": "return {\n msg: msg,\n metadata: metadata,\n msgType: msgType\n};" "status": false
}, },
"zIndex": 1006, "zIndex": 1005,
"text": { "text": {
"x": 610, "x": 670,
"y": 460, "y": 340,
"value": "分流" "value": "测试节点"
} }
} }
], ],
"edges": [ "edges": [
{ {
"id": "fde7f2de-cc0f-467d-a614-4505f058dc2a", "id": "b6c8b0c4-1481-40d3-b345-780f96efa909",
"type": "bezier-link", "type": "bezier-link",
"sourceNodeId": "3b6b8df4-445f-4e70-9674-f7aa486b3d81", "sourceNodeId": "d2cc123c-d0d7-4830-8547-21d5e52b4011",
"targetNodeId": "45afb241-1977-4cbf-8af3-c12844d5666b", "targetNodeId": "6c497a23-ece2-41fa-927d-9e2e9a1c7316",
"startPoint": { "startPoint": {
"x": 340, "x": 180,
"y": 280 "y": 340
}, },
"endPoint": { "endPoint": {
"x": 540, "x": 340,
"y": 160 "y": 340
}, },
"properties": { "properties": {
"type": "Success" "lineType": "True"
}, },
"zIndex": 1007, "zIndex": 1003,
"pointsList": [ "pointsList": [
{
"x": 180,
"y": 340
},
{
"x": 280,
"y": 340
},
{
"x": 240,
"y": 340
},
{ {
"x": 340, "x": 340,
"y": 280 "y": 340
},
{
"x": 440,
"y": 280
},
{
"x": 440,
"y": 160
},
{
"x": 540,
"y": 160
} }
] ]
}, },
{ {
"id": "986878cc-a9be-42b5-afc0-6c0a169c4e4d", "id": "1e38236e-716b-44e7-8d96-6424f63fdacc",
"type": "bezier-link", "type": "bezier-link",
"sourceNodeId": "3b6b8df4-445f-4e70-9674-f7aa486b3d81", "sourceNodeId": "6c497a23-ece2-41fa-927d-9e2e9a1c7316",
"targetNodeId": "95047b03-e966-4685-b625-3cea27415706", "targetNodeId": "7235c088-73e0-4683-982a-77b0fd31313d",
"startPoint": { "startPoint": {
"x": 340, "x": 460,
"y": 280 "y": 340
}, },
"endPoint": { "endPoint": {
"x": 540, "x": 600,
"y": 460 "y": 340
}, },
"properties": { "properties": {
"type": "Failure" "lineType": "Next"
}, },
"zIndex": 1008, "text": {
"x": 530,
"y": 340,
"value": "Next"
},
"zIndex": 1006,
"pointsList": [ "pointsList": [
{ {
"x": 340, "x": 460,
"y": 280 "y": 340
}, },
{ {
"x": 440, "x": 560,
"y": 280 "y": 340
}, },
{ {
"x": 440, "x": 500,
"y": 460 "y": 340
}, },
{ {
"x": 540, "x": 600,
"y": 460 "y": 340
} }
] ]
} }

View File

@@ -0,0 +1,29 @@
package nodes
import (
"log"
"pandax/pkg/rule_engine/message"
)
type MyNode struct {
bareNode
}
type myNodeFactory struct{}
func (f myNodeFactory) Name() string { return "MyNode" }
func (f myNodeFactory) Category() string { return NODE_CATEGORY_ACTION }
func (f myNodeFactory) Labels() []string { return []string{"Next", "Next2"} }
func (f myNodeFactory) Create(id string, meta Metadata) (Node, error) {
node := &MyNode{
bareNode: newBareNode(f.Name(), id, meta, f.Labels()),
}
return decodePath(meta, node)
}
func (n *MyNode) Handle(msg message.Message) error {
nextLableNode := n.GetLinkedNode("Next")
log.Println(nextLableNode.Name())
return nil
}

View File

@@ -31,4 +31,6 @@ func init() {
RegisterFactory(externalSendSmsNodeFactory{}) RegisterFactory(externalSendSmsNodeFactory{})
RegisterFactory(externalRuleChainNodeFactory{}) RegisterFactory(externalRuleChainNodeFactory{})
RegisterFactory(myNodeFactory{})
} }

View File

@@ -15,7 +15,7 @@ type inputNodeFactory struct{}
func (f inputNodeFactory) Name() string { return "InputNode" } func (f inputNodeFactory) Name() string { return "InputNode" }
func (f inputNodeFactory) Category() string { return NODE_CATEGORY_OTHERS } func (f inputNodeFactory) Category() string { return NODE_CATEGORY_OTHERS }
func (f inputNodeFactory) Labels() []string { return []string{} } func (f inputNodeFactory) Labels() []string { return []string{"True"} }
func (f inputNodeFactory) Create(id string, meta Metadata) (Node, error) { func (f inputNodeFactory) Create(id string, meta Metadata) (Node, error) {
node := &inputNode{ node := &inputNode{
bareNode: newBareNode(InputNodeName, id, meta, f.Labels()), bareNode: newBareNode(InputNodeName, id, meta, f.Labels()),

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB