| | |
| | | package model |
| | | |
| | | import ( |
| | | "apsClient/model/request" |
| | | "apsClient/pkg/logx" |
| | | "apsClient/pkg/sqlitex" |
| | | "encoding/json" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | | type ( |
| | | Procedures struct { |
| | | gorm.Model `json:"-"` |
| | | Id int `json:"id"` |
| | | ProcedureId string `json:"orderId"` |
| | | ProcedureName string `json:"product"` |
| | | DeviceId string `json:"deviceId"` |
| | | StartTime string `json:"startTime"` |
| | | EndTime string `json:"endTime"` |
| | | WorkHours string `json:"workHours"` |
| | | InputMaterialsId int `json:"-"` |
| | | InputMaterials *Materials `json:"inputMaterials" gorm:"foreignKey:InputMaterialsId"` |
| | | OutputMaterialsId int `json:"-"` |
| | | OutputMaterials *Materials `json:"outputMaterials" gorm:"foreignKey:InputMaterialsId"` |
| | | gorm.Model `json:"-"` |
| | | ID int `gorm:"primarykey"` |
| | | OrderID string `gorm:"index;type:varchar(191);not null;comment:订单ID" json:"-"` |
| | | Status ProcedureStatus `json:"-"` |
| | | ProcedureData string `json:"-"` //request.ProductProcedure json串 |
| | | ProceduresInfo request.ProductProcedure `json:"procedure" gorm:"-"` //request.ProductProcedure 对象 |
| | | } |
| | | |
| | | ProceduresSearch struct { |
| | | Procedures |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | StartTimeMin int64 |
| | | } |
| | | ) |
| | | |
| | | type ProcedureStatus int |
| | | |
| | | const ( |
| | | ProcedureStatusUnFinished ProcedureStatus = 1 |
| | | ProcedureStatusFinished ProcedureStatus = 2 |
| | | ) |
| | | |
| | | func (slf *Procedures) TableName() string { |
| | | return "procedures" |
| | | } |
| | | func (slf *Procedures) AfterFind() { |
| | | var proceduresInfo request.ProductProcedure |
| | | err := json.Unmarshal([]byte(slf.ProcedureData), &proceduresInfo) |
| | | if err != nil { |
| | | logx.Errorf("AfterFind Unmarshal err: %v", err.Error()) |
| | | return |
| | | } |
| | | slf.ProceduresInfo = proceduresInfo |
| | | } |
| | | |
| | | func NewProceduresSearch(db *gorm.DB) *ProceduresSearch { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProceduresSearch) SetOrderId(orderId string) *ProceduresSearch { |
| | | slf.OrderID = orderId |
| | | return slf |
| | | } |
| | | func (slf *ProceduresSearch) SetStartTimeMin(ts int64) *ProceduresSearch { |
| | | slf.StartTimeMin = ts |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProceduresSearch) SetId(id int) *ProceduresSearch { |
| | | slf.ID = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProceduresSearch) SetStatus(status ProcedureStatus) *ProceduresSearch { |
| | | slf.Status = status |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProceduresSearch) SetPreload(preload bool) *ProceduresSearch { |
| | | slf.Preload = preload |
| | | return slf |
| | |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |
| | | |
| | | if slf.OrderID != "" { |
| | | db = db.Where("order_id = ?", slf.OrderID) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Preload("InputMaterials").Preload("OutputMaterials") |
| | | } |
| | | |
| | | if slf.StartTimeMin != 0 { |
| | | db = db.Where("start_time >= ?", slf.StartTimeMin) |
| | | } |
| | | |
| | | if slf.Status != 0 { |
| | | db = db.Where("status = ?", slf.Status) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |