产品列表增加产品分类id数组参数 & 修复一些bug
| | |
| | | // @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) { |
| | |
| | | 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 |
| | |
| | | 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}). |
| | |
| | | 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}). |
| | |
| | | "schema": { |
| | | "$ref": "#/definitions/request.GetProductList" |
| | | } |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | |
| | | "type": "string" |
| | | }, |
| | | "silkMarket": { |
| | | "description": "庄口编码", |
| | | "description": "庄口", |
| | | "type": "string" |
| | | }, |
| | | "sourceNumber": { |
| | |
| | | "categoryId": { |
| | | "type": "integer" |
| | | }, |
| | | "categoryIds": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | }, |
| | | "keyWord": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "type": "number" |
| | | }, |
| | | "silkMarket": { |
| | | "description": "庄口编码", |
| | | "description": "庄口", |
| | | "type": "string" |
| | | }, |
| | | "silkMarketClose": { |
| | |
| | | "type": "string" |
| | | }, |
| | | "silkMarket": { |
| | | "description": "庄口编码", |
| | | "description": "庄口", |
| | | "type": "string" |
| | | }, |
| | | "sourceNumber": { |
| | |
| | | "schema": { |
| | | "$ref": "#/definitions/request.GetProductList" |
| | | } |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | |
| | | "type": "string" |
| | | }, |
| | | "silkMarket": { |
| | | "description": "庄口编码", |
| | | "description": "庄口", |
| | | "type": "string" |
| | | }, |
| | | "sourceNumber": { |
| | |
| | | "categoryId": { |
| | | "type": "integer" |
| | | }, |
| | | "categoryIds": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | }, |
| | | "keyWord": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "type": "number" |
| | | }, |
| | | "silkMarket": { |
| | | "description": "庄口编码", |
| | | "description": "庄口", |
| | | "type": "string" |
| | | }, |
| | | "silkMarketClose": { |
| | |
| | | "type": "string" |
| | | }, |
| | | "silkMarket": { |
| | | "description": "庄口编码", |
| | | "description": "庄口", |
| | | "type": "string" |
| | | }, |
| | | "sourceNumber": { |
| | |
| | | description: 联系电话 |
| | | type: string |
| | | silkMarket: |
| | | description: 庄口编码 |
| | | description: 庄口 |
| | | type: string |
| | | sourceNumber: |
| | | description: 源单号 |
| | |
| | | properties: |
| | | categoryId: |
| | | type: integer |
| | | categoryIds: |
| | | items: |
| | | type: integer |
| | | type: array |
| | | keyWord: |
| | | type: string |
| | | page: |
| | |
| | | description: 销售单价 |
| | | type: number |
| | | silkMarket: |
| | | description: 庄口编码 |
| | | description: 庄口 |
| | | type: string |
| | | silkMarketClose: |
| | | description: 庄口关闭 |
| | |
| | | description: 联系电话 |
| | | type: string |
| | | silkMarket: |
| | | description: 庄口编码 |
| | | description: 庄口 |
| | | type: string |
| | | sourceNumber: |
| | | description: 源单号 |
| | |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.GetProductList' |
| | | - description: token |
| | | in: header |
| | | name: Authorization |
| | | required: true |
| | | type: string |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | |
| | | 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 |
| | | } |
| | |
| | | |
| | | 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 { |