From 90341876ca9590b69f9a8fda7203bdec8fb210ae Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 29 七月 2024 20:08:45 +0800 Subject: [PATCH] 产品列表增加产品分类id数组参数 & 修复一些bug --- controllers/product_controller.go | 22 +++++++---- models/product_category.go | 8 ++++ request/product_request.go | 5 +- docs/swagger.yaml | 15 ++++++- docs/docs.go | 19 ++++++++- docs/swagger.json | 19 ++++++++- 6 files changed, 69 insertions(+), 19 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index 9b81e63..56ab486 100644 --- a/controllers/product_controller.go +++ b/controllers/product_controller.go @@ -109,6 +109,7 @@ // @Summary 鑾峰彇浜у搧鍒楄〃 // @Produce application/json // @Param object body request.GetProductList true "鏌ヨ鍙傛暟" +// @Param Authorization header string true "token" // @Success 200 {object} util.ResponseList{data=[]models.Material} "鎴愬姛" // @Router /api-wms/v1/product/getProductList [post] func (slf ProductController) GetProductList(c *gin.Context) { @@ -121,7 +122,12 @@ if params.PageInfo.Check() { search.SetPage(params.Page, params.PageSize) } - products, total, err := search.SetPreload(true).SetKeyword(params.KeyWord).SetCategoryId(params.CategoryId).SetOrder("created_at desc").Find() + products, total, err := search.SetPreload(true). + SetKeyword(params.KeyWord). + SetCategoryId(params.CategoryId). + SetCategoryIds(params.CategoryIds). + SetOrder("created_at desc"). + Find() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触") return @@ -136,15 +142,14 @@ util.ResponseFormat(c, code.RequestParamError, "浜у搧绫诲瀷鏌ユ壘澶辫触") return } + categoryMap := models.CategoryMap(categories) for _, product := range products { - for _, category := range categories { - if product.CategoryId == int(category.ID) { - product.CategoryName = category.Name - } + if product.CategoryId != 0 && categoryMap[product.CategoryId] != nil { + product.CategoryName = categoryMap[product.CategoryId].Name } var totalAmount decimal.Decimal - if err := models.NewOperationSearch().Orm. - Table("wms_operation_details"). + db := models.NewOperationSearch().Orm + if err := db.Table("wms_operation_details"). InnerJoins("INNER JOIN wms_operation on wms_operation_details.operation_id=wms_operation.id"). Select("IFNULL(SUM(wms_operation_details.amount), 0) as total_count"). Where("wms_operation_details.product_id=? and wms_operation.`status`=? and wms_operation.base_operation_type in (?)", product.ID, constvar.OperationStatus_Ready, []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeDisuse}). @@ -157,7 +162,8 @@ product.PredictionAmount = product.Amount.Add(totalAmount) var statisticsList []*request.ProductStatistics - if err := models.NewOperationSearch().Orm.Table("wms_operation"). + db2 := models.NewOperationSearch().Orm + if err := db2.Table("wms_operation"). InnerJoins("INNER JOIN wms_operation_details on wms_operation_details.operation_id=wms_operation.id"). Select("SUM(wms_operation_details.amount) as total_amount,wms_operation.base_operation_type"). Where("wms_operation_details.product_id=? and wms_operation.`status`=? and wms_operation.base_operation_type in (?)", product.ID, constvar.OperationStatus_Finish, []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeDisuse}). diff --git a/docs/docs.go b/docs/docs.go index 95b1f70..6d7e4cc 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -3229,6 +3229,13 @@ "schema": { "$ref": "#/definitions/request.GetProductList" } + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true } ], "responses": { @@ -6302,7 +6309,7 @@ "type": "string" }, "silkMarket": { - "description": "搴勫彛缂栫爜", + "description": "搴勫彛", "type": "string" }, "sourceNumber": { @@ -6784,6 +6791,12 @@ "categoryId": { "type": "integer" }, + "categoryIds": { + "type": "array", + "items": { + "type": "integer" + } + }, "keyWord": { "type": "string" }, @@ -6947,7 +6960,7 @@ "type": "number" }, "silkMarket": { - "description": "搴勫彛缂栫爜", + "description": "搴勫彛", "type": "string" }, "silkMarketClose": { @@ -7426,7 +7439,7 @@ "type": "string" }, "silkMarket": { - "description": "搴勫彛缂栫爜", + "description": "搴勫彛", "type": "string" }, "sourceNumber": { diff --git a/docs/swagger.json b/docs/swagger.json index 760e12d..3bc9602 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -3218,6 +3218,13 @@ "schema": { "$ref": "#/definitions/request.GetProductList" } + }, + { + "type": "string", + "description": "token", + "name": "Authorization", + "in": "header", + "required": true } ], "responses": { @@ -6291,7 +6298,7 @@ "type": "string" }, "silkMarket": { - "description": "搴勫彛缂栫爜", + "description": "搴勫彛", "type": "string" }, "sourceNumber": { @@ -6773,6 +6780,12 @@ "categoryId": { "type": "integer" }, + "categoryIds": { + "type": "array", + "items": { + "type": "integer" + } + }, "keyWord": { "type": "string" }, @@ -6936,7 +6949,7 @@ "type": "number" }, "silkMarket": { - "description": "搴勫彛缂栫爜", + "description": "搴勫彛", "type": "string" }, "silkMarketClose": { @@ -7415,7 +7428,7 @@ "type": "string" }, "silkMarket": { - "description": "搴勫彛缂栫爜", + "description": "搴勫彛", "type": "string" }, "sourceNumber": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 86a7c4e..e3e5cb4 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1582,7 +1582,7 @@ description: 鑱旂郴鐢佃瘽 type: string silkMarket: - description: 搴勫彛缂栫爜 + description: 搴勫彛 type: string sourceNumber: description: 婧愬崟鍙� @@ -1910,6 +1910,10 @@ properties: categoryId: type: integer + categoryIds: + items: + type: integer + type: array keyWord: type: string page: @@ -2029,7 +2033,7 @@ description: 閿�鍞崟浠� type: number silkMarket: - description: 搴勫彛缂栫爜 + description: 搴勫彛 type: string silkMarketClose: description: 搴勫彛鍏抽棴 @@ -2358,7 +2362,7 @@ description: 鑱旂郴鐢佃瘽 type: string silkMarket: - description: 搴勫彛缂栫爜 + description: 搴勫彛 type: string sourceNumber: description: 婧愬崟鍙� @@ -4554,6 +4558,11 @@ required: true schema: $ref: '#/definitions/request.GetProductList' + - description: token + in: header + name: Authorization + required: true + type: string produces: - application/json responses: diff --git a/models/product_category.go b/models/product_category.go index af90da8..fd051af 100644 --- a/models/product_category.go +++ b/models/product_category.go @@ -262,3 +262,11 @@ return nil } + +func CategoryMap(records []*ProductCategory) (m map[int]*ProductCategory) { + m = make(map[int]*ProductCategory, len(records)) + for _, record := range records { + m[record.Id] = record + } + return m +} diff --git a/request/product_request.go b/request/product_request.go index e9e10a1..d987c9b 100644 --- a/request/product_request.go +++ b/request/product_request.go @@ -7,8 +7,9 @@ type GetProductList struct { PageInfo - KeyWord string `json:"keyWord"` - CategoryId int `json:"categoryId"` + KeyWord string `json:"keyWord"` + CategoryId int `json:"categoryId"` + CategoryIds []int `json:"categoryIds"` } type QueryOperationList struct { -- Gitblit v1.8.0