From c88b7374788a7d596ab928cb0b7293a1118fcd96 Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Fri, 19 Jun 2020 14:11:37 +0800 Subject: [PATCH 1/4] qidongsheng 0619 --- business/jxstore/cms/store_sku.go | 17 ++ ...store_sku_check.go => store_sku_check.go1} | 229 ++++++++++++++++-- ...ck_test.go => store_sku_check.go1_test.go} | 0 business/jxutils/excel/excel.go | 29 ++- business/jxutils/tasksch/parallel_task.go | 1 + business/jxutils/tasksch/task.go | 2 +- business/model/sku.go | 7 +- controllers/temp_op.go | 19 ++ routers/commentsRouter_controllers.go | 18 ++ 9 files changed, 292 insertions(+), 30 deletions(-) rename business/jxstore/cms/{store_sku_check.go => store_sku_check.go1} (71%) rename business/jxstore/cms/{store_sku_check_test.go => store_sku_check.go1_test.go} (100%) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index b08ea8622..6fa4ee8dc 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -4447,3 +4447,20 @@ func GetStoreSkuAudit(ctx *jxcontext.Context, storeIDs, nameIDs, skuIDs []int, s pagedInfo, err = dao.GetStoreSkuAudit(dao.GetDB(), storeIDs, nameIDs, skuIDs, status, name, remark, applyTimeStart, applyTimeEnd, auditTimeStart, auditTimeEnd, pageSize, offset) return pagedInfo, err } + +func SetJxPrice(jxSkuInfoDataMulti *dao.StoreSkuNamesInfo,storeId int) (err error){ + db := dao.GetDB() + storeDetail, err := dao.GetStoreDetail(dao.GetDB(), storeId, model.VendorIDJX) + if err != nil { + dao.Rollback(db) + return err + } + /*重新计算京西价格*/ + for _,values := range jxSkuInfoDataMulti.SkuNames{ + for _,value := range values.Skus{ + value.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), value.JxPrice) + } + } + /*重新计算京西价格*/ + return nil +} \ No newline at end of file diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go1 similarity index 71% rename from business/jxstore/cms/store_sku_check.go rename to business/jxstore/cms/store_sku_check.go1 index af4fe0995..c0a8cda70 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go1 @@ -2,6 +2,8 @@ package cms import ( "fmt" + "github.com/astaxie/beego" + "strconv" "strings" "sync" "time" @@ -22,7 +24,7 @@ import ( const ( canWriteTolocal = false - needStatistic = true + needStatistic = false isFilterToBeCreateAndNotSale = true parallelCount = 5 fileExt = ".xlsx" @@ -38,6 +40,7 @@ const ( DatAanalyse6 = "京西商品库有,平台商品库没有" DatAanalyse7 = "同步状态异常" DatAanalyse8 = "平台门店未关注或平台门店商品库存为0,应添加对应的平台门店商品" + DatAanalyse9 = "平台门店价格与京西商品库价格不一致" ) var ( @@ -62,6 +65,8 @@ var ( "平台商品名", "京西可售状态", "平台可售状态", + "京西价格", + "平台价格", "数据分析", } @@ -136,6 +141,8 @@ type DiffData struct { VendorSkuName string `json:"平台商品名"` JxStatus string `json:"京西可售状态"` VendorStatus string `json:"平台可售状态"` + JxSkuPrice string `json:"京西价格"` /*哇,不能小写,不然会搞事情*/ + VendorPrice string `json:"平台价格"` DatAanalyse string `json:"数据分析"` } @@ -216,7 +223,13 @@ func GetMultiStoreAllSkuInfo(ctx *jxcontext.Context, vendorMap map[int]bool) { if err != nil { baseapi.SugarLogger.Errorf("GetMultiStoreAllSkuInfo error:%v", err) } else { - multiStoreAllSkuInfoList[vendorID][vendorOrgCode] = StoreSkuFullList2BareFilter(allSkuNameInfoList) //map[平台ID:[]StoreSkuInfo1,StoreSkuInfo2...] + if multiStoreAllSkuInfoList[vendorID] != nil { + multiStoreAllSkuInfoList[vendorID][vendorOrgCode] = StoreSkuFullList2BareFilter(allSkuNameInfoList) //map[平台ID:[]StoreSkuInfo1,StoreSkuInfo2...] + } else { + multiStoreAllSkuInfoList = make(map[int]map[string][]*partner.StoreSkuInfo) + multiStoreAllSkuInfoList[vendorID] = make(map[string][]*partner.StoreSkuInfo) + multiStoreAllSkuInfoList[vendorID][vendorOrgCode] = StoreSkuFullList2BareFilter(allSkuNameInfoList) //map[平台ID:[]StoreSkuInfo1,StoreSkuInfo2...] + } tempMap := make(map[int]*partner.SkuNameInfo) for _, value := range allSkuNameInfoList { for _, skuInfo := range value.SkuList { @@ -334,8 +347,11 @@ func IsSkuCanSale(saleStatus int) bool { //京西平台和其他平台商品的对比 //storeIDStr 京西商家id ,vendorStoreID 平台商家id func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName string, filterJxSkuInfoMap map[int]*dao.StoreSkuNameExt, filterVendorSkuInfoMap map[int]*partner.SkuNameInfo) { + utils.Writelog("进入 CompareJxAndVendor 方法") for skuID, jxSkuInfo := range filterJxSkuInfoMap { skuIDStr := utils.Int2Str(skuID) + /*写京西skuIDStr*/ + utils.Writelog("skuIDStr" + skuIDStr) var jxSkuDetailName string //多规格商品不用比较数量单位 if jxSkuInfo.IsSpu == 0 { @@ -345,11 +361,13 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin //jxSkuDetailName : 前缀 ([荐]) + 分类名(xxx水饺) + 数量单位(约..g/份) + 注释 (补充..) jxSkuDetailName = jxutils.ComposeSkuNameOriginal(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, jxSkuInfo.Skus[0].Comment, "", jxSkuInfo.Skus[0].SkuSpecQuality, "", 0) } - + utils.Writelog("jxSkuDetailName:" + jxSkuDetailName) //jxSkuSaleStatus : 商品状态 ,skustatus 优先级高于 StoreSkuStatus jxSkuSaleStatus := jxutils.MergeSkuStatus(jxSkuInfo.Skus[0].SkuStatus, jxSkuInfo.Skus[0].StoreSkuStatus) jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus) - + /*京西价格*/ + jxSkuPrice := fmt.Sprintf("%.2f", float64(jxSkuInfo.Skus[0].JxPrice)/float64(100)) + //jxSkuPrice := strconv.Itoa(jxSkuInfo.Skus[0].JxPrice) vendorSkuInfo := filterVendorSkuInfoMap[skuID] var status int8 if vendorID == model.VendorIDMTWM { @@ -366,13 +384,18 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin if vendorSkuInfo != nil { vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status) - + /* 供货商价格 */ + vendorPrice := fmt.Sprintf("%.2f", float64(vendorSkuInfo.SkuList[0].StoreSkuInfo.VendorPrice)/float64(100)) isSaleStatusDiff := jxSkuSaleStatusName != vendorSkuSaleStatusName isNameDiff := jxSkuDetailName != vendorSkuDetailName + /*比较价格*/ + isPriceDiff := vendorPrice != jxSkuPrice + utils.Writelog("isSaleStatusDiff:" + strconv.FormatBool(isSaleStatusDiff)) + utils.Writelog("isNameDiff:" + strconv.FormatBool(isNameDiff)) if jxSkuDetailName != "" && vendorSkuDetailName != "" && strings.Contains(jxSkuDetailName, vendorSkuDetailName) { isNameDiff = false } - if isSaleStatusDiff || isNameDiff { + if isSaleStatusDiff || isNameDiff || isPriceDiff { reason := "" if isNameDiff { reason += DatAanalyse3 @@ -380,15 +403,18 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin if isSaleStatusDiff { reason += DatAanalyse4 } + if isPriceDiff { + reason += DatAanalyse9 + } if status != model.SkuStatusDontSale { reason += DatAanalyse7 } - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, vendorSkuDetailName, jxSkuSaleStatusName, vendorSkuSaleStatusName, reason} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, vendorSkuDetailName, jxSkuSaleStatusName, vendorSkuSaleStatusName, jxSkuPrice,vendorPrice, reason} diffData.AppendData(vendorID, outPutData) } if !isSaleStatusDiff && !isNameDiff { if status != model.SkuStatusDontSale { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, vendorSkuDetailName, jxSkuSaleStatusName, vendorSkuSaleStatusName, DatAanalyse7} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, vendorSkuDetailName, jxSkuSaleStatusName, vendorSkuSaleStatusName, jxSkuPrice,vendorPrice, DatAanalyse7} diffData.AppendData(vendorID, outPutData) } } @@ -405,7 +431,7 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin if status != model.SkuStatusDontSale { reason += DatAanalyse7 } - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, "", jxSkuSaleStatusName, "", reason} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, "", jxSkuSaleStatusName, "", jxSkuPrice,"", reason} diffData.AppendData(vendorID, outPutData) } } @@ -415,10 +441,13 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin skuIDStr := utils.Int2Str(skuID) vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status) - + /* 供货商价格 */ + vendorPrice := fmt.Sprintf("%.2f", float64(vendorSkuInfo.SkuList[0].StoreSkuInfo.VendorPrice)/float64(100)) + /* 供货商价格 */ jxSkuInfo := filterJxSkuInfoMap[skuID] + /*平台有,京西没有*/ if jxSkuInfo == nil { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", "", "", "", vendorSkuDetailName, "", vendorSkuSaleStatusName, DatAanalyse1} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", "", "", "", vendorSkuDetailName, "", vendorSkuSaleStatusName, "",vendorPrice, DatAanalyse1} diffData.AppendData(vendorID, outPutData) } } else { @@ -469,10 +498,10 @@ func CompareJxAndMultiVenderDepot(ctx *jxcontext.Context, vendorMap map[int]bool vendorSkuInfoMap := filterVendorSkuInfoMap[skuid] jxSkuSaleStatus := jxSkuInfo.Status - jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus) + jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus+3) skuIDStr := utils.Int2Str(skuid) if vendorSkuInfoMap != nil { - vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfoMap.SkuList[0].Status) + vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfoMap.SkuList[0].Status+3) vendorSkuDetailName := vendorSkuInfoMap.SkuList[0].SkuName isSaleStatusDiff := jxSkuSaleStatusName != vendorSkuSaleStatusName isNameDiff := strings.Compare(jxSkuDetailName, vendorSkuDetailName) != 0 @@ -497,7 +526,7 @@ func CompareJxAndMultiVenderDepot(ctx *jxcontext.Context, vendorMap map[int]bool if len(vendorSkuInfo.SkuList) > 0 { skuIDStr := utils.Int2Str(skuID) vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName - vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status) + vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status+3) jxSkuInfo := filterJxSkuInfoMap2[skuID] if jxSkuInfo == nil { @@ -515,6 +544,177 @@ func CompareJxAndMultiVenderDepot(ctx *jxcontext.Context, vendorMap map[int]bool } } +func TestDiff(ctx *jxcontext.Context, vendorIDList []int, storeIDList []int) { + baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor start time: %v", time.Now()) + startProcessTime := time.Now().Unix() + vendorMap := make(map[int]bool) + for _, vendorID := range vendorIDList { + vendorMap[vendorID] = true //map[平台ID:true] + } + storeIDMap := make(map[int]bool) + for _, storeID := range storeIDList { + storeIDMap[storeID] = true //map[门店ID:true] + } + /************************************************update**************************************************/ + //自己存值 + + for vendorID, _ := range vendorNameList { + //filter for vendorID + if len(vendorMap) > 0 { + if _, ok := vendorMap[vendorID]; !ok { + continue + } + } + if partner.IsMultiStore(vendorID) { + multiHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler) + for _, vendorOrgCode := range apimanager.CurAPIManager.GetAppOrgCodeList(vendorID) { + allSkuNameInfoList, err := multiHandler.GetSkus(ctx, vendorOrgCode, 0, "") + //获取单个表格对比的物品信息列表 + skuNameInfoList = allSkuNameInfoList + if err != nil { + fmt.Println("allSkuNameInfoList赋值错误,error信息" + err.Error()) + continue + } + //*partner.StoreSkuInfo skuNameList []*SkuNameInfo + var bareStoreSkuList []*partner.StoreSkuInfo + for _, v := range allSkuNameInfoList { + for _, v2 := range v.SkuList { + if v2.Status > model.SkuStatusDontSale { + for _, v2 := range v.SkuList { + bareStoreSkuList = append(bareStoreSkuList, &v2.StoreSkuInfo) + } + } + } + } + //if multiStoreAllSkuInfoList[vendorID][vendorOrgCode] != nil && bareStoreSkuList != nil { + if multiStoreAllSkuInfoList[vendorID] != nil && bareStoreSkuList != nil { + multiStoreAllSkuInfoList[vendorID][vendorOrgCode] = bareStoreSkuList + //}else if multiStoreAllSkuInfoList[vendorID][vendorOrgCode] == nil{ + } else if multiStoreAllSkuInfoList[vendorID] == nil { + multiStoreAllSkuInfoList = make(map[int]map[string][]*partner.StoreSkuInfo) + multiStoreAllSkuInfoList[vendorID] = make(map[string][]*partner.StoreSkuInfo) + multiStoreAllSkuInfoList[vendorID][vendorOrgCode] = bareStoreSkuList + } + tempMap := make(map[int]*partner.SkuNameInfo) + for _, value := range allSkuNameInfoList { + for _, skuInfo := range value.SkuList { + //表示平台商品库未下架的 + if skuInfo.Status > model.SkuStatusDontSale { + filterVendorDepotUnSaleSkuIds = append(filterVendorDepotUnSaleSkuIds, skuInfo.SkuID) + tempMap[skuInfo.SkuID] = value + } + } + } + //商品信息 + if multiStoreAllSkuInfoMap[vendorID] == nil { + multiStoreAllSkuInfoMap = make(map[int]map[string]map[int]*partner.SkuNameInfo) + multiStoreAllSkuInfoMap[vendorID] = make(map[string]map[int]*partner.SkuNameInfo) + //multiStoreAllSkuInfoMap[vendorID][vendorOrgCode] = make(map[int]*partner.SkuNameInfo) + multiStoreAllSkuInfoMap[vendorID][vendorOrgCode] = tempMap + } else { + multiStoreAllSkuInfoMap[vendorID][vendorOrgCode] = tempMap + } + } + } + } + /*第二步 为了获取 filterJxDepotUnSaleSkuIds*/ + depotDiffData.InitData2() + CompareJxAndMultiVenderDepot(ctx, vendorMap) + /*第二步*/ + /************************************************update****************************************************/ + + taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { + //1.获取京西本地所有门店信息 store、place、user表联查 jxStoreInfoList + //2.过滤所有门店信息,只留下传进来的vendorMap,storeIDMap中对应的平台和门台信息 filterStoreList + //3.判断是否多平台门店,两种情况两种处理 + 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 { + //获取总共几个门店任务 + filterStoreList := GetFilterStoreList(jxStoreInfoList.Stores, vendorMap, storeIDMap) + diffData.InitData() + //循环门店store + taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + //func() (retVal interface{}, err error) { + jxStoreInfoListValue := batchItemList[0].(*StoreExt) + storeID := jxStoreInfoListValue.ID + storeIDStr := utils.Int2Str(storeID) + storeName := jxStoreInfoListValue.Name + jxSkuInfoDataSingle := &dao.StoreSkuNamesInfo{} + jxSkuInfoDataMulti := &dao.StoreSkuNamesInfo{} + if jxStoreInfoListValue.StoreMaps != nil { + var multiFlag = false + var singleFlag = false + var filterJxSkuInfoMapSingle map[int]*dao.StoreSkuNameExt + var filterJxSkuInfoMapMulti map[int]*dao.StoreSkuNameExt + for _, vendorListValue := range jxStoreInfoListValue.StoreMaps { + vendorID := vendorListValue.VendorID + if partner.IsMultiStore(vendorID) { + if multiFlag == false { + jxSkuInfoDataMulti, _ = GetStoreSkus(ctx, storeID, filterJxDepotUnSaleSkuIds, true, "", true, false, map[string]interface{}{}, 0, -1) + /*重新计算价格*/ + SetJxPrice(jxSkuInfoDataMulti,storeID) + filterJxSkuInfoMapMulti = GetFilterJxSkuInfoMap(jxSkuInfoDataMulti.SkuNames) //map[京西商品ID:StoreSkuNameExt] + multiFlag = true + } + } else { + if singleFlag == false { + jxSkuInfoDataSingle, _ = GetStoreSkus(ctx, storeID, nil, true, "", true, false, map[string]interface{}{}, 0, -1) + filterJxSkuInfoMapSingle = GetFilterJxSkuInfoMap(jxSkuInfoDataSingle.SkuNames) //map[京西商品ID:StoreSkuNameExt] + singleFlag = true + } + } + + vendorStoreID := vendorListValue.VendorStoreID + baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor storeID:%d vendorID:%d vendorStoreID:%s vendorListValue:%v", storeID, vendorID, vendorStoreID, vendorListValue) + + if partner.IsMultiStore(vendorID) { + singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler) + allSkuInfoList := GetMultiStoreAllSkuInfoList(vendorID, vendorListValue.VendorOrgCode) + skuBareInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, vendorListValue.VendorOrgCode, task, storeID, vendorStoreID, allSkuInfoList) + if err != nil { + baseapi.SugarLogger.Infof("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err) + } else if len(skuBareInfoList) > 0 { + //获取京东的商品 + filterSkuInfoMap := GetFilterMultiStoreSkuInfoMap(vendorID, vendorListValue.VendorOrgCode, skuBareInfoList) //map[京东商品ID:SkuNameInfo] + CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMapMulti, filterSkuInfoMap) + } + } else { + singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) + vendorSkuInfoList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil) + if err != nil { + baseapi.SugarLogger.Infof("CheckSkuDiffBetweenJxAndVendor GetStoreSkusFullInfo error:%v", err) + } else if len(vendorSkuInfoList) > 0 { + //获取京东的商品 + filterVendorSkuInfoMap := GetFilterVendorSkuInfoMap(vendorSkuInfoList) //map[平台商品ID:SkuNameInfo] + CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMapSingle, filterVendorSkuInfoMap) + } + } + } + } + return retVal, err + } + 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) + } + } + /********************************第三步****************************/ + WriteToExcel(task, diffData.diffDataMap, depotDiffData.diffDataMap) + endProcessTime := time.Now().Unix() + diff := endProcessTime - startProcessTime + baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor end time: %v", time.Now()) + baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor cost time: %d sec", diff) + /********************************第三步****************************/ + return result, err + } + taskSeq := tasksch.NewSeqTask("京西和平台商品差异对比-序列任务", ctx, taskSeqFunc, 4) + tasksch.HandleTask(taskSeq, nil, true).Run() +} + //入口函数,校验本地商品京西和其他平台的差异 func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int, storeIDList []int) { startProcessTime := time.Now().Unix() @@ -719,6 +919,7 @@ func WriteToExcel(task *tasksch.SeqTask, data map[int][]DiffData, depotData map[ jxutils.WriteFile(diffFullFileName, excelBin) } baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", diffFullFileName) + //上传 downloadURL, err := jxutils.UploadExportContent(excelBin, diffFullFileName) if err != nil { baseapi.SugarLogger.Errorf("WriteToExcel:upload %s failed error:%v", diffFullFileName, err) diff --git a/business/jxstore/cms/store_sku_check_test.go b/business/jxstore/cms/store_sku_check.go1_test.go similarity index 100% rename from business/jxstore/cms/store_sku_check_test.go rename to business/jxstore/cms/store_sku_check.go1_test.go diff --git a/business/jxutils/excel/excel.go b/business/jxutils/excel/excel.go index ff991a88d..23d3d45e0 100644 --- a/business/jxutils/excel/excel.go +++ b/business/jxutils/excel/excel.go @@ -3,12 +3,11 @@ package excel import ( "bytes" "fmt" - "io" - "reflect" - "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/globals" "github.com/360EntSecGroup-Skylar/excelize" + "io" + "reflect" ) type Obj2ExcelSheetConfig struct { @@ -20,7 +19,8 @@ type Obj2ExcelSheetConfig struct { func Obj2Excel(sheetList []*Obj2ExcelSheetConfig) []byte { globals.SugarLogger.Debug("Obj2Excel") excelFile := excelize.NewFile() - for sheetIndex, sheetConfig := range sheetList { + //for sheetIndex, sheetConfig := range sheetList { + for _, sheetConfig := range sheetList { obj := sheetConfig.Data typeInfo := reflect.TypeOf(obj) @@ -39,12 +39,14 @@ func Obj2Excel(sheetList []*Obj2ExcelSheetConfig) []byte { } valueInfo := reflect.Indirect(reflect.ValueOf(obj)) - if sheetIndex == 0 { - sheetName := excelFile.GetSheetName(1) - excelFile.SetSheetName(sheetName, sheetConfig.Title) - } else { - excelFile.NewSheet(sheetConfig.Title) - } + /*因爲默認是Sheet1,所以直接賦值就叫sheet1,然後再改名字就行了,不然會默認多一頁空白頁為sheet1*/ + //if sheetIndex == 0 { + index := excelFile.NewSheet("Sheet1") + // sheetName := excelFile.GetSheetName(1) + excelFile.SetSheetName("Sheet1", sheetConfig.Title) + //} else { + // excelFile.NewSheet(sheetConfig.Title) + //} isMemberStruct := typeInfo.Kind() == reflect.Struct colWithList := make([]float64, len(sheetConfig.CaptionList)) if isMemberStruct { @@ -63,9 +65,9 @@ func Obj2Excel(sheetList []*Obj2ExcelSheetConfig) []byte { for i := 0; i < valueInfo.Len(); i++ { for col, index := range indexSlice { str := fmt.Sprint(reflect.Indirect(valueInfo.Index(i)).FieldByIndex(index).Interface()) - // if colWith := float64(len(str)); colWith > colWithList[col] { - // colWithList[col] = colWith - // } + //// if colWith := float64(len(str)); colWith > colWithList[col] { + //// colWithList[col] = colWith + //// } excelFile.SetCellStr(sheetConfig.Title, genAxis(i+1, col), str) } } @@ -104,6 +106,7 @@ func Obj2Excel(sheetList []*Obj2ExcelSheetConfig) []byte { // colName, _ := excelize.ColumnNumberToName(col + 1) // excelFile.SetColWidth(sheetConfig.Title, colName, colName, colWithList[col]) // } + excelFile.SetActiveSheet(index) } buf := &bytes.Buffer{} excelFile.Write(buf) diff --git a/business/jxutils/tasksch/parallel_task.go b/business/jxutils/tasksch/parallel_task.go index f99361328..a396b84cc 100644 --- a/business/jxutils/tasksch/parallel_task.go +++ b/business/jxutils/tasksch/parallel_task.go @@ -80,6 +80,7 @@ func NewParallelTask2(taskName string, config *ParallelConfig, ctx *jxcontext.Co if config.ParallelCount > MaxParallelCount { config.ParallelCount = MaxParallelCount } + //?? realItemList := utils.Interface2Slice(itemList) jobList := jxutils.SplitSlice(realItemList, config.BatchSize) jobListLen := len(jobList) diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index 89f407e4a..93fd90d11 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -482,7 +482,7 @@ func (t *BaseTask) run(taskHandler func()) { } } -func SendMessage(t *BaseTask) { +func SendMessage(t *BaseTask) {//基类任务 time.Sleep(10 * time.Millisecond) // 等待GetResult中的isGetResultCalled赋值 globals.SugarLogger.Debugf("BaseTask task ID:%s, name:%s finished, isGetResultCalled:%t", t.ID, t.Name, t.isGetResultCalled) if !t.isGetResultCalled && t.parent == nil && len(GetTasks(t.ID, TaskStatusBegin, TaskStatusEnd, 24, "")) > 0 { diff --git a/business/model/sku.go b/business/model/sku.go index 25c31e894..1a467dd09 100644 --- a/business/model/sku.go +++ b/business/model/sku.go @@ -90,8 +90,11 @@ var ( } SkuStatusName = map[int]string{ SkuStatusDeleted: "删除", - SkuStatusDontSale: "下架", - SkuStatusNormal: "上架", + SkuStatusDontSale: "不可售", + SkuStatusNormal: "可售", + 2: "删除", + 3: "下架", + 4: "上架", } ) diff --git a/controllers/temp_op.go b/controllers/temp_op.go index 82c9ba8ef..26d56039f 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -292,6 +292,25 @@ func (c *TempOpController) CheckSkuDiffBetweenJxAndVendor() { }) } +// @Title 京西平台和其他平台商品的对比Test +// @Description 对比Test +// @Param token header string true "认证token" +// @Param vendorIDs formData string false "运营商ID列表(京东0 美团1 饿百3)" +// @Param storeIDs formData string false "京西门店ID列表" +// @Success 200 {object} controllers.CallResult +// @Failure 404 User not found +// @router /StaticBlock [post] +func (c *TempOpController) StaticBlock() { + c.callCheckSkuDiffBetweenJxAndVendor(func(params *tTempopCheckSkuDiffBetweenJxAndVendorParams) (retVal interface{}, errCode string, err error) { + var vendorIDList []int + var storeIDList []int + if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil { + cms.TestDiff(params.Ctx, vendorIDList, storeIDList) + } + return retVal, "", err + }) +} + // @Title 通过订单创建消费者用户 // @Description 通过订单创建消费者用户 // @Param token header string true "认证token" diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 86c0ff4f1..a9c819671 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1944,6 +1944,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"], + beego.ControllerComments{ + Method: "GetStoreSkuAudit", + Router: `/GetStoreSkuAudit`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"], beego.ControllerComments{ Method: "GetStoreSkus", @@ -2448,6 +2457,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"], + beego.ControllerComments{ + Method: "StaticBlock", + Router: `/StaticBlock`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"], beego.ControllerComments{ Method: "TestIt", From 36f9c4feae25402bc301a6a96baac9fcf7138cc3 Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Fri, 19 Jun 2020 14:15:21 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=EF=BC=8C=E5=A5=BD=E5=83=8F=E4=B9=8B=E5=89=8D=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E3=80=82=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...store_sku_check.go1 => store_sku_check.go} | 365 +++++++++++------- .../jxstore/cms/store_sku_check.go1_test.go | 13 - 2 files changed, 233 insertions(+), 145 deletions(-) rename business/jxstore/cms/{store_sku_check.go1 => store_sku_check.go} (75%) delete mode 100644 business/jxstore/cms/store_sku_check.go1_test.go diff --git a/business/jxstore/cms/store_sku_check.go1 b/business/jxstore/cms/store_sku_check.go similarity index 75% rename from business/jxstore/cms/store_sku_check.go1 rename to business/jxstore/cms/store_sku_check.go index c0a8cda70..c66fe58d8 100644 --- a/business/jxstore/cms/store_sku_check.go1 +++ b/business/jxstore/cms/store_sku_check.go @@ -2,6 +2,8 @@ package cms import ( "fmt" + "git.rosy.net.cn/baseapi/platformapi/dingdingapi" + "git.rosy.net.cn/jx-callback/business/jxutils/ddmsg" "github.com/astaxie/beego" "strconv" "strings" @@ -141,7 +143,7 @@ type DiffData struct { VendorSkuName string `json:"平台商品名"` JxStatus string `json:"京西可售状态"` VendorStatus string `json:"平台可售状态"` - JxSkuPrice string `json:"京西价格"` /*哇,不能小写,不然会搞事情*/ + JxSkuPrice string `json:"京西价格"` /*哇,不能小写,不然会搞事情*/ VendorPrice string `json:"平台价格"` DatAanalyse string `json:"数据分析"` } @@ -409,12 +411,12 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin if status != model.SkuStatusDontSale { reason += DatAanalyse7 } - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, vendorSkuDetailName, jxSkuSaleStatusName, vendorSkuSaleStatusName, jxSkuPrice,vendorPrice, reason} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, vendorSkuDetailName, jxSkuSaleStatusName, vendorSkuSaleStatusName, jxSkuPrice, vendorPrice, reason} diffData.AppendData(vendorID, outPutData) } if !isSaleStatusDiff && !isNameDiff { if status != model.SkuStatusDontSale { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, vendorSkuDetailName, jxSkuSaleStatusName, vendorSkuSaleStatusName, jxSkuPrice,vendorPrice, DatAanalyse7} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, vendorSkuDetailName, jxSkuSaleStatusName, vendorSkuSaleStatusName, jxSkuPrice, vendorPrice, DatAanalyse7} diffData.AppendData(vendorID, outPutData) } } @@ -431,7 +433,7 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin if status != model.SkuStatusDontSale { reason += DatAanalyse7 } - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, "", jxSkuSaleStatusName, "", jxSkuPrice,"", reason} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, syncStatus, toBeCreate, toBeDel, jxSkuDetailName, "", jxSkuSaleStatusName, "", jxSkuPrice, "", reason} diffData.AppendData(vendorID, outPutData) } } @@ -447,7 +449,7 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin jxSkuInfo := filterJxSkuInfoMap[skuID] /*平台有,京西没有*/ if jxSkuInfo == nil { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", "", "", "", vendorSkuDetailName, "", vendorSkuSaleStatusName, "",vendorPrice, DatAanalyse1} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", "", "", "", vendorSkuDetailName, "", vendorSkuSaleStatusName, "", vendorPrice, DatAanalyse1} diffData.AppendData(vendorID, outPutData) } } else { @@ -498,10 +500,10 @@ func CompareJxAndMultiVenderDepot(ctx *jxcontext.Context, vendorMap map[int]bool vendorSkuInfoMap := filterVendorSkuInfoMap[skuid] jxSkuSaleStatus := jxSkuInfo.Status - jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus+3) + jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus + 3) skuIDStr := utils.Int2Str(skuid) if vendorSkuInfoMap != nil { - vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfoMap.SkuList[0].Status+3) + vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfoMap.SkuList[0].Status + 3) vendorSkuDetailName := vendorSkuInfoMap.SkuList[0].SkuName isSaleStatusDiff := jxSkuSaleStatusName != vendorSkuSaleStatusName isNameDiff := strings.Compare(jxSkuDetailName, vendorSkuDetailName) != 0 @@ -526,7 +528,7 @@ func CompareJxAndMultiVenderDepot(ctx *jxcontext.Context, vendorMap map[int]bool if len(vendorSkuInfo.SkuList) > 0 { skuIDStr := utils.Int2Str(skuID) vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName - vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status+3) + vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status + 3) jxSkuInfo := filterJxSkuInfoMap2[skuID] if jxSkuInfo == nil { @@ -557,76 +559,73 @@ func TestDiff(ctx *jxcontext.Context, vendorIDList []int, storeIDList []int) { } /************************************************update**************************************************/ //自己存值 - - for vendorID, _ := range vendorNameList { - //filter for vendorID - if len(vendorMap) > 0 { - if _, ok := vendorMap[vendorID]; !ok { - continue - } - } - if partner.IsMultiStore(vendorID) { - multiHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler) - for _, vendorOrgCode := range apimanager.CurAPIManager.GetAppOrgCodeList(vendorID) { - allSkuNameInfoList, err := multiHandler.GetSkus(ctx, vendorOrgCode, 0, "") - //获取单个表格对比的物品信息列表 - skuNameInfoList = allSkuNameInfoList - if err != nil { - fmt.Println("allSkuNameInfoList赋值错误,error信息" + err.Error()) + a := func() { + for vendorID, _ := range vendorNameList { + //filter for vendorID + if len(vendorMap) > 0 { + if _, ok := vendorMap[vendorID]; !ok { continue } - //*partner.StoreSkuInfo skuNameList []*SkuNameInfo - var bareStoreSkuList []*partner.StoreSkuInfo - for _, v := range allSkuNameInfoList { - for _, v2 := range v.SkuList { - if v2.Status > model.SkuStatusDontSale { - for _, v2 := range v.SkuList { - bareStoreSkuList = append(bareStoreSkuList, &v2.StoreSkuInfo) + } + if partner.IsMultiStore(vendorID) { + multiHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler) + for _, vendorOrgCode := range apimanager.CurAPIManager.GetAppOrgCodeList(vendorID) { + allSkuNameInfoList, err := multiHandler.GetSkus(ctx, vendorOrgCode, 0, "") + //获取单个表格对比的物品信息列表 + skuNameInfoList = allSkuNameInfoList + if err != nil { + fmt.Println("allSkuNameInfoList赋值错误,error信息" + err.Error()) + continue + } + //*partner.StoreSkuInfo skuNameList []*SkuNameInfo + var bareStoreSkuList []*partner.StoreSkuInfo + for _, v := range allSkuNameInfoList { + for _, v2 := range v.SkuList { + if v2.Status > model.SkuStatusDontSale { + for _, v2 := range v.SkuList { + bareStoreSkuList = append(bareStoreSkuList, &v2.StoreSkuInfo) + } } } } - } - //if multiStoreAllSkuInfoList[vendorID][vendorOrgCode] != nil && bareStoreSkuList != nil { - if multiStoreAllSkuInfoList[vendorID] != nil && bareStoreSkuList != nil { - multiStoreAllSkuInfoList[vendorID][vendorOrgCode] = bareStoreSkuList - //}else if multiStoreAllSkuInfoList[vendorID][vendorOrgCode] == nil{ - } else if multiStoreAllSkuInfoList[vendorID] == nil { - multiStoreAllSkuInfoList = make(map[int]map[string][]*partner.StoreSkuInfo) - multiStoreAllSkuInfoList[vendorID] = make(map[string][]*partner.StoreSkuInfo) - multiStoreAllSkuInfoList[vendorID][vendorOrgCode] = bareStoreSkuList - } - tempMap := make(map[int]*partner.SkuNameInfo) - for _, value := range allSkuNameInfoList { - for _, skuInfo := range value.SkuList { - //表示平台商品库未下架的 - if skuInfo.Status > model.SkuStatusDontSale { - filterVendorDepotUnSaleSkuIds = append(filterVendorDepotUnSaleSkuIds, skuInfo.SkuID) - tempMap[skuInfo.SkuID] = value + //if multiStoreAllSkuInfoList[vendorID][vendorOrgCode] != nil && bareStoreSkuList != nil { + if multiStoreAllSkuInfoList[vendorID] != nil && bareStoreSkuList != nil { + multiStoreAllSkuInfoList[vendorID][vendorOrgCode] = bareStoreSkuList + //}else if multiStoreAllSkuInfoList[vendorID][vendorOrgCode] == nil{ + } else if multiStoreAllSkuInfoList[vendorID] == nil { + multiStoreAllSkuInfoList = make(map[int]map[string][]*partner.StoreSkuInfo) + multiStoreAllSkuInfoList[vendorID] = make(map[string][]*partner.StoreSkuInfo) + multiStoreAllSkuInfoList[vendorID][vendorOrgCode] = bareStoreSkuList + } + tempMap := make(map[int]*partner.SkuNameInfo) + for _, value := range allSkuNameInfoList { + for _, skuInfo := range value.SkuList { + //表示平台商品库未下架的 + if skuInfo.Status > model.SkuStatusDontSale { + filterVendorDepotUnSaleSkuIds = append(filterVendorDepotUnSaleSkuIds, skuInfo.SkuID) + tempMap[skuInfo.SkuID] = value + } } } - } - //商品信息 - if multiStoreAllSkuInfoMap[vendorID] == nil { - multiStoreAllSkuInfoMap = make(map[int]map[string]map[int]*partner.SkuNameInfo) - multiStoreAllSkuInfoMap[vendorID] = make(map[string]map[int]*partner.SkuNameInfo) - //multiStoreAllSkuInfoMap[vendorID][vendorOrgCode] = make(map[int]*partner.SkuNameInfo) - multiStoreAllSkuInfoMap[vendorID][vendorOrgCode] = tempMap - } else { - multiStoreAllSkuInfoMap[vendorID][vendorOrgCode] = tempMap + //商品信息 + if multiStoreAllSkuInfoMap[vendorID] == nil { + multiStoreAllSkuInfoMap = make(map[int]map[string]map[int]*partner.SkuNameInfo) + multiStoreAllSkuInfoMap[vendorID] = make(map[string]map[int]*partner.SkuNameInfo) + //multiStoreAllSkuInfoMap[vendorID][vendorOrgCode] = make(map[int]*partner.SkuNameInfo) + multiStoreAllSkuInfoMap[vendorID][vendorOrgCode] = tempMap + } else { + multiStoreAllSkuInfoMap[vendorID][vendorOrgCode] = tempMap + } } } } } - /*第二步 为了获取 filterJxDepotUnSaleSkuIds*/ - depotDiffData.InitData2() - CompareJxAndMultiVenderDepot(ctx, vendorMap) - /*第二步*/ - /************************************************update****************************************************/ - taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { - //1.获取京西本地所有门店信息 store、place、user表联查 jxStoreInfoList - //2.过滤所有门店信息,只留下传进来的vendorMap,storeIDMap中对应的平台和门台信息 filterStoreList - //3.判断是否多平台门店,两种情况两种处理 + /************************************************update****************************************************/ + //1.获取京西本地所有门店信息 store、place、user表联查 jxStoreInfoList + //2.过滤所有门店信息,只留下传进来的vendorMap,storeIDMap中对应的平台和门台信息 filterStoreList + //3.判断是否多平台门店,两种情况两种处理 + b := func() { 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) @@ -634,85 +633,170 @@ func TestDiff(ctx *jxcontext.Context, vendorIDList []int, storeIDList []int) { //获取总共几个门店任务 filterStoreList := GetFilterStoreList(jxStoreInfoList.Stores, vendorMap, storeIDMap) diffData.InitData() - //循环门店store - taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - //func() (retVal interface{}, err error) { - jxStoreInfoListValue := batchItemList[0].(*StoreExt) - storeID := jxStoreInfoListValue.ID - storeIDStr := utils.Int2Str(storeID) - storeName := jxStoreInfoListValue.Name - jxSkuInfoDataSingle := &dao.StoreSkuNamesInfo{} - jxSkuInfoDataMulti := &dao.StoreSkuNamesInfo{} - if jxStoreInfoListValue.StoreMaps != nil { - var multiFlag = false - var singleFlag = false - var filterJxSkuInfoMapSingle map[int]*dao.StoreSkuNameExt - var filterJxSkuInfoMapMulti map[int]*dao.StoreSkuNameExt - for _, vendorListValue := range jxStoreInfoListValue.StoreMaps { - vendorID := vendorListValue.VendorID - if partner.IsMultiStore(vendorID) { - if multiFlag == false { - jxSkuInfoDataMulti, _ = GetStoreSkus(ctx, storeID, filterJxDepotUnSaleSkuIds, true, "", true, false, map[string]interface{}{}, 0, -1) - /*重新计算价格*/ - SetJxPrice(jxSkuInfoDataMulti,storeID) - filterJxSkuInfoMapMulti = GetFilterJxSkuInfoMap(jxSkuInfoDataMulti.SkuNames) //map[京西商品ID:StoreSkuNameExt] - multiFlag = true - } - } else { - if singleFlag == false { - jxSkuInfoDataSingle, _ = GetStoreSkus(ctx, storeID, nil, true, "", true, false, map[string]interface{}{}, 0, -1) - filterJxSkuInfoMapSingle = GetFilterJxSkuInfoMap(jxSkuInfoDataSingle.SkuNames) //map[京西商品ID:StoreSkuNameExt] - singleFlag = true - } + jxStoreInfoListValue := filterStoreList[0] + storeID := jxStoreInfoListValue.ID + storeIDStr := utils.Int2Str(storeID) + storeName := jxStoreInfoListValue.Name + jxSkuInfoDataSingle := &dao.StoreSkuNamesInfo{} + jxSkuInfoDataMulti := &dao.StoreSkuNamesInfo{} + if jxStoreInfoListValue.StoreMaps != nil { + var multiFlag = false + var singleFlag = false + var filterJxSkuInfoMapSingle map[int]*dao.StoreSkuNameExt + var filterJxSkuInfoMapMulti map[int]*dao.StoreSkuNameExt + for _, vendorListValue := range jxStoreInfoListValue.StoreMaps { + vendorID := vendorListValue.VendorID + if partner.IsMultiStore(vendorID) { + if multiFlag == false { + jxSkuInfoDataMulti, _ = GetStoreSkus(ctx, storeID, filterJxDepotUnSaleSkuIds, true, "", true, false, map[string]interface{}{}, 0, -1) + /*重新计算价格*/ + SetJxPrice(jxSkuInfoDataMulti, storeID) + filterJxSkuInfoMapMulti = GetFilterJxSkuInfoMap(jxSkuInfoDataMulti.SkuNames) //map[京西商品ID:StoreSkuNameExt] + multiFlag = true } + } else { + if singleFlag == false { + jxSkuInfoDataSingle, _ = GetStoreSkus(ctx, storeID, nil, true, "", true, false, map[string]interface{}{}, 0, -1) + filterJxSkuInfoMapSingle = GetFilterJxSkuInfoMap(jxSkuInfoDataSingle.SkuNames) //map[京西商品ID:StoreSkuNameExt] + singleFlag = true + } + } - vendorStoreID := vendorListValue.VendorStoreID - baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor storeID:%d vendorID:%d vendorStoreID:%s vendorListValue:%v", storeID, vendorID, vendorStoreID, vendorListValue) + vendorStoreID := vendorListValue.VendorStoreID + baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor storeID:%d vendorID:%d vendorStoreID:%s vendorListValue:%v", storeID, vendorID, vendorStoreID, vendorListValue) - if partner.IsMultiStore(vendorID) { - singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler) - allSkuInfoList := GetMultiStoreAllSkuInfoList(vendorID, vendorListValue.VendorOrgCode) - skuBareInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, vendorListValue.VendorOrgCode, task, storeID, vendorStoreID, allSkuInfoList) - if err != nil { - baseapi.SugarLogger.Infof("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err) - } else if len(skuBareInfoList) > 0 { - //获取京东的商品 - filterSkuInfoMap := GetFilterMultiStoreSkuInfoMap(vendorID, vendorListValue.VendorOrgCode, skuBareInfoList) //map[京东商品ID:SkuNameInfo] - CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMapMulti, filterSkuInfoMap) - } - } else { - singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) - vendorSkuInfoList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil) - if err != nil { - baseapi.SugarLogger.Infof("CheckSkuDiffBetweenJxAndVendor GetStoreSkusFullInfo error:%v", err) - } else if len(vendorSkuInfoList) > 0 { - //获取京东的商品 - filterVendorSkuInfoMap := GetFilterVendorSkuInfoMap(vendorSkuInfoList) //map[平台商品ID:SkuNameInfo] - CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMapSingle, filterVendorSkuInfoMap) - } + if partner.IsMultiStore(vendorID) { + singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler) + allSkuInfoList := GetMultiStoreAllSkuInfoList(vendorID, vendorListValue.VendorOrgCode) + skuBareInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, vendorListValue.VendorOrgCode, nil, storeID, vendorStoreID, allSkuInfoList) + if err != nil { + baseapi.SugarLogger.Infof("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err) + } else if len(skuBareInfoList) > 0 { + //获取京东的商品 + filterSkuInfoMap := GetFilterMultiStoreSkuInfoMap(vendorID, vendorListValue.VendorOrgCode, skuBareInfoList) //map[京东商品ID:SkuNameInfo] + CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMapMulti, filterSkuInfoMap) + } + } else { + singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) + vendorSkuInfoList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, nil, storeID, vendorStoreID, nil) + if err != nil { + baseapi.SugarLogger.Infof("CheckSkuDiffBetweenJxAndVendor GetStoreSkusFullInfo error:%v", err) + } else if len(vendorSkuInfoList) > 0 { + //获取京东的商品 + filterVendorSkuInfoMap := GetFilterVendorSkuInfoMap(vendorSkuInfoList) //map[平台商品ID:SkuNameInfo] + CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMapSingle, filterVendorSkuInfoMap) } } } - return retVal, err - } - 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) } } - /********************************第三步****************************/ - WriteToExcel(task, diffData.diffDataMap, depotDiffData.diffDataMap) + } + + /********************************第三步****************************/ + c := func(data map[int][]DiffData, depotData map[int][]DepotDiffData) { + var sheetList []*excel.Obj2ExcelSheetConfig + for key, value := range data { + sheetName := vendorNameList[key] + if partner.IsMultiStore(key) { + excelConfDepot := &excel.Obj2ExcelSheetConfig{ + Title: sheetName + "商品库与京西商品库对比", + Data: depotData[key], + CaptionList: deoptTitleList, + } + sheetList = append(sheetList, excelConfDepot) + } + excelConf := &excel.Obj2ExcelSheetConfig{ + Title: sheetName, + Data: value, + CaptionList: titleList, + } + sheetList = append(sheetList, excelConf) + if needStatistic { + statisticSheet := AddStatisticSheet(sheetName, value) + sheetList = append(sheetList, statisticSheet) + } + baseapi.SugarLogger.Debugf("WriteToExcel:append:%s count:%d", sheetName, len(value)) + } + + if len(sheetList) > 0 { + excelBin := excel.Obj2Excel(sheetList) + sheetList = nil + timeStr := utils.Int64ToStr(time.Now().Unix()) + diffFullFileName := diffFileName[IsJXCS()] + timeStr + fileExt + if canWriteTolocal { + jxutils.WriteFile(diffFullFileName, excelBin) + } + baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", diffFullFileName) + //上传 + downloadURL, err := jxutils.UploadExportContent(excelBin, diffFullFileName) + if err != nil { + baseapi.SugarLogger.Errorf("WriteToExcel:upload %s failed error:%v", diffFullFileName, err) + } else { + baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL: %s", diffFullFileName, downloadURL) + /*************发送钉钉消息**************/ + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "", "异步任务完成", "京西平台对比数据上传成功:Excel下载地址是 "+downloadURL) + } + } else { + baseapi.SugarLogger.Debug("WriteToExcel:No diff data!!!") + } + //} endProcessTime := time.Now().Unix() diff := endProcessTime - startProcessTime baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor end time: %v", time.Now()) baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor cost time: %d sec", diff) - /********************************第三步****************************/ - return result, err } - taskSeq := tasksch.NewSeqTask("京西和平台商品差异对比-序列任务", ctx, taskSeqFunc, 4) - tasksch.HandleTask(taskSeq, nil, true).Run() + apiover := make(chan int, 1) + compover := make(chan int, 1) + over := false + /********************************第三步****************************/ + /*异步任务*/ + /************************************************************************************/ + go func() { + defer func() { + if recover() != nil { + beego.Info("执行任务失败") + panic("API调用失败") + } + }() + a() + depotDiffData.InitData2() + CompareJxAndMultiVenderDepot(ctx, vendorMap) + apiover <- 0 + }() + /*a等待a现成执行完*/ + go func() { + for !over { + select { + case <-apiover: + /*第二步 为了获取 filterJxDepotUnSaleSkuIds*/ + go func() { + defer func() { + if recover() != nil { + beego.Info("比较任务失败") + panic("比较任务失败") + } + }() + b() + compover <- 0 //比较任务完成 + }() + /*第二步*/ + case <-compover: + go func() { + defer func() { + if recover() != nil { + beego.Info("写入任务失败") + panic("写入任务失败") + } + }() + c(diffData.diffDataMap, depotDiffData.diffDataMap) + fmt.Println("任务执行完成") + over = true + }() + break + } + } + }() + /************************************************************************************/ } //入口函数,校验本地商品京西和其他平台的差异 @@ -932,3 +1016,20 @@ func WriteToExcel(task *tasksch.SeqTask, data map[int][]DiffData, depotData map[ baseapi.SugarLogger.Debug("WriteToExcel:No diff data!!!") } } + +func SetAAJxPrice(jxSkuInfoDataMulti *dao.StoreSkuNamesInfo, storeId int) (err error) { + db := dao.GetDB() + storeDetail, err := dao.GetStoreDetail(dao.GetDB(), storeId, model.VendorIDJX) + if err != nil { + dao.Rollback(db) + return err + } + /*重新计算京西价格*/ + for _, values := range jxSkuInfoDataMulti.SkuNames { + for _, value := range values.Skus { + value.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), value.JxPrice) + } + } + /*重新计算京西价格*/ + return nil +} diff --git a/business/jxstore/cms/store_sku_check.go1_test.go b/business/jxstore/cms/store_sku_check.go1_test.go deleted file mode 100644 index 731575b51..000000000 --- a/business/jxstore/cms/store_sku_check.go1_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package cms - -import ( - "testing" - - "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" -) - -func TestCheckSkuDiffBetweenJxAndVendor(t *testing.T) { - vendorIDList := []int{} - storeIDList := []int{} - CheckSkuDiffBetweenJxAndVendor(jxcontext.AdminCtx, vendorIDList, storeIDList) -} From ad5739a9774b68d0a147dd71229c605875416891 Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Fri, 19 Jun 2020 14:41:22 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E2=80=9D=E5=B1=8F=E8=94=BDwritelog?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E5=BF=97=E6=96=B9=E6=B3=95=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 562cec2ff..9e73ac443 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -5,7 +5,6 @@ import ( "git.rosy.net.cn/baseapi/platformapi/dingdingapi" "git.rosy.net.cn/jx-callback/business/jxutils/ddmsg" "github.com/astaxie/beego" - "strconv" "strings" "sync" "time" @@ -349,11 +348,11 @@ func IsSkuCanSale(saleStatus int) bool { //京西平台和其他平台商品的对比 //storeIDStr 京西商家id ,vendorStoreID 平台商家id func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName string, filterJxSkuInfoMap map[int]*dao.StoreSkuNameExt, filterVendorSkuInfoMap map[int]*partner.SkuNameInfo) { - utils.Writelog("进入 CompareJxAndVendor 方法") + //utils.Writelog("进入 CompareJxAndVendor 方法") for skuID, jxSkuInfo := range filterJxSkuInfoMap { skuIDStr := utils.Int2Str(skuID) /*写京西skuIDStr*/ - utils.Writelog("skuIDStr" + skuIDStr) + //utils.Writelog("skuIDStr" + skuIDStr) var jxSkuDetailName string //多规格商品不用比较数量单位 if jxSkuInfo.IsSpu == 0 { @@ -363,7 +362,7 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin //jxSkuDetailName : 前缀 ([荐]) + 分类名(xxx水饺) + 数量单位(约..g/份) + 注释 (补充..) jxSkuDetailName = jxutils.ComposeSkuNameOriginal(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, jxSkuInfo.Skus[0].Comment, "", jxSkuInfo.Skus[0].SkuSpecQuality, "", 0) } - utils.Writelog("jxSkuDetailName:" + jxSkuDetailName) + //utils.Writelog("jxSkuDetailName:" + jxSkuDetailName) //jxSkuSaleStatus : 商品状态 ,skustatus 优先级高于 StoreSkuStatus jxSkuSaleStatus := jxutils.MergeSkuStatus(jxSkuInfo.Skus[0].SkuStatus, jxSkuInfo.Skus[0].StoreSkuStatus) jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus) @@ -392,8 +391,8 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin isNameDiff := jxSkuDetailName != vendorSkuDetailName /*比较价格*/ isPriceDiff := vendorPrice != jxSkuPrice - utils.Writelog("isSaleStatusDiff:" + strconv.FormatBool(isSaleStatusDiff)) - utils.Writelog("isNameDiff:" + strconv.FormatBool(isNameDiff)) + //utils.Writelog("isSaleStatusDiff:" + strconv.FormatBool(isSaleStatusDiff)) + //utils.Writelog("isNameDiff:" + strconv.FormatBool(isNameDiff)) if jxSkuDetailName != "" && vendorSkuDetailName != "" && strings.Contains(jxSkuDetailName, vendorSkuDetailName) { isNameDiff = false } From 552165395733be3c20a1a1739d9e0550d77d8f4e Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Fri, 19 Jun 2020 14:41:22 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=B0=83=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=BD=B1=E5=93=8D=E4=B9=8B=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8A=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 10 +++++----- business/jxutils/tasksch/task.go | 2 +- business/model/sku.go | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 9e73ac443..255ef7f2a 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -365,7 +365,7 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin //utils.Writelog("jxSkuDetailName:" + jxSkuDetailName) //jxSkuSaleStatus : 商品状态 ,skustatus 优先级高于 StoreSkuStatus jxSkuSaleStatus := jxutils.MergeSkuStatus(jxSkuInfo.Skus[0].SkuStatus, jxSkuInfo.Skus[0].StoreSkuStatus) - jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus) + jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus + 3) /*京西价格*/ jxSkuPrice := fmt.Sprintf("%.2f", float64(jxSkuInfo.Skus[0].JxPrice)/float64(100)) //jxSkuPrice := strconv.Itoa(jxSkuInfo.Skus[0].JxPrice) @@ -384,7 +384,7 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin if vendorSkuInfo != nil { vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName - vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status) + vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status + 3) /* 供货商价格 */ vendorPrice := fmt.Sprintf("%.2f", float64(vendorSkuInfo.SkuList[0].StoreSkuInfo.VendorPrice)/float64(100)) isSaleStatusDiff := jxSkuSaleStatusName != vendorSkuSaleStatusName @@ -441,7 +441,7 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin if len(vendorSkuInfo.SkuList) > 0 { skuIDStr := utils.Int2Str(skuID) vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName - vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status) + vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status + 3) /* 供货商价格 */ vendorPrice := fmt.Sprintf("%.2f", float64(vendorSkuInfo.SkuList[0].StoreSkuInfo.VendorPrice)/float64(100)) /* 供货商价格 */ @@ -499,10 +499,10 @@ func CompareJxAndMultiVenderDepot(ctx *jxcontext.Context, vendorMap map[int]bool vendorSkuInfoMap := filterVendorSkuInfoMap[skuid] jxSkuSaleStatus := jxSkuInfo.Status - jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus + 3) + jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus) skuIDStr := utils.Int2Str(skuid) if vendorSkuInfoMap != nil { - vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfoMap.SkuList[0].Status + 3) + vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfoMap.SkuList[0].Status) vendorSkuDetailName := vendorSkuInfoMap.SkuList[0].SkuName isSaleStatusDiff := jxSkuSaleStatusName != vendorSkuSaleStatusName isNameDiff := strings.Compare(jxSkuDetailName, vendorSkuDetailName) != 0 diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index 93fd90d11..89f407e4a 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -482,7 +482,7 @@ func (t *BaseTask) run(taskHandler func()) { } } -func SendMessage(t *BaseTask) {//基类任务 +func SendMessage(t *BaseTask) { time.Sleep(10 * time.Millisecond) // 等待GetResult中的isGetResultCalled赋值 globals.SugarLogger.Debugf("BaseTask task ID:%s, name:%s finished, isGetResultCalled:%t", t.ID, t.Name, t.isGetResultCalled) if !t.isGetResultCalled && t.parent == nil && len(GetTasks(t.ID, TaskStatusBegin, TaskStatusEnd, 24, "")) > 0 { diff --git a/business/model/sku.go b/business/model/sku.go index c6aa85847..04c154089 100644 --- a/business/model/sku.go +++ b/business/model/sku.go @@ -90,11 +90,11 @@ var ( } SkuStatusName = map[int]string{ SkuStatusDeleted: "删除", - SkuStatusDontSale: "不可售", - SkuStatusNormal: "可售", - 2: "删除", - 3: "下架", - 4: "上架", + SkuStatusDontSale: "下架", + SkuStatusNormal: "上架", + 2: "删除", + 3: "不可售", + 4: "可售", } )