From c950586b718ae6fc198bedf424609a4ac94cb5d1 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 04 七月 2024 18:16:07 +0800
Subject: [PATCH] 增加根据位置或仓库查询产品及库存列表

---
 models/db.go                           |    1 
 models/location_product_amount.go      |   18 ++-
 models/operation.go                    |    2 
 request/location_product_amount.go     |   12 ++
 docs/swagger.yaml                      |   45 ++++++++
 docs/docs.go                           |   64 ++++++++++++
 docs/swagger.json                      |   64 ++++++++++++
 controllers/location_product_amount.go |   46 +++++++++
 router/router.go                       |    1 
 9 files changed, 240 insertions(+), 13 deletions(-)

diff --git a/controllers/location_product_amount.go b/controllers/location_product_amount.go
index 87ff91b..02d4bad 100644
--- a/controllers/location_product_amount.go
+++ b/controllers/location_product_amount.go
@@ -143,6 +143,52 @@
 	util.ResponseFormatListWithPage(c, code.Success, records, int(total), params.Page, params.PageSize)
 }
 
+// LocationProductList
+// @Tags      搴撳瓨鐩樼偣
+// @Summary   鑾峰彇浣嶇疆瀵瑰簲浜у搧鍒楄〃
+// @Produce   application/json
+// @Param		 object  body  request.GetLocationProductList true  "鏌ヨ鍙傛暟"
+// @Param     Authorization	header string true "token"
+// @Success   200 {object} util.Response	"鎴愬姛"
+// @Router    /api-wms/v1/locationProductAmount/locationProductList [post]
+func (slf LocationProductAmountController) LocationProductList(c *gin.Context) {
+	var params request.GetLocationProductList
+	if err := c.BindJSON(&params); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�:"+err.Error())
+		return
+	}
+	if !params.Check() {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟寮傚父")
+		return
+	}
+	productIds := make([]string, 0)
+	locationIds := make([]int, 0)
+	if params.Keyword != "" {
+		materials, _ := models.NewMaterialSearch().SetKeyword(params.Keyword).FindNotTotal()
+		for _, material := range materials {
+			productIds = append(productIds, material.ID)
+		}
+		locations, _ := models.NewLocationSearch().SetKeyword(params.Keyword).FindNotTotal()
+		for _, location := range locations {
+			locationIds = append(locationIds, location.Id)
+		}
+	}
+
+	search := models.NewLocationProductAmountSearch()
+	records, total, err := search.
+		SetLocationIds(locationIds).SetWarehouseId(params.WarehouseId).SetProductIds(productIds).SetLocationId(params.LocationId).
+		SetPage(params.Page, params.PageSize).
+		SetOrder("id desc").
+		SetPreload(true).
+		FindByPage()
+	if err != nil {
+		util.ResponseFormat(c, code.InternalError, "鏌ヨ澶辫触")
+		return
+	}
+
+	util.ResponseFormatList(c, code.Success, records, int(total))
+}
+
 // Add
 // @Tags      搴撳瓨鐩樼偣
 // @Summary   娣诲姞搴撳瓨鐩樼偣淇℃伅
diff --git a/docs/docs.go b/docs/docs.go
index 597d1c7..711fe86 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -1847,6 +1847,43 @@
                 }
             }
         },
+        "/api-wms/v1/locationProductAmount/locationProductList": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "搴撳瓨鐩樼偣"
+                ],
+                "summary": "鑾峰彇浣嶇疆瀵瑰簲浜у搧鍒楄〃",
+                "parameters": [
+                    {
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.GetLocationProductList"
+                        }
+                    },
+                    {
+                        "type": "string",
+                        "description": "token",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/api-wms/v1/locationProductAmount/update": {
             "post": {
                 "produces": [
@@ -4581,7 +4618,7 @@
                     "$ref": "#/definitions/models.Location"
                 },
                 "locationId": {
-                    "description": "LocationProductId int             ` + "`" + `json:\"locationProductId\" gorm:\"type:int;not null;comment:涓婃灦瑙勫垯id\"` + "`" + ` //涓婃灦瑙勫垯id\nLocationProduct   LocationProduct ` + "`" + `json:\"locationProduct\" gorm:\"foreignKey:LocationProductId;references:Id\"` + "`" + `",
+                    "description": "浣嶇疆id",
                     "type": "integer"
                 },
                 "product": {
@@ -4600,6 +4637,9 @@
                 },
                 "updateTime": {
                     "type": "string"
+                },
+                "warehouseId": {
+                    "type": "integer"
                 }
             }
         },
@@ -6395,6 +6435,28 @@
                 }
             }
         },
+        "request.GetLocationProductList": {
+            "type": "object",
+            "properties": {
+                "keyword": {
+                    "type": "string"
+                },
+                "locationId": {
+                    "type": "integer"
+                },
+                "page": {
+                    "description": "椤电爜",
+                    "type": "integer"
+                },
+                "pageSize": {
+                    "description": "姣忛〉澶у皬",
+                    "type": "integer"
+                },
+                "warehouseId": {
+                    "type": "integer"
+                }
+            }
+        },
         "request.GetMiniDictList": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 340d84d..10da27b 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -1836,6 +1836,43 @@
                 }
             }
         },
