| | |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | //LocationProductIds []int |
| | | LocationIds []int |
| | | ProductIds []string |
| | | Ids []int |
| | | Query string |
| | | Fields string |
| | | LocationIds []int |
| | | ProductIds []string |
| | | Ids []int |
| | | Query string |
| | | Fields string |
| | | CategoryIds []int |
| | | JoinedMaterials bool |
| | | } |
| | | |
| | | LocationProductAmountWithOperation struct { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) SetCategoryIds(ids []int) *LocationProductAmountSearch { |
| | | slf.CategoryIds = ids |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&LocationProductAmount{}) |
| | | |
| | |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | if !slf.JoinedMaterials { |
| | | db = db.Joins("left join material on wms_location_product_amount.product_id = material.id") |
| | | slf.JoinedMaterials = true |
| | | } |
| | | 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"). |
| | |
| | | db = db.Select(slf.Fields) |
| | | } |
| | | |
| | | if len(slf.CategoryIds) > 0 { |
| | | if !slf.JoinedMaterials { |
| | | db = db.Joins("left join material on wms_location_product_amount.product_id = material.id") |
| | | slf.JoinedMaterials = true |
| | | } |
| | | db = db.Where("material.category_id in ?", slf.CategoryIds) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |