zhangqian
2024-07-29 90341876ca9590b69f9a8fda7203bdec8fb210ae
产品列表增加产品分类id数组参数 & 修复一些bug
6个文件已修改
88 ■■■■ 已修改文件
controllers/product_controller.go 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/product_category.go 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/product_request.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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}).
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": {
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": {
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:
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
}
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 {