ctx传参

This commit is contained in:
Rosy-zhudan
2019-08-13 09:17:50 +08:00
parent 262cc9d4f3
commit 505dc40559
2 changed files with 10 additions and 12 deletions

View File

@@ -57,8 +57,7 @@ var (
}
)
func AddOrDelExtraStoreOptime(vendorID, storeID int, vendorStoreID string, storeInfo *model.Store, startOpStoreTime, endOpStoreTime int16, needAddTime bool) bool {
ctx := jxcontext.AdminCtx
func AddOrDelExtraStoreOptime(ctx *jxcontext.Context, vendorID, storeID int, vendorStoreID string, storeInfo *model.Store, startOpStoreTime, endOpStoreTime int16, needAddTime bool) bool {
opTimeList := storeInfo.GetOpTimeList()
if needAddTime {
opTimeList = []int16{startOpStoreTime, endOpStoreTime}
@@ -97,8 +96,7 @@ func SetSkuStock(isStart bool, storeSkuNameList []*partner.SkuNameInfo) {
}
}
func SetSpecialSkuStatus(storeID, vendorID int, vendorStoreID string, storeSkuNameList []*partner.SkuNameInfo) {
ctx := jxcontext.AdminCtx
func SetSpecialSkuStatus(ctx *jxcontext.Context, storeID, vendorID int, vendorStoreID string, storeSkuNameList []*partner.SkuNameInfo) {
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
for _, skuNameInfo := range storeSkuNameList {
for _, skuInfo := range skuNameInfo.SkuList {
@@ -120,7 +118,7 @@ func GetFilterStoreSkuList(storeSkuList []*partner.StoreSkuInfo) (storeSkuListOu
return storeSkuListOut
}
func StartOrEndOpStore(isStart bool, vendorIDList []int, storeIDList []int, startTime, endTime int16, isAsync, isContinueWhenError bool) (retVal interface{}, err error) {
func StartOrEndOpStore(ctx *jxcontext.Context, isStart bool, vendorIDList []int, storeIDList []int, startTime, endTime int16, isAsync, isContinueWhenError bool) (retVal interface{}, err error) {
startProcessTime := time.Now().Unix()
vendorMap := make(map[int]bool)
for _, vendorID := range vendorIDList {
@@ -131,7 +129,6 @@ func StartOrEndOpStore(isStart bool, vendorIDList []int, storeIDList []int, star
storeIDMap[storeID] = true
}
baseapi.SugarLogger.Debugf("StartOrEndOpStore start time: %v", time.Now())
ctx := jxcontext.AdminCtx
storeInfo, err := cms.GetStores(ctx, "", map[string]interface{}{}, 0, -1, utils.DefaultTimeValue, utils.DefaultTimeValue, 0, 0)
if err != nil {
@@ -170,14 +167,14 @@ func StartOrEndOpStore(isStart bool, vendorIDList []int, storeIDList []int, star
baseapi.SugarLogger.Errorf("StartOrEndOpStore GetStoreSkusFullInfo error:%v storeID:%d vendorID:%d vendorStoreID:%s", err, storeID, vendorID, vendorStoreID)
} else {
SetSkuStock(isStart, storeSkuNameList)
SetSpecialSkuStatus(storeID, vendorID, vendorStoreID, storeSkuNameList)
SetSpecialSkuStatus(ctx, storeID, vendorID, vendorStoreID, storeSkuNameList)
storeSkuList := putils.StoreSkuFullList2Bare(storeSkuNameList)
if vendorID == model.VendorIDMTWM {
storeSkuList = GetFilterStoreSkuList(storeSkuList)
}
if len(storeSkuList) > 0 {
if !isStart {
AddOrDelExtraStoreOptime(vendorID, storeID, vendorStoreID, &storeListValue.Store, startOpStoreTime, endOpStoreTime, false)
AddOrDelExtraStoreOptime(ctx, vendorID, storeID, vendorStoreID, &storeListValue.Store, startOpStoreTime, endOpStoreTime, false)
}
_, err = putils.FreeBatchStoreSkuInfo("更新门店商品库存", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
@@ -190,7 +187,7 @@ func StartOrEndOpStore(isStart bool, vendorIDList []int, storeIDList []int, star
}, ctx, task, storeSkuList, singleStoreHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusStock), true)
if isStart {
AddOrDelExtraStoreOptime(vendorID, storeID, vendorStoreID, &storeListValue.Store, startOpStoreTime, endOpStoreTime, true)
AddOrDelExtraStoreOptime(ctx, vendorID, storeID, vendorStoreID, &storeListValue.Store, startOpStoreTime, endOpStoreTime, true)
}
}
}
@@ -233,17 +230,18 @@ func GetVendorStoreRefreshTime(vendorID int) (startTimeList, stopTimeList []stri
}
func RefreshStore(vendorID int) {
ctx := jxcontext.AdminCtx
startTimeList, stopTimeList := GetVendorStoreRefreshTime(vendorID)
vendorIDList := []int{vendorID}
storeIDList := []int{}
ScheduleTimerFunc("StartOpStore", func() {
if !IsImportantTaskRunning(TaskNameSyncStoreSku) {
StartOrEndOpStore(true, vendorIDList, storeIDList, 0, 0, false, true)
StartOrEndOpStore(ctx, true, vendorIDList, storeIDList, 0, 0, false, true)
}
}, startTimeList)
ScheduleTimerFunc("EndOpStore", func() {
if !IsImportantTaskRunning(TaskNameSyncStoreSku) {
StartOrEndOpStore(false, vendorIDList, storeIDList, 0, 0, false, true)
StartOrEndOpStore(ctx, false, vendorIDList, storeIDList, 0, 0, false, true)
}
}, stopTimeList)
}

View File

@@ -292,7 +292,7 @@ func (c *TempOpController) TestStartOrEndOpStore() {
var vendorIDList []int
var storeIDList []int
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil {
retVal, err = misc.StartOrEndOpStore(params.StartOrEndStore, vendorIDList, storeIDList, int16(params.StartTime), int16(params.EndTime), params.IsAsync, params.IsContinueWhenError)
retVal, err = misc.StartOrEndOpStore(params.Ctx, params.StartOrEndStore, vendorIDList, storeIDList, int16(params.StartTime), int16(params.EndTime), params.IsAsync, params.IsContinueWhenError)
}
return retVal, "", err
})