Browse Source

test json

lijian 2 years ago
parent
commit
a94b595414
2 changed files with 10 additions and 18 deletions
  1. 7 6
      pkg/models/rulechain.go
  2. 3 12
      services/knowoapi/services/rule_chain.go

+ 7 - 6
pkg/models/rulechain.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"errors"
+	"github.com/gogf/gf/encoding/gjson"
 	"github.com/jinzhu/gorm"
 )
 
@@ -23,7 +24,7 @@ type RuleChain struct {
 type RuleChainParams struct {
 	VendorId string      `json:"VendorID"` // 厂商id
 	RecordId string      `json:"RecordId"` // 记录id
-	Cell     interface{} `json:"cell"`
+	Cell     *gjson.Json `json:"cell"`
 	Cells    []*Cell
 }
 
@@ -43,11 +44,11 @@ type CreatChainReq struct {
 type Cells []*Cell
 
 type Cell struct {
-	Id     string                 `json:"id"` // id
-	Shape  string                 `json:"shape"`
-	Data   map[string]interface{} `json:"data"`   // 数据
-	Source Branch                 `json:"source"` // 上级节点
-	Target Branch                 `json:"target"` // 下级节点
+	Id     string   `json:"id"` // id
+	Shape  string   `json:"shape"`
+	Data   CellData `json:"data"`   // 数据
+	Source Branch   `json:"source"` // 上级节点
+	Target Branch   `json:"target"` // 下级节点
 }
 
 type CellData struct {

+ 3 - 12
services/knowoapi/services/rule_chain.go

@@ -1,7 +1,6 @@
 package services
 
 import (
-	"encoding/json"
 	"fmt"
 	"github.com/gogf/gf/encoding/gjson"
 	"github.com/gogf/gf/util/guid"
@@ -68,7 +67,7 @@ func (a ruleChainService) Create(ruleChain *models.RuleChain) error {
 }
 
 func (a ruleChainService) create(params *models.RuleChainParams) (firstNodeId string, err error) {
-
+	fmt.Println(params.Cell.MustToJsonString())
 	nodeMap := make(map[string]models.RuleNode)
 	var inputNodeId string
 	for _, v := range params.Cells {
@@ -118,10 +117,9 @@ func (a ruleChainService) create(params *models.RuleChainParams) (firstNodeId st
 			//		}
 			//	}
 			//}
-			fmt.Println(v.Data)
+
 			str, err := gjson.DecodeToJson(v.Data)
 			if err != nil {
-				server.Log.Error(err)
 				return "", err
 			}
 			ruleNode.Configuration = fmt.Sprintf("%s", str.MustToJsonString())
@@ -212,14 +210,7 @@ func (a ruleChainService) Update(params *models.RuleChainParams) error {
 		return err
 	}
 	if params.Cell != nil {
-
-		marshal, _ := json.Marshal(params.Cell)
-		ruleChain.Configuration = string(marshal)
-
-		err = json.Unmarshal(marshal, &params.Cells)
-		if err != nil {
-			return err
-		}
+		ruleChain.Configuration = params.Cell.MustToJsonString()
 		ruleChain.FirstRuleNodeID, err = a.create(params)
 		if err != nil {
 			return err