fix
zhangqian
2023-10-19 cab6eea89a0d82710369604ecb51f1cdb122e433
model/procedures.go
@@ -6,23 +6,23 @@
   "apsClient/pkg/sqlitex"
   "encoding/json"
   "fmt"
   "gorm.io/gorm"
   "github.com/jinzhu/gorm"
)
type (
   Procedures struct {
      gorm.Model     `json:"-"`
      ID             int    `gorm:"primarykey"`
      WorkOrderID    string `gorm:"index;type:varchar(191);not null;comment:工单ID" json:"-"`
      OrderID        string `gorm:"index;type:varchar(191);not null;comment:订单ID" json:"-"`
      DeviceID       string `gorm:"index;type:varchar(191);comment:设备ID" json:"deviceId"`
      ProcedureID    string `gorm:"index;type:varchar(191);comment:工序ID" json:"procedureId"`
      Position       int    `gorm:"type:int;comment:工作位置" json:"position"` //每个设备可能有多个机位同时生产,用position表示位置
      StartTime      int64  `gorm:"comment:计划开始时间" json:"startTime"`
      EndTime        int64  `gorm:"comment:计划结束时间" json:"endTime"`
      Status         ProcedureStatus
      ProcedureData  string                  `json:"-"`                  //common.ProductProcedure  json串
      ProceduresInfo common.ProductProcedure `json:"procedure" gorm:"-"` //common.ProductProcedure  对象
      gorm.Model
      WorkOrderID        string `gorm:"index;type:varchar(191);not null" json:"-"`
      OrderID            string `gorm:"index;type:varchar(191);not null" json:"-"`
      DeviceID           string `gorm:"index;type:varchar(191)" json:"deviceId"`
      ProcedureID        string `gorm:"index;type:varchar(191)" json:"procedureId"`
      Channel            int32  `gorm:"index;" json:"channel"`            //通道
      ProcessModelNumber string `gorm:"index;" json:"processModelNumber"` //工艺模型编号
      StartTime          int64  `json:"startTime"`
      EndTime            int64  `json:"endTime"`
      Status             ProcedureStatus
      ProcedureData      string                  `json:"-"`                  //common.ProductProcedure  json串
      ProceduresInfo     common.ProductProcedure `json:"procedure" gorm:"-"` //common.ProductProcedure  对象
   }
   ProceduresSearch struct {
@@ -36,6 +36,7 @@
      EndTimeMin   int64
      StatusNot    ProcedureStatus
      ProcedureIds []string
      Channels     []int32
   }
)
@@ -103,7 +104,7 @@
   return slf
}
func (slf *ProceduresSearch) SetId(id int) *ProceduresSearch {
func (slf *ProceduresSearch) SetId(id uint) *ProceduresSearch {
   slf.ID = id
   return slf
}
@@ -130,6 +131,11 @@
func (slf *ProceduresSearch) SetPreload(preload bool) *ProceduresSearch {
   slf.Preload = preload
   return slf
}
func (slf *ProceduresSearch) SetChannels(channels []int32) *ProceduresSearch {
   slf.Channels = channels
   return slf
}
@@ -173,11 +179,15 @@
   }
   if len(slf.ProcedureIds) > 0 {
      db = db.Where("procedure_id in ?", slf.ProcedureIds)
      db = db.Where("procedure_id IN (?)", slf.ProcedureIds)
   }
   if slf.ProcedureID != "" {
      db = db.Where("procedure_id = ?", slf.ProcedureID)
   }
   if len(slf.Channels) > 0 {
      db = db.Where("channel IN (?)", slf.Channels)
   }
   return db
@@ -205,6 +215,22 @@
   return nil
}
func (slf *ProceduresSearch) Upsert(record *Procedures) error {
   var db = slf.build()
   old, err := slf.First()
   if err != gorm.ErrRecordNotFound && old.ID != 0 {
      record.ID = old.ID
      err = db.Save(&record).Error
   } else {
      err = db.Create(&record).Error
   }
   if err != nil {
      return fmt.Errorf("save err: %v, record: %+v", err, record)
   }
   return nil
}
func (slf *ProceduresSearch) Updates(record *Procedures) error {
   var db = slf.build()