Merge remote-tracking branch 'origin/mark' into don
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -30,9 +30,3 @@ func (*PageShop) TableUnique() [][]string {
|
||||
[]string{"VendorStoreID", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
func (*PageShop) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"Tel1"},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user