liuxiulin 2 년 전
부모
커밋
f85793dd9f
2개의 변경된 파일12개의 추가작업 그리고 6개의 파일을 삭제
  1. 4 3
      pkg/models/rulechain.go
  2. 8 3
      services/knowoapi/services/rule_chain.go

+ 4 - 3
pkg/models/rulechain.go

@@ -21,9 +21,10 @@ type RuleChain struct {
 
 // RuleChainParams 更新规则链参数
 type RuleChainParams struct {
-	VendorId string `json:"vendor_id"` // 厂商id
-	RecordId string `json:"record_id"` // 记录id
-	Cell     Cells  `json:"cell"`
+	VendorId string      `json:"vendor_id"` // 厂商id
+	RecordId string      `json:"record_id"` // 记录id
+	Cell     interface{} `json:"cell"`
+	Cells    []*Cell
 }
 
 type CreatChainReq struct {

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

@@ -69,7 +69,7 @@ func (a ruleChainService) create(params *models.RuleChainParams) error {
 
 	nodeMap := make(map[string]models.RuleNode)
 	var inputNodeId string
-	for _, v := range params.Cell {
+	for _, v := range params.Cells {
 		if v.Shape != "edge" {
 			if v.Shape == "input-node" {
 				inputNodeId = v.Source.Cell
@@ -128,7 +128,7 @@ func (a ruleChainService) create(params *models.RuleChainParams) error {
 		}
 	}
 
-	for _, v := range params.Cell {
+	for _, v := range params.Cells {
 		if v.Shape == "edge" && v.Source.Cell != inputNodeId {
 			err := a.model.Relation.Create(&models.Relation{
 				RecordId:    guid.S(),
@@ -201,10 +201,15 @@ func (a ruleChainService) Update(params *models.RuleChainParams) error {
 	if err != nil {
 		return err
 	}
-	if len(params.Cell) > 0 {
+	if params.Cell != nil {
+
 		marshal, _ := json.Marshal(params.Cell)
 		ruleChain.Configuration = string(marshal)
 
+		err = json.Unmarshal(marshal, &params.Cells)
+		if err != nil {
+			return err
+		}
 		err = a.create(params)
 		if err != nil {
 			return err