错开同步时间
This commit is contained in:
@@ -1101,7 +1101,7 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
if storeMap.Status > model.StoreStatusDisabled && storeMap.StoreID != model.JdShopMainStoreID && storeMap.SyncRule != 0 {
|
||||
_, err = syncJdsStoresSkus(ctx, db, task, storeMap, isAsync, isContinueWhenError)
|
||||
err = syncJdsStoresSkus(ctx, db, task, storeMap, isAsync, isContinueWhenError)
|
||||
}
|
||||
return nil, err
|
||||
}, loopMapInfo.StoreMapList)
|
||||
@@ -1113,7 +1113,7 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (err error) {
|
||||
var (
|
||||
mainSkusMap = make(map[int]*model.StoreSkuBind)
|
||||
skusMap = make(map[int]*model.StoreSkuBind)
|
||||
@@ -1140,35 +1140,20 @@ func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
for _, v := range updateList {
|
||||
skuBindInfos1 = append(skuBindInfos1, buildStoreSkuBindInfo(db, storeMap.StoreID, v, false))
|
||||
}
|
||||
hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos1, isAsync, isContinueWhenError, false)
|
||||
}
|
||||
case 1:
|
||||
if len(addList) > 0 {
|
||||
for _, v := range addList {
|
||||
skuBindInfos2 = append(skuBindInfos2, buildStoreSkuBindInfo(db, storeMap.StoreID, v, false))
|
||||
}
|
||||
hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos2, isAsync, isContinueWhenError, false)
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{0, 1})
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
if isAsync {
|
||||
hint = task.GetID()
|
||||
} else {
|
||||
_, err = task.GetResult(0)
|
||||
hint = "1"
|
||||
if len(updateList) > 0 {
|
||||
for _, v := range updateList {
|
||||
skuBindInfos1 = append(skuBindInfos1, buildStoreSkuBindInfo(db, storeMap.StoreID, v, false))
|
||||
}
|
||||
_, err = UpdateStoresSkusByBind(ctx, parentTask, skuBindInfos1, isAsync, isContinueWhenError, false)
|
||||
}
|
||||
return hint, err
|
||||
|
||||
if len(addList) > 0 {
|
||||
for _, v := range addList {
|
||||
skuBindInfos2 = append(skuBindInfos2, buildStoreSkuBindInfo(db, storeMap.StoreID, v, false))
|
||||
}
|
||||
_, err = UpdateStoresSkusByBind(ctx, parentTask, skuBindInfos2, isAsync, isContinueWhenError, false)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func buildStoreSkuBindInfo(db *dao.DaoDB, storeID int, storeBind *model.StoreSkuBind, isFocus bool) (skuBindInfo *StoreSkuBindInfo) {
|
||||
|
||||
@@ -45,6 +45,9 @@ var (
|
||||
dailyWorkTimeList = []string{
|
||||
"22:00:00",
|
||||
}
|
||||
dailyWorkTimeList2 = []string{
|
||||
"23:00:00",
|
||||
}
|
||||
priceReferTimeList = []string{
|
||||
"01:00:00",
|
||||
}
|
||||
@@ -158,6 +161,8 @@ func Init() {
|
||||
if globals.IsProductEnv() {
|
||||
ScheduleTimerFunc("doDailyWork", doDailyWork, dailyWorkTimeList)
|
||||
|
||||
ScheduleTimerFunc("doDailyWork2", doDailyWork2, dailyWorkTimeList2)
|
||||
|
||||
ScheduleTimerFuncByInterval(func() {
|
||||
orderman.SaveJdsOrders(jxcontext.AdminCtx, time.Now().Add(-5*time.Minute), time.Now())
|
||||
}, 5*time.Second, 5*time.Minute)
|
||||
@@ -375,6 +380,13 @@ func syncStoreSku() {
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
}
|
||||
|
||||
func doDailyWork2() {
|
||||
globals.SugarLogger.Debug("doDailyWork2")
|
||||
|
||||
//同步京东商城门店库存和商品
|
||||
cms.CurVendorSync.SyncJdsStoresSkus(jxcontext.AdminCtx, nil, true, true)
|
||||
}
|
||||
|
||||
func doDailyWork() {
|
||||
globals.SugarLogger.Debug("doDailyWork")
|
||||
|
||||
@@ -405,8 +417,6 @@ func doDailyWork() {
|
||||
cms.CurVendorSync.SyncStoreSkusFromYb(jxcontext.AdminCtx, nil, true, true)
|
||||
//刷新京东商城订单结算价
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user