京西平台和其他平台商品的对比
This commit is contained in:
@@ -2,6 +2,7 @@ package cms
|
||||
|
||||
import (
|
||||
"time"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -198,16 +200,14 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin
|
||||
}
|
||||
}
|
||||
|
||||
func CheckSkuDiffBetweenJxAndVendor(vendorIDList []string, storeIDList []string) {
|
||||
func CheckSkuDiffBetweenJxAndVendor(vendorIDList []int, storeIDList []int) {
|
||||
startProcessTime := time.Now().Unix()
|
||||
vendorMap := make(map[int]bool)
|
||||
for _, value := range vendorIDList {
|
||||
vendorID := int(utils.Str2Int64(value))
|
||||
for _, vendorID := range vendorIDList {
|
||||
vendorMap[vendorID] = true
|
||||
}
|
||||
storeIDMap := make(map[int]bool)
|
||||
for _, value := range storeIDList {
|
||||
storeID := int(utils.Str2Int64(value))
|
||||
for _, storeID := range storeIDList {
|
||||
storeIDMap[storeID] = true
|
||||
}
|
||||
baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor start time: %v", time.Now())
|
||||
@@ -218,75 +218,84 @@ func CheckSkuDiffBetweenJxAndVendor(vendorIDList []string, storeIDList []string)
|
||||
} else {
|
||||
GetJdAllSkuInfo()
|
||||
diffData = make(map[int][]DiffData)
|
||||
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 {
|
||||
for vendorListIndex, vendorListValue := range jxStoreInfoListValue.StoreMaps {
|
||||
vendorID := int(utils.MustInterface2Int64(vendorListValue["vendorID"]))
|
||||
//filter for vendorID
|
||||
if len(vendorMap) > 0 {
|
||||
if _, ok := vendorMap[vendorID]; !ok {
|
||||
return retVal, err
|
||||
}
|
||||
}
|
||||
if _, ok := vendorNameList[vendorID]; ok {
|
||||
var filterJxSkuInfoMap map[int]*StoreSkuNameExt
|
||||
if vendorListIndex == 0 {
|
||||
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 vendorID == model.VendorIDJD {
|
||||
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
||||
jdSkuInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, nil, storeID, vendorStoreID, jdAllSkuInfoList)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err)
|
||||
} else if len(jdSkuInfoList) > 0 {
|
||||
filterJdSkuInfoMap := GetFilterJdSkuInfoMap(jdSkuInfoList)
|
||||
CompareJxAndJd(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterJdSkuInfoMap)
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
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
|
||||
}
|
||||
} else {
|
||||
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
vendorSkuInfoList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, nil, 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)
|
||||
}
|
||||
storeIDStr := utils.Int2Str(storeID)
|
||||
storeName := jxStoreInfoListValue.Name
|
||||
if jxStoreInfoListValue.StoreMaps != nil {
|
||||
for vendorListIndex, vendorListValue := range jxStoreInfoListValue.StoreMaps {
|
||||
vendorID := int(utils.MustInterface2Int64(vendorListValue["vendorID"]))
|
||||
//filter for vendorID
|
||||
if len(vendorMap) > 0 {
|
||||
if _, ok := vendorMap[vendorID]; !ok {
|
||||
return retVal, err
|
||||
}
|
||||
}
|
||||
if _, ok := vendorNameList[vendorID]; ok {
|
||||
var filterJxSkuInfoMap map[int]*StoreSkuNameExt
|
||||
if vendorListIndex == 0 {
|
||||
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 vendorID == model.VendorIDJD {
|
||||
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
||||
jdSkuInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, nil, storeID, vendorStoreID, jdAllSkuInfoList)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err)
|
||||
} else if len(jdSkuInfoList) > 0 {
|
||||
filterJdSkuInfoMap := GetFilterJdSkuInfoMap(jdSkuInfoList)
|
||||
CompareJxAndJd(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterJdSkuInfoMap)
|
||||
}
|
||||
} else {
|
||||
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
vendorSkuInfoList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, nil, 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)
|
||||
tasksch.HandleTask(taskParallel, task, false).Run()
|
||||
_, err = taskParallel.GetResult(0)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor taskParallel error:%v", err)
|
||||
}
|
||||
case 1:
|
||||
WriteToExcel(task, diffData)
|
||||
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 retVal, err
|
||||
return result, err
|
||||
}
|
||||
task := tasksch.NewParallelTask("CheckSkuDiffBetweenJxAndVendor", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc, jxStoreInfoList.Stores)
|
||||
tasksch.HandleTask(task, nil, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor tasksch error:%v", err)
|
||||
}
|
||||
WriteToExcel(diffData)
|
||||
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)
|
||||
taskSeq := tasksch.NewSeqTask("CheckSkuDiffBetweenJxAndVendor SeqTask", ctx, taskSeqFunc, 2)
|
||||
tasksch.HandleTask(taskSeq, nil, false).Run()
|
||||
}
|
||||
}
|
||||
|
||||
func WriteToExcel(data map[int][]DiffData) {
|
||||
func WriteToExcel(task *tasksch.SeqTask, data map[int][]DiffData) {
|
||||
var sheetList []*excel.Obj2ExcelSheetConfig
|
||||
for key, value := range data {
|
||||
sheetName := vendorNameList[key]
|
||||
@@ -310,6 +319,8 @@ func WriteToExcel(data map[int][]DiffData) {
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s failed error:%v", diffFullFileName, err)
|
||||
} else {
|
||||
noticeMsg := fmt.Sprintf("[详情点我](%s/billshow/?normal=true&path=%s) \n", globals.BackstageHost, downloadURL)
|
||||
task.SetNoticeMsg(noticeMsg)
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL:%s", diffFullFileName, downloadURL)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/tempop"
|
||||
@@ -295,23 +294,20 @@ func (c *TempOpController) TestStartOrEndOpStore() {
|
||||
|
||||
// @Title 京西平台和其他平台商品的对比
|
||||
// @Description 京西平台和其他平台商品的对比
|
||||
// @Param token header string true "认证token"
|
||||
// @Param vendorIDList query string false "运营商ID列表(京东0 美团1 饿百3)"
|
||||
// @Param storeIDList query string false "京西门店ID列表"
|
||||
// @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 200 {object} controllers.CallResult
|
||||
// @router /CheckSkuDiffBetweenJxAndVendor [get]
|
||||
// @router /CheckSkuDiffBetweenJxAndVendor [post]
|
||||
func (c *TempOpController) CheckSkuDiffBetweenJxAndVendor() {
|
||||
c.callCheckSkuDiffBetweenJxAndVendor(func(params *tTempopCheckSkuDiffBetweenJxAndVendorParams) (retVal interface{}, errCode string, err error) {
|
||||
var vendorIDList []string
|
||||
if params.VendorIDList != "" {
|
||||
vendorIDList = strings.Split(params.VendorIDList, ",")
|
||||
var vendorIDList []int
|
||||
var storeIDList []int
|
||||
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil {
|
||||
cms.CheckSkuDiffBetweenJxAndVendor(vendorIDList, storeIDList)
|
||||
}
|
||||
var storeIDList []string
|
||||
if params.StoreIDList != "" {
|
||||
storeIDList = strings.Split(params.StoreIDList, ",")
|
||||
}
|
||||
cms.CheckSkuDiffBetweenJxAndVendor(vendorIDList, storeIDList)
|
||||
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1658,7 +1658,7 @@ func init() {
|
||||
beego.ControllerComments{
|
||||
Method: "CheckSkuDiffBetweenJxAndVendor",
|
||||
Router: `/CheckSkuDiffBetweenJxAndVendor`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
Reference in New Issue
Block a user