From 80a82ea3a4770782da5531e6da4138e1185a557b Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Wed, 14 Aug 2019 11:28:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=AC=E8=A5=BF=E5=92=8C?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=95=86=E5=93=81=E5=B7=AE=E5=BC=82=E5=AF=B9?= =?UTF-8?q?=E6=AF=94=E7=9A=84=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 127 +++++++++++++++--------- 1 file changed, 78 insertions(+), 49 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index abfaff712..6c7002adf 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -105,9 +105,15 @@ func GetMultiStoreAllSkuInfoList(vendorID int) []*partner.StoreSkuInfo { return multiStoreAllSkuInfoList[vendorID] } -func GetMultiStoreAllSkuInfo(ctx *jxcontext.Context) { +func GetMultiStoreAllSkuInfo(ctx *jxcontext.Context, vendorMap map[int]bool) { InitMultiStoreData() for vendorID, _ := range vendorNameList { + //filter for vendorID + if len(vendorMap) > 0 { + if _, ok := vendorMap[vendorID]; !ok { + continue + } + } if IsMultiStore(vendorID) { multiHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler) allSkuNameInfoList, err := multiHandler.GetSkus(ctx, 0, "", "") @@ -161,6 +167,44 @@ func GetFilterMultiStoreSkuInfoMap(vendorID int, skuInfoList []*partner.StoreSku return filterSkuInfoMap } +func GetFilterStoreList(storeList []*StoreExt, vendorMap, storeIDMap map[int]bool) (outStoreList []*StoreExt) { + for _, storeInfo := range storeList { + storeID := storeInfo.ID + //filter for storeID + if len(storeIDMap) > 0 { + if _, ok := storeIDMap[storeID]; !ok { + continue + } + } + if storeInfo.StoreMaps != nil { + var tempStoreMaps []map[string]interface{} + for _, vendorStoreInfo := range storeInfo.StoreMaps { + vendorID := int(utils.MustInterface2Int64(vendorStoreInfo["vendorID"])) + isSyncStoreSku := int(utils.MustInterface2Int64(vendorStoreInfo["isSync"])) + if isSyncStoreSku == 0 { + continue + } + //filter for vendorID + if len(vendorMap) > 0 { + if _, ok := vendorMap[vendorID]; !ok { + continue + } + } + if _, ok := vendorNameList[vendorID]; !ok { + continue + } + tempStoreMaps = append(tempStoreMaps, vendorStoreInfo) + } + if len(tempStoreMaps) > 0 { + storeInfo.StoreMaps = tempStoreMaps + outStoreList = append(outStoreList, storeInfo) + } + } + } + + return outStoreList +} + func GetSkuSaleStatusName(status int) string { return model.SkuStatusName[status] } @@ -245,21 +289,17 @@ func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int, taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { switch step { case 0: + GetMultiStoreAllSkuInfo(ctx, vendorMap) + case 1: jxStoreInfoList, err := GetStores(ctx, "", map[string]interface{}{}, 0, -1, utils.DefaultTimeValue, utils.DefaultTimeValue, 0, 0) if err != nil { baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStores error:%v", err) } else { - GetMultiStoreAllSkuInfo(ctx) + filterStoreList := GetFilterStoreList(jxStoreInfoList.Stores, vendorMap, storeIDMap) diffData.InitData() taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { jxStoreInfoListValue := batchItemList[0].(*StoreExt) storeID := jxStoreInfoListValue.ID - //filter for storeID - if len(storeIDMap) > 0 { - if _, ok := storeIDMap[storeID]; !ok { - return retVal, err - } - } storeIDStr := utils.Int2Str(storeID) storeName := jxStoreInfoListValue.Name if jxStoreInfoListValue.StoreMaps != nil { @@ -267,59 +307,48 @@ func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int, var filterJxSkuInfoMap map[int]*StoreSkuNameExt for _, vendorListValue := range jxStoreInfoListValue.StoreMaps { vendorID := int(utils.MustInterface2Int64(vendorListValue["vendorID"])) - isSyncStoreSku := int(utils.MustInterface2Int64(vendorListValue["isSync"])) - if isSyncStoreSku == 0 { - continue - } - //filter for vendorID - if len(vendorMap) > 0 { - if _, ok := vendorMap[vendorID]; !ok { - continue - } - } - if _, ok := vendorNameList[vendorID]; ok { - if isGetJxSkuInfoData == false { //only get once jx sku info list every store id - isGetJxSkuInfoData = true - jxSkuInfoData, _ := GetStoreSkus(ctx, storeID, []int{}, true, "", true, map[string]interface{}{}, 0, -1) - filterJxSkuInfoMap = GetFilterJxSkuInfoMap(jxSkuInfoData.SkuNames) - } - vendorStoreID := utils.Interface2String(vendorListValue["vendorStoreID"]) - baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor storeID:%d vendorID:%d vendorStoreID:%s vendorListValue:%v", storeID, vendorID, vendorStoreID, vendorListValue) - - if IsMultiStore(vendorID) { - singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler) - allSkuInfoList := GetMultiStoreAllSkuInfoList(vendorID) - skuBareInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, task, storeID, vendorStoreID, allSkuInfoList) - if err != nil { - baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err) - } else if len(skuBareInfoList) > 0 { - filterSkuInfoMap := GetFilterMultiStoreSkuInfoMap(vendorID, skuBareInfoList) - CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterSkuInfoMap) - } - } else { - singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) - vendorSkuInfoList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil) - if err != nil { - baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusFullInfo error:%v", err) - } else if len(vendorSkuInfoList) > 0 { - filterVendorSkuInfoMap := GetFilterVendorSkuInfoMap(vendorSkuInfoList) - CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterVendorSkuInfoMap) - } + if isGetJxSkuInfoData == false { //only get once jx sku info list every store id + isGetJxSkuInfoData = true + jxSkuInfoData, _ := GetStoreSkus(ctx, storeID, []int{}, true, "", true, map[string]interface{}{}, 0, -1) + filterJxSkuInfoMap = GetFilterJxSkuInfoMap(jxSkuInfoData.SkuNames) + } + + vendorStoreID := utils.Interface2String(vendorListValue["vendorStoreID"]) + baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor storeID:%d vendorID:%d vendorStoreID:%s vendorListValue:%v", storeID, vendorID, vendorStoreID, vendorListValue) + + if IsMultiStore(vendorID) { + singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler) + allSkuInfoList := GetMultiStoreAllSkuInfoList(vendorID) + skuBareInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, task, storeID, vendorStoreID, allSkuInfoList) + if err != nil { + baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err) + } else if len(skuBareInfoList) > 0 { + filterSkuInfoMap := GetFilterMultiStoreSkuInfoMap(vendorID, skuBareInfoList) + CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterSkuInfoMap) + } + } else { + singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) + vendorSkuInfoList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil) + if err != nil { + baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusFullInfo error:%v", err) + } else if len(vendorSkuInfoList) > 0 { + filterVendorSkuInfoMap := GetFilterVendorSkuInfoMap(vendorSkuInfoList) + CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterVendorSkuInfoMap) } } } } return retVal, err } - taskParallel := tasksch.NewParallelTask("CheckSkuDiffBetweenJxAndVendor", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc, jxStoreInfoList.Stores) + taskParallel := tasksch.NewParallelTask("京西和平台商品差异对比-门店商品对比", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc, filterStoreList) tasksch.HandleTask(taskParallel, task, true).Run() _, err = taskParallel.GetResult(0) if err != nil { baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor taskParallel error:%v", err) } } - case 1: + case 2: WriteToExcel(task, diffData.diffDataMap) endProcessTime := time.Now().Unix() diff := endProcessTime - startProcessTime @@ -328,7 +357,7 @@ func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int, } return result, err } - taskSeq := tasksch.NewSeqTask("CheckSkuDiffBetweenJxAndVendor SeqTask", ctx, taskSeqFunc, 2) + taskSeq := tasksch.NewSeqTask("京西和平台商品差异对比-序列任务", ctx, taskSeqFunc, 3) tasksch.HandleTask(taskSeq, nil, true).Run() }