| | |
| | | |
| | | import ( |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "wms/constvar" |
| | | "wms/pkg/mysqlx" |
| | |
| | | Operation struct { |
| | | WmsModel |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255)"` //单号 |
| | | Number string `json:"number" gorm:"type:varchar(255)"` //单号 |
| | | SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //源单号 |
| | | OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id |
| | | Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"` //状态 |
| | |
| | | Tracking string `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"` |
| | | ContacterID int `json:"contacterID" gorm:"type:int;comment:联系人ID"` |
| | | ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"` |
| | | Weight float64 `json:"weight" gorm:"type:decimal;comment:重量(kg)"` |
| | | TransferWeight float64 `json:"transferWeight" gorm:"type:decimal;comment:物流重量(kg)"` |
| | | Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"` |
| | | TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"` |
| | | CompanyID int `json:"companyID" gorm:"type:int;comment:公司ID"` |
| | | CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:公司名称(kg)"` |
| | | Details []*OperationDetails `json:"details"` |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OperationSearch) SetID(id uint) *OperationSearch { |
| | | slf.ID = id |
| | | func (slf *OperationSearch) SetID(id int) *OperationSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch { |
| | | slf.Keyword = keyword |
| | | //func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch { |
| | | // slf.Keyword = keyword |
| | | // return slf |
| | | //} |
| | | |
| | | func (slf *OperationSearch) SetOperationTypeId(operationTypeId int) *OperationSearch { |
| | | slf.OperationTypeId = operationTypeId |
| | | return slf |
| | | } |
| | | |
| | |
| | | func (slf *OperationSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Operation{}) |
| | | |
| | | if slf.ID != 0 { |
| | | db = db.Where("id = ?", slf.ID) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | //if slf.Keyword != "" { |
| | | // db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | //} |
| | | |
| | | if slf.OperationTypeId != 0 { |
| | | db.Where("operation_type_id = ?", slf.OperationTypeId) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Model(&Operation{}).Preload("Details") |
| | | } |
| | | |
| | | return db |
| | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *OperationSearch) Save(record *Operation) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.Omit("CreatedAt").Save(record).Error; err != nil { |
| | | return fmt.Errorf("save err: %v, record: %+v", err, record) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *OperationSearch) Update(record *Operation) error { |
| | | var db = slf.build() |
| | | |