| | |
| | | import ( |
| | | "apsClient/pkg/sqlitex" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "github.com/jinzhu/gorm" |
| | | ) |
| | | |
| | | type ( |
| | | ProductionProgress struct { |
| | | gorm.Model `json:"-"` |
| | | ID int `gorm:"primarykey"` |
| | | WorkOrderID string `gorm:"index;type:varchar(191);not null;comment:工单ID" json:"workOrderID"` |
| | | OrderID string `gorm:"index;type:varchar(191);not null;comment:订单ID" json:"orderID"` |
| | | ProcedureID string `gorm:"type:varchar(191);comment:工序ID" json:"procedureId"` |
| | | DeviceID string `gorm:"type:varchar(191);not null;comment:设备ID" json:"deviceId"` |
| | | FinishedQuantity int64 `gorm:"type:int;not null;comment:完成数量" json:"finishedQuantity"` |
| | | Position int `gorm:"type:int;comment:工作位置" json:"position"` //每个设备可能有多个机位同时生产,用position表示位置 |
| | | TotalQuantity int64 `gorm:"type:int;not null;comment:总量" json:"totalQuantity"` |
| | | 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"` |
| | | } |
| | | |
| | | ProductionProgressSearch struct { |
| | | ProductionProgress |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | UnFinished bool |
| | | } |
| | | ) |
| | | |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProductionProgressSearch) SetId(id int) *ProductionProgressSearch { |
| | | func (slf *ProductionProgressSearch) SetId(id uint) *ProductionProgressSearch { |
| | | slf.ID = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProductionProgressSearch) SetPosition(position int) *ProductionProgressSearch { |
| | | slf.Position = position |
| | | func (slf *ProductionProgressSearch) SetChannel(channel int32) *ProductionProgressSearch { |
| | | slf.Channel = channel |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProductionProgressSearch) SetUnFinished() *ProductionProgressSearch { |
| | | slf.UnFinished = true |
| | | return slf |
| | | } |
| | | |
| | |
| | | db = db.Where("device_id = ?", slf.DeviceID) |
| | | } |
| | | |
| | | if slf.Position != 0 { |
| | | db = db.Where("position = ?", slf.Position) |
| | | if slf.Channel != 0 { |
| | | db = db.Where("channel = ?", slf.Channel) |
| | | } |
| | | |
| | | if slf.UnFinished { |
| | | db = db.Where("finished_quantity < total_quantity") |
| | | } |
| | | |
| | | 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 |