liuxiulin 2 роки тому
батько
коміт
cd8562354c

+ 14 - 0
pkg/models/rulechain.go

@@ -27,6 +27,13 @@ type RuleChainParams struct {
 	Cells    []*Cell
 }
 
+// ChangeRootParams 更新规则链参数
+type ChangeRootParams struct {
+	VendorId string `json:"vendor_id"` // 厂商id
+	RecordId string `json:"record_id"` // 记录id
+	Root     bool   `json:"root"`
+}
+
 type CreatChainReq struct {
 	RecordId string `json:"record_id"`
 	Name     string `json:"name"`
@@ -90,6 +97,13 @@ func (a *RuleChain) Validate() error {
 
 // Validate ``
 func (a *RuleChainParams) Validate() error {
+	return nil
+}
 
+// Validate ``
+func (a *ChangeRootParams) Validate() error {
+	if a.RecordId == "" {
+		return errors.New("记录id不能为空")
+	}
 	return nil
 }

+ 6 - 6
services/knowoapi/controllers/rule_chain.go

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

+ 4 - 4
services/knowoapi/services/rule_chain.go

@@ -25,7 +25,7 @@ type RuleChainService interface {
 	Update(*models.RuleChainParams) error
 	Query(int, int, string) ([]models.RuleChain, int, error)
 	Get(vendorId, recordId string) (models.RuleChain, error)
-	UpdateChainRoot(*models.RuleChain) error
+	UpdateChainRoot(*models.ChangeRootParams) error
 }
 type ruleChainService struct {
 	model *model.All
@@ -232,12 +232,12 @@ func (a ruleChainService) Update(params *models.RuleChainParams) error {
 	return nil
 }
 
-func (a ruleChainService) UpdateChainRoot(ruleChain *models.RuleChain) error {
+func (a ruleChainService) UpdateChainRoot(params *models.ChangeRootParams) error {
 	var isRoot int = 0
-	if ruleChain.Root {
+	if params.Root {
 		isRoot = 1
 	}
-	_, err := a.model.RuleChain.UpdateChainRoot(ruleChain.VendorID, ruleChain.RecordId, isRoot)
+	_, err := a.model.RuleChain.UpdateChainRoot(params.VendorId, params.RecordId, isRoot)
 	if err != nil {
 		return err
 	}