+        "/api-wms/v1/locationProductAmount/locationProductList": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "搴撳瓨鐩樼偣"
+                ],
+                "summary": "鑾峰彇浣嶇疆瀵瑰簲浜у搧鍒楄〃",
+                "parameters": [
+                    {
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.GetLocationProductList"
+                        }
+                    },
+                    {
+                        "type": "string",
+                        "description": "token",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/api-wms/v1/locationProductAmount/update": {
             "post": {
                 "produces": [
@@ -4570,7 +4607,7 @@
                     "$ref": "#/definitions/models.Location"
                 },
                 "locationId": {
-                    "description": "LocationProductId int             `json:\"locationProductId\" gorm:\"type:int;not null;comment:涓婃灦瑙勫垯id\"` //涓婃灦瑙勫垯id\nLocationProduct   LocationProduct `json:\"locationProduct\" gorm:\"foreignKey:LocationProductId;references:Id\"`",
+                    "description": "浣嶇疆id",
                     "type": "integer"
                 },
                 "product": {
@@ -4589,6 +4626,9 @@
                 },
                 "updateTime": {
                     "type": "string"
+                },
+                "warehouseId": {
+                    "type": "integer"
                 }
             }
         },
@@ -6384,6 +6424,28 @@
                 }
             }
         },
+        "request.GetLocationProductList": {
+            "type": "object",
+            "properties": {
+                "keyword": {
+                    "type": "string"
+                },
+                "locationId": {
+                    "type": "integer"
+                },
+                "page": {
+                    "description": "椤电爜",
+                    "type": "integer"
+                },
+                "pageSize": {
+                    "description": "姣忛〉澶у皬",
+                    "type": "integer"
+                },
+                "warehouseId": {
+                    "type": "integer"
+                }
+            }
+        },
         "request.GetMiniDictList": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 6dd0214..b575f22 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -526,9 +526,7 @@
       location:
         $ref: '#/definitions/models.Location'
       locationId:
-        description: |-
-          LocationProductId int             `json:"locationProductId" gorm:"type:int;not null;comment:涓婃灦瑙勫垯id"` //涓婃灦瑙勫垯id
-          LocationProduct   LocationProduct `json:"locationProduct" gorm:"foreignKey:LocationProductId;references:Id"`
+        description: 浣嶇疆id
         type: integer
       product:
         $ref: '#/definitions/models.Material'
@@ -542,6 +540,8 @@
         type: string
       updateTime:
         type: string
+      warehouseId:
+        type: integer
     type: object
   models.LogisticCompany:
     properties:
@@ -1778,6 +1778,21 @@
         type: integer
       warehouseId:
         description: 浠撳簱ID
+        type: integer
+    type: object
+  request.GetLocationProductList:
+    properties:
+      keyword:
+        type: string
+      locationId:
+        type: integer
+      page:
+        description: 椤电爜
+        type: integer
+      pageSize:
+        description: 姣忛〉澶у皬
+        type: integer
+      warehouseId:
         type: integer
     type: object
   request.GetMiniDictList:
@@ -3537,6 +3552,30 @@
       summary: 搴撳瓨鐩樼偣鍒楄〃
       tags:
       - 搴撳瓨鐩樼偣
+  /api-wms/v1/locationProductAmount/locationProductList:
+    post:
+      parameters:
+      - description: 鏌ヨ鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.GetLocationProductList'
+      - description: token
+        in: header
+        name: Authorization
+        required: true
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            $ref: '#/definitions/util.Response'
+      summary: 鑾峰彇浣嶇疆瀵瑰簲浜у搧鍒楄〃
+      tags:
+      - 搴撳瓨鐩樼偣
   /api-wms/v1/locationProductAmount/update:
     post:
       parameters:
