同步返回错误

This commit is contained in:
苏尹岚
2019-11-20 10:49:19 +08:00
parent 0e481ffe72
commit 82ac23ab0a
7 changed files with 115 additions and 18 deletions

View File

@@ -541,10 +541,12 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
case 6:
if len(priceList) > 0 {
_, err = putils.FreeBatchStoreSkuInfo("更新门店商品价格", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
var successList []*partner.StoreSkuInfo
if successList, err = storeSkuHandler.UpdateStoreSkusPrice(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil {
successList = batchedStoreSkuList
var failedList []*tasksch.ErrMsg
failedList, err = storeSkuHandler.UpdateStoreSkusPrice(ctx, storeID, vendorStoreID, batchedStoreSkuList)
if len(failedList) > 0 {
task.AddErrMsg(failedList)
}
successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList))
if len(successList) > 0 {
updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagPriceMask)
}
@@ -842,3 +844,13 @@ func MergeSkuSaleStatusWithStoreOpTime(sku *dao.StoreSkuSyncInfo, storeDetail *d
}
return sku.MergedStatus
}
func GetVendorSkuIDList(l []*tasksch.ErrMsg) (vendorSkuIDs []string) {
if len(l) > 0 {
vendorSkuIDs = make([]string, len(l))
for k, v := range l {
vendorSkuIDs[k] = v.VendorSkuID
}
}
return vendorSkuIDs
}

View File

@@ -63,9 +63,18 @@ type ITask interface {
// GetDetailErrList() []error
GetLeafResult() (finishedItemCount, failedItemCount int)
AddBatchErr(err error)
AddErrMsg(failedList []*ErrMsg)
GetErrMsg() (failedList []*ErrMsg)
json.Marshaler
}
type ErrMsg struct {
SkuID int
VendorSkuID string
StoreID int
Status int
VendorPrice int64
Err string
}
// type TaskError struct {
// name string
@@ -128,6 +137,7 @@ type BaseTask struct {
ctx *jxcontext.Context
isGetResultCalled bool
FailedList []*ErrMsg
}
func (s TaskList) Len() int {
@@ -355,6 +365,24 @@ func (t *BaseTask) Error() (errMsg string) {
return errMsg
}
func (t *BaseTask) GetErrMsg() (failedList []*ErrMsg) {
if len(t.FailedList) == 0 {
return nil
}
if t.parent != nil {
for _, v := range t.FailedList {
failedList = append(failedList, v)
}
}
return failedList
}
func (t *BaseTask) AddErrMsg(failedList []*ErrMsg) {
t.locker.Lock()
defer t.locker.Unlock()
t.FailedList = append(t.FailedList, failedList...)
}
// func (t *BaseTask) GetDetailErrList() []error {
// t.locker.RLock()
// defer t.locker.RUnlock()
@@ -411,7 +439,7 @@ func (t *BaseTask) run(taskHandler func()) {
task.TerminatedAt = time.Now()
task.locker.Unlock()
task.Error()
task.GetErrMsg()
globals.SugarLogger.Debugf("Task:%s, mainErr:%v, batchErrList:%v", task.Name, task.mainErr, task.batchErrList)
select {

View File

@@ -131,7 +131,7 @@ type IPurchasePlatformStoreSkuHandler interface {
GetStoreSkusBareInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*StoreSkuInfo) (outStoreSkuList []*StoreSkuInfo, err error)
UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (successList []*StoreSkuInfo, err error)
UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo, status int) (successList []*StoreSkuInfo, err error)
UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (successList []*StoreSkuInfo, err error)
UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (failedList []*tasksch.ErrMsg, err error)
}
type ISingleStoreStoreSkuHandler interface {
@@ -139,7 +139,7 @@ type ISingleStoreStoreSkuHandler interface {
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) (successList []*dao.StoreSkuSyncInfo, err error)
UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (successList []*dao.StoreSkuSyncInfo, err error)
UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*dao.StoreSkuSyncInfo, err error)
DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (successList []*StoreSkuInfo, err error)
DeleteStoreAllSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, isContinueWhenError bool) (err error)
IsErrSkuExist(err error) (isExist bool)

View File

