fix
zhangqian
2023-10-19 cab6eea89a0d82710369604ecb51f1cdb122e433
model/procedures.go
@@ -6,22 +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"`
      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 {
@@ -32,8 +33,10 @@
      Orm          *gorm.DB
      Preload      bool
      StartTimeMax int64
      EndTimeMin   int64
      StatusNot    ProcedureStatus
      ProcedureIds []string
      Channels     []int32
   }
)
@@ -96,7 +99,12 @@
   return slf
}
func (slf *ProceduresSearch) SetId(id int) *ProceduresSearch {
func (slf *ProceduresSearch) SetEndTimeMin(ts int64) *ProceduresSearch {
   slf.EndTimeMin = ts
   return slf
}
func (slf *ProceduresSearch) SetId(id uint) *ProceduresSearch {
   slf.ID = id
   return slf
}
@@ -123,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
}
@@ -153,6 +166,10 @@
      db = db.Where("start_time <= ?", slf.StartTimeMax)
   }
   if slf.EndTimeMin != 0 {
      db = db.Where("end_time > ?", slf.EndTimeMin)
   }
   if slf.Status != 0 {
      db = db.Where("status = ?", slf.Status)
   }
@@ -162,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
@@ -194,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()