浏览代码

更新规则链管理接口

liuxiulin 2 年之前
父节点
当前提交
2fb64b3cf8
共有 2 个文件被更改,包括 10 次插入8 次删除
  1. 7 0
      pkg/models/rulechain.go
  2. 3 8
      services/knowoapi/services/rule_chain.go

+ 7 - 0
pkg/models/rulechain.go

@@ -17,6 +17,13 @@ type RuleChain struct {
 	DebugModel      bool   `gorm:"column:debug_model"`        //调试模式
 	Intro           string `gorm:"column:intro"`              //描述
 	VendorID        string `gorm:"column:vendor_id"`          //厂商ID
+	Cell            Cells  `json:"cell"`
+}
+
+type CreatChainReq struct {
+	RecordId string `json:"record_id"`
+	Name     string `json:"name"`
+	Cell     Cells  `json:"cells"`
 }
 
 type Cells []*Cell

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

@@ -47,14 +47,9 @@ func (a ruleChainService) Create(ruleChain *models.RuleChain) error {
 }
 
 func (a ruleChainService) create(ruleChain *models.RuleChain) error {
-	if ruleChain.Configuration != "" {
-		var cells models.Cells
-		err := json.Unmarshal([]byte(ruleChain.Configuration), &cells)
-		if err != nil {
-			return err
-		}
+	if len(ruleChain.Cell) > 0 {
 		nodeMap := make(map[string]models.RuleNode)
-		for _, v := range cells {
+		for _, v := range ruleChain.Cell {
 			if v.Data.Shape != "edge" {
 				ruleNode := models.RuleNode{
 					Model:       gorm.Model{},
@@ -88,7 +83,7 @@ func (a ruleChainService) create(ruleChain *models.RuleChain) error {
 			}
 		}
 
-		for _, v := range cells {
+		for _, v := range ruleChain.Cell {
 			if v.Data.Shape == "edge" {
 				err := a.model.Relation.Create(&models.Relation{
 					RecordId:    guid.S(),