@@ -203,18 +203,21 @@ func StoreSkuInfoList2Ebai(storeSkuList []*partner.StoreSkuInfo) (outList ebaiap
return outList
}
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) {
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*tasksch.ErrMsg, err error) {
if globals.EnableEbaiStoreWrite {
if len(storeSkuList) > 1 {
opResult, err2 := api.EbaiAPI.SkuPriceUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID)
if err = err2; err != nil && opResult != nil {
successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult))
failedList = putils.SelectStoreSkuListByOpResult(storeID, storeSkuList, opResult)
}
} else if len(storeSkuList) == 1 {
err = api.EbaiAPI.SkuPriceUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0])
opResult2, err := api.EbaiAPI.SkuPriceUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0])
if err != nil && opResult2 != nil {
failedList = putils.SelectStoreSkuListByOpResult(storeID, storeSkuList, opResult2)
}
}
}
return successList, err
return failedList, err
}
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) {

View File

@@ -1,6 +1,8 @@
package jd
import (
"fmt"
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
@@ -128,7 +130,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
return successList, err
}
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) {
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*tasksch.ErrMsg, err error) {
if len(storeSkuList) == 1 {
if globals.EnableJdStoreWrite {
_, err = getAPI("").UpdateStationPrice(ctx.GetTrackInfo(), utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), vendorStoreID, int(storeSkuList[0].VendorPrice))
@@ -144,11 +146,12 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
if globals.EnableJdStoreWrite {
responseList, err2 := getAPI("").UpdateVendorStationPrice(ctx.GetTrackInfo(), "", vendorStoreID, skuPriceInfoList)
if err = err2; isErrPartialFailed(err) {
successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false)))
successList := putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false)))
fmt.Println(successList)
}
}
}
return successList, err
return failedList, err
}
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) {

View File

@@ -336,17 +336,18 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
return successList, err
}
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) {
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*tasksch.ErrMsg, err error) {
priceList := storeSku2Mtwm(storeSkuList, updateTypePrice)
if globals.EnableMtwmStoreWrite {
failedFoodList, err2 := api.MtwmAPI.RetailSkuPrice(ctx.GetTrackInfo(), vendorStoreID, priceList)
if err = err2; err == nil {
if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil {
successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList))
if len(failedFoodList) > 0 {
failedList = putils.SelectStoreSkuListByFoodList(storeID, storeSkuList, failedFoodList)
err = putils.GenPartialFailedErr(failedList, len(failedList))
}
}
}
return successList, err
return failedList, err
}
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) {

View File

@@ -4,6 +4,10 @@ import (
"fmt"
"sort"
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/baseapi/utils"
@@ -230,6 +234,52 @@ func UnselectStoreSkuListByVendorSkuIDs(storeSkuList []*partner.StoreSkuInfo, ve
return selectedStoreSkuList
}
func SelectStoreSkuListByFoodList(storeID int, storeSkuList []*partner.StoreSkuInfo, foodList []*mtwmapi.AppFoodResult) (selectedStoreSkuList []*tasksch.ErrMsg) {
foodMap := make(map[string]string)
if len(foodList) > 0 {
for _, v := range foodList {
foodMap[v.AppFoodCode] = v.ErrorMsg
}
for _, v := range storeSkuList {
if foodMap[v.VendorSkuID] != "" {
foodFailed := &tasksch.ErrMsg{
SkuID: v.SkuID,
VendorSkuID: v.VendorSkuID,
StoreID: storeID,
Status: v.Status,
VendorPrice: v.VendorPrice,
Err: foodMap[v.VendorSkuID],
}
selectedStoreSkuList = append(selectedStoreSkuList, foodFailed)
}
}
}
return selectedStoreSkuList
}
func SelectStoreSkuListByOpResult(storeID int, storeSkuList []*partner.StoreSkuInfo, opResult *ebaiapi.BatchOpResult) (selectedStoreSkuList []*tasksch.ErrMsg) {
opResultMap := make(map[int64]string)
if len(opResult.FailedList) > 0 {
for _, v := range opResult.FailedList {
opResultMap[v.SkuID] = v.ErrorMsg
}
for _, v := range storeSkuList {
if opResultMap[utils.Str2Int64(v.VendorSkuID)] != "" {
opFailed := &tasksch.ErrMsg{
SkuID: v.SkuID,
VendorSkuID: v.VendorSkuID,
StoreID: storeID,
Status: v.Status,
VendorPrice: v.VendorPrice,
Err: opResultMap[utils.Str2Int64(v.VendorSkuID)],
}
selectedStoreSkuList = append(selectedStoreSkuList, opFailed)
}
}
}
return selectedStoreSkuList
}
func UnselectStoreSkuSyncListByVendorSkuIDs(storeSkuList []*dao.StoreSkuSyncInfo, vendorSkuIDs []string) (selectedStoreSkuList []*dao.StoreSkuSyncInfo) {
if len(vendorSkuIDs) > 0 {
vendorSkuIDMap := jxutils.StringList2Map(vendorSkuIDs)