From 82ac23ab0af649a25e27ac596cdbc7f75a169712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 20 Nov 2019 10:49:19 +0800 Subject: [PATCH 01/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 18 +++++-- business/jxutils/tasksch/task.go | 32 ++++++++++++- business/partner/partner_store_sku.go | 4 +- business/partner/purchase/ebai/store_sku2.go | 11 +++-- business/partner/purchase/jd/store_sku2.go | 9 ++-- business/partner/purchase/mtwm/store_sku2.go | 9 ++-- business/partner/putils/store_sku.go | 50 ++++++++++++++++++++ 7 files changed, 115 insertions(+), 18 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 79f050b0b..aeabe1024 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -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 +} diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index b9a6bb194..3c038b3e8 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -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 { diff --git a/business/partner/partner_store_sku.go b/business/partner/partner_store_sku.go index 605d7b458..5110cc4dd 100644 --- a/business/partner/partner_store_sku.go +++ b/business/partner/partner_store_sku.go @@ -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) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 9b5465ae5..7c15f4c2a 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -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) { diff --git a/business/partner/purchase/jd/store_sku2.go b/business/partner/purchase/jd/store_sku2.go index 15943b0f2..c426169f5 100644 --- a/business/partner/purchase/jd/store_sku2.go +++ b/business/partner/purchase/jd/store_sku2.go @@ -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) { diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index 74766b407..e14af3a10 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -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) { diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index c01d99252..55c96d116 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -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) From 8fc161709d3bd7c09c312640353252d1a4da2b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 20 Nov 2019 10:52:36 +0800 Subject: [PATCH 02/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/ebai/store_sku2.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 7c15f4c2a..ae6e17455 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -206,10 +206,10 @@ func StoreSkuInfoList2Ebai(storeSkuList []*partner.StoreSkuInfo) (outList ebaiap 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 { - failedList = putils.SelectStoreSkuListByOpResult(storeID, storeSkuList, opResult) - } + // _, err2 := api.EbaiAPI.SkuPriceUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID) + // if err = err2; err != nil && opResult != nil { + // failedList = putils.SelectStoreSkuListByOpResult(storeID, storeSkuList, opResult) + // } } else if len(storeSkuList) == 1 { opResult2, err := api.EbaiAPI.SkuPriceUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0]) if err != nil && opResult2 != nil { From 52ae9085e34a09a1ff4af58ff5b4e4283e8c92a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 20 Nov 2019 10:55:23 +0800 Subject: [PATCH 03/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/ebai/store_sku2.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index ae6e17455..986c5bc03 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -206,6 +206,7 @@ func StoreSkuInfoList2Ebai(storeSkuList []*partner.StoreSkuInfo) (outList ebaiap 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 { + // _, err2 := api.EbaiAPI.SkuPriceUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID) // if err = err2; err != nil && opResult != nil { // failedList = putils.SelectStoreSkuListByOpResult(storeID, storeSkuList, opResult) From 54778bc01381717f25f873dfa1ea8d4ccbb5563a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 20 Nov 2019 10:56:11 +0800 Subject: [PATCH 04/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/ebai/store_sku2.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 986c5bc03..60bde45c1 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -206,16 +206,15 @@ func StoreSkuInfoList2Ebai(storeSkuList []*partner.StoreSkuInfo) (outList ebaiap 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 { - - // _, err2 := api.EbaiAPI.SkuPriceUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID) - // if err = err2; err != nil && opResult != nil { - // failedList = putils.SelectStoreSkuListByOpResult(storeID, storeSkuList, opResult) - // } - } else if len(storeSkuList) == 1 { - opResult2, err := api.EbaiAPI.SkuPriceUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0]) - if err != nil && opResult2 != nil { - failedList = putils.SelectStoreSkuListByOpResult(storeID, storeSkuList, opResult2) + opResult, err2 := api.EbaiAPI.SkuPriceUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID) + if err = err2; err != nil && opResult != nil { + failedList = putils.SelectStoreSkuListByOpResult(storeID, storeSkuList, opResult) } + } else if len(storeSkuList) == 1 { + err = api.EbaiAPI.SkuPriceUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0]) + // if err != nil && opResult2 != nil { + // failedList = putils.SelectStoreSkuListByOpResult(storeID, storeSkuList, opResult2) + // } } } return failedList, err From 1898d2932ad554fa0dda5cb48cb6c9064e25030e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 20 Nov 2019 13:36:38 +0800 Subject: [PATCH 05/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/tasksch/task.go | 16 +++++++++------- business/partner/putils/store_sku.go | 2 -- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index 3c038b3e8..984b13c56 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -63,7 +63,7 @@ type ITask interface { // GetDetailErrList() []error GetLeafResult() (finishedItemCount, failedItemCount int) AddBatchErr(err error) - AddErrMsg(failedList []*ErrMsg) + AddErrMsg(failedList ...interface{}) GetErrMsg() (failedList []*ErrMsg) json.Marshaler } @@ -71,7 +71,6 @@ type ErrMsg struct { SkuID int VendorSkuID string StoreID int - Status int VendorPrice int64 Err string } @@ -137,7 +136,7 @@ type BaseTask struct { ctx *jxcontext.Context isGetResultCalled bool - FailedList []*ErrMsg + FailedList []interface{} } func (s TaskList) Len() int { @@ -366,21 +365,25 @@ func (t *BaseTask) Error() (errMsg string) { } func (t *BaseTask) GetErrMsg() (failedList []*ErrMsg) { + t.locker.RLock() + defer t.locker.RUnlock() if len(t.FailedList) == 0 { return nil } if t.parent != nil { for _, v := range t.FailedList { - failedList = append(failedList, v) + failedList = append(failedList, v.(*ErrMsg)) } } return failedList } -func (t *BaseTask) AddErrMsg(failedList []*ErrMsg) { +func (t *BaseTask) AddErrMsg(failedList ...interface{}) { t.locker.Lock() defer t.locker.Unlock() - t.FailedList = append(t.FailedList, failedList...) + for _, v := range failedList { + t.FailedList = append(t.FailedList, v) + } } // func (t *BaseTask) GetDetailErrList() []error { @@ -439,7 +442,6 @@ 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 { diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index 55c96d116..e22f50ff2 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -246,7 +246,6 @@ func SelectStoreSkuListByFoodList(storeID int, storeSkuList []*partner.StoreSkuI SkuID: v.SkuID, VendorSkuID: v.VendorSkuID, StoreID: storeID, - Status: v.Status, VendorPrice: v.VendorPrice, Err: foodMap[v.VendorSkuID], } @@ -269,7 +268,6 @@ func SelectStoreSkuListByOpResult(storeID int, storeSkuList []*partner.StoreSkuI SkuID: v.SkuID, VendorSkuID: v.VendorSkuID, StoreID: storeID, - Status: v.Status, VendorPrice: v.VendorPrice, Err: opResultMap[utils.Str2Int64(v.VendorSkuID)], } From e2d34ea4bd85a14f6eee1ce78f4e3c34e891f8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 21 Nov 2019 11:48:21 +0800 Subject: [PATCH 06/44] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=B0=B8=E8=BE=89excel?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/yonghui/yonghui.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 4477fad48..4374bea0c 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -89,8 +89,10 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i return "", errors.New("没有文件上传!") } fileHeader := files[0] + fileName := fileHeader.Filename + fmt.Println(fileName) file, err := fileHeader.Open() - hint, err = LoadExcelBinByYongHui(ctx, file, true, true) + // hint, err = LoadExcelBinByYongHui(ctx, file, true, true) file.Close() return hint, err } @@ -128,6 +130,10 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is return "", errors.New(errMsg) } } + //修改分组名 + // 分类名格式为:可定XX日 + // XX为上传永辉 提供的 价格表时间 +2天 + case 1: //获取微盟所有商品 goodsList, err = GetWeiMobGoodsList() @@ -292,15 +298,15 @@ func updateWeiMobGoods(costPrice, salePrice float64, goodsDetail *weimobapi.Good return 0, nil, errors.New(fmt.Sprintf("未查询到此商品的分类信息!goodsID : [%v] ,", goodsDetail.GoodsID)) } + //获取分组 selectedClassifyList := goodsDetail.SelectedClassifyList var selectedClassifyListID []int64 if len(selectedClassifyList) > 0 { for _, v := range selectedClassifyList { - selectedClassifyListID = append(selectedClassifyListID, v.ChildrenClassify[0].ClassifyID) + for _, vv := range v.ChildrenClassify { + selectedClassifyListID = append(selectedClassifyListID, vv.ClassifyID) + } } - // categoryID = categoryList[len(categoryList)-1].CategoryID - } else { - return 0, nil, errors.New(fmt.Sprintf("未查询到此商品的分类信息!goodsID : [%v] ,", goodsDetail.GoodsID)) } b2CSku := &weimobapi.B2CSku{ Weight: skuListInfo.B2CSku.Weight, @@ -417,3 +423,7 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM func Float64Round(f float64) (flt float64) { return math.Round(f*100) / 100 } + +func UpdateClassifyName() { + +} From 640b8203a878a37bbbab2cb02bc9c34e25170f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 21 Nov 2019 13:31:29 +0800 Subject: [PATCH 07/44] =?UTF-8?q?=E9=94=99=E8=AF=AF=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 19 ++++--- business/jxstore/cms/sync.go | 4 ++ business/jxstore/cms/sync_store_sku.go | 36 ++++++++---- business/jxutils/tasksch/task.go | 20 +++---- business/partner/partner_store_sku.go | 11 +++- business/partner/purchase/ebai/store_sku2.go | 26 ++++++--- business/partner/purchase/jd/store_sku2.go | 23 ++++---- business/partner/purchase/mtwm/store_sku2.go | 43 +++++++------- business/partner/putils/store_sku.go | 59 +++++++++++++++----- 9 files changed, 155 insertions(+), 86 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 9ef91776c..b81257e84 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -537,30 +537,31 @@ func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int, } else { filterStoreList := GetFilterStoreList(jxStoreInfoList.Stores, vendorMap, storeIDMap) diffData.InitData() + //循环门店store taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { jxStoreInfoListValue := batchItemList[0].(*StoreExt) storeID := jxStoreInfoListValue.ID storeIDStr := utils.Int2Str(storeID) storeName := jxStoreInfoListValue.Name - jxSkuInfoDataSingle := &StoreSkuNamesInfo{} - jxSkuInfoDataMulti := &StoreSkuNamesInfo{} if jxStoreInfoListValue.StoreMaps != nil { var filterJxSkuInfoMapSingle map[int]*StoreSkuNameExt var filterJxSkuInfoMapMulti map[int]*StoreSkuNameExt + var multiFlag = false + var singleFlag = false + //循环平台vendor for _, vendorListValue := range jxStoreInfoListValue.StoreMaps { vendorID := int(utils.MustInterface2Int64(vendorListValue["vendorID"])) - var flag = false if partner.IsMultiStore(vendorID) { - if flag == false { - jxSkuInfoDataMulti, _ = GetStoreSkus(ctx, storeID, filterJxDepotUnSaleSkuIds, true, "", true, false, map[string]interface{}{}, 0, -1) + if multiFlag == false { + jxSkuInfoDataMulti, _ := GetStoreSkus(ctx, storeID, filterJxDepotUnSaleSkuIds, true, "", true, false, map[string]interface{}{}, 0, -1) filterJxSkuInfoMapMulti = GetFilterJxSkuInfoMap(jxSkuInfoDataMulti.SkuNames) //map[京西商品ID:StoreSkuNameExt] - flag = true + multiFlag = true } } else { - if flag == false { - jxSkuInfoDataSingle, _ = GetStoreSkus(ctx, storeID, []int{}, true, "", true, false, map[string]interface{}{}, 0, -1) + if singleFlag == false { + jxSkuInfoDataSingle, _ := GetStoreSkus(ctx, storeID, []int{}, true, "", true, false, map[string]interface{}{}, 0, -1) filterJxSkuInfoMapSingle = GetFilterJxSkuInfoMap(jxSkuInfoDataSingle.SkuNames) //map[京西商品ID:StoreSkuNameExt] - flag = true + singleFlag = true } } diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 543c09ca6..c7d653caa 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -389,6 +389,10 @@ func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vend return nil, partner.AddVendorInfo2Err(err, loopMapInfo.VendorID) }, isContinueWhenError) if task != nil { + task.SetFinishHook(func(task2 tasksch.ITask) { + failedList := task2.GetErrMsg() + fmt.Println(failedList) + }) err = makeSyncError(err) } return hint, err diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index aeabe1024..e37a9f2ad 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -31,6 +31,13 @@ var ( subSensitiveWordRegexp = regexp.MustCompile(`[^\[\]\"\}]`) ) +type ErrMsg struct { + SkuID int + StoreID int + VendorID int + Err string +} + func CreateStoreCategoryByStoreSku(ctx *jxcontext.Context, vendorID, storeID int, vendorStoreID string, nameIDs, skuIDs []int) (err error) { globals.SugarLogger.Debugf("CreateStoreCategoryByStoreSku vendorID:%d, storeID:%d", vendorID, storeID) db := dao.GetDB() @@ -506,10 +513,15 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo for k, list := range [][]*partner.StoreSkuInfo{stockList /*, onlineList*/} { if len(list) > 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.UpdateStoreSkusStock(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil { - successList = batchedStoreSkuList + var failedList []*partner.StoreSkuInfoWithErr + failedList, err = storeSkuHandler.UpdateStoreSkusStock(ctx, storeID, vendorStoreID, batchedStoreSkuList) + if len(failedList) > 0 { + for _, v := range failedList { + fmt.Println(v.StoreSkuInfo, v.ErrMsg) + } + task.AddErrMsg(failedList) } + successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) if k == 0 && len(successList) > 0 { updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagStockMask) } @@ -528,10 +540,12 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo } if len(statusList) > 0 { _, err = putils.FreeBatchStoreSkuInfo(name, func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { - var successList []*partner.StoreSkuInfo - if successList, err = storeSkuHandler.UpdateStoreSkusStatus(ctx, storeID, vendorStoreID, batchedStoreSkuList, status); err == nil { - successList = batchedStoreSkuList + var failedList []*partner.StoreSkuInfoWithErr + failedList, err = storeSkuHandler.UpdateStoreSkusStatus(ctx, storeID, vendorStoreID, batchedStoreSkuList, status) + if len(failedList) > 0 { + task.AddErrMsg(failedList) } + successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) if len(successList) > 0 { updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagSaleMask) } @@ -541,7 +555,7 @@ 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 failedList []*tasksch.ErrMsg + var failedList []*partner.StoreSkuInfoWithErr failedList, err = storeSkuHandler.UpdateStoreSkusPrice(ctx, storeID, vendorStoreID, batchedStoreSkuList) if len(failedList) > 0 { task.AddErrMsg(failedList) @@ -845,12 +859,12 @@ func MergeSkuSaleStatusWithStoreOpTime(sku *dao.StoreSkuSyncInfo, storeDetail *d return sku.MergedStatus } -func GetVendorSkuIDList(l []*tasksch.ErrMsg) (vendorSkuIDs []string) { +func GetVendorSkuIDList(l []*partner.StoreSkuInfoWithErr) (vendorSkuIDs []string) { + vendorSkuIDs2 := make([]string, len(l)) if len(l) > 0 { - vendorSkuIDs = make([]string, len(l)) for k, v := range l { - vendorSkuIDs[k] = v.VendorSkuID + vendorSkuIDs2[k] = v.StoreSkuInfo.VendorSkuID } } - return vendorSkuIDs + return vendorSkuIDs2 } diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index 984b13c56..b218f9855 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -64,16 +64,10 @@ type ITask interface { GetLeafResult() (finishedItemCount, failedItemCount int) AddBatchErr(err error) AddErrMsg(failedList ...interface{}) - GetErrMsg() (failedList []*ErrMsg) + GetErrMsg() (failedList []interface{}) + SetFinishHook(func(task ITask)) json.Marshaler } -type ErrMsg struct { - SkuID int - VendorSkuID string - StoreID int - VendorPrice int64 - Err string -} // type TaskError struct { // name string @@ -137,6 +131,7 @@ type BaseTask struct { ctx *jxcontext.Context isGetResultCalled bool FailedList []interface{} + FinishHook func(task ITask) } func (s TaskList) Len() int { @@ -364,7 +359,11 @@ func (t *BaseTask) Error() (errMsg string) { return errMsg } -func (t *BaseTask) GetErrMsg() (failedList []*ErrMsg) { +func (t *BaseTask) SetFinishHook(hook func(task ITask)) { + t.FinishHook = hook +} + +func (t *BaseTask) GetErrMsg() (failedList []interface{}) { t.locker.RLock() defer t.locker.RUnlock() if len(t.FailedList) == 0 { @@ -372,7 +371,7 @@ func (t *BaseTask) GetErrMsg() (failedList []*ErrMsg) { } if t.parent != nil { for _, v := range t.FailedList { - failedList = append(failedList, v.(*ErrMsg)) + failedList = append(failedList, v) } } return failedList @@ -475,6 +474,7 @@ func (t *BaseTask) run(taskHandler func()) { ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content) } } + t.SetFinishHook(t.FinishHook) }) } } diff --git a/business/partner/partner_store_sku.go b/business/partner/partner_store_sku.go index 5110cc4dd..f66a9f233 100644 --- a/business/partner/partner_store_sku.go +++ b/business/partner/partner_store_sku.go @@ -43,6 +43,11 @@ type StoreSkuInfo struct { Seq int `json:"seq,omitempty"` } +type StoreSkuInfoWithErr struct { + StoreSkuInfo *StoreSkuInfo + ErrMsg string +} + type SkuInfo struct { StoreSkuInfo SkuName string @@ -129,9 +134,9 @@ 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) (failedList []*tasksch.ErrMsg, err error) + UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (failedList []*StoreSkuInfoWithErr, err error) + UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo, status int) (failedList []*StoreSkuInfoWithErr, err error) + UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (failedList []*StoreSkuInfoWithErr, err error) } type ISingleStoreStoreSkuHandler interface { diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 3dd42be7d..a28d4bf4f 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -166,7 +166,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v return successList, err } -func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) { vendorSkuIDs := partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDIntList() if globals.EnableEbaiStoreWrite { var opResult *ebaiapi.BatchOpResult @@ -175,19 +175,24 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID opResult, err = api.EbaiAPI.SkuOnline(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs, nil, nil) } else if len(vendorSkuIDs) == 1 { err = api.EbaiAPI.SkuOnlineOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs[0], "", "") + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + return failedList, err } } else { if len(vendorSkuIDs) > 1 { opResult, err = api.EbaiAPI.SkuOffline(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs, nil, nil) } else if len(vendorSkuIDs) == 1 { err = api.EbaiAPI.SkuOfflineOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs[0], "", "") + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + return failedList, err } } if err != nil && opResult != nil { - successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) + failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult) + // failedList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) } } - return successList, err + return failedList, err } func StoreSkuInfoList2Ebai(storeSkuList []*partner.StoreSkuInfo) (outList ebaiapi.ShopSkuInfoList) { @@ -203,7 +208,7 @@ func StoreSkuInfoList2Ebai(storeSkuList []*partner.StoreSkuInfo) (outList ebaiap return outList } -func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*tasksch.ErrMsg, err error) { +func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { if globals.EnableEbaiStoreWrite { if len(storeSkuList) > 1 { opResult, err2 := api.EbaiAPI.SkuPriceUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID) @@ -211,24 +216,29 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i failedList = putils.SelectStoreSkuListByOpResult(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(storeSkuList, opResult2) + } } } return failedList, err } -func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { if globals.EnableEbaiStoreWrite { if len(storeSkuList) > 1 { opResult, err2 := api.EbaiAPI.SkuStockUpdateBatch(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(storeSkuList, opResult) + // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) } } else if len(storeSkuList) == 1 { err = api.EbaiAPI.SkuStockUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0]) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) } } - return successList, err + return failedList, err } func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo, isCreate bool) (params map[string]interface{}) { diff --git a/business/partner/purchase/jd/store_sku2.go b/business/partner/purchase/jd/store_sku2.go index db58ccfac..5148313b3 100644 --- a/business/partner/purchase/jd/store_sku2.go +++ b/business/partner/purchase/jd/store_sku2.go @@ -1,8 +1,6 @@ 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" @@ -112,7 +110,7 @@ func getStrOutSkuIDs(l []*jdapi.StoreSkuBatchUpdateResponse, isSuccess bool) (ou return outSkuIDs } -func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) { var skuVendibilityList []*jdapi.StockVendibility jdStatus := jxStoreSkuStatus2Jd(status) for _, v := range storeSkuList { @@ -124,16 +122,18 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID if globals.EnableJdStoreWrite { responseList, err2 := getAPI("").BatchUpdateVendibility(ctx.GetTrackInfo(), "", vendorStoreID, skuVendibilityList, ctx.GetUserName()) if err = err2; isErrPartialFailed(err) { - successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false))) + failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList) + // successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false))) } } - return successList, err + return failedList, err } -func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*tasksch.ErrMsg, err error) { +func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, 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)) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) } } else { var skuPriceInfoList []*jdapi.SkuPriceInfo @@ -146,18 +146,18 @@ 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))) - fmt.Println(successList) + failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList) } } } return failedList, err } -func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { if len(storeSkuList) == 1 { if globals.EnableJdStoreWrite { err = getAPI("").UpdateCurrentQty(ctx.GetTrackInfo(), vendorStoreID, utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), storeSkuList[0].Stock) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) } } else { var skuStockList []*jdapi.SkuStock @@ -170,11 +170,12 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i if globals.EnableJdStoreWrite { responseList, err2 := getAPI("").BatchUpdateCurrentQtys(ctx.GetTrackInfo(), "", vendorStoreID, skuStockList, ctx.GetUserName()) if err = err2; isErrPartialFailed(err) { - successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false))) + failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList) + // successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false))) } } } - return successList, err + return failedList, err } func (p *PurchaseHandler) SyncStoreProducts(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index e14af3a10..da1cc6176 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -322,45 +322,48 @@ func storeSku2Mtwm(storeSkuList []*partner.StoreSkuInfo, updateType int) (skuLis return skuList } -func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) { skuList := storeSku2Mtwm(storeSkuList, updateTypeStatus) mtwmStatus := skuStatusJX2Mtwm(status) if globals.EnableMtwmStoreWrite { failedFoodList, err2 := api.MtwmAPI.RetailSellStatus(ctx.GetTrackInfo(), vendorStoreID, skuList, mtwmStatus) if err = err2; err == nil { if len(failedFoodList) > 0 { - successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) - } - } - } - return successList, err -} - -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 len(failedFoodList) > 0 { - failedList = putils.SelectStoreSkuListByFoodList(storeID, storeSkuList, failedFoodList) - err = putils.GenPartialFailedErr(failedList, len(failedList)) + failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList) + // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) } } } return failedList, err } -func (p *PurchaseHandler) UpdateStoreSkusStock(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 []*partner.StoreSkuInfoWithErr, err error) { + priceList := storeSku2Mtwm(storeSkuList, updateTypePrice) + if globals.EnableMtwmStoreWrite { + failedFoodList, err2 := api.MtwmAPI.RetailSkuPrice(ctx.GetTrackInfo(), vendorStoreID, priceList) + if err = err2; err == nil { + if len(failedFoodList) > 0 { + failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList) + } + } + } + return failedList, err +} + +func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { stockList := storeSku2Mtwm(storeSkuList, updateTypeStock) if globals.EnableMtwmStoreWrite { failedFoodList, err2 := api.MtwmAPI.RetailSkuStock(ctx.GetTrackInfo(), vendorStoreID, stockList) 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(storeSkuList, failedFoodList) } + // if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil { + // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) + // } } } - return successList, err + return failedList, err } func mtwmSkuStatus2Jx(mtwmSkuStatus int) (jxSkuStatus int) { diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index e22f50ff2..e688c5e7a 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -4,6 +4,8 @@ import ( "fmt" "sort" + "git.rosy.net.cn/baseapi/platformapi/jdapi" + "git.rosy.net.cn/baseapi/platformapi/ebaiapi" "git.rosy.net.cn/baseapi/platformapi/mtwmapi" @@ -234,7 +236,8 @@ func UnselectStoreSkuListByVendorSkuIDs(storeSkuList []*partner.StoreSkuInfo, ve return selectedStoreSkuList } -func SelectStoreSkuListByFoodList(storeID int, storeSkuList []*partner.StoreSkuInfo, foodList []*mtwmapi.AppFoodResult) (selectedStoreSkuList []*tasksch.ErrMsg) { +//美团api返回 +func SelectStoreSkuListByFoodList(storeSkuList []*partner.StoreSkuInfo, foodList []*mtwmapi.AppFoodResult) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { foodMap := make(map[string]string) if len(foodList) > 0 { for _, v := range foodList { @@ -242,12 +245,9 @@ func SelectStoreSkuListByFoodList(storeID int, storeSkuList []*partner.StoreSkuI } for _, v := range storeSkuList { if foodMap[v.VendorSkuID] != "" { - foodFailed := &tasksch.ErrMsg{ - SkuID: v.SkuID, - VendorSkuID: v.VendorSkuID, - StoreID: storeID, - VendorPrice: v.VendorPrice, - Err: foodMap[v.VendorSkuID], + foodFailed := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: v, + ErrMsg: foodMap[v.VendorSkuID], } selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) } @@ -256,7 +256,8 @@ func SelectStoreSkuListByFoodList(storeID int, storeSkuList []*partner.StoreSkuI return selectedStoreSkuList } -func SelectStoreSkuListByOpResult(storeID int, storeSkuList []*partner.StoreSkuInfo, opResult *ebaiapi.BatchOpResult) (selectedStoreSkuList []*tasksch.ErrMsg) { +//饿百api返回 +func SelectStoreSkuListByOpResult(storeSkuList []*partner.StoreSkuInfo, opResult *ebaiapi.BatchOpResult) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { opResultMap := make(map[int64]string) if len(opResult.FailedList) > 0 { for _, v := range opResult.FailedList { @@ -264,12 +265,9 @@ func SelectStoreSkuListByOpResult(storeID int, storeSkuList []*partner.StoreSkuI } for _, v := range storeSkuList { if opResultMap[utils.Str2Int64(v.VendorSkuID)] != "" { - opFailed := &tasksch.ErrMsg{ - SkuID: v.SkuID, - VendorSkuID: v.VendorSkuID, - StoreID: storeID, - VendorPrice: v.VendorPrice, - Err: opResultMap[utils.Str2Int64(v.VendorSkuID)], + opFailed := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: v, + ErrMsg: opResultMap[utils.Str2Int64(v.VendorSkuID)], } selectedStoreSkuList = append(selectedStoreSkuList, opFailed) } @@ -278,6 +276,39 @@ func SelectStoreSkuListByOpResult(storeID int, storeSkuList []*partner.StoreSkuI return selectedStoreSkuList } +//京东api返回 +func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, responseList []*jdapi.StoreSkuBatchUpdateResponse) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { + responseMap := make(map[string]string) + if len(responseList) > 0 { + for _, v := range responseList { + responseMap[v.OutSkuID] = v.Msg + } + for _, v := range storeSkuList { + if responseMap[utils.Int2Str(v.SkuID)] != "" { + respFailed := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: v, + ErrMsg: responseMap[utils.Int2Str(v.SkuID)], + } + selectedStoreSkuList = append(selectedStoreSkuList, respFailed) + } + } + } + return selectedStoreSkuList +} + +func GetErrMsg2FailedSingleList(storeSkuList []*partner.StoreSkuInfo, err error) (failedList []*partner.StoreSkuInfoWithErr) { + failedList2 := make([]*partner.StoreSkuInfoWithErr, 1) + if err != nil { + if errExt, ok := err.(*utils.ErrorWithCode); ok { + failedList2[0] = &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: storeSkuList[0], + ErrMsg: errExt.ErrMsg(), + } + } + } + return failedList2 +} + func UnselectStoreSkuSyncListByVendorSkuIDs(storeSkuList []*dao.StoreSkuSyncInfo, vendorSkuIDs []string) (selectedStoreSkuList []*dao.StoreSkuSyncInfo) { if len(vendorSkuIDs) > 0 { vendorSkuIDMap := jxutils.StringList2Map(vendorSkuIDs) From d69ad7a9e41025ccac1939c71355ca8e3797a2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 26 Nov 2019 11:27:52 +0800 Subject: [PATCH 08/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 3 --- business/jxutils/tasksch/task.go | 7 ++++++- business/partner/partner_store_sku.go | 2 +- business/partner/putils/store_sku.go | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index f12d6da86..3c85c2913 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -517,9 +517,6 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo var failedList []*partner.StoreSkuInfoWithErr failedList, err = storeSkuHandler.UpdateStoreSkusStock(ctx, storeID, vendorStoreID, batchedStoreSkuList) if len(failedList) > 0 { - for _, v := range failedList { - fmt.Println(v.StoreSkuInfo, v.ErrMsg) - } task.AddErrMsg(failedList) } successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index b218f9855..a221a7787 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -66,6 +66,7 @@ type ITask interface { AddErrMsg(failedList ...interface{}) GetErrMsg() (failedList []interface{}) SetFinishHook(func(task ITask)) + GetFinishHook() func(task ITask) json.Marshaler } @@ -229,6 +230,10 @@ func (t *BaseTask) GetTotalJobCount() int { return t.TotalJobCount } +func (t *BaseTask) GetFinishHook() func(ITask) { + return t.FinishHook +} + func (t *BaseTask) GetFinishedJobCount() int { t.locker.RLock() defer t.locker.RUnlock() @@ -474,7 +479,7 @@ func (t *BaseTask) run(taskHandler func()) { ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content) } } - t.SetFinishHook(t.FinishHook) + t.GetFinishHook() }) } } diff --git a/business/partner/partner_store_sku.go b/business/partner/partner_store_sku.go index f66a9f233..9ed7ff3be 100644 --- a/business/partner/partner_store_sku.go +++ b/business/partner/partner_store_sku.go @@ -144,7 +144,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) (failedList []*dao.StoreSkuSyncInfo, err error) + UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*dao.StoreSkuInfoWithErr, 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) diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index e688c5e7a..c17608497 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -297,16 +297,16 @@ func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, resp } func GetErrMsg2FailedSingleList(storeSkuList []*partner.StoreSkuInfo, err error) (failedList []*partner.StoreSkuInfoWithErr) { - failedList2 := make([]*partner.StoreSkuInfoWithErr, 1) if err != nil { if errExt, ok := err.(*utils.ErrorWithCode); ok { - failedList2[0] = &partner.StoreSkuInfoWithErr{ + storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{ StoreSkuInfo: storeSkuList[0], ErrMsg: errExt.ErrMsg(), } + failedList = append(failedList, storeSkuInfoWithErr) } } - return failedList2 + return failedList } func UnselectStoreSkuSyncListByVendorSkuIDs(storeSkuList []*dao.StoreSkuSyncInfo, vendorSkuIDs []string) (selectedStoreSkuList []*dao.StoreSkuSyncInfo) { From edcd56eb452260389c499025a9c09f42a31e0945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 26 Nov 2019 14:20:49 +0800 Subject: [PATCH 09/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 17 ++++++------ business/partner/partner_store_sku.go | 4 +-- business/partner/purchase/ebai/store_sku2.go | 4 +-- business/partner/purchase/mtwm/store_sku2.go | 19 ++++++------- business/partner/putils/store_sku.go | 28 ++++++++++++++++++++ 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 3c85c2913..0a95aac2c 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -468,8 +468,8 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo case 1: if len(createList) > 0 { _, err = putils.FreeBatchStoreSkuSyncInfo("创建门店商品", func(task tasksch.ITask, batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, successCount int, err error) { - var successList []*dao.StoreSkuSyncInfo - if successList, err = singleStoreHandler.CreateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); singleStoreHandler.IsErrSkuExist(err) { + 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, @@ -483,14 +483,13 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo err = nil } } - if err == nil { - successList = batchedStoreSkuList - } else { + if err != nil { //handle error for sensitive words, if find, then insert to table sensitive_words if sensitiveWord := GetSensitiveWord(singleStoreHandler, err.Error()); sensitiveWord != "" { dao.InsertSensitiveWord(sensitiveWord, vendorID, ctx.GetUserName()) } } + successList := putils.UnselectStoreSkuSyncListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) if len(successList) > 0 { updateStoreSku(dao.GetDB(), vendorID, successList, model.SyncFlagNewMask) } @@ -500,10 +499,12 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo case 2: if len(updateList) > 0 { _, err = putils.FreeBatchStoreSkuSyncInfo("更新门店商品基础信息", func(task tasksch.ITask, batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, successCount int, err error) { - var successList []*dao.StoreSkuSyncInfo - if successList, err = singleStoreHandler.UpdateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil { - successList = batchedStoreSkuList + var failedList []*partner.StoreSkuInfoWithErr + failedList, err = singleStoreHandler.UpdateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList) + if len(failedList) > 0 { + task.AddErrMsg(failedList) } + successList := putils.UnselectStoreSkuSyncListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) if len(successList) > 0 { updateStoreSku(dao.GetDB(), vendorID, successList, model.SyncFlagModifiedMask) } diff --git a/business/partner/partner_store_sku.go b/business/partner/partner_store_sku.go index 9ed7ff3be..c674f9955 100644 --- a/business/partner/partner_store_sku.go +++ b/business/partner/partner_store_sku.go @@ -143,8 +143,8 @@ type ISingleStoreStoreSkuHandler interface { IPurchasePlatformStoreSkuHandler 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) (failedList []*dao.StoreSkuInfoWithErr, err error) + CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*StoreSkuInfoWithErr, err error) + UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*StoreSkuInfoWithErr, 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) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index a28d4bf4f..da0db966a 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -113,7 +113,7 @@ func (p *PurchaseHandler) IsErrSkuNotExist(err error) (isNotExist bool) { return ebaiapi.IsErrSkuNotExist(err) } -func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (successList []*dao.StoreSkuSyncInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { storeSku := storeSkuList[0] strStoreID := utils.Int2Str(storeID) params := genSkuParamsFromStoreSkuInfo2(storeSku, false) @@ -127,7 +127,7 @@ func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, v } // 对于多门店平台来说,storeSkuList中只有SkuID与VendorSkuID有意义 -func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (successList []*dao.StoreSkuSyncInfo, err error) { +func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { storeSku := storeSkuList[0] var vendorSkuID int64 params := genSkuParamsFromStoreSkuInfo2(storeSku, true) diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index 0196b7e78..f63673631 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -211,28 +211,28 @@ func (p *PurchaseHandler) IsErrSkuNotExist(err error) (isNotExist bool) { // return newStoreSkuList // } -func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (successList []*dao.StoreSkuSyncInfo, err error) { - successList, err = p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, storeSkuList, false) +func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { + failedList, err = p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, storeSkuList, false) // if err == nil && vendorStoreID == specialStoreID { // for i := 0; i < 2; i++ { // p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, duplicateStoreSkuList(storeSkuList, i+1), true) // } // } - return successList, err + return failedList, err } -func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (successList []*dao.StoreSkuSyncInfo, err error) { - successList, err = p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, storeSkuList, true) +func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { + failedList, err = p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, storeSkuList, true) // if err == nil && vendorStoreID == specialStoreID { // for i := 0; i < 2; i++ { // p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, duplicateStoreSkuList(storeSkuList, i+1), true) // } // } - return successList, err + return failedList, err } // 对于多门店平台来说,storeSkuList中只有SkuID与VendorSkuID有意义 -func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo, isCreate bool) (successList []*dao.StoreSkuSyncInfo, err error) { +func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo, isCreate bool) (failedList []*partner.StoreSkuInfoWithErr, err error) { foodDataList := make([]map[string]interface{}, len(storeSkuList)) for i, storeSku := range storeSkuList { isNeedUpdatePrice := isCreate //storeSku.StoreSkuSyncStatus&( model.SyncFlagPriceMask| model.SyncFlagNewMask) != 0 @@ -297,7 +297,8 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI failedFoodList, err2 := api.MtwmAPI.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList) if err = err2; err == nil { if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil { - successList = putils.UnselectStoreSkuSyncListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) + failedList = putils.SelectStoreSynSkuByFoodList(storeSkuList, failedFoodList) + // successList = putils.UnselectStoreSkuSyncListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) } } } @@ -305,7 +306,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI for _, storeSku := range storeSkuList { storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID) } - return successList, err + return failedList, err } func getAppFoodCodeList(l []*mtwmapi.AppFoodResult) (vendorSkuIDs []string) { diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index c17608497..b824ff155 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -256,6 +256,34 @@ func SelectStoreSkuListByFoodList(storeSkuList []*partner.StoreSkuInfo, foodList return selectedStoreSkuList } +//美团api返回 +func SelectStoreSynSkuByFoodList(storeSkuList []*dao.StoreSkuSyncInfo, foodList []*mtwmapi.AppFoodResult) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { + 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] != "" { + storeSkuInfo := &partner.StoreSkuInfo{ + SkuID: v.SkuID, + VendorSkuID: v.VendorSkuID, + NameID: v.NameID, + VendorNameID: v.VendorNameID, + VendorPrice: v.VendorPrice, + Status: v.Status, + } + foodFailed := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: storeSkuInfo, + ErrMsg: foodMap[v.VendorSkuID], + } + selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) + } + } + } + return selectedStoreSkuList +} + //饿百api返回 func SelectStoreSkuListByOpResult(storeSkuList []*partner.StoreSkuInfo, opResult *ebaiapi.BatchOpResult) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { opResultMap := make(map[int64]string) From 799c8232d78543c0305f90f6729e8f0a2b9b1fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 26 Nov 2019 18:26:16 +0800 Subject: [PATCH 10/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 4 +++- business/partner/purchase/ebai/store_sku2.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 0a95aac2c..7d2ff5d38 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -299,7 +299,6 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo return err } vendorStoreID := storeDetail.VendorStoreID - var skus []*dao.StoreSkuSyncInfo if isFull { skus, err = dao.GetFullStoreSkus(db, vendorID, storeID) @@ -502,6 +501,9 @@ 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)) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index da0db966a..77af201e5 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -1,6 +1,7 @@ package ebai import ( + "fmt" "regexp" "time" @@ -117,6 +118,9 @@ 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) utils.CallFuncAsync(func() { From 2a486ea2ba80c039b32699edcf474ecf561e9bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 28 Nov 2019 11:47:19 +0800 Subject: [PATCH 11/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 33 +++++++++++--------- business/partner/purchase/ebai/store_sku2.go | 13 ++++---- business/partner/putils/store_sku.go | 21 +++++++++++++ 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index eb6608eeb..3815bb681 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -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)) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 77af201e5..d4fd3dfad 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -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) { diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index b824ff155..735f3bf89 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -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) From 363b44a21c5702af5a86af26eb7b6fba199930d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 28 Nov 2019 14:15:57 +0800 Subject: [PATCH 12/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 16 ++++++++-------- business/partner/partner_store_sku.go | 2 +- business/partner/purchase/ebai/store_sku2.go | 7 ++++--- business/partner/purchase/mtwm/store_sku2.go | 13 +++++++++++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 3815bb681..de8850c93 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -456,15 +456,18 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo case 0: if len(deleteList) > 0 { _, err = putils.FreeBatchStoreSkuInfo("删除门店商品", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { - var successList []*partner.StoreSkuInfo - if successList, err = singleStoreHandler.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); singleStoreHandler.IsErrSkuNotExist(err) { + var failedList []*partner.StoreSkuInfoWithErr + failedList, err = singleStoreHandler.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList) + if len(failedList) > 0 { + task.AddErrMsg(failedList) + } + if singleStoreHandler.IsErrSkuNotExist(err) { err = nil } - if err == nil { - successList = batchedStoreSkuList - } else { + if err != nil { offlineList = append(offlineList, batchedStoreSkuList...) } + successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) if len(successList) > 0 { updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagDeletedMask) } @@ -477,9 +480,6 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo var failedList []*partner.StoreSkuInfoWithErr 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) diff --git a/business/partner/partner_store_sku.go b/business/partner/partner_store_sku.go index c674f9955..e0c417be4 100644 --- a/business/partner/partner_store_sku.go +++ b/business/partner/partner_store_sku.go @@ -145,7 +145,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) (failedList []*StoreSkuInfoWithErr, err error) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (failedList []*StoreSkuInfoWithErr, err error) - DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (successList []*StoreSkuInfo, err error) + DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (failedList []*StoreSkuInfoWithErr, err error) DeleteStoreAllSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, isContinueWhenError bool) (err error) IsErrSkuExist(err error) (isExist bool) IsErrSkuNotExist(err error) (isNotExist bool) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index d4fd3dfad..9c76089b9 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -159,16 +159,17 @@ func getFailedVendorSkuIDsFromOpResult(opResult *ebaiapi.BatchOpResult) (skuIDs return skuIDs } -func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { if globals.EnableEbaiStoreWrite { opResult, err2 := api.EbaiAPI.SkuDelete(ctx.GetTrackInfo(), utils.Int2Str(storeID), partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDIntList(), nil) if err = err2; err2 != nil && opResult != nil { if len(storeSkuList) > len(opResult.FailedList) { - successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) + failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult) + // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) } } } - return successList, err + return failedList, err } func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) { diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index f63673631..7a275f917 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -1,6 +1,7 @@ package mtwm import ( + "encoding/json" "regexp" "strings" @@ -319,16 +320,24 @@ func getAppFoodCodeList(l []*mtwmapi.AppFoodResult) (vendorSkuIDs []string) { return vendorSkuIDs } -func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { if globals.EnableMtwmStoreWrite { if len(storeSkuList) == 1 { err = api.MtwmAPI.RetailDelete(ctx.GetTrackInfo(), vendorStoreID, storeSkuList[0].VendorSkuID) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) } else { // todo 部分失败 err = api.MtwmAPI.RetailCatSkuBatchDelete2(ctx.GetTrackInfo(), vendorStoreID, nil, nil, nil, nil, partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDList()) + if err != nil { + if errExt, ok := err.(*utils.ErrorWithCode); ok { + myMap := make(map[string][]*mtwmapi.AppFoodResult) + json.Unmarshal([]byte(errExt.ErrMsg()), &myMap) + failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, myMap["retail_error_list"]) + } + } } } - return nil, err + return failedList, err } func stockCount2Mtwm(stock int) (mtwmStock string) { From fa843d3d1e5515b3610665c43378e64606b77be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 28 Nov 2019 14:24:41 +0800 Subject: [PATCH 13/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index de8850c93..58bb5f81f 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -31,13 +31,6 @@ var ( subSensitiveWordRegexp = regexp.MustCompile(`[^\[\]\"\}]`) ) -type ErrMsg struct { - SkuID int - StoreID int - VendorID int - Err string -} - func CreateStoreCategoryByStoreSku(ctx *jxcontext.Context, vendorID, storeID int, vendorStoreID string, nameIDs, skuIDs []int) (err error) { globals.SugarLogger.Debugf("CreateStoreCategoryByStoreSku vendorID:%d, storeID:%d", vendorID, storeID) db := dao.GetDB() From 2836da8c942522036dbdb59df14794215fbe5b95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Mon, 2 Dec 2019 08:20:05 +0800 Subject: [PATCH 14/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index c7d653caa..8e62ed74d 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -389,10 +389,6 @@ func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vend return nil, partner.AddVendorInfo2Err(err, loopMapInfo.VendorID) }, isContinueWhenError) if task != nil { - task.SetFinishHook(func(task2 tasksch.ITask) { - failedList := task2.GetErrMsg() - fmt.Println(failedList) - }) err = makeSyncError(err) } return hint, err @@ -544,6 +540,11 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID]) } task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList) + task.SetFinishHook(func(task tasksch.ITask) { + fmt.Println("test2") + failedList := task.GetErrMsg() + fmt.Println(failedList) + }) tasksch.HandleTask(task, nil, isManageIt).Run() if !isAsync { resultList, err2 := task.GetResult(0) From 7ec9a99cfbe99e2377ad6df5f2505b2d78220d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Mon, 2 Dec 2019 15:42:01 +0800 Subject: [PATCH 15/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 8 ++--- business/jxutils/tasksch/task.go | 53 ++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 8e62ed74d..46a304bf6 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -540,11 +540,9 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID]) } task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList) - task.SetFinishHook(func(task tasksch.ITask) { - fmt.Println("test2") - failedList := task.GetErrMsg() - fmt.Println(failedList) - }) + task.SetFinishHook(task) + failedList := task.GetErrMsg() + tasksch.HandleTask(task, nil, isManageIt).Run() if !isAsync { resultList, err2 := task.GetResult(0) diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index a221a7787..ca52b2f06 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -65,8 +65,8 @@ type ITask interface { AddBatchErr(err error) AddErrMsg(failedList ...interface{}) GetErrMsg() (failedList []interface{}) - SetFinishHook(func(task ITask)) - GetFinishHook() func(task ITask) + SetFinishHook(task *ParallelTask) + GetFinishHook() *ParallelTask json.Marshaler } @@ -132,7 +132,7 @@ type BaseTask struct { ctx *jxcontext.Context isGetResultCalled bool FailedList []interface{} - FinishHook func(task ITask) + finishHook *ParallelTask } func (s TaskList) Len() int { @@ -230,10 +230,6 @@ func (t *BaseTask) GetTotalJobCount() int { return t.TotalJobCount } -func (t *BaseTask) GetFinishHook() func(ITask) { - return t.FinishHook -} - func (t *BaseTask) GetFinishedJobCount() int { t.locker.RLock() defer t.locker.RUnlock() @@ -364,8 +360,14 @@ func (t *BaseTask) Error() (errMsg string) { return errMsg } -func (t *BaseTask) SetFinishHook(hook func(task ITask)) { - t.FinishHook = hook +func (t *BaseTask) SetFinishHook(task *ParallelTask) { + t.locker.RLock() + defer t.locker.RUnlock() + t.finishHook = task +} + +func (t *BaseTask) GetFinishHook() *ParallelTask { + return t.finishHook } func (t *BaseTask) GetErrMsg() (failedList []interface{}) { @@ -425,7 +427,8 @@ func (t *BaseTask) run(taskHandler func()) { utils.CallFuncAsync(func() { defer func() { if r := recover(); r != nil { - globals.SugarLogger.Errorf("panic in BaseTask.run task:%s, task detail:%s, r:%v", t.Name, utils.Format4Output(t, false), r) + // globals.SugarLogger.Errorf("panic in BaseTask.run task:%s, task detail:%s, r:%v", t.Name, utils.Format4Output(t, false), r) + globals.SugarLogger.Errorf("panic in BaseTask.run task:%s, task detail:%s, r:%v", t.Name, "", r) } }() @@ -463,23 +466,27 @@ func (t *BaseTask) run(taskHandler func()) { close(t.finishChan) time.Sleep(10 * time.Millisecond) // 等待GetResult中的isGetResultCalled赋值 globals.SugarLogger.Debugf("BaseTask task ID:%s, name:%s finished, isGetResultCalled:%t", t.ID, t.Name, t.isGetResultCalled) - if !t.isGetResultCalled && t.parent == nil && len(GetTasks(t.ID, TaskStatusBegin, TaskStatusEnd, 24, "")) > 0 { - if authInfo, err := t.ctx.GetV2AuthInfo(); err == nil { // 这里应该是不管登录类型,直接以可能的方式发消息 - var content string - taskDesc := fmt.Sprintf("你的异步任务[%s],ID[%s],开始于:%s,结束于:%s,", t.Name, t.ID, utils.Time2Str(t.CreatedAt), utils.Time2Str(t.TerminatedAt)) - content = fmt.Sprintf("%s执行%s", taskDesc, TaskStatusName[t.Status]) - if t.Error() == "" { - noticeMsg := t.GetNoticeMsg() - if noticeMsg != "" { - content += ",通知消息:" + noticeMsg + p := t.GetFinishHook() + if p != nil { + if !t.isGetResultCalled && t.parent == nil && len(GetTasks(t.ID, TaskStatusBegin, TaskStatusEnd, 24, "")) > 0 { + if authInfo, err := t.ctx.GetV2AuthInfo(); err == nil { // 这里应该是不管登录类型,直接以可能的方式发消息 + var content string + taskDesc := fmt.Sprintf("你的异步任务[%s],ID[%s],开始于:%s,结束于:%s,", t.Name, t.ID, utils.Time2Str(t.CreatedAt), utils.Time2Str(t.TerminatedAt)) + content = fmt.Sprintf("%s执行%s", taskDesc, TaskStatusName[t.Status]) + if t.Error() == "" { + noticeMsg := t.GetNoticeMsg() + if noticeMsg != "" { + content += ",通知消息:" + noticeMsg + } + } else { + content += ",\n" + t.Error() } - } else { - content += ",\n" + t.Error() + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content) } - ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content) } + } else { + } - t.GetFinishHook() }) } } From 7f8615abfbecc8a8a24e204cb1d1308e1627a8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 4 Dec 2019 09:17:06 +0800 Subject: [PATCH 16/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 85 ++++++++++++++++++++++++++++++-- business/jxutils/tasksch/task.go | 69 +++++++++++--------------- 2 files changed, 111 insertions(+), 43 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 46a304bf6..9e73f490d 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -3,9 +3,15 @@ package cms import ( "errors" "fmt" + "sync" + "time" + "git.rosy.net.cn/baseapi" + "git.rosy.net.cn/baseapi/platformapi/dingdingapi" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils" + "git.rosy.net.cn/jx-callback/business/jxutils/ddmsg" + "git.rosy.net.cn/jx-callback/business/jxutils/excel" "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/model" @@ -15,6 +21,19 @@ import ( "git.rosy.net.cn/jx-callback/globals/refutil" ) +type SyncErrResult struct { + SkuID int `json:"商品ID"` + VendorSkuID string `json:"平台商品ID"` + NameID int `json:"商品nameID"` + VendorPrice int64 `json:"平台价"` + ErrMsg string `json:"错误信息"` +} + +type SyncErrResultLock struct { + syncErrResult []SyncErrResult + locker sync.RWMutex +} + type LoopStoreMapInfo struct { VendorID int StoreMapList []*model.StoreMap @@ -45,6 +64,14 @@ var ( var ( ErrHaveNotImplementedYet = errors.New("还没有实现") ErrEntityNotExist = errors.New("找不到相应实体") + SyncErrResultTitle = []string{ + "商品ID", + "平台商品ID", + "商品nameID", + "平台价", + "错误信息", + } + syncErrResultLock SyncErrResultLock ) func (p *MultiStoreHandlerWrapper) DeleteCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) (err error) { @@ -540,9 +567,9 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID]) } task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList) - task.SetFinishHook(task) - failedList := task.GetErrMsg() - + task.SetFinishHook(func(task tasksch.ITask, ctx *jxcontext.Context) { + err = WirteToExcelBySyncFailed(task, ctx) + }) tasksch.HandleTask(task, nil, isManageIt).Run() if !isAsync { resultList, err2 := task.GetResult(0) @@ -698,3 +725,55 @@ func GetTimeMixByInt(begin1, end1, begin2, end2 int16) (beginAt, endAt int16) { } return beginAt, endAt } + +func WirteToExcelBySyncFailed(task tasksch.ITask, ctx *jxcontext.Context) (err error) { + var ( + sheetList1 []*excel.Obj2ExcelSheetConfig + downloadURL1, fileName1 string + ) + syncErrResultLock.syncErrResult = syncErrResultLock.syncErrResult[0:0] + failedList := task.GetErrMsg() + if len(failedList) == 0 { + return + } + for _, v := range failedList { + for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { + result := SyncErrResult{ + SkuID: vv.StoreSkuInfo.SkuID, + VendorSkuID: vv.StoreSkuInfo.VendorSkuID, + NameID: vv.StoreSkuInfo.NameID, + VendorPrice: vv.StoreSkuInfo.VendorPrice, + ErrMsg: vv.ErrMsg, + } + syncErrResultLock.AppendData(result) + } + } + excelConf1 := &excel.Obj2ExcelSheetConfig{ + Title: "同步错误", + Data: syncErrResultLock.syncErrResult, + CaptionList: SyncErrResultTitle, + } + sheetList1 = append(sheetList1, excelConf1) + if excelConf1 != nil { + downloadURL1, fileName1, err = jxutils.UploadExeclAndPushMsg(sheetList1, time.Now().Format("2006-01-02")+"同步错误返回") + baseapi.SugarLogger.Debug("WriteToExcel: download is [%v]", downloadURL1) + } else { + baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!") + } + if err != nil { + baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName1, err) + } else { + if authInfo, err := ctx.GetV2AuthInfo(); err == nil { + noticeMsg := fmt.Sprintf("[详情点我]path1=%s\n", downloadURL1) + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "同步错误返回", noticeMsg) + baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL1:%s", fileName1, downloadURL1) + } + } + return err +} + +func (d *SyncErrResultLock) AppendData(syncErrResult SyncErrResult) { + d.locker.Lock() + defer d.locker.Unlock() + d.syncErrResult = append(d.syncErrResult, syncErrResult) +} diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index ca52b2f06..e80f8febf 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -65,8 +65,7 @@ type ITask interface { AddBatchErr(err error) AddErrMsg(failedList ...interface{}) GetErrMsg() (failedList []interface{}) - SetFinishHook(task *ParallelTask) - GetFinishHook() *ParallelTask + SetFinishHook(func(task ITask, ctx *jxcontext.Context)) json.Marshaler } @@ -132,7 +131,7 @@ type BaseTask struct { ctx *jxcontext.Context isGetResultCalled bool FailedList []interface{} - finishHook *ParallelTask + finishHook func(task ITask, ctx *jxcontext.Context) } func (s TaskList) Len() int { @@ -174,6 +173,9 @@ func (t *BaseTask) GetID() string { return t.ID } +func (t *BaseTask) Run() { +} + // 此函数成功返回结果后,结果在任务中会被删除(以免被管理的任务不必要的HOLD住对象) func (t *BaseTask) GetResult(duration time.Duration) (retVal []interface{}, err error) { if t.GetStatus() >= TaskStatusEndBegin { @@ -360,26 +362,19 @@ func (t *BaseTask) Error() (errMsg string) { return errMsg } -func (t *BaseTask) SetFinishHook(task *ParallelTask) { +func (t *BaseTask) SetFinishHook(hook func(task ITask, ctx *jxcontext.Context)) { t.locker.RLock() defer t.locker.RUnlock() - t.finishHook = task -} - -func (t *BaseTask) GetFinishHook() *ParallelTask { - return t.finishHook + t.finishHook = hook } func (t *BaseTask) GetErrMsg() (failedList []interface{}) { t.locker.RLock() - defer t.locker.RUnlock() - if len(t.FailedList) == 0 { - return nil - } - if t.parent != nil { - for _, v := range t.FailedList { - failedList = append(failedList, v) - } + failedList = append(failedList, t.FailedList...) + t.locker.RUnlock() + + for _, v := range t.Children { + failedList = append(failedList, v.GetErrMsg()...) } return failedList } @@ -387,9 +382,7 @@ func (t *BaseTask) GetErrMsg() (failedList []interface{}) { func (t *BaseTask) AddErrMsg(failedList ...interface{}) { t.locker.Lock() defer t.locker.Unlock() - for _, v := range failedList { - t.FailedList = append(t.FailedList, v) - } + t.FailedList = append(t.FailedList, failedList...) } // func (t *BaseTask) GetDetailErrList() []error { @@ -427,8 +420,7 @@ func (t *BaseTask) run(taskHandler func()) { utils.CallFuncAsync(func() { defer func() { if r := recover(); r != nil { - // globals.SugarLogger.Errorf("panic in BaseTask.run task:%s, task detail:%s, r:%v", t.Name, utils.Format4Output(t, false), r) - globals.SugarLogger.Errorf("panic in BaseTask.run task:%s, task detail:%s, r:%v", t.Name, "", r) + globals.SugarLogger.Errorf("panic in BaseTask.run task:%s, task detail:%s, r:%v", t.Name, utils.Format4Output(t, false), r) } }() @@ -462,30 +454,27 @@ func (t *BaseTask) run(taskHandler func()) { globals.SugarLogger.Infof("BaseTask run, failed with error:%v", err) } } - close(t.finishChan) time.Sleep(10 * time.Millisecond) // 等待GetResult中的isGetResultCalled赋值 globals.SugarLogger.Debugf("BaseTask task ID:%s, name:%s finished, isGetResultCalled:%t", t.ID, t.Name, t.isGetResultCalled) - p := t.GetFinishHook() - if p != nil { - if !t.isGetResultCalled && t.parent == nil && len(GetTasks(t.ID, TaskStatusBegin, TaskStatusEnd, 24, "")) > 0 { - if authInfo, err := t.ctx.GetV2AuthInfo(); err == nil { // 这里应该是不管登录类型,直接以可能的方式发消息 - var content string - taskDesc := fmt.Sprintf("你的异步任务[%s],ID[%s],开始于:%s,结束于:%s,", t.Name, t.ID, utils.Time2Str(t.CreatedAt), utils.Time2Str(t.TerminatedAt)) - content = fmt.Sprintf("%s执行%s", taskDesc, TaskStatusName[t.Status]) - if t.Error() == "" { - noticeMsg := t.GetNoticeMsg() - if noticeMsg != "" { - content += ",通知消息:" + noticeMsg - } - } else { - content += ",\n" + t.Error() + if !t.isGetResultCalled && t.parent == nil && len(GetTasks(t.ID, TaskStatusBegin, TaskStatusEnd, 24, "")) > 0 { + if authInfo, err := t.ctx.GetV2AuthInfo(); err == nil { // 这里应该是不管登录类型,直接以可能的方式发消息 + var content string + taskDesc := fmt.Sprintf("你的异步任务[%s],ID[%s],开始于:%s,结束于:%s,", t.Name, t.ID, utils.Time2Str(t.CreatedAt), utils.Time2Str(t.TerminatedAt)) + content = fmt.Sprintf("%s执行%s", taskDesc, TaskStatusName[t.Status]) + if t.Error() == "" { + noticeMsg := t.GetNoticeMsg() + if noticeMsg != "" { + content += ",通知消息:" + noticeMsg } - ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content) + } else { + content += ",\n" + t.Error() } + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content) } - } else { - + } + if t.finishHook != nil { + t.finishHook(t,t.ctx) } }) } From 4c4ed40c244f44cd2efba2d07c2292be0c94039b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 4 Dec 2019 10:32:43 +0800 Subject: [PATCH 17/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 8 +++++--- business/partner/purchase/ebai/store_sku2.go | 8 ++++---- business/partner/purchase/mtwm/store_sku2.go | 1 + business/partner/putils/store_sku.go | 4 +++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 10da225c4..887d5de19 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -472,9 +472,6 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo _, err = putils.FreeBatchStoreSkuSyncInfo("创建门店商品", func(task tasksch.ITask, batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, successCount int, err error) { var failedList []*partner.StoreSkuInfoWithErr failedList, err = singleStoreHandler.CreateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList) - if len(failedList) > 0 { - task.AddErrMsg(failedList) - } singleStoreHandler.IsErrSkuExist(err) if skuNameList, err2 := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, []*partner.StoreSkuInfo{ &partner.StoreSkuInfo{ @@ -487,6 +484,11 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo // 如果创建商品时已经存在,需要更新 updateList = append(updateList, calVendorPrice4StoreSku(batchedStoreSkuList[0], storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))) err = nil + } else { + failedList = append(failedList, putils.GetErrMsg2FailedSyncSingleList(batchedStoreSkuList, err2)) + } + if len(failedList) > 0 { + task.AddErrMsg(failedList) } if err != nil { //handle error for sensitive words, if find, then insert to table sensitive_words diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 9c76089b9..878b0bc9b 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -163,10 +163,10 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v if globals.EnableEbaiStoreWrite { opResult, err2 := api.EbaiAPI.SkuDelete(ctx.GetTrackInfo(), utils.Int2Str(storeID), partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDIntList(), nil) if err = err2; err2 != nil && opResult != nil { - if len(storeSkuList) > len(opResult.FailedList) { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult) - // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) - } + // if len(storeSkuList) > len(opResult.FailedList) { + failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult) + // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) + // } } } return failedList, err diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index 7a275f917..8015cc255 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -294,6 +294,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI if len(foodDataList) == 1 { foodDataList[0]["skus"] = string(utils.MustMarshal(foodDataList[0]["skus"])) err = api.MtwmAPI.RetailInitData(ctx.GetTrackInfo(), vendorStoreID, utils.Int2Str(storeSkuList[0].SkuID), foodDataList[0]) + failedList = putils.GetErrMsg2FailedSyncSingleList(storeSkuList, err) } else if len(foodDataList) > 0 { failedFoodList, err2 := api.MtwmAPI.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList) if err = err2; err == nil { diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index 735f3bf89..daef26e6f 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -309,7 +309,9 @@ func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, resp responseMap := make(map[string]string) if len(responseList) > 0 { for _, v := range responseList { - responseMap[v.OutSkuID] = v.Msg + if v.Code != "0" { + responseMap[v.OutSkuID] = v.Msg + } } for _, v := range storeSkuList { if responseMap[utils.Int2Str(v.SkuID)] != "" { From 9447c6b591653b3bdd678da77dc38b5e3cdb3a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 4 Dec 2019 10:37:40 +0800 Subject: [PATCH 18/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 887d5de19..43fd4115d 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -485,7 +485,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo updateList = append(updateList, calVendorPrice4StoreSku(batchedStoreSkuList[0], storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))) err = nil } else { - failedList = append(failedList, putils.GetErrMsg2FailedSyncSingleList(batchedStoreSkuList, err2)) + failedList = append(failedList, putils.GetErrMsg2FailedSyncSingleList(batchedStoreSkuList, err2)...) } if len(failedList) > 0 { task.AddErrMsg(failedList) From ecb9b79ec6a1df19600d63a795fc70453c338069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 4 Dec 2019 11:22:11 +0800 Subject: [PATCH 19/44] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/yonghui/yonghui.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 49fb9c62a..64d8769ac 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -225,10 +225,8 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i return "", errors.New("没有文件上传!") } fileHeader := files[0] - fileName := fileHeader.Filename - fmt.Println(fileName) file, err := fileHeader.Open() - // hint, err = LoadExcelBinByYongHui(ctx, file, true, true) + hint, err = LoadExcelBinByYongHui(ctx, file, true, true) file.Close() return hint, err } From 16a14e8b4dcf8c1330d6613973d45e50046c5299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 4 Dec 2019 11:56:02 +0800 Subject: [PATCH 20/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 2 +- business/partner/partner_store_sku.go | 3 + business/partner/purchase/ebai/store_sku2.go | 4 +- business/partner/purchase/mtwm/store_sku2.go | 4 +- business/partner/putils/store_sku.go | 103 +++++++++---------- 5 files changed, 54 insertions(+), 62 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 43fd4115d..4325933bb 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -485,7 +485,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo updateList = append(updateList, calVendorPrice4StoreSku(batchedStoreSkuList[0], storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))) err = nil } else { - failedList = append(failedList, putils.GetErrMsg2FailedSyncSingleList(batchedStoreSkuList, err2)...) + failedList = append(failedList, putils.GetErrMsg2FailedSingleList(batchedStoreSkuList, err2)...) } if len(failedList) > 0 { task.AddErrMsg(failedList) diff --git a/business/partner/partner_store_sku.go b/business/partner/partner_store_sku.go index e0c417be4..9333b0705 100644 --- a/business/partner/partner_store_sku.go +++ b/business/partner/partner_store_sku.go @@ -45,6 +45,9 @@ type StoreSkuInfo struct { type StoreSkuInfoWithErr struct { StoreSkuInfo *StoreSkuInfo + VendoreID int + StoreID int + SyncType string ErrMsg string } diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 878b0bc9b..22cfc8386 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -120,7 +120,7 @@ func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, v if globals.EnableEbaiStoreWrite { _, err = api.EbaiAPI.SkuUpdate(ctx.GetTrackInfo(), strStoreID, utils.Str2Int64(storeSku.VendorSkuID), params) if err != nil { - failedList = putils.GetErrMsg2FailedSyncSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) } utils.CallFuncAsync(func() { api.EbaiAPI.SkuShopCategoryMap(strStoreID, utils.Str2Int64(storeSku.VendorSkuID), "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku)) @@ -141,7 +141,7 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v api.EbaiAPI.SkuShopCategoryMap(strStoreID, vendorSkuID, "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku)) }) } else { - failedList = putils.GetErrMsg2FailedSyncSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) } } else { vendorSkuID = jxutils.GenFakeID() diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index 8015cc255..479b187a9 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -294,12 +294,12 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI if len(foodDataList) == 1 { foodDataList[0]["skus"] = string(utils.MustMarshal(foodDataList[0]["skus"])) err = api.MtwmAPI.RetailInitData(ctx.GetTrackInfo(), vendorStoreID, utils.Int2Str(storeSkuList[0].SkuID), foodDataList[0]) - failedList = putils.GetErrMsg2FailedSyncSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) } else if len(foodDataList) > 0 { failedFoodList, err2 := api.MtwmAPI.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList) if err = err2; err == nil { if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil { - failedList = putils.SelectStoreSynSkuByFoodList(storeSkuList, failedFoodList) + failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList) // successList = putils.UnselectStoreSkuSyncListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) } } diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index daef26e6f..c974c32d8 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -237,47 +237,40 @@ func UnselectStoreSkuListByVendorSkuIDs(storeSkuList []*partner.StoreSkuInfo, ve } //美团api返回 -func SelectStoreSkuListByFoodList(storeSkuList []*partner.StoreSkuInfo, foodList []*mtwmapi.AppFoodResult) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { +func SelectStoreSkuListByFoodList(storeSkuList interface{}, foodList []*mtwmapi.AppFoodResult) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { 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 := &partner.StoreSkuInfoWithErr{ - StoreSkuInfo: v, - ErrMsg: foodMap[v.VendorSkuID], + if storeSkuLists, ok := storeSkuList.([]*partner.StoreSkuInfo); ok { + for _, v := range storeSkuLists { + if foodMap[v.VendorSkuID] != "" { + foodFailed := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: v, + ErrMsg: foodMap[v.VendorSkuID], + } + selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) } - selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) } } - } - return selectedStoreSkuList -} - -//美团api返回 -func SelectStoreSynSkuByFoodList(storeSkuList []*dao.StoreSkuSyncInfo, foodList []*mtwmapi.AppFoodResult) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { - 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] != "" { - storeSkuInfo := &partner.StoreSkuInfo{ - SkuID: v.SkuID, - VendorSkuID: v.VendorSkuID, - NameID: v.NameID, - VendorNameID: v.VendorNameID, - VendorPrice: v.VendorPrice, - Status: v.Status, + if storeSkuLists, ok := storeSkuList.([]*dao.StoreSkuSyncInfo); ok { + for _, v := range storeSkuLists { + if foodMap[v.VendorSkuID] != "" { + storeSkuInfo := &partner.StoreSkuInfo{ + SkuID: v.SkuID, + VendorSkuID: v.VendorSkuID, + NameID: v.NameID, + VendorNameID: v.VendorNameID, + VendorPrice: v.VendorPrice, + Status: v.Status, + } + foodFailed := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: storeSkuInfo, + ErrMsg: foodMap[v.VendorSkuID], + } + selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) } - foodFailed := &partner.StoreSkuInfoWithErr{ - StoreSkuInfo: storeSkuInfo, - ErrMsg: foodMap[v.VendorSkuID], - } - selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) } } } @@ -326,35 +319,31 @@ func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, resp return selectedStoreSkuList } -func GetErrMsg2FailedSingleList(storeSkuList []*partner.StoreSkuInfo, err error) (failedList []*partner.StoreSkuInfoWithErr) { +func GetErrMsg2FailedSingleList(storeSkuList interface{}, err error) (failedList []*partner.StoreSkuInfoWithErr) { if err != nil { if errExt, ok := err.(*utils.ErrorWithCode); ok { - storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{ - StoreSkuInfo: storeSkuList[0], - ErrMsg: errExt.ErrMsg(), + if storeSkuLists, ok := storeSkuList.([]*partner.StoreSkuInfo); ok { + storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: storeSkuLists[0], + ErrMsg: errExt.ErrMsg(), + } + failedList = append(failedList, storeSkuInfoWithErr) } - failedList = append(failedList, storeSkuInfoWithErr) - } - } - 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, + if storeSkuLists, ok := storeSkuList.([]*dao.StoreSkuSyncInfo); ok { + storeSkuInfo := &partner.StoreSkuInfo{ + SkuID: storeSkuLists[0].SkuID, + VendorSkuID: storeSkuLists[0].VendorSkuID, + NameID: storeSkuLists[0].NameID, + VendorNameID: storeSkuLists[0].VendorNameID, + VendorPrice: storeSkuLists[0].VendorPrice, + Status: storeSkuLists[0].Status, + } + storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: storeSkuInfo, + ErrMsg: errExt.ErrMsg(), + } + failedList = append(failedList, storeSkuInfoWithErr) } - storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{ - StoreSkuInfo: storeSkuInfo, - ErrMsg: errExt.ErrMsg(), - } - failedList = append(failedList, storeSkuInfoWithErr) } } return failedList From 6d677bab43055cd0ac318866b88d6d72bc7377ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 4 Dec 2019 17:34:45 +0800 Subject: [PATCH 21/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 11 ++++++++- business/jxstore/cms/sync_store_sku.go | 2 +- business/partner/purchase/ebai/store_sku2.go | 20 +++++++-------- business/partner/purchase/jd/store_sku2.go | 10 ++++---- business/partner/purchase/mtwm/store_sku2.go | 20 +++++++++------ business/partner/putils/store_sku.go | 26 +++++++++++++++++--- 6 files changed, 61 insertions(+), 28 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 569f77b57..d15797789 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -23,9 +23,12 @@ import ( type SyncErrResult struct { SkuID int `json:"商品ID"` + StoreID int `json:"门店ID"` + VendorID int `json:"平台ID"` VendorSkuID string `json:"平台商品ID"` NameID int `json:"商品nameID"` VendorPrice int64 `json:"平台价"` + SyncType string `json:"同步类型"` ErrMsg string `json:"错误信息"` } @@ -71,9 +74,12 @@ var ( ErrEntityNotExist = errors.New("找不到相应实体") SyncErrResultTitle = []string{ "商品ID", + "门店ID", + "平台ID", "平台商品ID", "商品nameID", "平台价", + "同步类型", "错误信息", } syncErrResultLock SyncErrResultLock @@ -760,9 +766,12 @@ func WirteToExcelBySyncFailed(task tasksch.ITask, ctx *jxcontext.Context) (err e for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { result := SyncErrResult{ SkuID: vv.StoreSkuInfo.SkuID, + StoreID: vv.StoreID, + VendorID: vv.VendoreID, VendorSkuID: vv.StoreSkuInfo.VendorSkuID, NameID: vv.StoreSkuInfo.NameID, VendorPrice: vv.StoreSkuInfo.VendorPrice, + SyncType: vv.SyncType, ErrMsg: vv.ErrMsg, } syncErrResultLock.AppendData(result) @@ -775,7 +784,7 @@ func WirteToExcelBySyncFailed(task tasksch.ITask, ctx *jxcontext.Context) (err e } sheetList1 = append(sheetList1, excelConf1) if excelConf1 != nil { - downloadURL1, fileName1, err = jxutils.UploadExeclAndPushMsg(sheetList1, time.Now().Format("2006-01-02")+"同步错误返回") + downloadURL1, fileName1, err = jxutils.UploadExeclAndPushMsg(sheetList1, time.Now().Format("200601021504")+"同步错误返回") baseapi.SugarLogger.Debug("WriteToExcel: download is [%v]", downloadURL1) } else { baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!") diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 4325933bb..66b986641 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -485,7 +485,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo updateList = append(updateList, calVendorPrice4StoreSku(batchedStoreSkuList[0], storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))) err = nil } else { - failedList = append(failedList, putils.GetErrMsg2FailedSingleList(batchedStoreSkuList, err2)...) + failedList = append(failedList, putils.GetErrMsg2FailedSingleList(batchedStoreSkuList, err2, storeID, vendorID, "查询是否有该商品")...) } if len(failedList) > 0 { task.AddErrMsg(failedList) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 22cfc8386..f6e60ee80 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -120,7 +120,7 @@ func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, v if globals.EnableEbaiStoreWrite { _, err = api.EbaiAPI.SkuUpdate(ctx.GetTrackInfo(), strStoreID, utils.Str2Int64(storeSku.VendorSkuID), params) if err != nil { - failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDEBAI, "更新商品基础信息") } utils.CallFuncAsync(func() { api.EbaiAPI.SkuShopCategoryMap(strStoreID, utils.Str2Int64(storeSku.VendorSkuID), "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku)) @@ -141,7 +141,7 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v api.EbaiAPI.SkuShopCategoryMap(strStoreID, vendorSkuID, "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku)) }) } else { - failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDEBAI, "创建商品") } } else { vendorSkuID = jxutils.GenFakeID() @@ -164,7 +164,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v opResult, err2 := api.EbaiAPI.SkuDelete(ctx.GetTrackInfo(), utils.Int2Str(storeID), partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDIntList(), nil) if err = err2; err2 != nil && opResult != nil { // if len(storeSkuList) > len(opResult.FailedList) { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult) + failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "删除商品") // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) // } } @@ -181,7 +181,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID opResult, err = api.EbaiAPI.SkuOnline(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs, nil, nil) } else if len(vendorSkuIDs) == 1 { err = api.EbaiAPI.SkuOnlineOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs[0], "", "") - failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDEBAI, "更新商品状态") return failedList, err } } else { @@ -189,12 +189,12 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID opResult, err = api.EbaiAPI.SkuOffline(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs, nil, nil) } else if len(vendorSkuIDs) == 1 { err = api.EbaiAPI.SkuOfflineOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs[0], "", "") - failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDEBAI, "更新商品状态") return failedList, err } } if err != nil && opResult != nil { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult) + failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品状态") // failedList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) } } @@ -219,12 +219,12 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i 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 { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult) + failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品价格") } } else if len(storeSkuList) == 1 { opResult2, err := api.EbaiAPI.SkuPriceUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0]) if err != nil && opResult2 != nil { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult2) + failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult2, storeID, model.VendorIDEBAI, "更新商品价格") } } } @@ -236,12 +236,12 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i if len(storeSkuList) > 1 { opResult, err2 := api.EbaiAPI.SkuStockUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID) if err = err2; err != nil && opResult != nil { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult) + failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品库存") // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) } } else if len(storeSkuList) == 1 { err = api.EbaiAPI.SkuStockUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0]) - failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDEBAI, "更新商品库存") } } return failedList, err diff --git a/business/partner/purchase/jd/store_sku2.go b/business/partner/purchase/jd/store_sku2.go index 2c092b000..ef9fd0c32 100644 --- a/business/partner/purchase/jd/store_sku2.go +++ b/business/partner/purchase/jd/store_sku2.go @@ -122,7 +122,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID if globals.EnableJdStoreWrite { responseList, err2 := getAPI("").BatchUpdateVendibility(ctx.GetTrackInfo(), "", vendorStoreID, skuVendibilityList, ctx.GetUserName()) if err = err2; isErrPartialFailed(err) { - failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList) + failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品状态") // successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false))) } } @@ -133,7 +133,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i if len(storeSkuList) == 1 { if globals.EnableJdStoreWrite { _, err = getAPI("").UpdateStationPrice(ctx.GetTrackInfo(), utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), vendorStoreID, int(storeSkuList[0].VendorPrice)) - failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDJD, "更新商品价格") } } else { var skuPriceInfoList []*jdapi.SkuPriceInfo @@ -146,7 +146,7 @@ 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) { - failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList) + failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品价格") } } } @@ -157,7 +157,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i if len(storeSkuList) == 1 { if globals.EnableJdStoreWrite { err = getAPI("").UpdateCurrentQty(ctx.GetTrackInfo(), vendorStoreID, utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), storeSkuList[0].Stock) - failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDJD, "更新商品库存") } } else { var skuStockList []*jdapi.SkuStock @@ -170,7 +170,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i if globals.EnableJdStoreWrite { responseList, err2 := getAPI("").BatchUpdateCurrentQtys(ctx.GetTrackInfo(), "", vendorStoreID, skuStockList, ctx.GetUserName()) if err = err2; isErrPartialFailed(err) { - failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList) + failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品库存") // successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false))) } } diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index 479b187a9..97d5e98ea 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -234,7 +234,13 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v // 对于多门店平台来说,storeSkuList中只有SkuID与VendorSkuID有意义 func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo, isCreate bool) (failedList []*partner.StoreSkuInfoWithErr, err error) { + var syncType string foodDataList := make([]map[string]interface{}, len(storeSkuList)) + if isCreate { + syncType = "创建商品" + } else { + syncType = "更新商品" + } for i, storeSku := range storeSkuList { isNeedUpdatePrice := isCreate //storeSku.StoreSkuSyncStatus&( model.SyncFlagPriceMask| model.SyncFlagNewMask) != 0 foodData := make(map[string]interface{}) @@ -294,12 +300,12 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI if len(foodDataList) == 1 { foodDataList[0]["skus"] = string(utils.MustMarshal(foodDataList[0]["skus"])) err = api.MtwmAPI.RetailInitData(ctx.GetTrackInfo(), vendorStoreID, utils.Int2Str(storeSkuList[0].SkuID), foodDataList[0]) - failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDMTWM, syncType) } else if len(foodDataList) > 0 { failedFoodList, err2 := api.MtwmAPI.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList) if err = err2; err == nil { if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil { - failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList) + failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, syncType) // successList = putils.UnselectStoreSkuSyncListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) } } @@ -325,7 +331,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v if globals.EnableMtwmStoreWrite { if len(storeSkuList) == 1 { err = api.MtwmAPI.RetailDelete(ctx.GetTrackInfo(), vendorStoreID, storeSkuList[0].VendorSkuID) - failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err) + failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDMTWM, "删除商品") } else { // todo 部分失败 err = api.MtwmAPI.RetailCatSkuBatchDelete2(ctx.GetTrackInfo(), vendorStoreID, nil, nil, nil, nil, partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDList()) @@ -333,7 +339,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v if errExt, ok := err.(*utils.ErrorWithCode); ok { myMap := make(map[string][]*mtwmapi.AppFoodResult) json.Unmarshal([]byte(errExt.ErrMsg()), &myMap) - failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, myMap["retail_error_list"]) + failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, myMap["retail_error_list"], storeID, model.VendorIDMTWM, "批量删除商品") } } } @@ -374,7 +380,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID failedFoodList, err2 := api.MtwmAPI.RetailSellStatus(ctx.GetTrackInfo(), vendorStoreID, skuList, mtwmStatus) if err = err2; err == nil { if len(failedFoodList) > 0 { - failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList) + failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品状态") // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) } } @@ -388,7 +394,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i failedFoodList, err2 := api.MtwmAPI.RetailSkuPrice(ctx.GetTrackInfo(), vendorStoreID, priceList) if err = err2; err == nil { if len(failedFoodList) > 0 { - failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList) + failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品价格") } } } @@ -401,7 +407,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i failedFoodList, err2 := api.MtwmAPI.RetailSkuStock(ctx.GetTrackInfo(), vendorStoreID, stockList) if err = err2; err == nil { if len(failedFoodList) > 0 { - failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList) + failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品库存") } // if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil { // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index c974c32d8..ec57c16c3 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -237,7 +237,7 @@ func UnselectStoreSkuListByVendorSkuIDs(storeSkuList []*partner.StoreSkuInfo, ve } //美团api返回 -func SelectStoreSkuListByFoodList(storeSkuList interface{}, foodList []*mtwmapi.AppFoodResult) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { +func SelectStoreSkuListByFoodList(storeSkuList interface{}, foodList []*mtwmapi.AppFoodResult, storeID, vendorID int, syncType string) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { foodMap := make(map[string]string) if len(foodList) > 0 { for _, v := range foodList { @@ -249,6 +249,9 @@ func SelectStoreSkuListByFoodList(storeSkuList interface{}, foodList []*mtwmapi. foodFailed := &partner.StoreSkuInfoWithErr{ StoreSkuInfo: v, ErrMsg: foodMap[v.VendorSkuID], + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, } selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) } @@ -268,6 +271,9 @@ func SelectStoreSkuListByFoodList(storeSkuList interface{}, foodList []*mtwmapi. foodFailed := &partner.StoreSkuInfoWithErr{ StoreSkuInfo: storeSkuInfo, ErrMsg: foodMap[v.VendorSkuID], + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, } selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) } @@ -278,7 +284,7 @@ func SelectStoreSkuListByFoodList(storeSkuList interface{}, foodList []*mtwmapi. } //饿百api返回 -func SelectStoreSkuListByOpResult(storeSkuList []*partner.StoreSkuInfo, opResult *ebaiapi.BatchOpResult) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { +func SelectStoreSkuListByOpResult(storeSkuList []*partner.StoreSkuInfo, opResult *ebaiapi.BatchOpResult, storeID, vendorID int, syncType string) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { opResultMap := make(map[int64]string) if len(opResult.FailedList) > 0 { for _, v := range opResult.FailedList { @@ -289,6 +295,9 @@ func SelectStoreSkuListByOpResult(storeSkuList []*partner.StoreSkuInfo, opResult opFailed := &partner.StoreSkuInfoWithErr{ StoreSkuInfo: v, ErrMsg: opResultMap[utils.Str2Int64(v.VendorSkuID)], + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, } selectedStoreSkuList = append(selectedStoreSkuList, opFailed) } @@ -298,7 +307,7 @@ func SelectStoreSkuListByOpResult(storeSkuList []*partner.StoreSkuInfo, opResult } //京东api返回 -func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, responseList []*jdapi.StoreSkuBatchUpdateResponse) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { +func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, responseList []*jdapi.StoreSkuBatchUpdateResponse, storeID, vendorID int, syncType string) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { responseMap := make(map[string]string) if len(responseList) > 0 { for _, v := range responseList { @@ -311,6 +320,9 @@ func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, resp respFailed := &partner.StoreSkuInfoWithErr{ StoreSkuInfo: v, ErrMsg: responseMap[utils.Int2Str(v.SkuID)], + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, } selectedStoreSkuList = append(selectedStoreSkuList, respFailed) } @@ -319,13 +331,16 @@ func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, resp return selectedStoreSkuList } -func GetErrMsg2FailedSingleList(storeSkuList interface{}, err error) (failedList []*partner.StoreSkuInfoWithErr) { +func GetErrMsg2FailedSingleList(storeSkuList interface{}, err error, storeID, vendorID int, syncType string) (failedList []*partner.StoreSkuInfoWithErr) { if err != nil { if errExt, ok := err.(*utils.ErrorWithCode); ok { if storeSkuLists, ok := storeSkuList.([]*partner.StoreSkuInfo); ok { storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{ StoreSkuInfo: storeSkuLists[0], ErrMsg: errExt.ErrMsg(), + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, } failedList = append(failedList, storeSkuInfoWithErr) } @@ -341,6 +356,9 @@ func GetErrMsg2FailedSingleList(storeSkuList interface{}, err error) (failedList storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{ StoreSkuInfo: storeSkuInfo, ErrMsg: errExt.ErrMsg(), + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, } failedList = append(failedList, storeSkuInfoWithErr) } From a3cbbd46c60e5d72cb0a796d8d36ac9b65f3b19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 12 Dec 2019 18:21:47 +0800 Subject: [PATCH 22/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=86=B2=E7=AA=81=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 2 ++ business/partner/purchase/ebai/store_sku2.go | 6 +++--- business/partner/purchase/jd/store_sku2.go | 2 +- business/partner/purchase/mtwm/store_sku2.go | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 4f524d104..d89090bc0 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -557,6 +557,8 @@ func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int, jxSkuInfoDataSingle := &dao.StoreSkuNamesInfo{} jxSkuInfoDataMulti := &dao.StoreSkuNamesInfo{} if jxStoreInfoListValue.StoreMaps != nil { + var multiFlag = false + var singleFlag = false var filterJxSkuInfoMapSingle map[int]*dao.StoreSkuNameExt var filterJxSkuInfoMapMulti map[int]*dao.StoreSkuNameExt for _, vendorListValue := range jxStoreInfoListValue.StoreMaps { diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 469fcb748..f11d4d038 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -172,7 +172,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v return failedList, err } -func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) { vendorSkuIDs := partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDIntList() if globals.EnableEbaiStoreWrite { var opResult *ebaiapi.BatchOpResult @@ -214,7 +214,7 @@ func StoreSkuInfoList2Ebai(storeSkuList []*partner.StoreSkuInfo) (outList ebaiap return outList } -func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { if globals.EnableEbaiStoreWrite { if len(storeSkuList) > 1 { opResult, err2 := api.EbaiAPI.SkuPriceUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID) @@ -231,7 +231,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrg return failedList, err } -func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { if globals.EnableEbaiStoreWrite { if len(storeSkuList) > 1 { opResult, err2 := api.EbaiAPI.SkuStockUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID) diff --git a/business/partner/purchase/jd/store_sku2.go b/business/partner/purchase/jd/store_sku2.go index 1688fb913..fbb96f51f 100644 --- a/business/partner/purchase/jd/store_sku2.go +++ b/business/partner/purchase/jd/store_sku2.go @@ -110,7 +110,7 @@ func getStrOutSkuIDs(l []*jdapi.StoreSkuBatchUpdateResponse, isSuccess bool) (ou return outSkuIDs } -func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) { var skuVendibilityList []*jdapi.StockVendibility jdStatus := jxStoreSkuStatus2Jd(status) for _, v := range storeSkuList { diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index 3b33f2c9b..a1c8ee428 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -373,7 +373,7 @@ func storeSku2Mtwm(storeSkuList []*partner.StoreSkuInfo, updateType int) (skuLis return skuList } -func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) { skuList := storeSku2Mtwm(storeSkuList, updateTypeStatus) mtwmStatus := skuStatusJX2Mtwm(status) if globals.EnableMtwmStoreWrite { @@ -388,7 +388,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr return failedList, err } -func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { priceList := storeSku2Mtwm(storeSkuList, updateTypePrice) if globals.EnableMtwmStoreWrite { failedFoodList, err2 := api.MtwmAPI.RetailSkuPrice(ctx.GetTrackInfo(), vendorStoreID, priceList) @@ -401,7 +401,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrg return failedList, err } -func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) { +func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { stockList := storeSku2Mtwm(storeSkuList, updateTypeStock) if globals.EnableMtwmStoreWrite { failedFoodList, err2 := api.MtwmAPI.RetailSkuStock(ctx.GetTrackInfo(), vendorStoreID, stockList) From 8278de023d7644105df1b8fa7cfdce62f75ceb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 12 Dec 2019 18:32:46 +0800 Subject: [PATCH 23/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=86=B2=E7=AA=81=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 5 ++--- business/jxstore/cms/sync.go | 12 ------------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index d89090bc0..c64fa5bd8 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -563,16 +563,15 @@ func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int, var filterJxSkuInfoMapMulti map[int]*dao.StoreSkuNameExt for _, vendorListValue := range jxStoreInfoListValue.StoreMaps { vendorID := vendorListValue.VendorID - var flag = false if partner.IsMultiStore(vendorID) { if multiFlag == false { - jxSkuInfoDataMulti, _ := GetStoreSkus(ctx, storeID, filterJxDepotUnSaleSkuIds, true, "", true, false, map[string]interface{}{}, 0, -1) + jxSkuInfoDataMulti, _ = GetStoreSkus(ctx, storeID, filterJxDepotUnSaleSkuIds, true, "", true, false, map[string]interface{}{}, 0, -1) filterJxSkuInfoMapMulti = GetFilterJxSkuInfoMap(jxSkuInfoDataMulti.SkuNames) //map[京西商品ID:StoreSkuNameExt] multiFlag = true } } else { if singleFlag == false { - jxSkuInfoDataSingle, _ := GetStoreSkus(ctx, storeID, []int{}, true, "", true, false, map[string]interface{}{}, 0, -1) + jxSkuInfoDataSingle, _ = GetStoreSkus(ctx, storeID, []int{}, true, "", true, false, map[string]interface{}{}, 0, -1) filterJxSkuInfoMapSingle = GetFilterJxSkuInfoMap(jxSkuInfoDataSingle.SkuNames) //map[京西商品ID:StoreSkuNameExt] singleFlag = true } diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index de67b3528..49a8579ef 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -803,15 +803,3 @@ func (d *SyncErrResultLock) AppendData(syncErrResult SyncErrResult) { defer d.locker.Unlock() d.syncErrResult = append(d.syncErrResult, syncErrResult) } - -func OnCreateThing(db *dao.DaoDB, thingID int64, thingType int8) (err error) { - return err -} - -func OnUpdateThing(db *dao.DaoDB, thingID int64, thingType int8) (err error) { - return err -} - -func OnDeleteThing(db *dao.DaoDB, thingID int64, thingType int8) (err error) { - return err -} From 540209eadc556690eb7e3aaa99c3c79d7688c408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 7 Jan 2020 14:20:56 +0800 Subject: [PATCH 24/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index adefdb036..b0775f60b 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -625,9 +625,15 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID]) } task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList) - task.SetFinishHook(func(task tasksch.ITask, ctx *jxcontext.Context) { - err = WirteToExcelBySyncFailed(task, ctx) - }) + if isAsync { + task.SetFinishHook(func(task tasksch.ITask, ctx *jxcontext.Context) { + if len(task.GetErrMsg()) > 10 { + err = WirteToExcelBySyncFailed(task, ctx) + } else { + err = errors.New(utils.Format4Output(task.GetErrMsg(), true)) + } + }) + } tasksch.HandleTask(task, nil, isManageIt).Run() if !isAsync { resultList, err2 := task.GetResult(0) From 6c935643aeabe0df430a28beb8cbe0e99a6dff95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 7 Jan 2020 14:25:39 +0800 Subject: [PATCH 25/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index b0775f60b..486caec51 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -637,6 +637,9 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN tasksch.HandleTask(task, nil, isManageIt).Run() if !isAsync { resultList, err2 := task.GetResult(0) + if err2 != nil { + err2 = errors.New(utils.Format4Output(task.GetErrMsg(), true)) + } if err = err2; err == nil { if len(resultList) == 0 { hint = "1" // todo 暂时这样 From 68c9f17d73d51888767e734a754e5f9c4e73ff11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 7 Jan 2020 14:37:24 +0800 Subject: [PATCH 26/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 486caec51..eb027b4bb 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -638,7 +638,24 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN if !isAsync { resultList, err2 := task.GetResult(0) if err2 != nil { - err2 = errors.New(utils.Format4Output(task.GetErrMsg(), true)) + var resultL []*SyncErrResult + failedList := task.GetErrMsg() + for _, v := range failedList { + for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { + result := &SyncErrResult{ + SkuID: vv.StoreSkuInfo.SkuID, + StoreID: vv.StoreID, + VendorID: vv.VendoreID, + VendorSkuID: vv.StoreSkuInfo.VendorSkuID, + NameID: vv.StoreSkuInfo.NameID, + VendorPrice: vv.StoreSkuInfo.VendorPrice, + SyncType: vv.SyncType, + ErrMsg: vv.ErrMsg, + } + resultL = append(resultL, result) + } + } + err2 = fmt.Errorf(utils.Format4Output(resultL, true)) } if err = err2; err == nil { if len(resultList) == 0 { From 617b361fbeda0643237086090ffcb40be68825b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 7 Jan 2020 14:43:50 +0800 Subject: [PATCH 27/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 43 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index eb027b4bb..a8161b48c 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -630,7 +630,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN if len(task.GetErrMsg()) > 10 { err = WirteToExcelBySyncFailed(task, ctx) } else { - err = errors.New(utils.Format4Output(task.GetErrMsg(), true)) + err = buildErrMsg(task) } }) } @@ -638,24 +638,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN if !isAsync { resultList, err2 := task.GetResult(0) if err2 != nil { - var resultL []*SyncErrResult - failedList := task.GetErrMsg() - for _, v := range failedList { - for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { - result := &SyncErrResult{ - SkuID: vv.StoreSkuInfo.SkuID, - StoreID: vv.StoreID, - VendorID: vv.VendoreID, - VendorSkuID: vv.StoreSkuInfo.VendorSkuID, - NameID: vv.StoreSkuInfo.NameID, - VendorPrice: vv.StoreSkuInfo.VendorPrice, - SyncType: vv.SyncType, - ErrMsg: vv.ErrMsg, - } - resultL = append(resultL, result) - } - } - err2 = fmt.Errorf(utils.Format4Output(resultL, true)) + err2 = buildErrMsg(task) } if err = err2; err == nil { if len(resultList) == 0 { @@ -670,6 +653,28 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN return task, hint, err } +func buildErrMsg(task tasksch.ITask) (err error) { + var resultL []*SyncErrResult + failedList := task.GetErrMsg() + for _, v := range failedList { + for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { + result := &SyncErrResult{ + SkuID: vv.StoreSkuInfo.SkuID, + StoreID: vv.StoreID, + VendorID: vv.VendoreID, + VendorSkuID: vv.StoreSkuInfo.VendorSkuID, + NameID: vv.StoreSkuInfo.NameID, + VendorPrice: vv.StoreSkuInfo.VendorPrice, + SyncType: vv.SyncType, + ErrMsg: vv.ErrMsg, + } + resultL = append(resultL, result) + } + } + err = fmt.Errorf(utils.Format4Output(resultL, true)) + return err +} + func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) { _, hint, err = v.LoopStoresMap2(ctx, db, taskName, isAsync, isManageIt, vendorIDs, storeIDs, false, handler, isContinueWhenError) return hint, err From e813e81ed8c891300119a77efcce933b529c43c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 7 Jan 2020 14:53:23 +0800 Subject: [PATCH 28/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index a8161b48c..d9c5e05da 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -629,6 +629,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN task.SetFinishHook(func(task tasksch.ITask, ctx *jxcontext.Context) { if len(task.GetErrMsg()) > 10 { err = WirteToExcelBySyncFailed(task, ctx) + err = buildErrMsg(task) } else { err = buildErrMsg(task) } From 86e783a4d02056f03e6cc46ae32002d0a56b61fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 7 Jan 2020 17:53:56 +0800 Subject: [PATCH 29/44] =?UTF-8?q?=E9=94=99=E8=AF=AF=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 15 ++++--- business/jxstore/cms/sync.go | 3 +- business/jxstore/cms/sync_store_sku.go | 22 ++++++---- business/jxutils/tasksch/task.go | 43 +++++++++++--------- business/model/error_code.go | 1 + business/partner/partner_store_sku.go | 7 ++-- business/partner/purchase/ebai/store_sku2.go | 21 +++++++--- business/partner/purchase/mtwm/store_sku2.go | 20 +++++---- business/partner/putils/store_sku.go | 14 +++++-- controllers/cms_store_sku.go | 12 +++--- 10 files changed, 99 insertions(+), 59 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 65bd5c91b..4be6a123c 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -775,22 +775,22 @@ func asyncStoreSkuOpFilter(ctx *jxcontext.Context, isAsync bool) bool { return isAsync } -func UpdateStoreSku(ctx *jxcontext.Context, storeID int, skuBindInfo *StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) { +func UpdateStoreSku(ctx *jxcontext.Context, storeID int, skuBindInfo *StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint, errCode string, err error) { return UpdateStoreSkus(ctx, storeID, []*StoreSkuBindInfo{skuBindInfo}, isAsync, isContinueWhenError) } -func UpdateStoreSkus(ctx *jxcontext.Context, storeID int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) { +func UpdateStoreSkus(ctx *jxcontext.Context, storeID int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint, errCode string, err error) { return UpdateStoresSkus(ctx, []int{storeID}, skuBindInfos, false, isAsync, isContinueWhenError) } -func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isAsync, isContinueWhenError bool) (hint string, err error) { +func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isAsync, isContinueWhenError bool) (hint, errCode string, err error) { globals.SugarLogger.Debugf("UpdateStoresSkus:%s, storeIDs:%v, skuBindInfos:%s", ctx.GetTrackInfo(), storeIDs, utils.Format4Output(skuBindInfos, true)) var num int64 db := dao.GetDB() skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos, isScale) if err != nil { - return "", err + return "", "", err } isAsync = asyncStoreSkuOpFilter(ctx, isAsync) num = int64(len(skuIDs)) @@ -800,7 +800,10 @@ func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*St if num == 0 || !isAsync || hint == "" { hint = utils.Int64ToStr(num) } - return hint, err + if _, ok := err.(*SyncError); ok { + return hint, model.ErrCodeJsonSyncErr, err + } + return hint, "", err } func UpdateStoresSkusByBind(ctx *jxcontext.Context, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) { @@ -1693,7 +1696,7 @@ func AcceptStoreOpRequests(ctx *jxcontext.Context, reqIDs []int) (err error) { } } if err2 == nil { - _, err2 := UpdateStoresSkus(ctx, []int{op.StoreID}, []*StoreSkuBindInfo{skuBindInfo}, false, false, false) + _, _, err2 := UpdateStoresSkus(ctx, []int{op.StoreID}, []*StoreSkuBindInfo{skuBindInfo}, false, false, false) isLocalSucess := true if err2 != nil { subErrors[reqID] = err2 diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index d9c5e05da..1b15dd9ed 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -629,7 +629,6 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN task.SetFinishHook(func(task tasksch.ITask, ctx *jxcontext.Context) { if len(task.GetErrMsg()) > 10 { err = WirteToExcelBySyncFailed(task, ctx) - err = buildErrMsg(task) } else { err = buildErrMsg(task) } @@ -673,7 +672,7 @@ func buildErrMsg(task tasksch.ITask) (err error) { } } err = fmt.Errorf(utils.Format4Output(resultL, true)) - return err + return makeSyncError(err) } func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) { diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index d5c36bd27..170809ab1 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -80,15 +80,16 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo catInfo := batchItemList[0].(*dao.SkuStoreCatInfo) storeCatMap := &model.StoreSkuCategoryMap{} storeCatMap.ID = catInfo.MapID + var failedList []*partner.StoreSkuInfoWithErr if model.IsSyncStatusDelete(catInfo.CatSyncStatus) { // 删除 if model.IsSyncStatusDelete(catInfo.CatSyncStatus) && !dao.IsVendorThingIDEmpty(catInfo.VendorCatID) { - err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID, level) + failedList, err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID, level) if err != nil && handler.IsErrCategoryNotExist(err) { err = nil } } } else if model.IsSyncStatusNew(catInfo.CatSyncStatus) { // 新增 - err = handler.CreateStoreCategory(ctx, storeID, vendorStoreID, catInfo) + failedList, err = handler.CreateStoreCategory(ctx, storeID, vendorStoreID, catInfo) if err != nil && handler.IsErrCategoryExist(err) { if cat, err2 := handler.GetStoreCategory(ctx, storeID, vendorStoreID, catInfo.Name); err2 == nil { catInfo.VendorCatID = cat.VendorCatID @@ -103,10 +104,17 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo } } } else if model.IsSyncStatusUpdate(catInfo.CatSyncStatus) { // 修改 - if err = handler.UpdateStoreCategory(ctx, storeID, vendorStoreID, catInfo); err == nil { + failedList, err = handler.UpdateStoreCategory(ctx, storeID, vendorStoreID, catInfo) + if err == nil { updateFields = append(updateFields, idFieldName) } } + if len(failedList) > 0 { + for _, v := range failedList { + v.CategoryName = catInfo.Name + } + task.AddErrMsg(failedList) + } if err == nil { if vendorID == model.VendorIDMTWM { refutil.SetObjFieldByName(storeCatMap, idFieldName, catInfo.VendorCatID) @@ -548,7 +556,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo if len(list) > 0 { _, err = putils.FreeBatchStoreSkuInfo("更新门店商品库存", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { var failedList []*partner.StoreSkuInfoWithErr - failedList, err = storeSkuHandler.UpdateStoreSkusStock(ctx,storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList) + failedList, err = storeSkuHandler.UpdateStoreSkusStock(ctx, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList) if len(failedList) > 0 { task.AddErrMsg(failedList) } @@ -572,7 +580,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo if len(statusList) > 0 { _, err = putils.FreeBatchStoreSkuInfo(name, func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { var failedList []*partner.StoreSkuInfoWithErr - failedList, err = storeSkuHandler.UpdateStoreSkusStatus(ctx, storeDetail.VendorOrgCode,storeID, vendorStoreID, batchedStoreSkuList, status) + failedList, err = storeSkuHandler.UpdateStoreSkusStatus(ctx, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList, status) if len(failedList) > 0 { task.AddErrMsg(failedList) } @@ -587,7 +595,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo if len(priceList) > 0 { _, err = putils.FreeBatchStoreSkuInfo("更新门店商品价格", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { var failedList []*partner.StoreSkuInfoWithErr - failedList, err = storeSkuHandler.UpdateStoreSkusPrice(ctx, storeDetail.VendorOrgCode,storeID, vendorStoreID, batchedStoreSkuList) + failedList, err = storeSkuHandler.UpdateStoreSkusPrice(ctx, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList) if len(failedList) > 0 { task.AddErrMsg(failedList) } @@ -789,7 +797,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v task4Delete := tasksch.NewParallelTask(fmt.Sprintf("删除商家分类,level:%d", level), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { cat := batchItemList[0].(*partner.BareCategoryInfo) - err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, cat.VendorCatID, level) + _, err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, cat.VendorCatID, level) return nil, err }, levelCat2Delete) tasksch.HandleTask(task4Delete, task, true).Run() diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index b7e2f643e..f8325d333 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -449,31 +449,36 @@ func (t *BaseTask) run(taskHandler func()) { } } close(t.finishChan) - time.Sleep(10 * time.Millisecond) // 等待GetResult中的isGetResultCalled赋值 - globals.SugarLogger.Debugf("BaseTask task ID:%s, name:%s finished, isGetResultCalled:%t", t.ID, t.Name, t.isGetResultCalled) - if !t.isGetResultCalled && t.parent == nil && len(GetTasks(t.ID, TaskStatusBegin, TaskStatusEnd, 24, "")) > 0 { - if authInfo, err := t.ctx.GetV2AuthInfo(); err == nil { // 这里应该是不管登录类型,直接以可能的方式发消息 - var content string - taskDesc := fmt.Sprintf("你的异步任务[%s],ID[%s],开始于:%s,结束于:%s,", t.Name, t.ID, utils.Time2Str(t.CreatedAt), utils.Time2Str(t.TerminatedAt)) - content = fmt.Sprintf("%s执行%s", taskDesc, TaskStatusName[t.Status]) - if t.Error() == "" { - noticeMsg := t.GetNoticeMsg() - if noticeMsg != "" { - content += ",通知消息:" + noticeMsg - } - } else { - content += ",\n" + t.Error() - } - ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content) - } - } if t.finishHook != nil { - t.finishHook(t,t.ctx) + t.finishHook(t, t.ctx) + } else { + SendMessage(t) } }) } } +func SendMessage(t *BaseTask) { + time.Sleep(10 * time.Millisecond) // 等待GetResult中的isGetResultCalled赋值 + globals.SugarLogger.Debugf("BaseTask task ID:%s, name:%s finished, isGetResultCalled:%t", t.ID, t.Name, t.isGetResultCalled) + if !t.isGetResultCalled && t.parent == nil && len(GetTasks(t.ID, TaskStatusBegin, TaskStatusEnd, 24, "")) > 0 { + if authInfo, err := t.ctx.GetV2AuthInfo(); err == nil { // 这里应该是不管登录类型,直接以可能的方式发消息 + var content string + taskDesc := fmt.Sprintf("你的异步任务[%s],ID[%s],开始于:%s,结束于:%s,", t.Name, t.ID, utils.Time2Str(t.CreatedAt), utils.Time2Str(t.TerminatedAt)) + content = fmt.Sprintf("%s执行%s", taskDesc, TaskStatusName[t.Status]) + if t.Error() == "" { + noticeMsg := t.GetNoticeMsg() + if noticeMsg != "" { + content += ",通知消息:" + noticeMsg + } + } else { + content += ",\n" + t.Error() + } + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content) + } + } +} + // successCount表示在返回错误的情况下,(部分)成功的个数,如果没有返回错误,则successCount无意义 func (t *BaseTask) finishedOneJob(itemCount, successCount int, err error) { t.locker.Lock() diff --git a/business/model/error_code.go b/business/model/error_code.go index 70a49bcea..39ca69d95 100644 --- a/business/model/error_code.go +++ b/business/model/error_code.go @@ -16,6 +16,7 @@ const ( ErrCodeJsonActPriceTooLarger = "-102" // 这个错误号表示description中的是一个json对象,不是错误文本 ErrCodeJsonActEarningPriceIsZero = "-103" ErrCodeJsonUserAlreadyExist = "-104" // 用户已经存在错,且能成功登录 + ErrCodeJsonSyncErr = "-105" //同步错误 ) var ( diff --git a/business/partner/partner_store_sku.go b/business/partner/partner_store_sku.go index f3f61a19c..af8e78685 100644 --- a/business/partner/partner_store_sku.go +++ b/business/partner/partner_store_sku.go @@ -45,6 +45,7 @@ type StoreSkuInfo struct { type StoreSkuInfoWithErr struct { StoreSkuInfo *StoreSkuInfo + CategoryName string VendoreID int StoreID int SyncType string @@ -155,9 +156,9 @@ type ISingleStoreStoreSkuHandler interface { 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, level int) (err error) + CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*StoreSkuInfoWithErr, err error) + UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*StoreSkuInfoWithErr, err error) + DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (failedList []*StoreSkuInfoWithErr, err error) DeleteStoreAllCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, isContinueWhenError bool) (err error) IsErrCategoryExist(err error) (isExist bool) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 1ce4b10c2..3ec06a021 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -68,7 +68,7 @@ func (p *PurchaseHandler) IsErrCategoryNotExist(err error) (isNotExist bool) { return ebaiapi.IsErrCategoryNotExist(err) } -func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) { +func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { var vendorCatID int64 if globals.EnableEbaiStoreWrite { vendorCatID, err = api.EbaiAPI.ShopCategoryCreate(utils.Int2Str(storeID), utils.Str2Int64WithDefault(storeCat.ParentVendorCatID, 0), formatCatName(storeCat.Name), jxCatSeq2Ebai(storeCat.Seq)) @@ -76,10 +76,13 @@ func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID in vendorCatID = jxutils.GenFakeID() } storeCat.VendorCatID = utils.Int64ToStr(vendorCatID) - return err + if err != nil { + failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorIDEBAI, "创建分类") + } + return failedList, err } -func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) { +func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { if globals.EnableEbaiStoreWrite { err = api.EbaiAPI.ShopCategoryUpdate(utils.Int2Str(storeID), utils.Str2Int64WithDefault(storeCat.VendorCatID, 0), formatCatName(storeCat.Name), jxCatSeq2Ebai(storeCat.Seq)) // todo, 饿百将一个分类重复改名,也会报分类名重复错,特殊处理一下,不过因为GetStoreCategory其实会拉取所有的门店分类,是比较耗时的操作 @@ -90,15 +93,21 @@ func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID in } } } + if err != nil { + failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorIDEBAI, "修改分类") + } } - return err + return failedList, err } -func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error) { +func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (failedList []*partner.StoreSkuInfoWithErr, err error) { if globals.EnableEbaiStoreWrite { err = api.EbaiAPI.ShopCategoryDelete(utils.Int2Str(storeID), utils.Str2Int64WithDefault(vendorCatID, 0)) + if err != nil { + failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorIDEBAI, "删除分类") + } } - return err + return failedList, err } // 门店商品 diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index d17ca7a73..399786d41 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -102,7 +102,7 @@ func tryCatName2Code(originName string) (catCodeStr string) { return catCodeStr } -func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) { +func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { level := 1 if storeCat.ParentCatName != "" { level = 2 @@ -151,24 +151,27 @@ func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID in Sequence: storeCat.Seq, } err = api.MtwmAPI.RetailCatUpdate(vendorStoreID, catName, param4Update) + if err != nil { + failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorIDMTWM, "创建修改分类") + } if storeCat.CatSyncStatus&model.SyncFlagNewMask == 0 && // 修改分类名,但分类不存在 p.IsErrCategoryNotExist(err) && originName != "" { storeCat.CatSyncStatus |= model.SyncFlagNewMask - err = p.CreateStoreCategory(ctx, storeID, vendorStoreID, storeCat) + failedList, err = p.CreateStoreCategory(ctx, storeID, vendorStoreID, storeCat) } } if err == nil { // storeCat.VendorCatID = utils.FilterEmoji(storeCat.Name) storeCat.VendorCatID = utils.Int2Str(storeCat.ID) } - return err + return failedList, err } -func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) { +func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { return p.CreateStoreCategory(ctx, storeID, vendorStoreID, storeCat) } -func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error) { +func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (failedList []*partner.StoreSkuInfoWithErr, err error) { if false { if globals.EnableMtwmStoreWrite { err = api.MtwmAPI.RetailCatDelete(vendorStoreID, tryCatName2Code(vendorCatID), vendorCatID) @@ -184,9 +187,12 @@ func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID in } else { err = api.MtwmAPI.RetailCatSkuBatchDelete2(ctx.GetTrackInfo(), vendorStoreID, nil, nil, catCodes, []string{vendorCatID}, nil) } + if err != nil { + failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorIDMTWM, "删除分类") + } } } - return err + return failedList, err } // 门店商品 @@ -411,7 +417,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrg if len(failedFoodList) > 0 { failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品库存") } - // if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil { + //if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil { // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) // } } diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index 893295781..3877ce83b 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -64,7 +64,8 @@ func (p *DefSingleStorePlatform) DeleteStoreAllCategories(ctx *jxcontext.Context vendorCatIDs[k] = v.VendorCatID } err = FreeBatchCategoryIDOp(func(vendorCatID string) (err error) { - return p.DeleteStoreCategory(ctx, storeID, vendorStoreID, vendorCatID, step) + _, err2 := p.DeleteStoreCategory(ctx, storeID, vendorStoreID, vendorCatID, step) + return err2 }, ctx, task, vendorCatIDs, isContinueWhenError) return nil, err }, len(levelList)) @@ -343,8 +344,7 @@ func GetErrMsg2FailedSingleList(storeSkuList interface{}, err error, storeID, ve SyncType: syncType, } failedList = append(failedList, storeSkuInfoWithErr) - } - if storeSkuLists, ok := storeSkuList.([]*dao.StoreSkuSyncInfo); ok { + } else if storeSkuLists, ok := storeSkuList.([]*dao.StoreSkuSyncInfo); ok { storeSkuInfo := &partner.StoreSkuInfo{ SkuID: storeSkuLists[0].SkuID, VendorSkuID: storeSkuLists[0].VendorSkuID, @@ -361,6 +361,14 @@ func GetErrMsg2FailedSingleList(storeSkuList interface{}, err error, storeID, ve SyncType: syncType, } failedList = append(failedList, storeSkuInfoWithErr) + } else { + storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{ + ErrMsg: errExt.ErrMsg(), + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, + } + failedList = append(failedList, storeSkuInfoWithErr) } } } diff --git a/controllers/cms_store_sku.go b/controllers/cms_store_sku.go index dc1c5ae62..86a9ae216 100644 --- a/controllers/cms_store_sku.go +++ b/controllers/cms_store_sku.go @@ -151,9 +151,9 @@ func (c *StoreSkuController) UpdateStoreSku() { c.callUpdateStoreSku(func(params *tStoreSkuUpdateStoreSkuParams) (retVal interface{}, errCode string, err error) { var skuBindInfo cms.StoreSkuBindInfo if err = jxutils.Strings2Objs(params.Payload, &skuBindInfo); err == nil { - retVal, err = cms.UpdateStoreSku(params.Ctx, params.StoreID, &skuBindInfo, params.IsAsync, params.IsContinueWhenError) + retVal, errCode, err = cms.UpdateStoreSku(params.Ctx, params.StoreID, &skuBindInfo, params.IsAsync, params.IsContinueWhenError) } - return retVal, "", err + return retVal, errCode, err }) } @@ -171,9 +171,9 @@ func (c *StoreSkuController) UpdateStoreSkus() { c.callUpdateStoreSkus(func(params *tStoreSkuUpdateStoreSkusParams) (retVal interface{}, errCode string, err error) { var skuBindInfos []*cms.StoreSkuBindInfo if err = jxutils.Strings2Objs(params.Payload, &skuBindInfos); err == nil { - retVal, err = cms.UpdateStoreSkus(params.Ctx, params.StoreID, skuBindInfos, params.IsAsync, params.IsContinueWhenError) + retVal, errCode, err = cms.UpdateStoreSkus(params.Ctx, params.StoreID, skuBindInfos, params.IsAsync, params.IsContinueWhenError) } - return retVal, "", err + return retVal, errCode, err }) } @@ -219,8 +219,8 @@ func (c *StoreSkuController) UpdateStoresSkus() { if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.Payload, &skuBindInfos); err != nil { return retVal, "", err } - retVal, err = cms.UpdateStoresSkus(params.Ctx, storeIDs, skuBindInfos, params.IsScale, params.IsAsync, params.IsContinueWhenError) - return retVal, "", err + retVal, errCode, err = cms.UpdateStoresSkus(params.Ctx, storeIDs, skuBindInfos, params.IsScale, params.IsAsync, params.IsContinueWhenError) + return retVal, errCode, err }) } From e53df61baab56558e54483180408e85d24e11376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 7 Jan 2020 18:02:14 +0800 Subject: [PATCH 30/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 1b15dd9ed..ca75ec2bd 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -21,14 +21,15 @@ import ( ) type SyncErrResult struct { - SkuID int `json:"商品ID"` - StoreID int `json:"门店ID"` - VendorID int `json:"平台ID"` - VendorSkuID string `json:"平台商品ID"` - NameID int `json:"商品nameID"` - VendorPrice int64 `json:"平台价"` - SyncType string `json:"同步类型"` - ErrMsg string `json:"错误信息"` + SkuID int `json:"商品ID"` + CategoryName string `json:"分类名"` + StoreID int `json:"门店ID"` + VendorID int `json:"平台ID"` + VendorSkuID string `json:"平台商品ID"` + NameID int `json:"商品nameID"` + VendorPrice int64 `json:"平台价"` + SyncType string `json:"同步类型"` + ErrMsg string `json:"错误信息"` } type SyncErrResultLock struct { @@ -68,6 +69,7 @@ var ( ErrEntityNotExist = errors.New("找不到相应实体") SyncErrResultTitle = []string{ "商品ID", + "分类名", "门店ID", "平台ID", "平台商品ID", @@ -820,14 +822,15 @@ func WirteToExcelBySyncFailed(task tasksch.ITask, ctx *jxcontext.Context) (err e for _, v := range failedList { for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { result := SyncErrResult{ - SkuID: vv.StoreSkuInfo.SkuID, - StoreID: vv.StoreID, - VendorID: vv.VendoreID, - VendorSkuID: vv.StoreSkuInfo.VendorSkuID, - NameID: vv.StoreSkuInfo.NameID, - VendorPrice: vv.StoreSkuInfo.VendorPrice, - SyncType: vv.SyncType, - ErrMsg: vv.ErrMsg, + SkuID: vv.StoreSkuInfo.SkuID, + CategoryName: vv.CategoryName, + StoreID: vv.StoreID, + VendorID: vv.VendoreID, + VendorSkuID: vv.StoreSkuInfo.VendorSkuID, + NameID: vv.StoreSkuInfo.NameID, + VendorPrice: vv.StoreSkuInfo.VendorPrice, + SyncType: vv.SyncType, + ErrMsg: vv.ErrMsg, } syncErrResultLock.AppendData(result) } From c6c2febfd199f14e9e2777b4998b267ccaec1805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 7 Jan 2020 18:19:14 +0800 Subject: [PATCH 31/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index ca75ec2bd..705317fe5 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -674,7 +674,11 @@ func buildErrMsg(task tasksch.ITask) (err error) { } } err = fmt.Errorf(utils.Format4Output(resultL, true)) - return makeSyncError(err) + if err != nil { + return makeSyncError(err) + } else { + return err + } } func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) { From 28c75def4ee2946254154b869fee5aaa1a9ffe1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 7 Jan 2020 18:26:01 +0800 Subject: [PATCH 32/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 4be6a123c..e6e9f507b 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -800,8 +800,10 @@ func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*St if num == 0 || !isAsync || hint == "" { hint = utils.Int64ToStr(num) } - if _, ok := err.(*SyncError); ok { - return hint, model.ErrCodeJsonSyncErr, err + if err != nil { + if _, ok := err.(*SyncError); ok { + return hint, model.ErrCodeJsonSyncErr, err + } } return hint, "", err } From 4f4e6698e767280a6d8e3f5cbe60f20c2fcdfa0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 8 Jan 2020 09:09:32 +0800 Subject: [PATCH 33/44] tongbu --- business/jxstore/cms/sync.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 705317fe5..a0e6de2db 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -632,7 +632,9 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN if len(task.GetErrMsg()) > 10 { err = WirteToExcelBySyncFailed(task, ctx) } else { - err = buildErrMsg(task) + if err != nil { + err = buildErrMsg(task) + } } }) } @@ -674,11 +676,7 @@ func buildErrMsg(task tasksch.ITask) (err error) { } } err = fmt.Errorf(utils.Format4Output(resultL, true)) - if err != nil { - return makeSyncError(err) - } else { - return err - } + return err } func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) { From b22d880bdeac7551aed9e331fa4a2cc6a8c351e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 8 Jan 2020 10:02:56 +0800 Subject: [PATCH 34/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index a0e6de2db..aee98a6c2 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -663,20 +663,21 @@ func buildErrMsg(task tasksch.ITask) (err error) { for _, v := range failedList { for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { result := &SyncErrResult{ - SkuID: vv.StoreSkuInfo.SkuID, - StoreID: vv.StoreID, - VendorID: vv.VendoreID, - VendorSkuID: vv.StoreSkuInfo.VendorSkuID, - NameID: vv.StoreSkuInfo.NameID, - VendorPrice: vv.StoreSkuInfo.VendorPrice, - SyncType: vv.SyncType, - ErrMsg: vv.ErrMsg, + SkuID: vv.StoreSkuInfo.SkuID, + StoreID: vv.StoreID, + CategoryName: vv.CategoryName, + VendorID: vv.VendoreID, + VendorSkuID: vv.StoreSkuInfo.VendorSkuID, + NameID: vv.StoreSkuInfo.NameID, + VendorPrice: vv.StoreSkuInfo.VendorPrice, + SyncType: vv.SyncType, + ErrMsg: vv.ErrMsg, } resultL = append(resultL, result) } } err = fmt.Errorf(utils.Format4Output(resultL, true)) - return err + return makeSyncError(err) } func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) { From 2b3d7ce83a43334a4d0a6438e8654f85a2bc5d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 8 Jan 2020 15:35:53 +0800 Subject: [PATCH 35/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index aee98a6c2..435f5e65a 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -662,18 +662,28 @@ func buildErrMsg(task tasksch.ITask) (err error) { failedList := task.GetErrMsg() for _, v := range failedList { for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { - result := &SyncErrResult{ - SkuID: vv.StoreSkuInfo.SkuID, - StoreID: vv.StoreID, - CategoryName: vv.CategoryName, - VendorID: vv.VendoreID, - VendorSkuID: vv.StoreSkuInfo.VendorSkuID, - NameID: vv.StoreSkuInfo.NameID, - VendorPrice: vv.StoreSkuInfo.VendorPrice, - SyncType: vv.SyncType, - ErrMsg: vv.ErrMsg, + if vv.StoreSkuInfo != nil { + result := &SyncErrResult{ + SkuID: vv.StoreSkuInfo.SkuID, + StoreID: vv.StoreID, + VendorID: vv.VendoreID, + VendorSkuID: vv.StoreSkuInfo.VendorSkuID, + NameID: vv.StoreSkuInfo.NameID, + VendorPrice: vv.StoreSkuInfo.VendorPrice, + SyncType: vv.SyncType, + ErrMsg: vv.ErrMsg, + } + resultL = append(resultL, result) + } else { + result := &SyncErrResult{ + StoreID: vv.StoreID, + CategoryName: vv.CategoryName, + VendorID: vv.VendoreID, + SyncType: vv.SyncType, + ErrMsg: vv.ErrMsg, + } + resultL = append(resultL, result) } - resultL = append(resultL, result) } } err = fmt.Errorf(utils.Format4Output(resultL, true)) From 90513226e96385eaf052078f4f58ba8e9c15b2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 8 Jan 2020 15:50:55 +0800 Subject: [PATCH 36/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 5142c1edb..59c10855d 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -800,11 +800,6 @@ func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*St if num == 0 || !isAsync || hint == "" { hint = utils.Int64ToStr(num) } - if err != nil { - if _, ok := err.(*SyncError); ok { - return hint, model.ErrCodeJsonSyncErr, err - } - } return hint, "", err } From 19ab93ab1e9aa03fdd621051f890d4f62660c900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 8 Jan 2020 16:07:36 +0800 Subject: [PATCH 37/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 435f5e65a..7ca22d248 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -664,21 +664,26 @@ func buildErrMsg(task tasksch.ITask) (err error) { for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { if vv.StoreSkuInfo != nil { result := &SyncErrResult{ - SkuID: vv.StoreSkuInfo.SkuID, - StoreID: vv.StoreID, - VendorID: vv.VendoreID, - VendorSkuID: vv.StoreSkuInfo.VendorSkuID, - NameID: vv.StoreSkuInfo.NameID, - VendorPrice: vv.StoreSkuInfo.VendorPrice, - SyncType: vv.SyncType, - ErrMsg: vv.ErrMsg, + SkuID: vv.StoreSkuInfo.SkuID, + StoreID: vv.StoreID, + CategoryName: "", + VendorID: vv.VendoreID, + VendorSkuID: vv.StoreSkuInfo.VendorSkuID, + NameID: vv.StoreSkuInfo.NameID, + VendorPrice: vv.StoreSkuInfo.VendorPrice, + SyncType: vv.SyncType, + ErrMsg: vv.ErrMsg, } resultL = append(resultL, result) } else { result := &SyncErrResult{ + SkuID: 0, StoreID: vv.StoreID, CategoryName: vv.CategoryName, VendorID: vv.VendoreID, + VendorSkuID: "", + NameID: 0, + VendorPrice: 0, SyncType: vv.SyncType, ErrMsg: vv.ErrMsg, } From 77e4fb078fcaf1c020eb27c254d7d0274881761f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 9 Jan 2020 08:50:23 +0800 Subject: [PATCH 38/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 12 ++++++------ controllers/cms_store_sku.go | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 66252481d..fdd9b2ac3 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -775,22 +775,22 @@ func asyncStoreSkuOpFilter(ctx *jxcontext.Context, isAsync bool) bool { return isAsync } -func UpdateStoreSku(ctx *jxcontext.Context, storeID int, skuBindInfo *StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint, errCode string, err error) { +func UpdateStoreSku(ctx *jxcontext.Context, storeID int, skuBindInfo *StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) { return UpdateStoreSkus(ctx, storeID, []*StoreSkuBindInfo{skuBindInfo}, isAsync, isContinueWhenError) } -func UpdateStoreSkus(ctx *jxcontext.Context, storeID int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint, errCode string, err error) { +func UpdateStoreSkus(ctx *jxcontext.Context, storeID int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) { return UpdateStoresSkus(ctx, []int{storeID}, skuBindInfos, false, isAsync, isContinueWhenError) } -func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isAsync, isContinueWhenError bool) (hint, errCode string, err error) { +func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isAsync, isContinueWhenError bool) (hint string, err error) { globals.SugarLogger.Debugf("UpdateStoresSkus:%s, storeIDs:%v, skuBindInfos:%s", ctx.GetTrackInfo(), storeIDs, utils.Format4Output(skuBindInfos, true)) var num int64 db := dao.GetDB() skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos, isScale) if err != nil { - return "", "", err + return "", err } isAsync = asyncStoreSkuOpFilter(ctx, isAsync) num = int64(len(skuIDs)) @@ -800,7 +800,7 @@ func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*St if num == 0 || !isAsync || hint == "" { hint = utils.Int64ToStr(num) } - return hint, "", err + return hint, err } func UpdateStoresSkusByBind(ctx *jxcontext.Context, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) { @@ -1693,7 +1693,7 @@ func AcceptStoreOpRequests(ctx *jxcontext.Context, reqIDs []int) (err error) { } } if err2 == nil { - _, _, err2 := UpdateStoresSkus(ctx, []int{op.StoreID}, []*StoreSkuBindInfo{skuBindInfo}, false, false, false) + _, err2 := UpdateStoresSkus(ctx, []int{op.StoreID}, []*StoreSkuBindInfo{skuBindInfo}, false, false, false) isLocalSucess := true if err2 != nil { subErrors[reqID] = err2 diff --git a/controllers/cms_store_sku.go b/controllers/cms_store_sku.go index 86a9ae216..dc1c5ae62 100644 --- a/controllers/cms_store_sku.go +++ b/controllers/cms_store_sku.go @@ -151,9 +151,9 @@ func (c *StoreSkuController) UpdateStoreSku() { c.callUpdateStoreSku(func(params *tStoreSkuUpdateStoreSkuParams) (retVal interface{}, errCode string, err error) { var skuBindInfo cms.StoreSkuBindInfo if err = jxutils.Strings2Objs(params.Payload, &skuBindInfo); err == nil { - retVal, errCode, err = cms.UpdateStoreSku(params.Ctx, params.StoreID, &skuBindInfo, params.IsAsync, params.IsContinueWhenError) + retVal, err = cms.UpdateStoreSku(params.Ctx, params.StoreID, &skuBindInfo, params.IsAsync, params.IsContinueWhenError) } - return retVal, errCode, err + return retVal, "", err }) } @@ -171,9 +171,9 @@ func (c *StoreSkuController) UpdateStoreSkus() { c.callUpdateStoreSkus(func(params *tStoreSkuUpdateStoreSkusParams) (retVal interface{}, errCode string, err error) { var skuBindInfos []*cms.StoreSkuBindInfo if err = jxutils.Strings2Objs(params.Payload, &skuBindInfos); err == nil { - retVal, errCode, err = cms.UpdateStoreSkus(params.Ctx, params.StoreID, skuBindInfos, params.IsAsync, params.IsContinueWhenError) + retVal, err = cms.UpdateStoreSkus(params.Ctx, params.StoreID, skuBindInfos, params.IsAsync, params.IsContinueWhenError) } - return retVal, errCode, err + return retVal, "", err }) } @@ -219,8 +219,8 @@ func (c *StoreSkuController) UpdateStoresSkus() { if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.Payload, &skuBindInfos); err != nil { return retVal, "", err } - retVal, errCode, err = cms.UpdateStoresSkus(params.Ctx, storeIDs, skuBindInfos, params.IsScale, params.IsAsync, params.IsContinueWhenError) - return retVal, errCode, err + retVal, err = cms.UpdateStoresSkus(params.Ctx, storeIDs, skuBindInfos, params.IsScale, params.IsAsync, params.IsContinueWhenError) + return retVal, "", err }) } From e6c59c4850332ca44fd0c67ea01cd041f33e934e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 9 Jan 2020 14:02:32 +0800 Subject: [PATCH 39/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 83 +++++++-------- business/jxstore/cms/sync_store_sku.go | 14 ++- business/jxutils/tasksch/task.go | 8 +- business/partner/partner_store_sku.go | 6 +- business/partner/purchase/ebai/store_sku2.go | 54 ++++++---- business/partner/purchase/jd/store_sku2.go | 31 +++++- business/partner/purchase/mtwm/store_sku2.go | 75 +++++++++++--- business/partner/putils/store_sku.go | 103 +------------------ 8 files changed, 176 insertions(+), 198 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 7ca22d248..ae618a5f7 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -628,14 +628,19 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN } task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList) if isAsync { - task.SetFinishHook(func(task tasksch.ITask, ctx *jxcontext.Context) { + task.SetFinishHook(func(task tasksch.ITask) { + var noticeMsg string if len(task.GetErrMsg()) > 10 { - err = WirteToExcelBySyncFailed(task, ctx) + downloadURL, _, _ := WirteToExcelBySyncFailed(task) + noticeMsg = fmt.Sprintf("[详情点我]path1=%s\n", downloadURL) } else { if err != nil { - err = buildErrMsg(task) + noticeMsg = utils.Format4Output(buildErrMsgJson(task), true) } } + if authInfo, err := ctx.GetV2AuthInfo(); err == nil { + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "同步错误返回", noticeMsg) + } }) } tasksch.HandleTask(task, nil, isManageIt).Run() @@ -658,41 +663,36 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN } func buildErrMsg(task tasksch.ITask) (err error) { - var resultL []*SyncErrResult + err = fmt.Errorf(utils.Format4Output(buildErrMsgJson(task), true)) + return makeSyncError(err) +} + +func buildErrMsgJson(task tasksch.ITask) (resultL []*SyncErrResult) { failedList := task.GetErrMsg() for _, v := range failedList { for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { - if vv.StoreSkuInfo != nil { - result := &SyncErrResult{ - SkuID: vv.StoreSkuInfo.SkuID, - StoreID: vv.StoreID, - CategoryName: "", - VendorID: vv.VendoreID, - VendorSkuID: vv.StoreSkuInfo.VendorSkuID, - NameID: vv.StoreSkuInfo.NameID, - VendorPrice: vv.StoreSkuInfo.VendorPrice, - SyncType: vv.SyncType, - ErrMsg: vv.ErrMsg, - } - resultL = append(resultL, result) - } else { - result := &SyncErrResult{ - SkuID: 0, - StoreID: vv.StoreID, - CategoryName: vv.CategoryName, - VendorID: vv.VendoreID, - VendorSkuID: "", - NameID: 0, - VendorPrice: 0, - SyncType: vv.SyncType, - ErrMsg: vv.ErrMsg, - } - resultL = append(resultL, result) + result := &SyncErrResult{ + SkuID: 0, + StoreID: vv.StoreID, + CategoryName: vv.CategoryName, + VendorID: vv.VendoreID, + VendorSkuID: "", + NameID: 0, + VendorPrice: 0, + SyncType: vv.SyncType, + ErrMsg: vv.ErrMsg, } + if vv.StoreSkuInfo != nil { + result.SkuID = vv.StoreSkuInfo.SkuID + result.CategoryName = "" + result.VendorSkuID = vv.StoreSkuInfo.VendorSkuID + result.NameID = vv.StoreSkuInfo.NameID + result.VendorPrice = vv.StoreSkuInfo.VendorPrice + } + resultL = append(resultL, result) } } - err = fmt.Errorf(utils.Format4Output(resultL, true)) - return makeSyncError(err) + return resultL } func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) { @@ -827,10 +827,9 @@ func GetTimeMixByInt(begin1, end1, begin2, end2 int16) (beginAt, endAt int16) { return beginAt, endAt } -func WirteToExcelBySyncFailed(task tasksch.ITask, ctx *jxcontext.Context) (err error) { +func WirteToExcelBySyncFailed(task tasksch.ITask) (downloadURL, fileName string, err error) { var ( - sheetList1 []*excel.Obj2ExcelSheetConfig - downloadURL1, fileName1 string + sheetList1 []*excel.Obj2ExcelSheetConfig ) syncErrResultLock.syncErrResult = syncErrResultLock.syncErrResult[0:0] failedList := task.GetErrMsg() @@ -860,21 +859,15 @@ func WirteToExcelBySyncFailed(task tasksch.ITask, ctx *jxcontext.Context) (err e } sheetList1 = append(sheetList1, excelConf1) if excelConf1 != nil { - downloadURL1, fileName1, err = jxutils.UploadExeclAndPushMsg(sheetList1, time.Now().Format("200601021504")+"同步错误返回") - baseapi.SugarLogger.Debug("WriteToExcel: download is [%v]", downloadURL1) + downloadURL, fileName, err = jxutils.UploadExeclAndPushMsg(sheetList1, time.Now().Format("200601021504")+"同步错误返回") + baseapi.SugarLogger.Debug("WriteToExcel: download is [%v]", downloadURL) } else { baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!") } if err != nil { - baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName1, err) - } else { - if authInfo, err := ctx.GetV2AuthInfo(); err == nil { - noticeMsg := fmt.Sprintf("[详情点我]path1=%s\n", downloadURL1) - ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "同步错误返回", noticeMsg) - baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL1:%s", fileName1, downloadURL1) - } + baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName, err) } - return err + return downloadURL, fileName, err } func (d *SyncErrResultLock) AppendData(syncErrResult SyncErrResult) { diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 170809ab1..1f26ab906 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -83,17 +83,21 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo var failedList []*partner.StoreSkuInfoWithErr if model.IsSyncStatusDelete(catInfo.CatSyncStatus) { // 删除 if model.IsSyncStatusDelete(catInfo.CatSyncStatus) && !dao.IsVendorThingIDEmpty(catInfo.VendorCatID) { - failedList, err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID, level) + err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID, level) if err != nil && handler.IsErrCategoryNotExist(err) { err = nil + } else if err != nil && !handler.IsErrCategoryNotExist(err) { + failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, vendorID, "删除分类") } } } else if model.IsSyncStatusNew(catInfo.CatSyncStatus) { // 新增 - failedList, err = handler.CreateStoreCategory(ctx, storeID, vendorStoreID, catInfo) + err = handler.CreateStoreCategory(ctx, storeID, vendorStoreID, catInfo) if err != nil && handler.IsErrCategoryExist(err) { if cat, err2 := handler.GetStoreCategory(ctx, storeID, vendorStoreID, catInfo.Name); err2 == nil { catInfo.VendorCatID = cat.VendorCatID err = nil + } else if err != nil && !handler.IsErrCategoryExist(err) { + failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, vendorID, "新增分类") } } if err == nil { @@ -104,9 +108,11 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo } } } else if model.IsSyncStatusUpdate(catInfo.CatSyncStatus) { // 修改 - failedList, err = handler.UpdateStoreCategory(ctx, storeID, vendorStoreID, catInfo) + err = handler.UpdateStoreCategory(ctx, storeID, vendorStoreID, catInfo) if err == nil { updateFields = append(updateFields, idFieldName) + } else { + failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, vendorID, "修改分类") } } if len(failedList) > 0 { @@ -797,7 +803,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v task4Delete := tasksch.NewParallelTask(fmt.Sprintf("删除商家分类,level:%d", level), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { cat := batchItemList[0].(*partner.BareCategoryInfo) - _, err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, cat.VendorCatID, level) + err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, cat.VendorCatID, level) return nil, err }, levelCat2Delete) tasksch.HandleTask(task4Delete, task, true).Run() diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index f8325d333..a91d3ce9a 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -65,7 +65,7 @@ type ITask interface { AddBatchErr(err error) AddErrMsg(failedList ...interface{}) GetErrMsg() (failedList []interface{}) - SetFinishHook(func(task ITask, ctx *jxcontext.Context)) + SetFinishHook(func(task ITask)) json.Marshaler } @@ -131,7 +131,7 @@ type BaseTask struct { ctx *jxcontext.Context isGetResultCalled bool FailedList []interface{} - finishHook func(task ITask, ctx *jxcontext.Context) + finishHook func(task ITask) } func (s TaskList) Len() int { @@ -362,7 +362,7 @@ func (t *BaseTask) Error() (errMsg string) { return errMsg } -func (t *BaseTask) SetFinishHook(hook func(task ITask, ctx *jxcontext.Context)) { +func (t *BaseTask) SetFinishHook(hook func(task ITask)) { t.locker.RLock() defer t.locker.RUnlock() t.finishHook = hook @@ -450,7 +450,7 @@ func (t *BaseTask) run(taskHandler func()) { } close(t.finishChan) if t.finishHook != nil { - t.finishHook(t, t.ctx) + t.finishHook(t) } else { SendMessage(t) } diff --git a/business/partner/partner_store_sku.go b/business/partner/partner_store_sku.go index af8e78685..d873e93ac 100644 --- a/business/partner/partner_store_sku.go +++ b/business/partner/partner_store_sku.go @@ -156,9 +156,9 @@ type ISingleStoreStoreSkuHandler interface { 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) (failedList []*StoreSkuInfoWithErr, err error) - UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*StoreSkuInfoWithErr, err error) - DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (failedList []*StoreSkuInfoWithErr, 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, level int) (err error) DeleteStoreAllCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, isContinueWhenError bool) (err error) IsErrCategoryExist(err error) (isExist bool) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 3ec06a021..8681bcd29 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -68,7 +68,7 @@ func (p *PurchaseHandler) IsErrCategoryNotExist(err error) (isNotExist bool) { return ebaiapi.IsErrCategoryNotExist(err) } -func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*partner.StoreSkuInfoWithErr, 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(utils.Int2Str(storeID), utils.Str2Int64WithDefault(storeCat.ParentVendorCatID, 0), formatCatName(storeCat.Name), jxCatSeq2Ebai(storeCat.Seq)) @@ -76,13 +76,10 @@ func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID in vendorCatID = jxutils.GenFakeID() } storeCat.VendorCatID = utils.Int64ToStr(vendorCatID) - if err != nil { - failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorIDEBAI, "创建分类") - } - return failedList, err + return err } -func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*partner.StoreSkuInfoWithErr, 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(utils.Int2Str(storeID), utils.Str2Int64WithDefault(storeCat.VendorCatID, 0), formatCatName(storeCat.Name), jxCatSeq2Ebai(storeCat.Seq)) // todo, 饿百将一个分类重复改名,也会报分类名重复错,特殊处理一下,不过因为GetStoreCategory其实会拉取所有的门店分类,是比较耗时的操作 @@ -93,21 +90,15 @@ func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID in } } } - if err != nil { - failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorIDEBAI, "修改分类") - } } - return failedList, err + return err } -func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (failedList []*partner.StoreSkuInfoWithErr, err error) { +func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error) { if globals.EnableEbaiStoreWrite { err = api.EbaiAPI.ShopCategoryDelete(utils.Int2Str(storeID), utils.Str2Int64WithDefault(vendorCatID, 0)) - if err != nil { - failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorIDEBAI, "删除分类") - } } - return failedList, err + return err } // 门店商品 @@ -182,7 +173,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v opResult, err2 := api.EbaiAPI.SkuDelete(ctx.GetTrackInfo(), utils.Int2Str(storeID), partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDIntList(), nil) if err = err2; err2 != nil && opResult != nil { // if len(storeSkuList) > len(opResult.FailedList) { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "删除商品") + failedList = SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "删除商品") // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) // } } @@ -212,7 +203,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr } } if err != nil && opResult != nil { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品状态") + failedList = SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品状态") // failedList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) } } @@ -237,12 +228,12 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrg 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 { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品价格") + failedList = SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品价格") } } else if len(storeSkuList) == 1 { opResult2, err := api.EbaiAPI.SkuPriceUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0]) if err != nil && opResult2 != nil { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult2, storeID, model.VendorIDEBAI, "更新商品价格") + failedList = SelectStoreSkuListByOpResult(storeSkuList, opResult2, storeID, model.VendorIDEBAI, "更新商品价格") } } } @@ -254,7 +245,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrg if len(storeSkuList) > 1 { opResult, err2 := api.EbaiAPI.SkuStockUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID) if err = err2; err != nil && opResult != nil { - failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品库存") + failedList = SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品库存") // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult)) } } else if len(storeSkuList) == 1 { @@ -439,3 +430,26 @@ func vendorSkuList2Jx(vendorSkuList []*ebaiapi.SkuInfo) (skuNameList []*partner. func (p *PurchaseHandler) GetSensitiveWordRegexp() *regexp.Regexp { return sensitiveWordRegexp } + +//饿百api返回 +func SelectStoreSkuListByOpResult(storeSkuList []*partner.StoreSkuInfo, opResult *ebaiapi.BatchOpResult, storeID, vendorID int, syncType string) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { + 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 := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: v, + ErrMsg: opResultMap[utils.Str2Int64(v.VendorSkuID)], + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, + } + selectedStoreSkuList = append(selectedStoreSkuList, opFailed) + } + } + } + return selectedStoreSkuList +} diff --git a/business/partner/purchase/jd/store_sku2.go b/business/partner/purchase/jd/store_sku2.go index fbb96f51f..6f9908730 100644 --- a/business/partner/purchase/jd/store_sku2.go +++ b/business/partner/purchase/jd/store_sku2.go @@ -122,7 +122,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr if globals.EnableJdStoreWrite { responseList, err2 := getAPI(vendorOrgCode).BatchUpdateVendibility(ctx.GetTrackInfo(), "", vendorStoreID, skuVendibilityList, ctx.GetUserName()) if err = err2; isErrPartialFailed(err) { - failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品状态") + failedList = SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品状态") // successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false))) } } @@ -146,7 +146,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrg if globals.EnableJdStoreWrite { responseList, err2 := getAPI(vendorOrgCode).UpdateVendorStationPrice(ctx.GetTrackInfo(), "", vendorStoreID, skuPriceInfoList) if err = err2; isErrPartialFailed(err) { - failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品价格") + failedList = SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品价格") } } } @@ -170,7 +170,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrg if globals.EnableJdStoreWrite { responseList, err2 := getAPI(vendorOrgCode).BatchUpdateCurrentQtys(ctx.GetTrackInfo(), "", vendorStoreID, skuStockList, ctx.GetUserName()) if err = err2; isErrPartialFailed(err) { - failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品库存") + failedList = SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品库存") // successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false))) } } @@ -215,3 +215,28 @@ func (p *PurchaseHandler) SyncStoreProducts(ctx *jxcontext.Context, vendorOrgCod } return hint, err } + +//京东api返回 +func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, responseList []*jdapi.StoreSkuBatchUpdateResponse, storeID, vendorID int, syncType string) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { + responseMap := make(map[string]string) + if len(responseList) > 0 { + for _, v := range responseList { + if v.Code != "0" { + responseMap[v.OutSkuID] = v.Msg + } + } + for _, v := range storeSkuList { + if responseMap[utils.Int2Str(v.SkuID)] != "" { + respFailed := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: v, + ErrMsg: responseMap[utils.Int2Str(v.SkuID)], + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, + } + selectedStoreSkuList = append(selectedStoreSkuList, respFailed) + } + } + } + return selectedStoreSkuList +} diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index 399786d41..054504afc 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -102,7 +102,7 @@ func tryCatName2Code(originName string) (catCodeStr string) { return catCodeStr } -func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*partner.StoreSkuInfoWithErr, 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 @@ -151,27 +151,24 @@ func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID in Sequence: storeCat.Seq, } err = api.MtwmAPI.RetailCatUpdate(vendorStoreID, catName, param4Update) - if err != nil { - failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorIDMTWM, "创建修改分类") - } if storeCat.CatSyncStatus&model.SyncFlagNewMask == 0 && // 修改分类名,但分类不存在 p.IsErrCategoryNotExist(err) && originName != "" { storeCat.CatSyncStatus |= model.SyncFlagNewMask - failedList, err = p.CreateStoreCategory(ctx, storeID, vendorStoreID, storeCat) + err = p.CreateStoreCategory(ctx, storeID, vendorStoreID, storeCat) } } if err == nil { // storeCat.VendorCatID = utils.FilterEmoji(storeCat.Name) storeCat.VendorCatID = utils.Int2Str(storeCat.ID) } - return failedList, err + return err } -func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) { +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, storeID int, vendorStoreID, vendorCatID string, level int) (failedList []*partner.StoreSkuInfoWithErr, err error) { +func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error) { if false { if globals.EnableMtwmStoreWrite { err = api.MtwmAPI.RetailCatDelete(vendorStoreID, tryCatName2Code(vendorCatID), vendorCatID) @@ -187,12 +184,9 @@ func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID in } else { err = api.MtwmAPI.RetailCatSkuBatchDelete2(ctx.GetTrackInfo(), vendorStoreID, nil, nil, catCodes, []string{vendorCatID}, nil) } - if err != nil { - failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorIDMTWM, "删除分类") - } } } - return failedList, err + return err } // 门店商品 @@ -313,7 +307,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI failedFoodList, err2 := api.MtwmAPI.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList) if err = err2; err == nil { if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil { - failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, syncType) + failedList = SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, syncType) // successList = putils.UnselectStoreSkuSyncListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) } } @@ -347,7 +341,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v if errExt, ok := err.(*utils.ErrorWithCode); ok { myMap := make(map[string][]*mtwmapi.AppFoodResult) json.Unmarshal([]byte(errExt.ErrMsg()), &myMap) - failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, myMap["retail_error_list"], storeID, model.VendorIDMTWM, "批量删除商品") + failedList = SelectStoreSkuListByFoodList(storeSkuList, myMap["retail_error_list"], storeID, model.VendorIDMTWM, "批量删除商品") } } } @@ -388,7 +382,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOr failedFoodList, err2 := api.MtwmAPI.RetailSellStatus(ctx.GetTrackInfo(), vendorStoreID, skuList, mtwmStatus) if err = err2; err == nil { if len(failedFoodList) > 0 { - failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品状态") + failedList = SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品状态") // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) } } @@ -402,7 +396,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrg failedFoodList, err2 := api.MtwmAPI.RetailSkuPrice(ctx.GetTrackInfo(), vendorStoreID, priceList) if err = err2; err == nil { if len(failedFoodList) > 0 { - failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品价格") + failedList = SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品价格") } } } @@ -415,7 +409,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrg failedFoodList, err2 := api.MtwmAPI.RetailSkuStock(ctx.GetTrackInfo(), vendorStoreID, stockList) if err = err2; err == nil { if len(failedFoodList) > 0 { - failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品库存") + failedList = SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品库存") } //if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil { // successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList)) @@ -533,3 +527,50 @@ func vendorSkuList2Jx(appFoodList []*mtwmapi.AppFood) (skuNameList []*partner.Sk func (p *PurchaseHandler) GetSensitiveWordRegexp() *regexp.Regexp { return sensitiveWordRegexp } + +//美团api返回 +func SelectStoreSkuListByFoodList(storeSkuList interface{}, foodList []*mtwmapi.AppFoodResult, storeID, vendorID int, syncType string) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { + foodMap := make(map[string]string) + if len(foodList) > 0 { + for _, v := range foodList { + foodMap[v.AppFoodCode] = v.ErrorMsg + } + if storeSkuLists, ok := storeSkuList.([]*partner.StoreSkuInfo); ok { + for _, v := range storeSkuLists { + if foodMap[v.VendorSkuID] != "" { + foodFailed := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: v, + ErrMsg: foodMap[v.VendorSkuID], + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, + } + selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) + } + } + } + if storeSkuLists, ok := storeSkuList.([]*dao.StoreSkuSyncInfo); ok { + for _, v := range storeSkuLists { + if foodMap[v.VendorSkuID] != "" { + storeSkuInfo := &partner.StoreSkuInfo{ + SkuID: v.SkuID, + VendorSkuID: v.VendorSkuID, + NameID: v.NameID, + VendorNameID: v.VendorNameID, + VendorPrice: v.VendorPrice, + Status: v.Status, + } + foodFailed := &partner.StoreSkuInfoWithErr{ + StoreSkuInfo: storeSkuInfo, + ErrMsg: foodMap[v.VendorSkuID], + StoreID: storeID, + VendoreID: vendorID, + SyncType: syncType, + } + selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) + } + } + } + } + return selectedStoreSkuList +} diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index 3877ce83b..0b4743c8d 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -4,12 +4,6 @@ import ( "fmt" "sort" - "git.rosy.net.cn/baseapi/platformapi/jdapi" - - "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" @@ -64,7 +58,7 @@ func (p *DefSingleStorePlatform) DeleteStoreAllCategories(ctx *jxcontext.Context vendorCatIDs[k] = v.VendorCatID } err = FreeBatchCategoryIDOp(func(vendorCatID string) (err error) { - _, err2 := p.DeleteStoreCategory(ctx, storeID, vendorStoreID, vendorCatID, step) + err2 := p.DeleteStoreCategory(ctx, storeID, vendorStoreID, vendorCatID, step) return err2 }, ctx, task, vendorCatIDs, isContinueWhenError) return nil, err @@ -237,101 +231,6 @@ func UnselectStoreSkuListByVendorSkuIDs(storeSkuList []*partner.StoreSkuInfo, ve return selectedStoreSkuList } -//美团api返回 -func SelectStoreSkuListByFoodList(storeSkuList interface{}, foodList []*mtwmapi.AppFoodResult, storeID, vendorID int, syncType string) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { - foodMap := make(map[string]string) - if len(foodList) > 0 { - for _, v := range foodList { - foodMap[v.AppFoodCode] = v.ErrorMsg - } - if storeSkuLists, ok := storeSkuList.([]*partner.StoreSkuInfo); ok { - for _, v := range storeSkuLists { - if foodMap[v.VendorSkuID] != "" { - foodFailed := &partner.StoreSkuInfoWithErr{ - StoreSkuInfo: v, - ErrMsg: foodMap[v.VendorSkuID], - StoreID: storeID, - VendoreID: vendorID, - SyncType: syncType, - } - selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) - } - } - } - if storeSkuLists, ok := storeSkuList.([]*dao.StoreSkuSyncInfo); ok { - for _, v := range storeSkuLists { - if foodMap[v.VendorSkuID] != "" { - storeSkuInfo := &partner.StoreSkuInfo{ - SkuID: v.SkuID, - VendorSkuID: v.VendorSkuID, - NameID: v.NameID, - VendorNameID: v.VendorNameID, - VendorPrice: v.VendorPrice, - Status: v.Status, - } - foodFailed := &partner.StoreSkuInfoWithErr{ - StoreSkuInfo: storeSkuInfo, - ErrMsg: foodMap[v.VendorSkuID], - StoreID: storeID, - VendoreID: vendorID, - SyncType: syncType, - } - selectedStoreSkuList = append(selectedStoreSkuList, foodFailed) - } - } - } - } - return selectedStoreSkuList -} - -//饿百api返回 -func SelectStoreSkuListByOpResult(storeSkuList []*partner.StoreSkuInfo, opResult *ebaiapi.BatchOpResult, storeID, vendorID int, syncType string) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { - 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 := &partner.StoreSkuInfoWithErr{ - StoreSkuInfo: v, - ErrMsg: opResultMap[utils.Str2Int64(v.VendorSkuID)], - StoreID: storeID, - VendoreID: vendorID, - SyncType: syncType, - } - selectedStoreSkuList = append(selectedStoreSkuList, opFailed) - } - } - } - return selectedStoreSkuList -} - -//京东api返回 -func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, responseList []*jdapi.StoreSkuBatchUpdateResponse, storeID, vendorID int, syncType string) (selectedStoreSkuList []*partner.StoreSkuInfoWithErr) { - responseMap := make(map[string]string) - if len(responseList) > 0 { - for _, v := range responseList { - if v.Code != "0" { - responseMap[v.OutSkuID] = v.Msg - } - } - for _, v := range storeSkuList { - if responseMap[utils.Int2Str(v.SkuID)] != "" { - respFailed := &partner.StoreSkuInfoWithErr{ - StoreSkuInfo: v, - ErrMsg: responseMap[utils.Int2Str(v.SkuID)], - StoreID: storeID, - VendoreID: vendorID, - SyncType: syncType, - } - selectedStoreSkuList = append(selectedStoreSkuList, respFailed) - } - } - } - return selectedStoreSkuList -} - func GetErrMsg2FailedSingleList(storeSkuList interface{}, err error, storeID, vendorID int, syncType string) (failedList []*partner.StoreSkuInfoWithErr) { if err != nil { if errExt, ok := err.(*utils.ErrorWithCode); ok { From b4a2970c5baa334e8b066b3b6a372afc450611b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 9 Jan 2020 14:57:24 +0800 Subject: [PATCH 40/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index ae618a5f7..41c48fc3e 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -684,7 +684,6 @@ func buildErrMsgJson(task tasksch.ITask) (resultL []*SyncErrResult) { } if vv.StoreSkuInfo != nil { result.SkuID = vv.StoreSkuInfo.SkuID - result.CategoryName = "" result.VendorSkuID = vv.StoreSkuInfo.VendorSkuID result.NameID = vv.StoreSkuInfo.NameID result.VendorPrice = vv.StoreSkuInfo.VendorPrice @@ -832,25 +831,9 @@ func WirteToExcelBySyncFailed(task tasksch.ITask) (downloadURL, fileName string, sheetList1 []*excel.Obj2ExcelSheetConfig ) syncErrResultLock.syncErrResult = syncErrResultLock.syncErrResult[0:0] - failedList := task.GetErrMsg() - if len(failedList) == 0 { - return - } - for _, v := range failedList { - for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { - result := SyncErrResult{ - SkuID: vv.StoreSkuInfo.SkuID, - CategoryName: vv.CategoryName, - StoreID: vv.StoreID, - VendorID: vv.VendoreID, - VendorSkuID: vv.StoreSkuInfo.VendorSkuID, - NameID: vv.StoreSkuInfo.NameID, - VendorPrice: vv.StoreSkuInfo.VendorPrice, - SyncType: vv.SyncType, - ErrMsg: vv.ErrMsg, - } - syncErrResultLock.AppendData(result) - } + list := buildErrMsgJson(task) + for _, v := range list { + syncErrResultLock.AppendData(*v) } excelConf1 := &excel.Obj2ExcelSheetConfig{ Title: "同步错误", From 2b872e34cd8f526c8572b520ec764a31ea70aad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 9 Jan 2020 15:41:00 +0800 Subject: [PATCH 41/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 4 ++-- business/jxstore/cms/sync_store_sku.go | 14 +++++++------- business/jxutils/tasksch/task.go | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 41c48fc3e..bbd964ee1 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -630,7 +630,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN if isAsync { task.SetFinishHook(func(task tasksch.ITask) { var noticeMsg string - if len(task.GetErrMsg()) > 10 { + if len(task.GetFailedList()) > 10 { downloadURL, _, _ := WirteToExcelBySyncFailed(task) noticeMsg = fmt.Sprintf("[详情点我]path1=%s\n", downloadURL) } else { @@ -668,7 +668,7 @@ func buildErrMsg(task tasksch.ITask) (err error) { } func buildErrMsgJson(task tasksch.ITask) (resultL []*SyncErrResult) { - failedList := task.GetErrMsg() + failedList := task.GetFailedList() for _, v := range failedList { for _, vv := range v.([]*partner.StoreSkuInfoWithErr) { result := &SyncErrResult{ diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 1f26ab906..a65e65171 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -119,7 +119,7 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo for _, v := range failedList { v.CategoryName = catInfo.Name } - task.AddErrMsg(failedList) + task.AddFailedList(failedList) } if err == nil { if vendorID == model.VendorIDMTWM { @@ -491,7 +491,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo var failedList []*partner.StoreSkuInfoWithErr failedList, err = singleStoreHandler.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList) if len(failedList) > 0 { - task.AddErrMsg(failedList) + task.AddFailedList(failedList) } if singleStoreHandler.IsErrSkuNotExist(err) { err = nil @@ -527,7 +527,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo failedList = append(failedList, putils.GetErrMsg2FailedSingleList(batchedStoreSkuList, err2, storeID, vendorID, "查询是否有该商品")...) } if len(failedList) > 0 { - task.AddErrMsg(failedList) + task.AddFailedList(failedList) } if err != nil { //handle error for sensitive words, if find, then insert to table sensitive_words @@ -548,7 +548,7 @@ 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 { - task.AddErrMsg(failedList) + task.AddFailedList(failedList) } successList := putils.UnselectStoreSkuSyncListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) if len(successList) > 0 { @@ -564,7 +564,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo var failedList []*partner.StoreSkuInfoWithErr failedList, err = storeSkuHandler.UpdateStoreSkusStock(ctx, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList) if len(failedList) > 0 { - task.AddErrMsg(failedList) + task.AddFailedList(failedList) } successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) if k == 0 && len(successList) > 0 { @@ -588,7 +588,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo var failedList []*partner.StoreSkuInfoWithErr failedList, err = storeSkuHandler.UpdateStoreSkusStatus(ctx, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList, status) if len(failedList) > 0 { - task.AddErrMsg(failedList) + task.AddFailedList(failedList) } successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) if len(successList) > 0 { @@ -603,7 +603,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo var failedList []*partner.StoreSkuInfoWithErr failedList, err = storeSkuHandler.UpdateStoreSkusPrice(ctx, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList) if len(failedList) > 0 { - task.AddErrMsg(failedList) + task.AddFailedList(failedList) } successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList)) if len(successList) > 0 { diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index a91d3ce9a..4f10d3f8f 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -63,8 +63,8 @@ type ITask interface { // GetDetailErrList() []error GetLeafResult() (finishedItemCount, failedItemCount int) AddBatchErr(err error) - AddErrMsg(failedList ...interface{}) - GetErrMsg() (failedList []interface{}) + AddFailedList(failedList ...interface{}) + GetFailedList() (failedList []interface{}) SetFinishHook(func(task ITask)) json.Marshaler } @@ -368,18 +368,18 @@ func (t *BaseTask) SetFinishHook(hook func(task ITask)) { t.finishHook = hook } -func (t *BaseTask) GetErrMsg() (failedList []interface{}) { +func (t *BaseTask) GetFailedList() (failedList []interface{}) { t.locker.RLock() failedList = append(failedList, t.FailedList...) t.locker.RUnlock() for _, v := range t.Children { - failedList = append(failedList, v.GetErrMsg()...) + failedList = append(failedList, v.GetFailedList()...) } return failedList } -func (t *BaseTask) AddErrMsg(failedList ...interface{}) { +func (t *BaseTask) AddFailedList(failedList ...interface{}) { t.locker.Lock() defer t.locker.Unlock() t.FailedList = append(t.FailedList, failedList...) From 867f94a3f11be1224a3721e1a5f9f97a260d1f6c Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 9 Jan 2020 17:32:02 +0800 Subject: [PATCH 42/44] =?UTF-8?q?ActStoreSkuParam2Model=E9=87=8D=E5=8F=A0?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index bc4595fc3..b5a4ca2b7 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -151,6 +151,8 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac storeIDMap := make(map[int]int) skuIDMap := make(map[int]int) storeSkuParamMap := make(map[int][]*ActStoreSkuParam) + + actStoreSkuMap := make(map[int64]bool) var wrongSkuList []*ActStoreSkuParam for _, v := range actStoreSku { if act.Type == model.ActSkuFake && v.EarningPrice == 0 { @@ -159,6 +161,8 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac storeIDMap[v.StoreID] = 1 skuIDMap[v.SkuID] = 1 storeSkuParamMap[v.StoreID] = append(storeSkuParamMap[v.StoreID], v) + + actStoreSkuMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] = true } } if len(wrongSkuList) > 0 { @@ -166,7 +170,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac } storeIDs := jxutils.IntMap2List(storeIDMap) skuIDs := jxutils.IntMap2List(skuIDMap) - // 判断活动是否重叠的检查,当前忽略京东平台及所有结算信息 + if act.OverlapRule == model.OverlapRuleNormal { effectActStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, 0, vendorIDs, act.Type, storeIDs, skuIDs, act.BeginAt, act.EndAt) if err != nil { @@ -174,7 +178,15 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac return nil, nil, nil, err } if len(effectActStoreSkuList) > 0 { - return nil, nil, nil, jsonerr.New(effectActStoreSkuList, model.ErrCodeJsonActSkuConflict) + var realEffectActStoreSkuList []*model.ActStoreSku2 + for _, v := range effectActStoreSkuList { + if actStoreSkuMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] { + realEffectActStoreSkuList = append(realEffectActStoreSkuList, v) + } + } + if len(realEffectActStoreSkuList) > 0 { + return nil, nil, nil, jsonerr.New(realEffectActStoreSkuList, model.ErrCodeJsonActSkuConflict) + } } } From 08be46ca0243ed03cae192798b6441a7db56542a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 9 Jan 2020 17:44:28 +0800 Subject: [PATCH 43/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 4 ++-- business/model/dao/store_sku.go | 33 ++++++++++++++++++-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index a65e65171..72abba655 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -69,7 +69,7 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo rootTask := tasksch.NewSeqTask(fmt.Sprintf("%s SyncStoreCategory step1", model.VendorChineseNames[vendorID]), ctx, func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { level := step + 1 - catList, err := dao.GetDirtyStoreCategories(db, vendorID, storeID, level) + catList, err := dao.GetDirtyStoreCategories(db, vendorID, storeID, level, skuIDs) if len(catList) > 0 { num += len(catList) task := tasksch.NewParallelTask(fmt.Sprintf("%s SyncStoreCategory step2, level=%d", model.VendorChineseNames[vendorID], level), @@ -752,7 +752,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v } sku2Delete = nil case 2: - localCatList, err := dao.GetStoreCategories(db, vendorID, storeID, 0, false) + localCatList, err := dao.GetStoreCategories(db, vendorID, storeID, nil, 0, false) if err != nil { return nil, err } diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 2204bed55..6b05ec369 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -279,7 +279,7 @@ func GetSkusCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level int // 单门店模式厂商适用 // 单纯的从已经创建的store_sku_category_map中,得到相关的同步信息 -func GetStoreCategories(db *DaoDB, vendorID, storeID int, level int, mustDirty bool) (cats []*SkuStoreCatInfo, err error) { +func GetStoreCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level int, mustDirty bool) (cats []*SkuStoreCatInfo, err error) { fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID]) sql := ` SELECT t4.*, @@ -288,16 +288,29 @@ func GetStoreCategories(db *DaoDB, vendorID, storeID int, level int, mustDirty b t5p.id parent_map_id, t5p.%s_id parent_vendor_cat_id, t5p.%s_sync_status parent_cat_sync_status FROM store_sku_category_map t5 JOIN sku_category t4 ON t5.category_id = t4.id AND t4.deleted_at = ? + ` + sqlParams := []interface{}{ + utils.DefaultTimeValue, + } + fieldPrefixParams := []interface{}{fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix} + if len(skuIDs) > 0 { + sql += ` + JOIN ( + SELECT DISTINCT b.category_id + FROM sku a + JOIN sku_name b ON a.name_id = b.id AND b.deleted_at = ? + WHERE 1=1 + AND a.id IN (` + GenQuestionMarks(len(skuIDs)) + `) + AND a.deleted_at = ? + )t6 ON t6.category_id = t4.id + ` + sqlParams = append(sqlParams, utils.DefaultTimeValue, skuIDs, utils.DefaultTimeValue) + } + sql += ` LEFT JOIN sku_category t4p ON t4.parent_id = t4p.id LEFT JOIN store_sku_category_map t5p ON t4p.id = t5p.category_id AND t5.store_id = t5p.store_id AND t5p.deleted_at = ? WHERE t5.store_id = ? AND t5.deleted_at = ?` - fieldPrefixParams := []interface{}{fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix} - sqlParams := []interface{}{ - utils.DefaultTimeValue, - utils.DefaultTimeValue, - storeID, - utils.DefaultTimeValue, - } + sqlParams = append(sqlParams, utils.DefaultTimeValue, storeID, utils.DefaultTimeValue) if mustDirty { sql += " AND t5.%s_sync_status <> 0" fieldPrefixParams = append(fieldPrefixParams, fieldPrefix) @@ -312,8 +325,8 @@ func GetStoreCategories(db *DaoDB, vendorID, storeID int, level int, mustDirty b return cats, err } -func GetDirtyStoreCategories(db *DaoDB, vendorID, storeID int, level int) (cats []*SkuStoreCatInfo, err error) { - return GetStoreCategories(db, vendorID, storeID, level, true) +func GetDirtyStoreCategories(db *DaoDB, vendorID, storeID int, level int, skuIDs []int) (cats []*SkuStoreCatInfo, err error) { + return GetStoreCategories(db, vendorID, storeID, skuIDs, level, true) } // 以store_sku_bind为基础来做同步,正常情况下使用 From e430c8ae5901192a5049bf23f7fb331c9a506b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 9 Jan 2020 17:53:13 +0800 Subject: [PATCH 44/44] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/store_sku.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 6b05ec369..fcbcabbdd 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -299,10 +299,9 @@ func GetStoreCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level in SELECT DISTINCT b.category_id FROM sku a JOIN sku_name b ON a.name_id = b.id AND b.deleted_at = ? - WHERE 1=1 - AND a.id IN (` + GenQuestionMarks(len(skuIDs)) + `) + WHERE a.id IN (` + GenQuestionMarks(len(skuIDs)) + `) AND a.deleted_at = ? - )t6 ON t6.category_id = t4.id + ) t6 ON t6.category_id = t4.id ` sqlParams = append(sqlParams, utils.DefaultTimeValue, skuIDs, utils.DefaultTimeValue) }