liujiandao
2024-04-25 c0f8f8d3a74dbdab4f6ab4926fc664d818fb50f2
获取供应商产品
4个文件已修改
55 ■■■■■ 已修改文件
api/v1/test/supplier.go 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/request/supplier.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/test/supplier.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/test/supplier.go 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/test/supplier.go
@@ -226,3 +226,34 @@
        response.OkWithMessage("修改成功", c)
    }
}
// GetSupplierProductList 获取供应商提供产品列表
// @Tags Supplier
// @Summary 获取供应商提供产品列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query testReq.SupplierProduct true "获取供应商提供产品列表"
// @Param Authorization    header string true "token"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /s/getSupplierProductList [get]
func (sApi *SupplierApi) GetSupplierProductList(c *gin.Context) {
    var params testReq.SupplierProduct
    err := c.ShouldBindQuery(&params)
    if err != nil {
        response.FailWithMessage(err.Error(), c)
        return
    }
    list, total, err := sService.GetSupplierProduct(params)
    if err != nil {
        global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     params.Page,
        PageSize: params.PageSize,
    }, "获取成功", c)
}
model/test/request/supplier.go
@@ -17,3 +17,8 @@
    Id     uint `json:"id"`
    Status int  `json:"status"`
}
type SupplierProduct struct {
    request.PageInfo
    SupplierId uint `json:"supplierId" form:"supplierId"`
}
router/test/supplier.go
@@ -19,6 +19,7 @@
        sRouter.DELETE("deleteSupplierByIds", sApi.DeleteSupplierByIds) // 批量删除Supplier
        sRouter.PUT("updateSupplier", sApi.UpdateSupplier)              // 更新Supplier
        sRouter.POST("changeSupplierStatus", sApi.ChangeSupplierStatus) // 更新Supplier状态
        sRouter.GET("getSupplierProductList", sApi.GetSupplierProductList) // 获取供应商提供产品列表
    }
    {
        sRouterWithoutRecord.GET("findSupplier", sApi.FindSupplier)                       // 根据ID获取Supplier
service/test/supplier.go
@@ -101,3 +101,21 @@
    err := global.GVA_DB.Model(&test.Supplier{}).Count(&total).Error
    return int(total), err
}
func (sService *SupplierService) GetSupplierProduct(info testReq.SupplierProduct) ([]test.SupplierMaterial, int64, error) {
    limit := info.PageSize
    offset := info.PageSize * (info.Page - 1)
    // 创建db
    db := global.GVA_DB.Model(&test.SupplierMaterial{})
    var ps []test.SupplierMaterial
    var total int64
    if info.SupplierId > 0 {
        db = db.Where("supplier_id = ?", info.SupplierId)
    }
    err := db.Count(&total).Error
    if err != nil {
        return ps, total, err
    }
    err = db.Limit(limit).Offset(offset).Order("id desc").Preload("Supplier").Find(&ps).Error
    return ps, total, err
}