| | |
| | | "apsClient/pkg/sqlitex" |
| | | "encoding/json" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "gorm.io/gorm/clause" |
| | | "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"` |
| | | Channel int32 `gorm:"index;comment:通道" json:"channel"` //通道 |
| | | ProcessModelNumber string `gorm:"index;comment:工艺模型编号" json:"processModelNumber"` //工艺模型编号 |
| | | StartTime int64 `gorm:"comment:计划开始时间" json:"startTime"` |
| | | EndTime int64 `gorm:"comment:计划结束时间" json:"endTime"` |
| | | 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 对象 |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProceduresSearch) SetId(id int) *ProceduresSearch { |
| | | func (slf *ProceduresSearch) SetId(id uint) *ProceduresSearch { |
| | | slf.ID = id |
| | | return slf |
| | | } |
| | |
| | | } |
| | | |
| | | if len(slf.ProcedureIds) > 0 { |
| | | db = db.Where("procedure_id in ?", slf.ProcedureIds) |
| | | db = db.Where("procedure_id IN (?)", slf.ProcedureIds) |
| | | } |
| | | |
| | | if slf.ProcedureID != "" { |
| | |
| | | } |
| | | |
| | | if len(slf.Channels) > 0 { |
| | | db = db.Where("channel in ?", slf.Channels) |
| | | db = db.Where("channel IN (?)", slf.Channels) |
| | | } |
| | | |
| | | return db |
| | |
| | | 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 := db.Clauses(clause.OnConflict{ |
| | | UpdateAll: true, |
| | | }).Create(&record).Error; err != nil { |
| | | if err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |