浏览代码

更新规则链管理接口

liuxiulin 2 年之前
父节点
当前提交
a4d24791e2

+ 20 - 0
services/knowoapi/controllers/rule_chain.go

@@ -85,3 +85,23 @@ func (a *RuleChainController) Get() {
 		"total": total,
 	})
 }
+
+// PutChange 更新
+// PutChange /rule_chain/change
+func (a *RuleChainController) PutChange() {
+	ruleChain := new(models.RuleChain)
+	if err := parseBody(a.Ctx, ruleChain); err != nil {
+		badRequest(a.Ctx, err)
+		return
+	}
+	if ruleChain.VendorID == "" {
+		ruleChain.VendorID = a.Token.getVendorID(a.Ctx)
+	}
+
+	err := a.Service.UpdateChainRoot(ruleChain)
+	if err != nil {
+		responseError(a.Ctx, ErrDatabase, err.Error())
+		return
+	}
+	done(a.Ctx, ruleChain)
+}

+ 9 - 0
services/knowoapi/model/rule_chain.go

@@ -65,3 +65,12 @@ func (a *RuleChain) Delete(ruleChain *models.RuleChain) error {
 func (a *RuleChain) Update(ruleChain *models.RuleChain) error {
 	return a.db.Save(ruleChain).Error
 }
+
+// UpdateChainRoot 设置规则链
+func (a *RuleChain) UpdateChainRoot(vendorId string, id string, isRoot int) error {
+	err := a.db.Where("vendor_id = ? and record_id = ?", vendorId, id).
+		Update(map[string]interface{}{
+			"root": isRoot,
+		}).Error
+	return err
+}

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

@@ -25,6 +25,7 @@ type RuleChainService interface {
 	Update(*models.RuleChain) error
 	Query(int, int, string) ([]models.RuleChain, int, error)
 	Get(vendorId, recordId string) (models.RuleChain, error)
+	UpdateChainRoot(*models.RuleChain) error
 }
 type ruleChainService struct {
 	model *model.All
@@ -75,7 +76,8 @@ func (a ruleChainService) create(ruleChain *models.RuleChain) error {
 	}
 	marshal, _ := json.Marshal(ruleChain.Cell)
 	ruleChain.Configuration = fmt.Sprintf("%s", marshal)
-
+	fmt.Println("++++++++++++++++++++++++++++++++")
+	fmt.Println(ruleChain.Configuration)
 	nodeMap := make(map[string]models.RuleNode)
 	var inputNodeId string
 	for _, v := range ruleChain.Cell {
@@ -210,7 +212,8 @@ func (a ruleChainService) Update(ruleChain *models.RuleChain) error {
 	if err != nil {
 		return err
 	}
-
+	fmt.Println("-----------------------------------")
+	fmt.Println(ruleChain.Configuration)
 	err = a.model.RuleChain.Update(ruleChain)
 	if err != nil {
 		return err
@@ -226,3 +229,11 @@ func (a ruleChainService) Update(ruleChain *models.RuleChain) error {
 	}
 	return nil
 }
+
+func (a ruleChainService) UpdateChainRoot(ruleChain *models.RuleChain) error {
+	var isRoot int = 0
+	if ruleChain.Root {
+		isRoot = 1
+	}
+	return a.model.RuleChain.UpdateChainRoot(ruleChain.VendorID, ruleChain.RecordId, isRoot)
+}