From 076f911a3b8d09364d1d8c98a92b48e601ae6a21 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 31 七月 2024 11:30:27 +0800 Subject: [PATCH] 位置对应产品列表增加产品类别筛选 --- models/location_product_amount.go | 29 ++++++++++++++++++++++++----- request/location_product_amount.go | 1 + controllers/location_product_amount.go | 1 + 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/controllers/location_product_amount.go b/controllers/location_product_amount.go index cdc75a1..c717ed0 100644 --- a/controllers/location_product_amount.go +++ b/controllers/location_product_amount.go @@ -181,6 +181,7 @@ SetPage(params.Page, params.PageSize). SetOrder("id desc"). SetPreload(true). + SetCategoryIds(params.CategoryIds). FindByPage() if err != nil { util.ResponseFormat(c, code.InternalError, "鏌ヨ澶辫触") diff --git a/models/location_product_amount.go b/models/location_product_amount.go index 81cc55b..928dddb 100644 --- a/models/location_product_amount.go +++ b/models/location_product_amount.go @@ -36,11 +36,13 @@ 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 { @@ -172,6 +174,11 @@ 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{}) @@ -183,6 +190,10 @@ } 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"). @@ -226,6 +237,14 @@ 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 } diff --git a/request/location_product_amount.go b/request/location_product_amount.go index 48b978f..63c3243 100644 --- a/request/location_product_amount.go +++ b/request/location_product_amount.go @@ -44,4 +44,5 @@ Keyword string `json:"keyword"` WarehouseId int `json:"warehouseId"` LocationId int `json:"locationId"` + CategoryIds []int `json:"categoryIds"` } -- Gitblit v1.8.0