소스 검색

更新规则链管理接口

liuxiulin 2 년 전
부모
커밋
ee3fe19950
2개의 변경된 파일16개의 추가작업 그리고 18개의 파일을 삭제
  1. 3 3
      pkg/models/rulechain.go
  2. 13 15
      services/knowoapi/services/rule_chain.go

+ 3 - 3
pkg/models/rulechain.go

@@ -29,8 +29,9 @@ type CreatChainReq struct {
 type Cells []*Cell
 
 type Cell struct {
-	Id   string   `json:"id"`   // id
-	Data CellData `json:"data"` // 数据
+	Id    string   `json:"id"` // id
+	Shape string   `json:"shape"`
+	Data  CellData `json:"data"` // 数据
 }
 
 type CellData struct {
@@ -39,7 +40,6 @@ type CellData struct {
 	Type     string     `json:"type"`      // 节点类型
 	Desc     string     `json:"desc"`      // 备注
 	ZIndex   string     `json:"ZIndex"`    // 序号
-	Shape    string     `json:"shape"`     // 类型
 	FuncBody string     `json:"func_body"` // 代码
 	Labels   []string   `json:"labels"`
 	Source   string     `json:"source"` // 源节点id

+ 13 - 15
services/knowoapi/services/rule_chain.go

@@ -39,19 +39,22 @@ func (a ruleChainService) Get(vendorId, recordId string) (models.RuleChain, erro
 
 func (a ruleChainService) Create(ruleChain *models.RuleChain) error {
 	ruleChain.RecordId = guid.S()
-	err := a.create(ruleChain)
-	if err != nil {
-		return err
+	if len(ruleChain.Cell) > 0 {
+		marshal, _ := json.Marshal(ruleChain.Cell)
+		ruleChain.Configuration = fmt.Sprintf("%s", marshal)
+		err := a.create(ruleChain)
+		if err != nil {
+			return err
+		}
 	}
 	return a.model.RuleChain.Create(ruleChain)
 }
 
 func (a ruleChainService) create(ruleChain *models.RuleChain) error {
-	fmt.Printf("++++++++++++++++%d+++++++++++++++", len(ruleChain.Cell))
 	if len(ruleChain.Cell) > 0 {
 		nodeMap := make(map[string]models.RuleNode)
 		for _, v := range ruleChain.Cell {
-			if v.Data.Shape != "edge" {
+			if v.Shape != "edge" {
 				ruleNode := models.RuleNode{
 					Model:       gorm.Model{},
 					RecordId:    guid.S(),
@@ -61,21 +64,16 @@ func (a ruleChainService) create(ruleChain *models.RuleChain) error {
 					DebugModel:  true,
 					Intro:       v.Data.Desc,
 				}
-				if v.Data.Shape == "input-node" {
+				if v.Shape == "input-node" {
 					ruleChain.FirstRuleNodeID = ruleNode.RecordId
 					ruleNode.Name = "数据输入"
 				}
 
-				var configuration models.NodeConfiguration
-				if v.Data.Shape == "action_node" {
-					for _, header := range v.Data.Headers {
-						configuration.Headers[header.Key] = header.Value
-					}
+				if len(v.Data.Headers) > 0 {
+					marshal, _ := json.Marshal(v.Data.Headers)
+					ruleNode.Configuration = fmt.Sprintf("%s", marshal)
 				}
 
-				marshal, _ := json.Marshal(configuration)
-				ruleNode.Configuration = fmt.Sprintf("%s", marshal)
-
 				nodeMap[v.Id] = ruleNode
 
 				err := a.model.RuleNode.Create(&ruleNode)
@@ -86,7 +84,7 @@ func (a ruleChainService) create(ruleChain *models.RuleChain) error {
 		}
 
 		for _, v := range ruleChain.Cell {
-			if v.Data.Shape == "edge" {
+			if v.Shape == "edge" {
 				err := a.model.Relation.Create(&models.Relation{
 					RecordId:    guid.S(),
 					RuleChainId: ruleChain.RecordId,