From c113e72efaceba986a733a44f999c567e4296fdb Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期五, 20 十月 2023 10:08:56 +0800 Subject: [PATCH] 位置报表修改 --- request/report_forms_request.go | 4 + models/location_product.go | 22 ++++++++--- controllers/report_forms_controller.go | 31 ++++++++++++++- models/location.go | 2 models/location_product_amount.go | 21 +++++++--- docs/swagger.yaml | 4 ++ docs/docs.go | 6 +++ docs/swagger.json | 6 +++ 8 files changed, 79 insertions(+), 17 deletions(-) diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go index 85a48da..b3a8e53 100644 --- a/controllers/report_forms_controller.go +++ b/controllers/report_forms_controller.go @@ -186,21 +186,46 @@ if params.PageInfo.Check() { search.SetPage(params.Page, params.PageSize) } - find, total, err := search.SetKeyword(params.KeyWord).FindByPage() + //鏌ヨ浣嶇疆 + locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).FindAll() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浣嶇疆澶辫触") + return + } + ids := make([]int, 0) + for _, location := range locations { + ids = append(ids, location.Id) + } + + find, total, err := search.SetKeyword(params.KeyWord).SetProductId(params.ProductId).SetLocationIds(ids).FindByPage() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鏌ヨ涓婃灦瑙勫垯澶辫触") + return + } + ruleIds := make([]int, 0) + for _, product := range find { + ruleIds = append(ruleIds, product.Id) + } + amounts, err := models.NewLocationProductAmountSearch().SetLocationProductIds(ruleIds).Find() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鏁伴噺澶辫触") return } var result []response.LocationForms for _, product := range find { var resp response.LocationForms + for _, amount := range amounts { + if product.Id == amount.LocationProductId { + resp.Amount = amount.Amount + break + } + } resp.LocationName = product.Location.Name resp.ProduceId = product.Product.ID resp.ProductName = product.Product.Name resp.ProductTypeName = product.ProductCategory.Name - resp.Amount = product.Product.Amount resp.Unit = product.Product.Unit - resp.Value = product.Product.Amount.Mul(product.Product.Cost) + resp.Value = resp.Amount.Mul(product.Product.Cost) result = append(result, resp) } util.ResponseFormatList(c, code.Success, result, int(total)) diff --git a/docs/docs.go b/docs/docs.go index 80291e3..2d534d2 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -3122,6 +3122,12 @@ "pageSize": { "description": "姣忛〉澶у皬", "type": "integer" + }, + "productId": { + "type": "string" + }, + "wareHouseCode": { + "type": "string" } } }, diff --git a/docs/swagger.json b/docs/swagger.json index ccf0c51..0779019 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -3110,6 +3110,12 @@ "pageSize": { "description": "姣忛〉澶у皬", "type": "integer" + }, + "productId": { + "type": "string" + }, + "wareHouseCode": { + "type": "string" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 64383bf..24ee981 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -865,6 +865,10 @@ pageSize: description: 姣忛〉澶у皬 type: integer + productId: + type: string + wareHouseCode: + type: string type: object request.GetProductList: properties: diff --git a/models/location.go b/models/location.go index 15830ea..ef755e6 100644 --- a/models/location.go +++ b/models/location.go @@ -310,7 +310,7 @@ records = make([]*Location, 0) db = slf.build() ) - err := db.Find(&records) + err := db.Find(&records).Error if err != nil { fmt.Println(err) return records, fmt.Errorf("func FindAll err: %v", err) diff --git a/models/location_product.go b/models/location_product.go index c3f26c6..f42e2fe 100644 --- a/models/location_product.go +++ b/models/location_product.go @@ -22,12 +22,13 @@ 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 } ) @@ -79,6 +80,11 @@ 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{}) @@ -111,6 +117,10 @@ db = db.Where("product_id=?", slf.ProductId) } + if len(slf.LocationIds) > 0 { + db = db.Where("location_id in (?)", slf.LocationIds) + } + return db } diff --git a/models/location_product_amount.go b/models/location_product_amount.go index 9686a30..b834d4b 100644 --- a/models/location_product_amount.go +++ b/models/location_product_amount.go @@ -20,12 +20,13 @@ LocationProductAmountSearch struct { LocationProductAmount - 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 + LocationProductIds []int } LocationProductAmountWithOperation struct { @@ -88,6 +89,11 @@ return slf } +func (slf *LocationProductAmountSearch) SetLocationProductIds(ids []int) *LocationProductAmountSearch { + slf.LocationProductIds = ids + return slf +} + func (slf *LocationProductAmountSearch) build() *gorm.DB { var db = slf.Orm.Model(&LocationProductAmount{}) @@ -108,6 +114,9 @@ if slf.LocationProductId != 0 { db = db.Where("location_product_id=?", slf.LocationProductId) } + if len(slf.LocationProductIds) > 0 { + db = db.Where("location_product_id in (?)", slf.LocationProductIds) + } return db } diff --git a/request/report_forms_request.go b/request/report_forms_request.go index 11a80ef..3d1a5ae 100644 --- a/request/report_forms_request.go +++ b/request/report_forms_request.go @@ -17,5 +17,7 @@ type GetLocationForms struct { PageInfo - KeyWord string `json:"keyWord"` + KeyWord string `json:"keyWord"` + WareHouseCode string `json:"wareHouseCode"` + ProductId string `json:"productId"` } -- Gitblit v1.8.0