| | |
| | | LocationId int `json:"locationId" gorm:"type:int;not null;comment:位置id"` //位置id |
| | | Location Location `json:"location" gorm:"foreignKey:LocationId;references:id"` |
| | | ProductCategoryID int `json:"productCategoryId" gorm:"type:int;not null;comment:产品种类id"` //产品种类id |
| | | ProductCategory ProductCategory `json:"productCategory"` |
| | | ProductCategory ProductCategory `json:"productCategory" gorm:"foreignKey:ProductCategoryID;references:Id"` |
| | | ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:产品id"` //产品id |
| | | Product Material `json:"product" gorm:"foreignKey:ProductId;references:ID"` |
| | | Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:库存数量"` //库存数量 |
| | |
| | | //LocationProductIds []int |
| | | LocationIds []int |
| | | ProductIds []string |
| | | Ids []int |
| | | } |
| | | |
| | | LocationProductAmountWithOperation struct { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) SetIds(ids []int) *LocationProductAmountSearch { |
| | | slf.Ids = ids |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) SetKeyword(keyword string) *LocationProductAmountSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | db = db.Joins("left join wms_location on wms_location_product_amount.location_id = wms_location.id"). |
| | | Joins("left join material on wms_location_product_amount.product_id = material.id"). |
| | | Joins("left join wms_product_category on wms_location_product_amount.product_category_id = wms_product_category.id"). |
| | | Where("wms_location.name like ?", "%"+slf.Keyword+"%").Or("material.name like ?", "%"+slf.Keyword+"%"). |
| | | Or("wms_product_category.name like ?", "%"+slf.Keyword+"%") |
| | | } |
| | | |
| | | if slf.Preload { |
| | |
| | | |
| | | if slf.ProductId != "" { |
| | | db = db.Where("product_id=?", slf.ProductId) |
| | | } |
| | | |
| | | if len(slf.Ids) > 0 { |
| | | db = db.Where("id in (?)", slf.Ids) |
| | | } |
| | | |
| | | return db |
| | |
| | | |
| | | return record, db.First(&record) |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) Count() (int64, error) { |
| | | var ( |
| | | total int64 |
| | | db = slf.build() |
| | | ) |
| | | err := db.Count(&total).Error |
| | | return total, err |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) UpdateByMap(upMap map[string]interface{}) error { |
| | | var ( |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Updates(upMap).Error; err != nil { |
| | | return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap) |
| | | } |
| | | |
| | | return nil |
| | | } |