From 05ddde69e6fee2765e4b459d59c4c1ca42620c66 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, 25 May 2020 14:52:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=AC=E4=B8=9C=E5=95=86=E5=9F=8E=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 108 +++++++++++++++++----------------- business/jxstore/misc/misc.go | 1 + 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index ab5b9a2c1..aba24309c 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -1115,14 +1115,14 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (hint string, err error) { var ( - mainSkusMap = make(map[int]*model.StoreSkuBind) - skusMap = make(map[int]*model.StoreSkuBind) - updateList []*model.StoreSkuBind - addList []*model.StoreSkuBind - // skuBindInfos1 []*StoreSkuBindInfo - // skuBindInfos2 []*StoreSkuBindInfo - // resultInterface1 []interface{} - // resultInterface2 []interface{} + mainSkusMap = make(map[int]*model.StoreSkuBind) + skusMap = make(map[int]*model.StoreSkuBind) + updateList []*model.StoreSkuBind + addList []*model.StoreSkuBind + skuBindInfos1 []*StoreSkuBindInfo + skuBindInfos2 []*StoreSkuBindInfo + resultInterface1 []interface{} + resultInterface2 []interface{} ) storeSkusMain, err := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID}, nil) for _, v := range storeSkusMain { @@ -1142,52 +1142,52 @@ func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch } } } - fmt.Println("updateList", utils.Format4Output(updateList, false)) - fmt.Println("addList", utils.Format4Output(addList, false)) - // task := tasksch.NewParallelTask("正在同步京东商城的库存商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, - // func(ptTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - // step := batchItemList[0].(int) - // switch step { - // case 0: - // if len(updateList) > 0 { - // task := tasksch.NewParallelTask("同步门店库存", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, - // func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - // storeBind := batchItemList[0].(*model.StoreSkuBind) - // retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, false)} - // return retVal, err - // }, updateList) - // tasksch.HandleTask(task, ptTask, false).Run() - // resultInterface1, err = task.GetResult(0) - // for _, v := range resultInterface1 { - // skuBindInfos1 = append(skuBindInfos1, v.(*StoreSkuBindInfo)) - // } - // hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos1, isAsync, isContinueWhenError, false) - // } - // case 1: - // if len(addList) > 0 { - // task := tasksch.NewParallelTask("同步门店商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, - // func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - // storeBind := batchItemList[0].(*model.StoreSkuBind) - // retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, true)} - // return retVal, err - // }, addList) - // tasksch.HandleTask(task, ptTask, false).Run() - // resultInterface2, err = task.GetResult(0) - // for _, v := range resultInterface2 { - // skuBindInfos2 = append(skuBindInfos2, v.(*StoreSkuBindInfo)) - // } - // hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos2, isAsync, isContinueWhenError, false) - // } - // } - // return retVal, err - // }, []int{0, 1}) - // tasksch.HandleTask(task, nil, true).Run() - // if isAsync { - // hint = task.GetID() - // } else { - // _, err = task.GetResult(0) - // hint = "1" - // } + // fmt.Println("updateList", utils.Format4Output(updateList, false)) + // fmt.Println("addList", utils.Format4Output(addList, false)) + task := tasksch.NewParallelTask("正在同步京东商城的库存商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, + func(ptTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + step := batchItemList[0].(int) + switch step { + case 0: + if len(updateList) > 0 { + task := tasksch.NewParallelTask("同步门店库存", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, + func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + storeBind := batchItemList[0].(*model.StoreSkuBind) + retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, false)} + return retVal, err + }, updateList) + tasksch.HandleTask(task, ptTask, false).Run() + resultInterface1, err = task.GetResult(0) + for _, v := range resultInterface1 { + skuBindInfos1 = append(skuBindInfos1, v.(*StoreSkuBindInfo)) + } + hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos1, isAsync, isContinueWhenError, false) + } + case 1: + if len(addList) > 0 { + task := tasksch.NewParallelTask("同步门店商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, + func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + storeBind := batchItemList[0].(*model.StoreSkuBind) + retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, true)} + return retVal, err + }, addList) + tasksch.HandleTask(task, ptTask, false).Run() + resultInterface2, err = task.GetResult(0) + for _, v := range resultInterface2 { + skuBindInfos2 = append(skuBindInfos2, v.(*StoreSkuBindInfo)) + } + hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos2, isAsync, isContinueWhenError, false) + } + } + return retVal, err + }, []int{0, 1}) + tasksch.HandleTask(task, nil, true).Run() + if isAsync { + hint = task.GetID() + } else { + _, err = task.GetResult(0) + hint = "1" + } return hint, err } diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 72e0f41d6..0da1f7350 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -402,6 +402,7 @@ func doDailyWork() { //刷新京东商城订单结算价 orderman.RefreshJdShopOrdersEarningPrice(jxcontext.AdminCtx, time.Now().AddDate(0, 0, -3).Format("20060102"), time.Now().Format("20060102")) //同步京东商城门店库存和商品 + cms.CurVendorSync.SyncJdsStoresSkus(jxcontext.AdminCtx, nil, true, true) //同步上架京东商城待售商品 cms.RefreshJdsSkusStatus(jxcontext.AdminCtx) }