From 018ae0e4f941277b53ec220fe988fc5ceef9917b Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Thu, 1 Aug 2019 16:38:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=98=AF=E5=90=A6=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E7=AD=89=E5=8F=82=E6=95=B0=EF=BC=8C=E5=8C=BA=E5=88=86?= =?UTF-8?q?=E8=8F=9C=E5=B8=82=E5=92=8C=E6=9E=9C=E5=9B=AD=E7=9A=84=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/misc2.go | 51 ++++++++++++++++++++++++---------- controllers/temp_op.go | 12 ++++---- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/business/jxstore/misc/misc2.go b/business/jxstore/misc/misc2.go index a8d23957e..d7da6c7a8 100644 --- a/business/jxstore/misc/misc2.go +++ b/business/jxstore/misc/misc2.go @@ -10,6 +10,7 @@ import ( "git.rosy.net.cn/jx-callback/business/partner/putils" "git.rosy.net.cn/baseapi" "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" + "git.rosy.net.cn/jx-callback/globals" ) const ( @@ -23,10 +24,16 @@ const ( ) var ( - startOpStoreTimeList = []string { + startOpStoreTimeListJXCS = []string { + "22:10:00", + } + endOpStoreTimeListJXCS = []string { + "06:10:00", + } + startOpStoreTimeListJXGY = []string { "22:00:00", } - endOpStoreTimeList = []string { + endOpStoreTimeListJXGY = []string { "06:00:00", } vendorList = map[int]bool { @@ -72,7 +79,7 @@ func FilterSkuNameList(storeSkuNameList []*partner.SkuNameInfo) (filterStoreSkuN return filterStoreSkuNameList } -func StartOrEndOpStore(isStart bool, startTime, endTime int16) { +func StartOrEndOpStore(isStart bool, startTime, endTime int16, isAsync, isContinueWhenError bool) (retVal interface{}, err error) { startProcessTime := time.Now().Unix() baseapi.SugarLogger.Debugf("StartOrEndOpStore start time: %v", time.Now()) ctx := jxcontext.AdminCtx @@ -97,7 +104,7 @@ func StartOrEndOpStore(isStart bool, startTime, endTime int16) { vendorStoreID := utils.Interface2String(vendorListValue["vendorStoreID"]) baseapi.SugarLogger.Debugf("StartOrEndOpStore storeID:%d vendorID:%d vendorStoreID:%s", storeID, vendorID, vendorStoreID) singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) - storeSkuNameList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, nil, storeID, vendorStoreID, nil) + storeSkuNameList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil) if err != nil { baseapi.SugarLogger.Errorf("StartOrEndOpStore GetStoreSkusFullInfo error:%v storeID:%d vendorID:%d vendorStoreID:%s", err, storeID, vendorID, vendorStoreID) } else { @@ -130,24 +137,40 @@ func StartOrEndOpStore(isStart bool, startTime, endTime int16) { } return retVal, err } - task := tasksch.NewParallelTask("StartOrEndOpStore", nil, ctx, taskFunc, storeInfo.Stores) + task := tasksch.NewParallelTask("StartOrEndOpStore", tasksch.NewParallelConfig().SetParallelCount(4), ctx, taskFunc, storeInfo.Stores) tasksch.HandleTask(task, nil, true).Run() - _, err = task.GetResult(0) - if err != nil { - baseapi.SugarLogger.Debugf("StartOrEndOpStore tasksch error:%v", err) + if isAsync { + retVal = task.ID + } else { + _, err = task.GetResult(0) + if err != nil { + baseapi.SugarLogger.Debugf("StartOrEndOpStore tasksch error:%v", err) + } + retVal = "1" } } endProcessTime := time.Now().Unix() diff := endProcessTime - startProcessTime baseapi.SugarLogger.Debugf("StartOrEndOpStore end time: %v", time.Now()) baseapi.SugarLogger.Debugf("StartOrEndOpStore cost time: %d sec", diff) + + return retVal, err } func InitEx() { - ScheduleTimerFunc(func() { - StartOrEndOpStore(true, 0, 0) - }, startOpStoreTimeList) - ScheduleTimerFunc(func() { - StartOrEndOpStore(false, 0, 0) - }, endOpStoreTimeList) + 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) + } } \ No newline at end of file diff --git a/controllers/temp_op.go b/controllers/temp_op.go index d2fc4d144..9997036e8 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -275,16 +275,18 @@ func (c *TempOpController) TestIt() { // @Title 开启或结束所有平台商店的额外时间 // @Description 开启或结束所有平台商店的额外时间,并且修改所有商品库存为0或99999(开启:0 , 结束:99999) -// @Param token header string true "认证token" -// @Param startOrEndStore query bool true "开启或结束" -// @Param startTime query int false "开始营业时间(格式:930代表早上9点30分)" -// @Param endTime query int false "结束营业时间" +// @Param token header string true "认证token" +// @Param startOrEndStore query bool true "开启或结束" +// @Param startTime query int false "开始营业时间(格式:930代表早上9点30分)" +// @Param endTime query int false "结束营业时间" +// @Param isAsync query bool false "是否异步操作" +// @Param isContinueWhenError query bool false "单个同步失败是否继续,缺省false" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /TestStartOrEndOpStore [get] func (c *TempOpController) TestStartOrEndOpStore() { c.callTestStartOrEndOpStore(func(params *tTempopTestStartOrEndOpStoreParams) (retVal interface{}, errCode string, err error) { - misc.StartOrEndOpStore(params.StartOrEndStore, int16(params.StartTime), int16(params.EndTime)) + retVal, err = misc.StartOrEndOpStore(params.StartOrEndStore, int16(params.StartTime), int16(params.EndTime), params.IsAsync, params.IsContinueWhenError) return retVal, "", err }) }