同步错误返回

This commit is contained in:
苏尹岚
2019-11-28 11:47:19 +08:00
parent 49c42986ef
commit 2a486ea2ba
3 changed files with 46 additions and 21 deletions

View File

@@ -475,19 +475,25 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
if len(createList) > 0 {
_, err = putils.FreeBatchStoreSkuSyncInfo("创建门店商品", func(task tasksch.ITask, batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, successCount int, err error) {
var failedList []*partner.StoreSkuInfoWithErr
if failedList, err = singleStoreHandler.CreateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); singleStoreHandler.IsErrSkuExist(err) {
if skuNameList, err2 := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, []*partner.StoreSkuInfo{
&partner.StoreSkuInfo{
SkuID: batchedStoreSkuList[0].SkuID,
},
}); err2 == nil && len(skuNameList) > 0 {
batchedStoreSkuList[0].VendorNameID = skuNameList[0].VendorNameID
batchedStoreSkuList[0].VendorSkuID = skuNameList[0].SkuList[0].VendorSkuID
// 如果创建商品时已经存在,需要更新
updateList = append(updateList, calVendorPrice4StoreSku(batchedStoreSkuList[0], storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
err = nil
failedList, err = singleStoreHandler.CreateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList)
if len(failedList) > 0 {
for _, v := range failedList {
fmt.Println(v.StoreSkuInfo, v.ErrMsg)
}
task.AddErrMsg(failedList)
}
singleStoreHandler.IsErrSkuExist(err)
if skuNameList, err2 := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, []*partner.StoreSkuInfo{
&partner.StoreSkuInfo{
SkuID: batchedStoreSkuList[0].SkuID,
},
}); err2 == nil && len(skuNameList) > 0 {
batchedStoreSkuList[0].VendorNameID = skuNameList[0].VendorNameID
batchedStoreSkuList[0].VendorSkuID = skuNameList[0].SkuList[0].VendorSkuID
// 如果创建商品时已经存在,需要更新
updateList = append(updateList, calVendorPrice4StoreSku(batchedStoreSkuList[0], storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
err = nil
}
if err != nil {
//handle error for sensitive words, if find, then insert to table sensitive_words
@@ -508,9 +514,6 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
var failedList []*partner.StoreSkuInfoWithErr
failedList, err = singleStoreHandler.UpdateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList)
if len(failedList) > 0 {
for _, v := range failedList {
fmt.Println(v)
}
task.AddErrMsg(failedList)
}
successList := putils.UnselectStoreSkuSyncListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList))

View File

@@ -1,7 +1,6 @@
package ebai
import (
"fmt"
"regexp"
"time"
@@ -118,16 +117,16 @@ func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, v
storeSku := storeSkuList[0]
strStoreID := utils.Int2Str(storeID)
params := genSkuParamsFromStoreSkuInfo2(storeSku, false)
for _, v := range storeSkuList {
fmt.Println(v)
}
if globals.EnableEbaiStoreWrite {
_, err = api.EbaiAPI.SkuUpdate(ctx.GetTrackInfo(), strStoreID, utils.Str2Int64(storeSku.VendorSkuID), params)
if err != nil {
failedList = putils.GetErrMsg2FailedSyncSingleList(storeSkuList, err)
}
utils.CallFuncAsync(func() {
api.EbaiAPI.SkuShopCategoryMap(strStoreID, utils.Str2Int64(storeSku.VendorSkuID), "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku))
})
}
return nil, err
return failedList, err
}
// 对于多门店平台来说storeSkuList中只有SkuID与VendorSkuID有意义
@@ -141,12 +140,14 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v
utils.AfterFuncWithRecover(5*time.Second, func() {
api.EbaiAPI.SkuShopCategoryMap(strStoreID, vendorSkuID, "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku))
})
} else {
failedList = putils.GetErrMsg2FailedSyncSingleList(storeSkuList, err)
}
} else {
vendorSkuID = jxutils.GenFakeID()
}
storeSku.VendorSkuID = utils.Int64ToStr(vendorSkuID)
return nil, err
return failedList, err
}
func getFailedVendorSkuIDsFromOpResult(opResult *ebaiapi.BatchOpResult) (skuIDs []string) {

View File

@@ -337,6 +337,27 @@ func GetErrMsg2FailedSingleList(storeSkuList []*partner.StoreSkuInfo, err error)
return failedList
}
func GetErrMsg2FailedSyncSingleList(storeSkuList []*dao.StoreSkuSyncInfo, err error) (failedList []*partner.StoreSkuInfoWithErr) {
if err != nil {
if errExt, ok := err.(*utils.ErrorWithCode); ok {
storeSkuInfo := &partner.StoreSkuInfo{
SkuID: storeSkuList[0].SkuID,
VendorSkuID: storeSkuList[0].VendorSkuID,
NameID: storeSkuList[0].NameID,
VendorNameID: storeSkuList[0].VendorNameID,
VendorPrice: storeSkuList[0].VendorPrice,
Status: storeSkuList[0].Status,
}
storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{
StoreSkuInfo: storeSkuInfo,
ErrMsg: errExt.ErrMsg(),
}
failedList = append(failedList, storeSkuInfoWithErr)
}
}
return failedList
}
func UnselectStoreSkuSyncListByVendorSkuIDs(storeSkuList []*dao.StoreSkuSyncInfo, vendorSkuIDs []string) (selectedStoreSkuList []*dao.StoreSkuSyncInfo) {
if len(vendorSkuIDs) > 0 {
vendorSkuIDMap := jxutils.StringList2Map(vendorSkuIDs)