根据名字查询京东upc

This commit is contained in:
苏尹岚
2019-12-16 14:21:19 +08:00
parent f5166d59b6
commit 1f1835fa2d
4 changed files with 49 additions and 14 deletions

View File

@@ -7,6 +7,10 @@ import (
"strings" "strings"
"time" "time"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
@@ -1292,16 +1296,29 @@ func SortCategorySkus(ctx *jxcontext.Context, catID int, skuIDList []int) (err e
return err return err
} }
func GetJdUpcCodeByName(ctx *jxcontext.Context, name string) (pagedInfo *model.PagedInfo, err error) { func GetJdUpcCodeByName(ctx *jxcontext.Context, name, upcCode string) (productInfos []*jdapi.ProductInfo, err error) {
pageNo := 1 var (
pageSize := 30 pageNo = 5
jdSkus, totalCount, err := api.JdAPI.GetJdUpcCodeByName(name, pageNo, pageSize) pageSize = 30
for _, v := range jdSkus { pageNoList []int
fmt.Println(v) )
for i := 1; i < pageNo+1; i++ {
pageNoList = append(pageNoList, i)
} }
pagedInfo = &model.PagedInfo{ task := tasksch.NewParallelTask("获取京东商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
Data: jdSkus, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
TotalCount: totalCount, pageNum := batchItemList[0].(int)
productInfo, err := api.JdAPI.GetJdUpcCodeByName(name, upcCode, pageNum, pageSize)
if err != nil {
return retVal, err
} }
return pagedInfo, err retVal = productInfo
return retVal, err
}, pageNoList)
tasksch.HandleTask(task, nil, true).Run()
productInfoInterface, err := task.GetResult(0)
for _, v := range productInfoInterface {
productInfos = append(productInfos, v.(*jdapi.ProductInfo))
}
return productInfos, err
} }

View File

@@ -83,3 +83,20 @@ type OrderFinancialSkuExt struct {
OrderSkuFinancial OrderSkuFinancial
Image string `json:"image"` Image string `json:"image"`
} }
type ProductInfo struct {
OriginalName string `json:"originalName"`
OriginalSpec string `json:"originalSpec"`
Name string `json:"name"`
Img string `json:"img"`
ImgList []string `json:"imgList"`
SpecQuality int `json:"specQuality"`
SpecUnit string `json:"specUnit"`
Unit string `json:"unit"`
Weight float32 `json:"weight"`
Price int `json:"price"`
Categories []string `json:"categories"`
ManName string `json:"manName"` // 生产商
BrandName string `json:"brandName"`
UpcCode string `json:"upcCode"`
}

View File

@@ -379,13 +379,14 @@ func (c *SkuController) GetStoreSkuSalesInfo() {
// @Title 根据名字查询京东商品UPC信息 // @Title 根据名字查询京东商品UPC信息
// @Description 根据名字查询京东商品UPC信息 // @Description 根据名字查询京东商品UPC信息
// @Param token header string true "认证token" // @Param token header string true "认证token"
// @Param name formData string true "商品名" // @Param name query string false "商品名"
// @Param upcCode query string false "upcCode,不支持模糊"
// @Success 200 {object} controllers.CallResult // @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult
// @router /GetJdUpcCodeByName [post] // @router /GetJdUpcCodeByName [get]
func (c *SkuController) GetJdUpcCodeByName() { func (c *SkuController) GetJdUpcCodeByName() {
c.callGetJdUpcCodeByName(func(params *tSkuGetJdUpcCodeByNameParams) (retVal interface{}, errCode string, err error) { c.callGetJdUpcCodeByName(func(params *tSkuGetJdUpcCodeByNameParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.GetJdUpcCodeByName(params.Ctx, params.Name) retVal, err = cms.GetJdUpcCodeByName(params.Ctx, params.Name, params.UpcCode)
return retVal, "", err return retVal, "", err
}) })
} }

View File

@@ -1174,7 +1174,7 @@ func init() {
beego.ControllerComments{ beego.ControllerComments{
Method: "GetJdUpcCodeByName", Method: "GetJdUpcCodeByName",
Router: `/GetJdUpcCodeByName`, Router: `/GetJdUpcCodeByName`,
AllowHTTPMethods: []string{"post"}, AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(), MethodParams: param.Make(),
Filters: nil, Filters: nil,
Params: nil}) Params: nil})