|
@@ -9,6 +9,13 @@ import (
|
|
|
"sparrow/services/knowoapi/model"
|
|
|
)
|
|
|
|
|
|
+var nodeType = map[string]string{
|
|
|
+ "MsgTypeFilter": "MsgTypeFilterNode",
|
|
|
+ "MsgTypeSwitchNode": "MsgTypeSwitchNode",
|
|
|
+ "JavascriptFilter": "FilterJavascriptNode",
|
|
|
+ "RestApiAction": "RestApiRequestNode",
|
|
|
+}
|
|
|
+
|
|
|
// RuleChainService 业务接口
|
|
|
type RuleChainService interface {
|
|
|
Create(*models.RuleChain) error
|
|
@@ -17,7 +24,6 @@ type RuleChainService interface {
|
|
|
Query(int, int, string) ([]models.RuleChain, int, error)
|
|
|
Get(vendorId, recordId string) (models.RuleChain, error)
|
|
|
}
|
|
|
-
|
|
|
type ruleChainService struct {
|
|
|
model *model.All
|
|
|
}
|
|
@@ -59,27 +65,45 @@ func (a ruleChainService) create(ruleChain *models.RuleChain) error {
|
|
|
Model: gorm.Model{},
|
|
|
RecordId: guid.S(),
|
|
|
RuleChainID: ruleChain.RecordId,
|
|
|
- Type: v.Data.Type,
|
|
|
+ Type: nodeType[v.Data.Type],
|
|
|
Name: v.Data.Name,
|
|
|
DebugModel: true,
|
|
|
Intro: v.Data.Desc,
|
|
|
}
|
|
|
+
|
|
|
if v.Shape == "input-node" {
|
|
|
ruleChain.FirstRuleNodeID = ruleNode.RecordId
|
|
|
ruleNode.Name = "数据输入"
|
|
|
}
|
|
|
+ if ruleNode.Type == "MsgTypeSwitchNode" {
|
|
|
+ ruleNode.Name = "消息类型路由器"
|
|
|
+ }
|
|
|
|
|
|
- configuration := models.NodeConfiguration{
|
|
|
- Url: v.Data.Url,
|
|
|
- Method: v.Data.Method,
|
|
|
- Headers: v.Data.Headers,
|
|
|
- Retry: v.Data.Retry,
|
|
|
- TimeOut: v.Data.TimeOut,
|
|
|
- RetryWait: v.Data.RetryWait,
|
|
|
+ if ruleNode.Type == "FilterJavascriptNode" {
|
|
|
+ conMap := map[string]string{
|
|
|
+ "func_body": v.Data.FuncBody,
|
|
|
+ }
|
|
|
+ marshal, _ := json.Marshal(conMap)
|
|
|
+ ruleNode.Configuration = fmt.Sprintf("%s", marshal)
|
|
|
}
|
|
|
|
|
|
- marshal, _ := json.Marshal(configuration)
|
|
|
- ruleNode.Configuration = fmt.Sprintf("%s", marshal)
|
|
|
+ if ruleNode.Type == "RestApiRequestNode" {
|
|
|
+ configuration := models.NodeConfiguration{
|
|
|
+ Url: v.Data.Url,
|
|
|
+ Method: v.Data.Method,
|
|
|
+ Retry: v.Data.Retry,
|
|
|
+ TimeOut: v.Data.TimeOut,
|
|
|
+ RetryWait: v.Data.RetryWait,
|
|
|
+ Headers: make(map[string]interface{}),
|
|
|
+ }
|
|
|
+ if len(v.Data.Headers) > 0 {
|
|
|
+ for _, header := range v.Data.Headers {
|
|
|
+ configuration.Headers[header.Key] = header.Value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ marshal, _ := json.Marshal(configuration)
|
|
|
+ ruleNode.Configuration = fmt.Sprintf("%s", marshal)
|
|
|
+ }
|
|
|
|
|
|
nodeMap[v.Id] = ruleNode
|
|
|
|
|
@@ -93,10 +117,10 @@ func (a ruleChainService) create(ruleChain *models.RuleChain) error {
|
|
|
for _, v := range ruleChain.Cell {
|
|
|
if v.Shape == "edge" {
|
|
|
err := a.model.Relation.Create(&models.Relation{
|
|
|
- RecordId: guid.S(),
|
|
|
- RuleChainId: ruleChain.RecordId,
|
|
|
- FromID: nodeMap[v.Source.Cell].RecordId,
|
|
|
- FromType: nodeMap[v.Source.Cell].Type,
|
|
|
+ RecordId: guid.S(),
|
|
|
+ RuleChainId: ruleChain.RecordId,
|
|
|
+ FromID: nodeMap[v.Source.Cell].RecordId,
|
|
|
+ //FromType: nodeMap[v.Source.Cell].Type,
|
|
|
ToID: nodeMap[v.Target.Cell].RecordId,
|
|
|
ToType: nodeMap[v.Target.Cell].Type,
|
|
|
RelationType: v.Data.Label,
|