- 继续重构新版同步逻辑
This commit is contained in:
@@ -6,6 +6,12 @@ import (
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/elm"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/weimob/wsc"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
|
||||
"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"
|
||||
@@ -21,29 +19,32 @@ func DeleteStoreAllSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, handle
|
||||
return err
|
||||
}
|
||||
batchSize := handler.GetStoreSkusBatchSize(partner.FuncDeleteStoreSkus)
|
||||
skuNameListList := jxutils.SplitSlice(skuNameList, batchSize)
|
||||
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.BareStoreSkuInfo
|
||||
for _, v := range batchItemList {
|
||||
skuList = append(skuList, v.(*partner.BareStoreSkuInfo))
|
||||
skuName := v.(*partner.SkuNameInfo)
|
||||
skuList = append(skuList, &partner.BareStoreSkuInfo{
|
||||
VendorSkuID: skuName.SkuList[0].VendorSkuID,
|
||||
})
|
||||
}
|
||||
err = handler.DeleteStoreSkus(ctx, storeID, vendorStoreID, skuList)
|
||||
return nil, err
|
||||
}, skuNameListList)
|
||||
}, skuNameList)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteStoreAllCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, handler partner.ISingleStoreStoreSkuHandler, storeID int, vendorStoreID string, isContinueWhenError bool) (err error) {
|
||||
catList, err := handler.GetStoreAllCategories(ctx, vendorStoreID)
|
||||
catList, err := handler.GetStoreAllCategories(ctx, storeID, vendorStoreID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
catListMap := make(map[int][]*partner.BareCategoryInfo)
|
||||
for _, v := range catList {
|
||||
flattedCatList := flatCatList(catList)
|
||||
for _, v := range flattedCatList {
|
||||
catListMap[v.Level] = append(catListMap[v.Level], v)
|
||||
}
|
||||
var levelList []int
|
||||
@@ -56,7 +57,7 @@ func DeleteStoreAllCategories(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
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 = handler.DeleteStoreCategory(ctx, vendorStoreID, catInfo.VendorCatID)
|
||||
err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID)
|
||||
return nil, err
|
||||
}, catListMap[levelList[step]])
|
||||
tasksch.HandleTask(task2, task, true).Run()
|
||||
@@ -67,3 +68,11 @@ func DeleteStoreAllCategories(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
_, err = task1.GetResult(0)
|
||||
return err
|
||||
}
|
||||
|
||||
func flatCatList(catList []*partner.BareCategoryInfo) (flattedCatList []*partner.BareCategoryInfo) {
|
||||
flattedCatList = append(flattedCatList, catList...)
|
||||
for _, v := range catList {
|
||||
flattedCatList = append(flattedCatList, flatCatList(v.Children)...)
|
||||
}
|
||||
return flattedCatList
|
||||
}
|
||||
|
||||
42
business/jxstore/cms/sync_store_sku_test.go
Normal file
42
business/jxstore/cms/sync_store_sku_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
)
|
||||
|
||||
func TestDeleteStoreAllSkus(t *testing.T) {
|
||||
handler := partner.GetPurchasePlatformFromVendorID(model.VendorIDEBAI).(partner.ISingleStoreStoreSkuHandler)
|
||||
err := DeleteStoreAllSkus(jxcontext.AdminCtx, nil, handler, 2, "2267254343", true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteStoreAllCategories(t *testing.T) {
|
||||
handler := partner.GetPurchasePlatformFromVendorID(model.VendorIDEBAI).(partner.ISingleStoreStoreSkuHandler)
|
||||
err := DeleteStoreAllCategories(jxcontext.AdminCtx, nil, handler, 2, "2267254343", true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteStoreAllSkusMtwm(t *testing.T) {
|
||||
handler := partner.GetPurchasePlatformFromVendorID(model.VendorIDMTWM).(partner.ISingleStoreStoreSkuHandler)
|
||||
err := DeleteStoreAllSkus(jxcontext.AdminCtx, nil, handler, 2, "2523687", true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteStoreAllCategoriesMtwm(t *testing.T) {
|
||||
handler := partner.GetPurchasePlatformFromVendorID(model.VendorIDMTWM).(partner.ISingleStoreStoreSkuHandler)
|
||||
err := DeleteStoreAllCategories(jxcontext.AdminCtx, nil, handler, 2, "2523687", true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -104,12 +104,12 @@ type ISingleStoreStoreSkuHandler interface {
|
||||
|
||||
// 这个函数与GetStoreSkusInfo的区别是GetStoreAllSkus取的是全信息,而GetStoreSkusInfo只含库存,价格与可售信息
|
||||
GetStoreAllSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string) (skuNameList []*SkuNameInfo, err error)
|
||||
CreateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error)
|
||||
UpdateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (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 []*BareStoreSkuInfo) (err error)
|
||||
|
||||
GetStoreAllCategories(ctx *jxcontext.Context, vendorStoreID string) (cats []*BareCategoryInfo, err error)
|
||||
CreateStoreCategory(ctx *jxcontext.Context, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error)
|
||||
UpdateStoreCategory(ctx *jxcontext.Context, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error)
|
||||
DeleteStoreCategory(ctx *jxcontext.Context, vendorStoreID, vendorCatID string) (err error)
|
||||
GetStoreAllCategories(ctx *jxcontext.Context, storeID int, vendorStoreID string) (cats []*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)
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
|
||||
}
|
||||
|
||||
// 门店分类
|
||||
func (p *PurchaseHandler) GetStoreAllCategories(ctx *jxcontext.Context, vendorStoreID string) (cats []*partner.BareCategoryInfo, err error) {
|
||||
remoteCats, err := api.EbaiAPI.ShopCategoryGet(vendorStoreID)
|
||||
func (p *PurchaseHandler) GetStoreAllCategories(ctx *jxcontext.Context, storeID int, vendorStoreID string) (cats []*partner.BareCategoryInfo, err error) {
|
||||
remoteCats, err := api.EbaiAPI.ShopCategoryGet(utils.Int2Str(storeID))
|
||||
if err == nil {
|
||||
cats = convertVendorCatList(remoteCats)
|
||||
}
|
||||
@@ -49,10 +49,10 @@ func convertVendorCatList(remoteCats []*ebaiapi.CategoryInfo) (cats []*partner.B
|
||||
return cats
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
var vendorCatID int64
|
||||
if globals.EnableEbaiStoreWrite {
|
||||
vendorCatID, err = api.EbaiAPI.ShopCategoryCreate(vendorStoreID, utils.Str2Int64WithDefault(storeCat.ParentVendorCatID, 0), storeCat.Name, jxCatSeq2Ebai(storeCat.Seq))
|
||||
vendorCatID, err = api.EbaiAPI.ShopCategoryCreate(utils.Int2Str(storeID), utils.Str2Int64WithDefault(storeCat.ParentVendorCatID, 0), storeCat.Name, jxCatSeq2Ebai(storeCat.Seq))
|
||||
} else {
|
||||
vendorCatID = jxutils.GenFakeID()
|
||||
}
|
||||
@@ -60,16 +60,16 @@ func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, vendorStor
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
if globals.EnableEbaiStoreWrite {
|
||||
err = api.EbaiAPI.ShopCategoryUpdate(vendorStoreID, utils.Str2Int64WithDefault(storeCat.VendorCatID, 0), storeCat.Name, jxCatSeq2Ebai(storeCat.Seq))
|
||||
err = api.EbaiAPI.ShopCategoryUpdate(utils.Int2Str(storeID), utils.Str2Int64WithDefault(storeCat.VendorCatID, 0), storeCat.Name, jxCatSeq2Ebai(storeCat.Seq))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, vendorStoreID, vendorCatID string) (err error) {
|
||||
func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string) (err error) {
|
||||
if globals.EnableEbaiStoreWrite {
|
||||
err = api.EbaiAPI.ShopCategoryDelete(vendorStoreID, utils.Str2Int64WithDefault(vendorCatID, 0))
|
||||
err = api.EbaiAPI.ShopCategoryDelete(utils.Int2Str(storeID), utils.Str2Int64WithDefault(vendorCatID, 0))
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, vendorStor
|
||||
// 门店商品
|
||||
|
||||
// 多门店平台不需要实现这个接口
|
||||
func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) {
|
||||
func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) {
|
||||
storeSku := storeSkuList[0]
|
||||
if globals.EnableEbaiStoreWrite {
|
||||
_, err = api.EbaiAPI.SkuUpdate(vendorStoreID, utils.Str2Int64(storeSku.VendorSkuID), genSkuParamsFromStoreSkuInfo2(storeSku))
|
||||
@@ -86,7 +86,7 @@ func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, vendorStoreID
|
||||
}
|
||||
|
||||
// 对于多门店平台来说,storeSkuList中只有SkuID与VendorSkuID有意义
|
||||
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) {
|
||||
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) {
|
||||
storeSku := storeSkuList[0]
|
||||
var vendorSkuID int64
|
||||
if globals.EnableEbaiStoreWrite {
|
||||
@@ -100,7 +100,7 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, vendorStoreID
|
||||
|
||||
func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
|
||||
if globals.EnableEbaiStoreWrite {
|
||||
err = api.EbaiAPI.SkuDelete(vendorStoreID, strings.Join(partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDList(), ","))
|
||||
err = api.EbaiAPI.SkuDelete(utils.Int2Str(storeID), strings.Join(partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDList(), ","))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
|
||||
}
|
||||
|
||||
// 门店分类
|
||||
func (p *PurchaseHandler) GetStoreAllCategories(ctx *jxcontext.Context, vendorStoreID string) (cats []*partner.BareCategoryInfo, err error) {
|
||||
func (p *PurchaseHandler) GetStoreAllCategories(ctx *jxcontext.Context, storeID int, vendorStoreID string) (cats []*partner.BareCategoryInfo, err error) {
|
||||
remoteCats, err := api.MtwmAPI.RetailCatList(vendorStoreID)
|
||||
if err == nil {
|
||||
cats = convertVendorCatList(remoteCats)
|
||||
@@ -48,7 +48,7 @@ func convertVendorCatList(remoteCats []*mtwmapi.RetailCategoryInfo) (cats []*par
|
||||
return cats
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
level := 1
|
||||
if storeCat.ParentCatName != "" {
|
||||
level = 2
|
||||
@@ -82,11 +82,11 @@ func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, vendorStor
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
return p.CreateStoreCategory(ctx, vendorStoreID, storeCat)
|
||||
func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
|
||||
return p.CreateStoreCategory(ctx, storeID, vendorStoreID, storeCat)
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, vendorStoreID, vendorCatID string) (err error) {
|
||||
func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string) (err error) {
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = api.MtwmAPI.RetailCatDelete(vendorStoreID, vendorCatID)
|
||||
}
|
||||
@@ -96,12 +96,12 @@ func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, vendorStor
|
||||
// 门店商品
|
||||
|
||||
// 多门店平台不需要实现这个接口
|
||||
func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) {
|
||||
return p.CreateStoreSkus(ctx, vendorStoreID, storeSkuList)
|
||||
func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) {
|
||||
return p.CreateStoreSkus(ctx, storeID, vendorStoreID, storeSkuList)
|
||||
}
|
||||
|
||||
// 对于多门店平台来说,storeSkuList中只有SkuID与VendorSkuID有意义
|
||||
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) {
|
||||
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error) {
|
||||
foodDataList := make([]map[string]interface{}, len(storeSkuList))
|
||||
for i, storeSku := range storeSkuList {
|
||||
foodData := make(map[string]interface{})
|
||||
|
||||
7
main.go
7
main.go
@@ -20,12 +20,17 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||
_ "git.rosy.net.cn/jx-callback/routers"
|
||||
|
||||
// _ "git.rosy.net.cn/jx-callback/business/jxstore/act"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/printer/feie"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/printer/xiaowm"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/printer/yilianyun"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/printer/zhongwu"
|
||||
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/elm"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/weimob/wsc"
|
||||
|
||||
_ "git.rosy.net.cn/jx-callback/business/jxstore/act"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user