diff --git a/models/db.go b/models/db.go
index 07c3fb9..eaa23cc 100644
--- a/models/db.go
+++ b/models/db.go
@@ -135,7 +135,6 @@
 
 func InsertDefaultData() {
 	models := []interface{}{
-		NewDepartmentSearch(),
 		NewLocationSearch(),
 	}
 	for _, model := range models {
diff --git a/models/location_product_amount.go b/models/location_product_amount.go
index d4990b1..98abd13 100644
--- a/models/location_product_amount.go
+++ b/models/location_product_amount.go
@@ -11,10 +11,9 @@
 type (
 	LocationProductAmount struct {
 		WmsModel
-		Id int `json:"id"  gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		//LocationProductId int             `json:"locationProductId" gorm:"type:int;not null;comment:涓婃灦瑙勫垯id"` //涓婃灦瑙勫垯id
-		//LocationProduct   LocationProduct `json:"locationProduct" gorm:"foreignKey:LocationProductId;references:Id"`
+		Id                int             `json:"id"  gorm:"column:id;primary_key;AUTO_INCREMENT"`
 		LocationId        int             `json:"locationId" gorm:"type:int;not null;comment:浣嶇疆id"` //浣嶇疆id
+		WarehouseId       int             `json:"warehouseId" gorm:"type:int;not null;default:0;comment:浠撳簱id"`
 		Location          Location        `json:"location" gorm:"foreignKey:LocationId;references:id"`
 		ProductCategoryID int             `json:"productCategoryId" gorm:"type:int;not null;comment:浜у搧绉嶇被id"` //浜у搧绉嶇被id
 		ProductCategory   ProductCategory `json:"productCategory" gorm:"foreignKey:ProductCategoryID;references:Id"`
@@ -127,6 +126,11 @@
 	return slf
 }
 
+func (slf *LocationProductAmountSearch) SetWarehouseId(wid int) *LocationProductAmountSearch {
+	slf.WarehouseId = wid
+	return slf
+}
+
 func (slf *LocationProductAmountSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&LocationProductAmount{})
 
@@ -148,9 +152,7 @@
 	if slf.Preload {
 		db = db.Model(&LocationProductAmount{}).Preload("Location").Preload("Product").Preload("ProductCategory")
 	}
-	//if slf.LocationProductId != 0 {
-	//	db = db.Where("location_product_id=?", slf.LocationProductId)
-	//}
+
 	if len(slf.ProductIds) > 0 {
 		db = db.Where("product_id in (?)", slf.ProductIds)
 	}
@@ -175,6 +177,10 @@
 		db = db.Where(slf.Query)
 	}
 
+	if slf.WarehouseId != 0 {
+		db = db.Where("warehouse_id = ?", slf.WarehouseId)
+	}
+
 	return db
 }
 
diff --git a/models/operation.go b/models/operation.go
index 9e2846c..12ea942 100644
--- a/models/operation.go
+++ b/models/operation.go
@@ -61,7 +61,7 @@
 		CheckedBy    string `json:"checkedBy" gorm:"type:varchar(255);comment:楠岃瘉鑰匲serId"`
 		Remark       string `json:"remark"`
 
-		WarehouseId         int       `json:"warehouseId" gorm:"type:int;not null;comment:浠撳簱id"`
+		WarehouseId         int       `json:"warehouseId" gorm:"type:int;not null;default:0;comment:浠撳簱id"`
 		Warehouse           Warehouse `json:"warehouse" gorm:"foreignKey:WarehouseId"`
 		IsInternalOutput    bool      `json:"isInternalOutput"` //鏄惁璋冩嫧浜х敓鐨勫嚭搴�
 		InventoryDealerType int       `json:"inventoryDealerType" gorm:"type:varchar(255);comment:璋冩嫧鍑哄叆搴撳垎绫�(瀵瑰簲dict瀛楀吀琛ㄧ殑ID)"`
diff --git a/request/location_product_amount.go b/request/location_product_amount.go
index 9b1a386..4deb759 100644
--- a/request/location_product_amount.go
+++ b/request/location_product_amount.go
@@ -2,6 +2,7 @@
 
 import (
 	"github.com/shopspring/decimal"
+	"wms/models"
 )
 
 type GetList struct {
@@ -38,3 +39,14 @@
 	ProductId               string `json:"productId"`               //浜у搧id
 	LocationProductAmountId int    `json:"locationProductAmountId"` //搴撳瓨鐩樼偣id
 }
+
+type GetLocationProductList struct {
+	PageInfo
+	Keyword     string `json:"keyword"`
+	WarehouseId int    `json:"warehouseId"`
+	LocationId  int    `json:"locationId"`
+}
+
+type GetLocationProductListResponse struct {
+	models.Material
+}
diff --git a/router/router.go b/router/router.go
index edf34ef..815904d 100644
--- a/router/router.go
+++ b/router/router.go
@@ -160,6 +160,7 @@
 	{
 		locationProductAmountAPI.POST("add", locationProductAmountController.Add)                                           //娣诲姞搴撳瓨鐩樼偣淇℃伅
 		locationProductAmountAPI.POST("list", locationProductAmountController.List)                                         //鏌ョ湅搴撳瓨鐩樼偣鍒楄〃
+		locationProductAmountAPI.POST("locationProductList", locationProductAmountController.LocationProductList)           //鏌ョ湅浜у搧搴撳瓨鍒楄〃
 		locationProductAmountAPI.POST("update", locationProductAmountController.Update)                                     //淇敼搴撳瓨鐩樼偣淇℃伅
 		locationProductAmountAPI.POST("finish", locationProductAmountController.Finish)                                     //搴旂敤銆侀獙璇佸簱瀛樼洏鐐逛俊鎭�
 		locationProductAmountAPI.POST("getRuleList", locationProductAmountController.GetRuleList)                           //鑾峰彇涓婃灦瑙勫垯

--
Gitblit v1.8.0