| | |
| | | type ( |
| | | ProductionProgress struct { |
| | | gorm.Model |
| | | WorkOrderID string `gorm:"index;type:varchar(191);not null" json:"workOrderID"` |
| | | OrderID string `gorm:"index;type:varchar(191);not null" json:"orderID"` |
| | | ProcedureID string `gorm:"type:varchar(191)" json:"procedureId"` |
| | | DeviceID string `gorm:"type:varchar(191);not null" json:"deviceId"` |
| | | FinishedQuantity int64 `gorm:"type:int;not null" json:"finishedQuantity"` |
| | | Channel int32 `gorm:"type:int" json:"channel"` //通道 |
| | | TotalQuantity int64 `gorm:"type:int;not null" json:"totalQuantity"` |
| | | ProceduresID uint `gorm:"index;type:varchar(191)" json:"proceduresId"` //procedures表的id |
| | | WorkOrderID string `gorm:"index;type:varchar(191);not null" json:"workOrderID"` |
| | | OrderID string `gorm:"index;type:varchar(191);not null" json:"orderID"` |
| | | ProcedureID string `gorm:"type:varchar(191)" json:"procedureId"` |
| | | ProductProcedureID string `gorm:"type:varchar(191);" json:"productProcedureID"` //产品工序id |
| | | DeviceID string `gorm:"type:varchar(191);not null" json:"deviceId"` |
| | | FinishedQuantity int64 `gorm:"type:int;not null" json:"finishedQuantity"` |
| | | Channel int32 `gorm:"type:int" json:"channel"` //通道 |
| | | TotalQuantity int64 `gorm:"type:int;not null" json:"totalQuantity"` |
| | | } |
| | | |
| | | ProductionProgressSearch struct { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProductionProgressSearch) SetProceduresId(proceduresId uint) *ProductionProgressSearch { |
| | | slf.ProceduresID = proceduresId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProductionProgressSearch) SetDeviceId(id string) *ProductionProgressSearch { |
| | | slf.DeviceID = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProductionProgressSearch) SetProductProcedureId(productProcedureId string) *ProductionProgressSearch { |
| | | slf.ProductProcedureID = productProcedureId |
| | | return slf |
| | | } |
| | | |
| | |
| | | db = db.Where("procedure_id = ?", slf.ProcedureID) |
| | | } |
| | | |
| | | if slf.ProceduresID != 0 { |
| | | db = db.Where("procedures_id = ?", slf.ProceduresID) |
| | | } |
| | | |
| | | if slf.DeviceID != "" { |
| | | db = db.Where("device_id = ?", slf.DeviceID) |
| | | } |
| | |
| | | db = db.Where("finished_quantity < total_quantity") |
| | | } |
| | | |
| | | if slf.ProductProcedureID != "" { |
| | | db = db.Where("product_procedure_id = ?", slf.ProductProcedureID) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | |
| | | |
| | | if err := db.Create(record).Error; err != nil { |
| | | return fmt.Errorf("create err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | // CreateBatch 批量插入 |
| | | func (slf *ProductionProgressSearch) CreateBatch(records []*ProductionProgress) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Create(&records).Error; err != nil { |
| | | return fmt.Errorf("create batch err: %v, records: %+v", err, records) |
| | | } |
| | | |
| | | return nil |