mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
规则链
This commit is contained in:
9
.idea/.gitignore
generated
vendored
Normal file
9
.idea/.gitignore
generated
vendored
Normal 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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
29
pkg/rule_engine/nodes/action_my_node.go
Normal file
29
pkg/rule_engine/nodes/action_my_node.go
Normal 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
|
||||
}
|
||||
@@ -31,4 +31,6 @@ func init() {
|
||||
RegisterFactory(externalSendSmsNodeFactory{})
|
||||
RegisterFactory(externalRuleChainNodeFactory{})
|
||||
|
||||
RegisterFactory(myNodeFactory{})
|
||||
|
||||
}
|
||||
|
||||
@@ -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()),
|
||||
|
||||
BIN
uploads/file/47bce5c74f589f4867dbd57e9ca9f808_20230414135050.jpg
Normal file
BIN
uploads/file/47bce5c74f589f4867dbd57e9ca9f808_20230414135050.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 MiB |
BIN
uploads/file/626213519d0907c2f2ab12919fbd7779_20230414142538.png
Normal file
BIN
uploads/file/626213519d0907c2f2ab12919fbd7779_20230414142538.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 182 KiB |
BIN
uploads/file/9b37cd4ca37090649adcee8bf17cfdcc_20230414141350.png
Normal file
BIN
uploads/file/9b37cd4ca37090649adcee8bf17cfdcc_20230414141350.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
BIN
uploads/file/dc49aad85da7ae4c37374bf79e29134c_20230414144346.png
Normal file
BIN
uploads/file/dc49aad85da7ae4c37374bf79e29134c_20230414144346.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 127 KiB |
Reference in New Issue
Block a user