- 对于单门店平台,同步商品时,多个门店同时并发同步

This commit is contained in:
gazebo
2019-06-18 10:30:17 +08:00
parent c64140fdcf
commit a9052f4bbc
2 changed files with 53 additions and 28 deletions

View File

@@ -403,17 +403,29 @@ func (v *VendorSync) SyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendo
dao.SetStoreSkuSyncStatus(db, loopMapInfo.VendorID, storeIDs, skuIDs, model.SyncFlagModifiedMask)
}
if len(loopMapInfo.StoreMapList) > 1 {
loopStoreTask := tasksch.NewSeqTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), ctx,
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
storeID := loopMapInfo.StoreMapList[step].StoreID
if _, err = handler.SyncStoreSkus(ctx, task, storeID, skuIDs, false, isContinueWhenError); err != nil {
globals.SugarLogger.Debugf("SyncStoresSkus failed1 store:%d failed with error:%v", storeID, err)
if isContinueWhenError {
err = nil
var loopStoreTask tasksch.ITask
if model.MultiStoresVendorMap[loopMapInfo.VendorID] == 1 {
loopStoreTask = tasksch.NewSeqTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), ctx,
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
storeID := loopMapInfo.StoreMapList[step].StoreID
if _, err = handler.SyncStoreSkus(ctx, task, storeID, skuIDs, false, isContinueWhenError); err != nil {
globals.SugarLogger.Debugf("SyncStoresSkus failed1 store:%d failed with error:%v", storeID, err)
if isContinueWhenError {
err = nil
}
}
}
return nil, err
}, len(loopMapInfo.StoreMapList))
return nil, err
}, len(loopMapInfo.StoreMapList))
} else {
loopStoreTask = tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeMap := batchItemList[0].(*model.StoreMap)
if _, err = handler.SyncStoreSkus(ctx, task, storeMap.StoreID, skuIDs, false, isContinueWhenError); err != nil {
globals.SugarLogger.Debugf("SyncStoresSkus failed2 store:%d failed with error:%v", storeMap.StoreID, err)
}
return nil, err
}, loopMapInfo.StoreMapList)
}
t.AddChild(loopStoreTask).Run()
_, err = loopStoreTask.GetResult(0)
} else {
@@ -447,17 +459,29 @@ func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, v
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
if len(loopMapInfo.StoreMapList) > 1 {
loopStoreTask := tasksch.NewSeqTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), ctx,
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
storeID := loopMapInfo.StoreMapList[step].StoreID
if _, err = handler.FullSyncStoreSkus(ctx, task, storeID, false, isContinueWhenError); err != nil {
globals.SugarLogger.Debugf("FullSyncStoresSkus failed1 store:%d failed with error:%v", storeID, err)
if isContinueWhenError {
err = nil
var loopStoreTask tasksch.ITask
if model.MultiStoresVendorMap[loopMapInfo.VendorID] == 1 {
loopStoreTask = tasksch.NewSeqTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), ctx,
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
storeID := loopMapInfo.StoreMapList[step].StoreID
if _, err = handler.FullSyncStoreSkus(ctx, task, storeID, false, isContinueWhenError); err != nil {
globals.SugarLogger.Debugf("FullSyncStoresSkus failed1 store:%d failed with error:%v", storeID, err)
if isContinueWhenError {
err = nil
}
}
}
return nil, err
}, len(loopMapInfo.StoreMapList))
return nil, err
}, len(loopMapInfo.StoreMapList))
} else {
loopStoreTask = tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeMap := batchItemList[0].(*model.StoreMap)
if _, err = handler.FullSyncStoreSkus(ctx, task, storeMap.StoreID, false, isContinueWhenError); err != nil {
globals.SugarLogger.Debugf("FullSyncStoresSkus failed2 store:%d failed with error:%v", storeMap.StoreID, err)
}
return nil, err
}, loopMapInfo.StoreMapList)
}
t.AddChild(loopStoreTask).Run()
_, err = loopStoreTask.GetResult(0)
} else {

View File

@@ -89,23 +89,24 @@ func (c *PurchaseHandler) getOrder(orderID string) (order *model.GoodsOrder, ord
switch taskIndex {
case 0:
orderMap, err = api.JdAPI.QuerySingleOrder(orderID)
if err == nil {
order = c.Map2Order(orderMap)
realMobile, err = api.JdAPI.GetRealMobile4Order(orderID, order.VendorStoreID)
if realMobile != "" {
order.ConsigneeMobile2 = jxutils.FormalizeMobile(realMobile)
}
}
case 1:
realMobile, err = api.JdAPI.GetRealMobile4Order(orderID, order.VendorStoreID)
case 2:
orderSettlement, err = api.JdAPI.OrderShoudSettlementService2(orderID)
}
return nil, err
}, []int{0, 1, 2})
}, []int{0, 1})
task.Run()
task.GetResult(0)
if orderMap != nil {
order = c.Map2Order(orderMap)
if order != nil {
if orderSettlement != nil {
order.TotalShopMoney = orderSettlement.SettlementAmount + orderSettlement.PlatOrderGoodsDiscountMoney
}
if realMobile != "" {
order.ConsigneeMobile2 = jxutils.FormalizeMobile(realMobile)
}
}
// if orderMap, err = api.JdAPI.QuerySingleOrder(orderID); err == nil {
// globals.SugarLogger.Debugf("jd getOrder2 orderID:%s", orderID)