zhangqian
2023-10-07 3e438843c57c2e3525c14832eb26e5ac343b817c
model/process_model.go
@@ -1,13 +1,15 @@
package model
import (
   "apsClient/pkg/logx"
   "apsClient/pkg/sqlitex"
   "encoding/json"
   "fmt"
   "gorm.io/gorm"
)
type (
   // ProcessModel 工艺流程参数
   // ProcessModel 工艺参数
   ProcessModel struct {
      gorm.Model `json:"-"`
      Number     string                 `gorm:"index;column:number;type:varchar(255);not null;default '';comment:工艺模型编号" json:"number"` //工艺模型编号
@@ -16,6 +18,8 @@
      Params     string                 `gorm:"type:text;comment:工艺参数键值对json串"`
      ParamsMap  map[string]interface{} `json:"paramsMap" gorm:"-"`
      DeviceId   string                 `json:"deviceId" gorm:"-"` //用于过滤获取nsq消息
      IsNew      bool                   `json:"isNew" gorm:"column:is_new;comment:是否最新的"` //是否最新的
      IsUpdate   bool                   `json:"isUpdate" gorm:"-"`                        //前端用
   }
   ProcessModelSearch struct {
@@ -24,11 +28,21 @@
      PageNum  int
      PageSize int
      Orm      *gorm.DB
      Procedures []string
   }
)
func (slf *ProcessModel) TableName() string {
   return "process_model"
}
func (slf *ProcessModel) AfterFind(db *gorm.DB) error {
   err := json.Unmarshal([]byte(slf.Params), &slf.ParamsMap)
   if err != nil {
      logx.Errorf("process model json.Unmarshal:%v", err)
      return err
   }
   return nil
}
func NewProcessModelSearch() *ProcessModelSearch {
@@ -64,8 +78,19 @@
   slf.Product = product
   return slf
}
func (slf *ProcessModelSearch) SetProcedure(procedure string) *ProcessModelSearch {
   slf.Procedure = procedure
   return slf
}
func (slf *ProcessModelSearch) SetProcedures(procedures []string) *ProcessModelSearch {
   slf.Procedures = procedures
   return slf
}
func (slf *ProcessModelSearch) SetIsNew(isNew bool) *ProcessModelSearch {
   slf.IsNew = isNew
   return slf
}
@@ -84,6 +109,10 @@
      db = db.Where("`procedure` = ?", slf.Procedure)
   }
   if len(slf.Procedures) != 0 {
      db = db.Where("`procedure` in ?", slf.Procedures)
   }
   if len(slf.Number) != 0 {
      db = db.Where("number = ?", slf.Number)
   }
@@ -92,6 +121,10 @@
      db = db.Order(slf.Order)
   }
   if slf.IsNew {
      db = db.Where("is_new = ?", 1)
   }
   return db
}