Accept Merge Request #34: (don -> mark)
Merge Request: 优化京西和平台商品差异对比的代码结构 Created By: @Nathan drake Accepted By: @Nathan drake URL: https://dev.tencent.com/u/XJH-Rosy/p/jx-callback/git/merge/34
This commit is contained in:
@@ -105,9 +105,15 @@ func GetMultiStoreAllSkuInfoList(vendorID int) []*partner.StoreSkuInfo {
|
|||||||
return multiStoreAllSkuInfoList[vendorID]
|
return multiStoreAllSkuInfoList[vendorID]
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMultiStoreAllSkuInfo(ctx *jxcontext.Context) {
|
func GetMultiStoreAllSkuInfo(ctx *jxcontext.Context, vendorMap map[int]bool) {
|
||||||
InitMultiStoreData()
|
InitMultiStoreData()
|
||||||
for vendorID, _ := range vendorNameList {
|
for vendorID, _ := range vendorNameList {
|
||||||
|
//filter for vendorID
|
||||||
|
if len(vendorMap) > 0 {
|
||||||
|
if _, ok := vendorMap[vendorID]; !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
if IsMultiStore(vendorID) {
|
if IsMultiStore(vendorID) {
|
||||||
multiHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler)
|
multiHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler)
|
||||||
allSkuNameInfoList, err := multiHandler.GetSkus(ctx, 0, "", "")
|
allSkuNameInfoList, err := multiHandler.GetSkus(ctx, 0, "", "")
|
||||||
@@ -161,6 +167,44 @@ func GetFilterMultiStoreSkuInfoMap(vendorID int, skuInfoList []*partner.StoreSku
|
|||||||
return filterSkuInfoMap
|
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 {
|
func GetSkuSaleStatusName(status int) string {
|
||||||
return model.SkuStatusName[status]
|
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) {
|
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
switch step {
|
switch step {
|
||||||
case 0:
|
case 0:
|
||||||
|
GetMultiStoreAllSkuInfo(ctx, vendorMap)
|
||||||
|
case 1:
|
||||||
jxStoreInfoList, err := GetStores(ctx, "", map[string]interface{}{}, 0, -1, utils.DefaultTimeValue, utils.DefaultTimeValue, 0, 0)
|
jxStoreInfoList, err := GetStores(ctx, "", map[string]interface{}{}, 0, -1, utils.DefaultTimeValue, utils.DefaultTimeValue, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStores error:%v", err)
|
baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStores error:%v", err)
|
||||||
} else {
|
} else {
|
||||||
GetMultiStoreAllSkuInfo(ctx)
|
filterStoreList := GetFilterStoreList(jxStoreInfoList.Stores, vendorMap, storeIDMap)
|
||||||
diffData.InitData()
|
diffData.InitData()
|
||||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
jxStoreInfoListValue := batchItemList[0].(*StoreExt)
|
jxStoreInfoListValue := batchItemList[0].(*StoreExt)
|
||||||
storeID := jxStoreInfoListValue.ID
|
storeID := jxStoreInfoListValue.ID
|
||||||
//filter for storeID
|
|
||||||
if len(storeIDMap) > 0 {
|
|
||||||
if _, ok := storeIDMap[storeID]; !ok {
|
|
||||||
return retVal, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
storeIDStr := utils.Int2Str(storeID)
|
storeIDStr := utils.Int2Str(storeID)
|
||||||
storeName := jxStoreInfoListValue.Name
|
storeName := jxStoreInfoListValue.Name
|
||||||
if jxStoreInfoListValue.StoreMaps != nil {
|
if jxStoreInfoListValue.StoreMaps != nil {
|
||||||
@@ -267,59 +307,48 @@ func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int,
|
|||||||
var filterJxSkuInfoMap map[int]*StoreSkuNameExt
|
var filterJxSkuInfoMap map[int]*StoreSkuNameExt
|
||||||
for _, vendorListValue := range jxStoreInfoListValue.StoreMaps {
|
for _, vendorListValue := range jxStoreInfoListValue.StoreMaps {
|
||||||
vendorID := int(utils.MustInterface2Int64(vendorListValue["vendorID"]))
|
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"])
|
if isGetJxSkuInfoData == false { //only get once jx sku info list every store id
|
||||||
baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor storeID:%d vendorID:%d vendorStoreID:%s vendorListValue:%v", storeID, vendorID, vendorStoreID, vendorListValue)
|
isGetJxSkuInfoData = true
|
||||||
|
jxSkuInfoData, _ := GetStoreSkus(ctx, storeID, []int{}, true, "", true, map[string]interface{}{}, 0, -1)
|
||||||
if IsMultiStore(vendorID) {
|
filterJxSkuInfoMap = GetFilterJxSkuInfoMap(jxSkuInfoData.SkuNames)
|
||||||
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
}
|
||||||
allSkuInfoList := GetMultiStoreAllSkuInfoList(vendorID)
|
|
||||||
skuBareInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, task, storeID, vendorStoreID, allSkuInfoList)
|
vendorStoreID := utils.Interface2String(vendorListValue["vendorStoreID"])
|
||||||
if err != nil {
|
baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor storeID:%d vendorID:%d vendorStoreID:%s vendorListValue:%v", storeID, vendorID, vendorStoreID, vendorListValue)
|
||||||
baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err)
|
|
||||||
} else if len(skuBareInfoList) > 0 {
|
if IsMultiStore(vendorID) {
|
||||||
filterSkuInfoMap := GetFilterMultiStoreSkuInfoMap(vendorID, skuBareInfoList)
|
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
||||||
CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterSkuInfoMap)
|
allSkuInfoList := GetMultiStoreAllSkuInfoList(vendorID)
|
||||||
}
|
skuBareInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, task, storeID, vendorStoreID, allSkuInfoList)
|
||||||
} else {
|
if err != nil {
|
||||||
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err)
|
||||||
vendorSkuInfoList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil)
|
} else if len(skuBareInfoList) > 0 {
|
||||||
if err != nil {
|
filterSkuInfoMap := GetFilterMultiStoreSkuInfoMap(vendorID, skuBareInfoList)
|
||||||
baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusFullInfo error:%v", err)
|
CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterSkuInfoMap)
|
||||||
} else if len(vendorSkuInfoList) > 0 {
|
}
|
||||||
filterVendorSkuInfoMap := GetFilterVendorSkuInfoMap(vendorSkuInfoList)
|
} else {
|
||||||
CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterVendorSkuInfoMap)
|
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
|
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()
|
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||||
_, err = taskParallel.GetResult(0)
|
_, err = taskParallel.GetResult(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor taskParallel error:%v", err)
|
baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor taskParallel error:%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 1:
|
case 2:
|
||||||
WriteToExcel(task, diffData.diffDataMap)
|
WriteToExcel(task, diffData.diffDataMap)
|
||||||
endProcessTime := time.Now().Unix()
|
endProcessTime := time.Now().Unix()
|
||||||
diff := endProcessTime - startProcessTime
|
diff := endProcessTime - startProcessTime
|
||||||
@@ -328,7 +357,7 @@ func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int,
|
|||||||
}
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
taskSeq := tasksch.NewSeqTask("CheckSkuDiffBetweenJxAndVendor SeqTask", ctx, taskSeqFunc, 2)
|
taskSeq := tasksch.NewSeqTask("京西和平台商品差异对比-序列任务", ctx, taskSeqFunc, 3)
|
||||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user