- 处理设置假营业时间的逻辑BUG(之前逻辑在10点以后重启后,可能导致库存不能恢复)
This commit is contained in:
@@ -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",
|
||||
@@ -48,8 +54,31 @@ var (
|
||||
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)
|
||||
@@ -74,6 +103,7 @@ func Init() {
|
||||
ScheduleTimerFunc(func() {
|
||||
dao.UpdateActStatusByTime(dao.GetDB(), time.Now().Add(-48*time.Hour))
|
||||
}, updateActStatusTimeList)
|
||||
InitEx()
|
||||
}
|
||||
ScheduleTimerFunc(func() {
|
||||
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)
|
||||
@@ -84,8 +114,10 @@ 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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user