From efbe2bd4bbc6444dad4ab5fe8d7e839c38230805 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期五, 12 四月 2024 16:22:57 +0800
Subject: [PATCH] 库存报表修改

---
 controllers/report_forms_controller.go |   55 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go
index 4f3bc71..1c7bb9a 100644
--- a/controllers/report_forms_controller.go
+++ b/controllers/report_forms_controller.go
@@ -32,9 +32,33 @@
 // @Router    /api-wms/v1/forms/getInventoryForms [post]
 func (slf ReportFormsController) GetInventoryForms(c *gin.Context) {
 	var params request.GetInventoryForms
-	if err := c.BindJSON(&params); err != nil {
+	err := c.BindJSON(&params)
+	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
 		return
+	}
+	locationIds := make([]int, 0)
+	productIds := make([]string, 0)
+	productAmounts := make([]*models.LocationProductAmount, 0)
+	if params.WarehouseCode != "" {
+		locations, err := models.NewLocationSearch().SetJointName(params.WarehouseCode).FindNotTotal()
+		if err != nil {
+			util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浠撳簱浣嶇疆澶辫触")
+			return
+		}
+
+		for _, location := range locations {
+			locationIds = append(locationIds, location.Id)
+		}
+		productAmounts, err = models.NewLocationProductAmountSearch().SetLocationIds(locationIds).SetQuery("amount > 0").Find()
+		if err != nil {
+			util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍦ㄥ簱鏁伴噺澶辫触")
+			return
+		}
+		for _, amount := range productAmounts {
+			productIds = append(productIds, amount.ProductId)
+		}
+
 	}
 	//鏌ヨ浜у搧
 	search := models.NewMaterialSearch()
@@ -46,6 +70,9 @@
 	}
 	if params.KeyWord != "" {
 		search.Orm.Where("material.name like ?", "%"+params.KeyWord+"%").Or("wms_product_category.name like ?", "%"+params.KeyWord+"%")
+	}
+	if len(productIds) > 0 {
+		search.Orm.Where("material.id in (?)", productIds)
 	}
 	var (
 		materials = make([]*models.Material, 0)
@@ -63,24 +90,16 @@
 		return
 	}
 
-	locations, err := models.NewLocationSearch().SetJointName(params.WarehouseCode).FindNotTotal()
-	if err != nil {
-		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浠撳簱浣嶇疆澶辫触")
-		return
-	}
-	locationIds := make([]int, 0)
-	for _, location := range locations {
-		locationIds = append(locationIds, location.Id)
-	}
 	//鏌ヨ鍦ㄥ簱鏁伴噺
-	productIds := make([]string, 0)
-	for _, material := range materials {
-		productIds = append(productIds, material.ID)
-	}
-	productAmounts, err := models.NewLocationProductAmountSearch().SetProductIds(productIds).SetLocationIds(locationIds).Find()
-	if err != nil {
-		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍦ㄥ簱鏁伴噺澶辫触")
-		return
+	if len(productIds) == 0 {
+		for _, material := range materials {
+			productIds = append(productIds, material.ID)
+		}
+		productAmounts, err = models.NewLocationProductAmountSearch().SetProductIds(productIds).SetLocationIds(locationIds).Find()
+		if err != nil {
+			util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍦ㄥ簱鏁伴噺澶辫触")
+			return
+		}
 	}
 
 	//鏌ヨ鍑哄叆搴撳氨缁暟閲�

--
Gitblit v1.8.0