diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index dd5ec5cc1..0fdfc558a 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -1337,22 +1337,24 @@ func GetStoresVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, v task := tasksch.NewParallelTask("GetStoresVendorSnapshot", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { storeMap := batchItemList[0].(*model.StoreMap) - if handler := partner.GetPurchasePlatformFromVendorID(storeMap.VendorID); handler != nil { - store, err2 := handler.ReadStore(ctx, storeMap.VendorStoreID) - if err = err2; err == nil { - retVal = []interface{}{&model.VendorStoreSnapshot{ - StoreID: storeMap.StoreID, - VendorID: storeMap.VendorID, - VendorStoreID: storeMap.VendorStoreID, + if storeMap.VendorID != model.VendorIDWSC { + if handler := partner.GetPurchasePlatformFromVendorID(storeMap.VendorID); handler != nil { + store, err2 := handler.ReadStore(ctx, storeMap.VendorStoreID) + if err = err2; err == nil { + retVal = []interface{}{&model.VendorStoreSnapshot{ + StoreID: storeMap.StoreID, + VendorID: storeMap.VendorID, + VendorStoreID: storeMap.VendorStoreID, - Status: store.Status, - OpenTime1: store.OpenTime1, - CloseTime1: store.CloseTime1, - OpenTime2: store.OpenTime2, - CloseTime2: store.CloseTime2, + Status: store.Status, + OpenTime1: store.OpenTime1, + CloseTime1: store.CloseTime1, + OpenTime2: store.OpenTime2, + CloseTime2: store.CloseTime2, - DeliveryType: store.DeliveryType, - }} + DeliveryType: store.DeliveryType, + }} + } } } return retVal, err diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 43645afa7..6b587a43c 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -2181,7 +2181,7 @@ func GetMissingStoreSkuFromOrder(ctx *jxcontext.Context, fromTime time.Time) (mi return missingList, err } -func AutoSaleStoreSku(ctx *jxcontext.Context, storeIDs []int) (err error) { +func AutoSaleStoreSku(ctx *jxcontext.Context, storeIDs []int, isNeedSync bool) (err error) { db := dao.GetDB() storeSkuList, err := dao.GetAutoSaleStoreSku(db, storeIDs) if err != nil { @@ -2206,7 +2206,7 @@ func AutoSaleStoreSku(ctx *jxcontext.Context, storeIDs []int) (err error) { } } } - if len(skuIDs) > 0 { + if isNeedSync && len(skuIDs) > 0 { if _, err = CurVendorSync.SyncStoresSkus(ctx, db, nil, []int{storeID}, skuIDs, false, true, true); err != nil { return err } diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index d36879390..a13d17676 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -163,7 +163,7 @@ func (v *VendorSync) syncCategories(ctx *jxcontext.Context, parentTask tasksch.I func (v *VendorSync) SyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) { globals.SugarLogger.Debug(v.MultiStoreVendorIDs) - hint, err = v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("同步分类信息:%d", categoryID), isAsync, userName, + hint, err = v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("同步分类信息:%d", categoryID), isAsync, false, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { vendorID := batchItemList[0].(int) var cats []*model.SkuCategory @@ -191,7 +191,7 @@ func (v *VendorSync) SyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, categor } func (v *VendorSync) SyncReorderCategories(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) { - hint, err = v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("分类重排序:%d", categoryID), isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { + hint, err = v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("分类重排序:%d", categoryID), isAsync, false, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { multiStoresHandler := v.GetMultiStoreHandler(batchItemList[0].(int)) err2 := multiStoresHandler.ReorderCategories(db, categoryID, userName) if err2 == nil { @@ -261,7 +261,8 @@ func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuI func (v *VendorSync) SyncSkus(ctx *jxcontext.Context, db *dao.DaoDB, nameIDs []int, skuIDs []int, isAsync, isContinueWhenError bool, userName string) (hint string, err error) { globals.SugarLogger.Debugf("SyncSku trackInfo:%s, nameIDs:%v, skuIDs:%v, userName:%s", ctx.GetTrackInfo(), nameIDs, skuIDs, userName) - return v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("同步商品信息, nameIDs:%v, skuIDs:%v", nameIDs, skuIDs), isAsync, userName, + isManagedIt := len(nameIDs) > 1 || len(skuIDs) > 1 + return v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("同步商品信息, nameIDs:%v, skuIDs:%v", nameIDs, skuIDs), isAsync, isManagedIt, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { var resultList []interface{} vendorID := batchItemList[0].(int) @@ -575,9 +576,9 @@ func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskNa return hint, err } -func (v *VendorSync) LoopMultiStoresVendors(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync bool, userName string, handler tasksch.WorkFunc) (hint string, err error) { +func (v *VendorSync) LoopMultiStoresVendors(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync bool, isManageIt bool, handler tasksch.WorkFunc) (hint string, err error) { task := tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, v.MultiStoreVendorIDs) - tasksch.HandleTask(task, nil, true).Run() + tasksch.HandleTask(task, nil, isManageIt).Run() if !isAsync { result, err2 := task.GetResult(0) if err = err2; err == nil { diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index b4b126001..3c80e0540 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -3,6 +3,7 @@ package misc import ( "fmt" "strings" + "sync" "time" "git.rosy.net.cn/baseapi/utils" @@ -18,6 +19,11 @@ import ( "git.rosy.net.cn/jx-callback/globals" ) +const ( + SpecialTaskID = "Running" + TaskNameSyncStoreSku = "SyncStoreSku" +) + var ( dailyWorkTimeList = []string{ "21:00:00", @@ -45,26 +51,34 @@ var ( "00:01:00", } - autoEnableStoreSkuTimeList = []string{ - "7:00:00", - "8:00:00", - "9:00:00", - "10:00:00", - "11:00:00", - "12:00:00", - "13:00:00", - "14:00:00", - "15:00:00", - "16:00:00", - "17:00:00", - "18:00:00", - "19:00:00", - "20:00:00", - "21:00:00", - "22:00:00", + autoSaleStoreSkuTimeList = []string{ + "20:50:00", } + + importantTaskMap = &sync.Map{} ) +func GetImportantTaskID(taskName string) string { + if value, ok := importantTaskMap.Load(taskName); ok { + return value.(string) + } + return "" +} + +func SaveImportantTaskID(taskName, taskID string) { + importantTaskMap.Store(taskName, taskID) +} + +func IsImportantTaskRunning(taskName string) bool { + taskID := GetImportantTaskID(taskName) + if taskID == "" { + return false + } else if taskID == SpecialTaskID { + return true + } + return tasksch.IsTaskRunning(taskID) +} + func Init() { if globals.IsProductEnv() { ScheduleTimerFunc(doDailyWork, dailyWorkTimeList) @@ -89,18 +103,21 @@ func Init() { ScheduleTimerFunc(func() { dao.UpdateActStatusByTime(dao.GetDB(), time.Now().Add(-48*time.Hour)) }, updateActStatusTimeList) + InitEx() } ScheduleTimerFunc(func() { - cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil) - }, autoEnableStoreSkuTimeList) + cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false) + }, autoSaleStoreSkuTimeList) } func doDailyWork() { globals.SugarLogger.Debug("doDailyWork") netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true) // cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, true, true) - cms.CurVendorSync.SyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD, model.VendorIDEBAI, model.VendorIDMTWM}, nil, nil, false, false, true) - InitEx() + + SaveImportantTaskID(TaskNameSyncStoreSku, SpecialTaskID) + taskID, _ := cms.CurVendorSync.SyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD, model.VendorIDEBAI, model.VendorIDMTWM}, nil, nil, false, true, true) + SaveImportantTaskID(TaskNameSyncStoreSku, taskID) } func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime time.Time, isAsync, isContinueWhenError bool) (hint string, err error) { diff --git a/business/jxstore/misc/misc2.go b/business/jxstore/misc/misc2.go index 29d8ea465..1937f9468 100644 --- a/business/jxstore/misc/misc2.go +++ b/business/jxstore/misc/misc2.go @@ -6,7 +6,6 @@ import ( "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxstore/cms" - "git.rosy.net.cn/jx-callback/business/jxutils" "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" @@ -160,38 +159,20 @@ func StartOrEndOpStore(isStart bool, startTime, endTime int16, isAsync, isContin } func InitEx() { - // if globals.IsMainProductEnv() { - // ScheduleTimerFunc(func() { - // StartOrEndOpStore(true, 0, 0, false, true) - // }, startOpStoreTimeListJXCS) - // ScheduleTimerFunc(func() { - // StartOrEndOpStore(false, 0, 0, false, true) - // }, endOpStoreTimeListJXCS) - // } else { - // ScheduleTimerFunc(func() { - // StartOrEndOpStore(true, 0, 0, false, true) - // }, startOpStoreTimeListJXGY) - // ScheduleTimerFunc(func() { - // StartOrEndOpStore(false, 0, 0, false, true) - // }, endOpStoreTimeListJXGY) - // } - var ( - time1, time2 time.Time - ) - now := time.Now() - if globals.IsMainProductEnv() { - time1 = jxutils.GetNextTimeFromList(now, startOpStoreTimeListJXCS) - time2 = jxutils.GetNextTimeFromList(now, endOpStoreTimeListJXCS) - } else { - time1 = jxutils.GetNextTimeFromList(now, startOpStoreTimeListJXGY) - time2 = jxutils.GetNextTimeFromList(now, endOpStoreTimeListJXGY) + startTimeList := startOpStoreTimeListJXCS + stopTimeList := endOpStoreTimeListJXCS + if !globals.IsMainProductEnv() { + startTimeList = startOpStoreTimeListJXGY + stopTimeList = endOpStoreTimeListJXGY } - if time1.Sub(now) < 2*time.Hour { - utils.AfterFuncWithRecover(time1.Sub(now), func() { + ScheduleTimerFunc(func() { + if !IsImportantTaskRunning(TaskNameSyncStoreSku) { StartOrEndOpStore(true, 0, 0, false, true) - }) - utils.AfterFuncWithRecover(time2.Sub(now), func() { + } + }, startTimeList) + ScheduleTimerFunc(func() { + if !IsImportantTaskRunning(TaskNameSyncStoreSku) { StartOrEndOpStore(false, 0, 0, false, true) - }) - } + } + }, stopTimeList) } diff --git a/business/jxutils/tasksch/task_man.go b/business/jxutils/tasksch/task_man.go index 68088628e..4dd270358 100644 --- a/business/jxutils/tasksch/task_man.go +++ b/business/jxutils/tasksch/task_man.go @@ -51,3 +51,10 @@ func GetTasks(taskID string, fromStatus, toStatus int, lastHours int, createdBy func ManageTask(task ITask) ITask { return defTaskMan.ManageTask(task) } + +func IsTaskRunning(taskID string) bool { + if taskList := GetTasks(taskID, TaskStatusBegin, TaskStatusWorking, 36, ""); len(taskList) > 0 { + return true + } + return false +} diff --git a/business/model/net_spider.go b/business/model/net_spider.go index d7b747e29..bf9e909b2 100644 --- a/business/model/net_spider.go +++ b/business/model/net_spider.go @@ -30,9 +30,3 @@ func (*PageShop) TableUnique() [][]string { []string{"VendorStoreID", "VendorID"}, } } - -func (*PageShop) TableIndex() [][]string { - return [][]string{ - []string{"Tel1"}, - } -}