From 505dc405592cba4de212e390c537253df0712138 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Tue, 13 Aug 2019 09:17:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ctx=E4=BC=A0=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/misc2.go | 20 +++++++++----------- controllers/temp_op.go | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/business/jxstore/misc/misc2.go b/business/jxstore/misc/misc2.go index e29593972..5c691e047 100644 --- a/business/jxstore/misc/misc2.go +++ b/business/jxstore/misc/misc2.go @@ -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) } diff --git a/controllers/temp_op.go b/controllers/temp_op.go index d42824a4c..4ef339976 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -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 }) From 06594330a5d1a761cddb3e8fb819a8e7aa97d942 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Tue, 13 Aug 2019 14:53:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=B8=8D=E6=AF=94=E8=BE=83=E5=BE=85?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=B8=94=E4=B8=8D=E5=8F=AF=E5=94=AE=E7=9A=84?= =?UTF-8?q?=EF=BC=8C=E4=BA=AC=E8=A5=BF=E6=9C=89=E5=B9=B3=E5=8F=B0=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 28 +++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index f3122f2a2..abfaff712 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -165,6 +165,18 @@ func GetSkuSaleStatusName(status int) string { return model.SkuStatusName[status] } +func GetBoolName(flag bool) string { + if flag { + return "是" + } else { + return "否" + } +} + +func IsSkuCanSale(saleStatus int) bool { + return saleStatus == model.SkuStatusNormal +} + func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName string, filterJxSkuInfoMap map[int]*StoreSkuNameExt, filterVendorSkuInfoMap map[int]*partner.SkuNameInfo) { for skuID, jxSkuInfo := range filterJxSkuInfoMap { skuIDStr := utils.Int2Str(skuID) @@ -182,23 +194,14 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin status = jxSkuInfo.Skus2[0].JdSyncStatus } syncStatus := utils.Int2Str(int(status)) - toBeCreate := "否" - if model.IsSyncStatusNeedCreate(status) { - toBeCreate = "是" - } - toBeDel := "否" - if model.IsSyncStatusNeedDelete(status) { - toBeDel = "是" - } + toBeCreate := GetBoolName(model.IsSyncStatusNeedCreate(status)) + toBeDel := GetBoolName(model.IsSyncStatusNeedDelete(status)) if vendorSkuInfo != nil { vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status) isSaleStatusDiff := jxSkuSaleStatusName != vendorSkuSaleStatusName - if isFilterToBeCreateAndNotSale && model.IsSyncStatusNeedCreate(status) && jxSkuSaleStatus != model.SkuStatusNormal { - continue - } isNameDiff := jxSkuDetailName != vendorSkuDetailName if jxSkuDetailName != "" && vendorSkuDetailName != "" && strings.Contains(jxSkuDetailName, vendorSkuDetailName) { isNameDiff = false @@ -208,6 +211,9 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin diffData.AppendData(vendorID, outPutData) } } else { + if isFilterToBeCreateAndNotSale && model.IsSyncStatusNeedCreate(status) && !IsSkuCanSale(jxSkuSaleStatus) { + continue + } outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, "", jxSkuSaleStatusName, ""} diffData.AppendData(vendorID, outPutData) }