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