- up
This commit is contained in:
@@ -48,9 +48,9 @@ func PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, ven
|
||||
}
|
||||
case 1:
|
||||
if len(sku2Delete) > 0 {
|
||||
err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (err error) {
|
||||
_, err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) {
|
||||
err = handler.DeleteStoreSkus(ctx, storeID, vendorStoreID, sku2Delete)
|
||||
return err
|
||||
return nil, err
|
||||
}, ctx, parentTask, sku2Delete, handler.GetStoreSkusBatchSize(partner.FuncDeleteStoreSkus))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
@@ -20,6 +22,8 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
UnlimitedBatchSize = math.MaxInt32
|
||||
|
||||
MaxStoreSkuStock = 9999
|
||||
UnlimitedStoreSkuStock = -1
|
||||
)
|
||||
@@ -109,13 +113,14 @@ type IPurchasePlatformStoreSkuHandler interface {
|
||||
type ISingleStoreStoreSkuHandler interface {
|
||||
IPurchasePlatformStoreSkuHandler
|
||||
|
||||
GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, skuIDs []int) (outSkuNameList []*SkuNameInfo, err error)
|
||||
GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (outSkuNameList []*SkuNameInfo, err error)
|
||||
CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error)
|
||||
UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error)
|
||||
DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (err error)
|
||||
DeleteStoreAllSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, isContinueWhenError bool) (err error)
|
||||
|
||||
GetStoreAllCategories(ctx *jxcontext.Context, storeID int, vendorStoreID string) (cats []*BareCategoryInfo, err error)
|
||||
GetStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, catName string) (cat *BareCategoryInfo, err error)
|
||||
CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error)
|
||||
UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error)
|
||||
DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string) (err error)
|
||||
|
||||
@@ -21,7 +21,7 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
|
||||
case partner.FuncUpdateStoreSkusStock, partner.FuncUpdateStoreSkusStatus, partner.FuncUpdateStoreSkusPrice, partner.FuncDeleteStoreSkus:
|
||||
batchSize = ebaiapi.MaxStoreSkuBatchSize
|
||||
case partner.FuncGetStoreSkusBareInfo:
|
||||
batchSize = 1
|
||||
batchSize = partner.UnlimitedBatchSize
|
||||
case partner.FuncCreateStoreSkus, partner.FuncUpdateStoreSkus:
|
||||
batchSize = 1
|
||||
case partner.FuncGetStoreSkusFullInfo:
|
||||
@@ -210,12 +210,17 @@ func ebaiSkuStatus2Jx(ebaiSkuStatus int) (jxSkuStatus int) {
|
||||
return jxSkuStatus
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, skuIDs []int) (skuNameList []*partner.SkuNameInfo, err error) {
|
||||
func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (skuNameList []*partner.SkuNameInfo, err error) {
|
||||
params := &ebaiapi.SkuListParams{
|
||||
PageSize: MaxPageSize,
|
||||
}
|
||||
if len(skuIDs) == 1 {
|
||||
params.CustomSkuID = utils.Int2Str(skuIDs[0])
|
||||
if len(storeSkuList) == 1 {
|
||||
if storeSkuList[0].SkuID > 0 {
|
||||
params.CustomSkuID = utils.Int2Str(storeSkuList[0].SkuID)
|
||||
}
|
||||
if storeSkuList[0].VendorSkuID != "" {
|
||||
params.SkuID = utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0)
|
||||
}
|
||||
}
|
||||
page1, err := api.EbaiAPI.SkuList(utils.Int2Str(storeID), params)
|
||||
if err == nil {
|
||||
|
||||
@@ -3,12 +3,18 @@ package ebai
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
)
|
||||
|
||||
func TestGetStoreSkusFullInfo(t *testing.T) {
|
||||
skuNameList, err := CurPurchaseHandler.GetStoreSkusFullInfo(jxcontext.AdminCtx, nil, testShopID, testShopBaiduID, []int{4256})
|
||||
skuNameList, err := CurPurchaseHandler.GetStoreSkusFullInfo(jxcontext.AdminCtx, nil, testShopID, testShopBaiduID, []*partner.StoreSkuInfo{
|
||||
&partner.StoreSkuInfo{
|
||||
SkuID: 4256,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
|
||||
case partner.FuncUpdateStoreSkusStock, partner.FuncUpdateStoreSkusStatus, partner.FuncUpdateStoreSkusPrice:
|
||||
batchSize = mtwmapi.MaxStoreSkuBatchSize
|
||||
case partner.FuncGetStoreSkusBareInfo:
|
||||
batchSize = 1
|
||||
batchSize = partner.UnlimitedBatchSize
|
||||
case partner.FuncDeleteStoreSkus:
|
||||
batchSize = 1 // 可考虑用批量操作
|
||||
case partner.FuncCreateStoreSkus, partner.FuncUpdateStoreSkus:
|
||||
@@ -246,8 +246,14 @@ func mtwmSkuStatus2Jx(mtwmSkuStatus int) (jxSkuStatus int) {
|
||||
return jxSkuStatus
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, skuIDs []int) (skuNameList []*partner.SkuNameInfo, err error) {
|
||||
if len(skuIDs) == 0 {
|
||||
func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (skuNameList []*partner.SkuNameInfo, err error) {
|
||||
if len(storeSkuList) == 1 {
|
||||
skuInfo, err := api.MtwmAPI.RetailGet(vendorStoreID, utils.Int2Str(storeSkuList[0].SkuID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
skuNameList = append(skuNameList, vendorSku2Jx(skuInfo))
|
||||
} else {
|
||||
for {
|
||||
result, err := api.MtwmAPI.RetailList(vendorStoreID, len(skuNameList), mtwmapi.GeneralMaxLimit)
|
||||
if err != nil {
|
||||
@@ -258,12 +264,6 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
skuInfo, err := api.MtwmAPI.RetailGet(vendorStoreID, utils.Int2Str(skuIDs[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
skuNameList = append(skuNameList, vendorSku2Jx(skuInfo))
|
||||
}
|
||||
return skuNameList, err
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
// _ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
)
|
||||
|
||||
func TestGetStoreSkusFullInfo(t *testing.T) {
|
||||
skuNameList, err := new(PurchaseHandler).GetStoreSkusFullInfo(jxcontext.AdminCtx, nil, 2, "2523687", nil)
|
||||
skuNameList, err := curPurchaseHandler.GetStoreSkusFullInfo(jxcontext.AdminCtx, nil, 2, "2523687", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -18,7 +19,14 @@ func TestGetStoreSkusFullInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetStoreSkusBareInfo(t *testing.T) {
|
||||
storeSkuList, err := curPurchaseHandler.GetStoreSkusBareInfo(jxcontext.AdminCtx, nil, 2, "2523687", nil)
|
||||
storeSkuList, err := curPurchaseHandler.GetStoreSkusBareInfo(jxcontext.AdminCtx, nil, 2, "2523687", []*partner.StoreSkuInfo{
|
||||
&partner.StoreSkuInfo{
|
||||
SkuID: 969,
|
||||
},
|
||||
&partner.StoreSkuInfo{
|
||||
SkuID: 1306,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
@@ -39,3 +47,18 @@ func TestDeleteStoreAllCategories(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetStoreCategory(t *testing.T) {
|
||||
_, err := curPurchaseHandler.GetStoreCategory(jxcontext.AdminCtx, 2, "2523687", "不存在的分类")
|
||||
if err == nil {
|
||||
t.Fatal("应该找不到这个分类")
|
||||
}
|
||||
catName := "小月饼"
|
||||
cat, err := curPurchaseHandler.GetStoreCategory(jxcontext.AdminCtx, 2, "2523687", catName)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if cat.Name != catName {
|
||||
t.Fatal("没有找到正确的商家分类")
|
||||
}
|
||||
t.Log(utils.Format4Output(cat, false))
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
@@ -20,22 +19,17 @@ func (p *DefSingleStorePlatform) DeleteStoreAllSkus(ctx *jxcontext.Context, pare
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
batchSize := p.GetStoreSkusBatchSize(partner.FuncDeleteStoreSkus)
|
||||
task := tasksch.NewParallelTask(fmt.Sprintf("DeleteStoreAllSkus, vendorStoreID:%s", vendorStoreID),
|
||||
tasksch.NewParallelConfig().SetBatchSize(batchSize).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
var skuList []*partner.StoreSkuInfo
|
||||
for _, v := range batchItemList {
|
||||
skuName := v.(*partner.SkuNameInfo)
|
||||
skuList = append(skuList, &partner.StoreSkuInfo{
|
||||
VendorSkuID: skuName.SkuList[0].VendorSkuID,
|
||||
})
|
||||
}
|
||||
err = p.DeleteStoreSkus(ctx, storeID, vendorStoreID, skuList)
|
||||
return nil, err
|
||||
}, skuNameList)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
storeStoreList := make([]*partner.StoreSkuInfo, len(skuNameList))
|
||||
for k, v := range skuNameList {
|
||||
storeStoreList[k] = &partner.StoreSkuInfo{
|
||||
SkuID: v.SkuList[0].SkuID,
|
||||
VendorSkuID: v.SkuList[0].VendorSkuID,
|
||||
}
|
||||
}
|
||||
_, err = FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) {
|
||||
err = p.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList)
|
||||
return nil, err
|
||||
}, ctx, parentTask, storeStoreList, p.GetStoreSkusBatchSize(partner.FuncDeleteStoreSkus))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -56,14 +50,13 @@ func (p *DefSingleStorePlatform) DeleteStoreAllCategories(ctx *jxcontext.Context
|
||||
sort.Sort(sort.Reverse(sort.IntSlice(levelList)))
|
||||
task1 := tasksch.NewSeqTask(fmt.Sprintf("DeleteStoreAllCategories1, vendorStoreID:%s", vendorStoreID), ctx,
|
||||
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
task2 := tasksch.NewParallelTask(fmt.Sprintf("DeleteStoreAllCategories2, vendorStoreID:%s", vendorStoreID), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
catInfo := batchItemList[0].(*partner.BareCategoryInfo)
|
||||
err = p.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID)
|
||||
return nil, err
|
||||
}, catListMap[levelList[step]])
|
||||
tasksch.HandleTask(task2, task, true).Run()
|
||||
_, err = task2.GetResult(0)
|
||||
vendorCatIDs := make([]string, len(catListMap[levelList[step]]))
|
||||
for k, v := range catListMap[levelList[step]] {
|
||||
vendorCatIDs[k] = v.VendorCatID
|
||||
}
|
||||
err = FreeBatchCategoryIDOp(func(vendorCatID string) (err error) {
|
||||
return p.DeleteStoreCategory(ctx, storeID, vendorStoreID, vendorCatID)
|
||||
}, ctx, task, vendorCatIDs)
|
||||
return nil, err
|
||||
}, len(levelList))
|
||||
tasksch.HandleTask(task1, parentTask, true).Run()
|
||||
@@ -80,28 +73,53 @@ func flatCatList(catList []*partner.BareCategoryInfo) (flattedCatList []*partner
|
||||
}
|
||||
|
||||
func (p *DefSingleStorePlatform) GetStoreSkusBareInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
|
||||
var skuIDs []int
|
||||
isSingle := len(inStoreSkuList) == 1
|
||||
if isSingle {
|
||||
skuIDs = []int{inStoreSkuList[0].SkuID}
|
||||
}
|
||||
globals.SugarLogger.Debug(p)
|
||||
skuNameList, err := p.GetStoreSkusFullInfo(ctx, parentTask, storeID, vendorStoreID, skuIDs)
|
||||
if err != nil {
|
||||
resultList, err := FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) {
|
||||
return p.GetStoreSkusFullInfo(ctx, parentTask, storeID, vendorStoreID, batchedStoreSkuList)
|
||||
}, ctx, parentTask, inStoreSkuList, p.GetStoreSkusBatchSize(partner.FuncGetStoreSkusFullInfo))
|
||||
if err != nil || len(resultList) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
for _, skuName := range skuNameList {
|
||||
inStoreSkuMap := make(map[string]*partner.StoreSkuInfo)
|
||||
for _, v := range inStoreSkuList {
|
||||
if v.VendorSkuID != "" {
|
||||
inStoreSkuMap[v.VendorNameID] = v
|
||||
}
|
||||
}
|
||||
for _, v := range resultList {
|
||||
skuName := v.(*partner.SkuNameInfo)
|
||||
storeSkuBareInfo := &skuName.SkuList[0].StoreSkuInfo
|
||||
if isSingle {
|
||||
storeSkuBareInfo.VendorNameID = inStoreSkuList[0].VendorNameID
|
||||
storeSkuBareInfo.VendorSkuID = inStoreSkuList[0].VendorSkuID
|
||||
if storeSkuBareInfo.SkuID == 0 && inStoreSkuMap[storeSkuBareInfo.VendorSkuID] != nil {
|
||||
storeSkuBareInfo.SkuID = inStoreSkuMap[storeSkuBareInfo.VendorSkuID].SkuID
|
||||
storeSkuBareInfo.NameID = inStoreSkuMap[storeSkuBareInfo.VendorSkuID].NameID
|
||||
}
|
||||
outStoreSkuList = append(outStoreSkuList, storeSkuBareInfo)
|
||||
}
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
func FreeBatchStoreSkuInfo(handler func([]*partner.StoreSkuInfo) (err error), ctx *jxcontext.Context, parentTask tasksch.ITask, storeSkuList []*partner.StoreSkuInfo, batchSize int) (err error) {
|
||||
func findCategoryByName(catList []*partner.BareCategoryInfo, catName string) (cat *partner.BareCategoryInfo) {
|
||||
for _, v := range catList {
|
||||
if v.Name == catName {
|
||||
cat = v
|
||||
break
|
||||
}
|
||||
if cat = findCategoryByName(v.Children, catName); cat != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return cat
|
||||
}
|
||||
func (p *DefSingleStorePlatform) GetStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, catName string) (cat *partner.BareCategoryInfo, err error) {
|
||||
catList, err := p.GetStoreAllCategories(ctx, storeID, vendorStoreID)
|
||||
if err == nil {
|
||||
if cat = findCategoryByName(catList, catName); cat == nil {
|
||||
err = fmt.Errorf("门店:%d,%s不能找到商家分类:%s", storeID, vendorStoreID, catName)
|
||||
}
|
||||
}
|
||||
return cat, err
|
||||
}
|
||||
|
||||
func FreeBatchStoreSkuInfo(handler func([]*partner.StoreSkuInfo) (interface{}, error), ctx *jxcontext.Context, parentTask tasksch.ITask, storeSkuList []*partner.StoreSkuInfo, batchSize int) (resultList []interface{}, err error) {
|
||||
if len(storeSkuList) > batchSize {
|
||||
task := tasksch.NewParallelTask("FreeBatchStoreSkuInfo", tasksch.NewParallelConfig().SetBatchSize(batchSize), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
@@ -109,13 +127,31 @@ func FreeBatchStoreSkuInfo(handler func([]*partner.StoreSkuInfo) (err error), ct
|
||||
for k, v := range batchItemList {
|
||||
batchStoreSkuList[k] = v.(*partner.StoreSkuInfo)
|
||||
}
|
||||
err = handler(batchStoreSkuList)
|
||||
return nil, err
|
||||
retVal, err = handler(batchStoreSkuList)
|
||||
return retVal, err
|
||||
}, storeSkuList)
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
resultList, err = task.GetResult(0)
|
||||
} else {
|
||||
err = handler(storeSkuList)
|
||||
result, err2 := handler(storeSkuList)
|
||||
if err = err2; err == nil {
|
||||
resultList = utils.Interface2Slice(result)
|
||||
}
|
||||
}
|
||||
return resultList, err
|
||||
}
|
||||
|
||||
func FreeBatchCategoryIDOp(handler func(vendorCatID string) (err error), ctx *jxcontext.Context, parentTask tasksch.ITask, vendorCatIDs []string) (err error) {
|
||||
if len(vendorCatIDs) > 1 {
|
||||
task := tasksch.NewParallelTask("FreeBatchCategoryIDOp", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
err = handler(batchItemList[0].(string))
|
||||
return nil, err
|
||||
}, vendorCatIDs)
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else if len(vendorCatIDs) > 0 {
|
||||
err = handler(vendorCatIDs[0])
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user