| | |
| | | |
| | | LocationProductSearch struct { |
| | | LocationProduct |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Keyword string |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Keyword string |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | LocationIds []int |
| | | } |
| | | ) |
| | | |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) SetLocationIds(locationIds []int) *LocationProductSearch { |
| | | slf.LocationIds = locationIds |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&LocationProduct{}) |
| | | |
| | |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | //db = db.Where("Product.name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | db.Joins("left join wms_location on wms_location_product.location_id = wms_location.id"). |
| | | Joins("left join material on wms_location_product.product_id = material.id"). |
| | | Joins("left join wms_product_category on wms_location_product.product_category_id = wms_product_category.id"). |
| | | Where("wms_location.name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)). |
| | | Or("material.name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)). |
| | | Or("wms_product_category.name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | } |
| | | |
| | | if slf.Preload { |
| | |
| | | db = db.Where("product_id=?", slf.ProductId) |
| | | } |
| | | |
| | | if len(slf.LocationIds) > 0 { |
| | | db = db.Where("location_id in (?)", slf.LocationIds) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |