规则链

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 (
"context"
"fmt"
"github.com/sirupsen/logrus"
"pandax/pkg/rule_engine/manifest"
"pandax/pkg/rule_engine/message"
"pandax/pkg/rule_engine/nodes"
"strings"
)
// 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,
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
}

View File

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

View File

@@ -15,7 +15,7 @@ type inputNodeFactory struct{}
func (f inputNodeFactory) Name() string { return "InputNode" }
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) {
node := &inputNode{
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