- 处理设置假营业时间的逻辑BUG(之前逻辑在10点以后重启后,可能导致库存不能恢复)
This commit is contained in:
@@ -3,6 +3,7 @@ package misc
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
@@ -18,6 +19,11 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
SpecialTaskID = "Running"
|
||||||
|
TaskNameSyncStoreSku = "SyncStoreSku"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dailyWorkTimeList = []string{
|
dailyWorkTimeList = []string{
|
||||||
"21:00:00",
|
"21:00:00",
|
||||||
@@ -48,8 +54,31 @@ var (
|
|||||||
autoSaleStoreSkuTimeList = []string{
|
autoSaleStoreSkuTimeList = []string{
|
||||||
"20:50:00",
|
"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() {
|
func Init() {
|
||||||
if globals.IsProductEnv() {
|
if globals.IsProductEnv() {
|
||||||
ScheduleTimerFunc(doDailyWork, dailyWorkTimeList)
|
ScheduleTimerFunc(doDailyWork, dailyWorkTimeList)
|
||||||
@@ -74,6 +103,7 @@ func Init() {
|
|||||||
ScheduleTimerFunc(func() {
|
ScheduleTimerFunc(func() {
|
||||||
dao.UpdateActStatusByTime(dao.GetDB(), time.Now().Add(-48*time.Hour))
|
dao.UpdateActStatusByTime(dao.GetDB(), time.Now().Add(-48*time.Hour))
|
||||||
}, updateActStatusTimeList)
|
}, updateActStatusTimeList)
|
||||||
|
InitEx()
|
||||||
}
|
}
|
||||||
ScheduleTimerFunc(func() {
|
ScheduleTimerFunc(func() {
|
||||||
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)
|
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)
|
||||||
@@ -84,8 +114,10 @@ func doDailyWork() {
|
|||||||
globals.SugarLogger.Debug("doDailyWork")
|
globals.SugarLogger.Debug("doDailyWork")
|
||||||
netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true)
|
netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true)
|
||||||
// cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, true, 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) {
|
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"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
"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/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
@@ -160,38 +159,20 @@ func StartOrEndOpStore(isStart bool, startTime, endTime int16, isAsync, isContin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func InitEx() {
|
func InitEx() {
|
||||||
// if globals.IsMainProductEnv() {
|
startTimeList := startOpStoreTimeListJXCS
|
||||||
// ScheduleTimerFunc(func() {
|
stopTimeList := endOpStoreTimeListJXCS
|
||||||
// StartOrEndOpStore(true, 0, 0, false, true)
|
if !globals.IsMainProductEnv() {
|
||||||
// }, startOpStoreTimeListJXCS)
|
startTimeList = startOpStoreTimeListJXGY
|
||||||
// ScheduleTimerFunc(func() {
|
stopTimeList = endOpStoreTimeListJXGY
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
if time1.Sub(now) < 2*time.Hour {
|
ScheduleTimerFunc(func() {
|
||||||
utils.AfterFuncWithRecover(time1.Sub(now), func() {
|
if !IsImportantTaskRunning(TaskNameSyncStoreSku) {
|
||||||
StartOrEndOpStore(true, 0, 0, false, true)
|
StartOrEndOpStore(true, 0, 0, false, true)
|
||||||
})
|
}
|
||||||
utils.AfterFuncWithRecover(time2.Sub(now), func() {
|
}, startTimeList)
|
||||||
|
ScheduleTimerFunc(func() {
|
||||||
|
if !IsImportantTaskRunning(TaskNameSyncStoreSku) {
|
||||||
StartOrEndOpStore(false, 0, 0, false, true)
|
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 {
|
func ManageTask(task ITask) ITask {
|
||||||
return defTaskMan.ManageTask(task)
|
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