From 6f105a759877742fe5bdccb36178cd41b32fc0ed Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Thu, 1 Aug 2019 16:00:43 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=AF=B9=E6=AF=94=E4=BA=AC=E8=A5=BF?= =?UTF-8?q?=E5=92=8C=E5=B9=B3=E5=8F=B0=E5=95=86=E5=93=81=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 277 +++++++++++++++++++ business/jxstore/cms/store_sku_check_test.go | 33 +++ business/jxutils/jxutils.go | 6 + controllers/temp_op.go | 18 +- routers/commentsRouter_controllers.go | 9 + 5 files changed, 341 insertions(+), 2 deletions(-) create mode 100644 business/jxstore/cms/store_sku_check.go create mode 100644 business/jxstore/cms/store_sku_check_test.go diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go new file mode 100644 index 000000000..8e7993abe --- /dev/null +++ b/business/jxstore/cms/store_sku_check.go @@ -0,0 +1,277 @@ +package cms + +import ( + "time" + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/jxutils" + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + "git.rosy.net.cn/jx-callback/business/model" + "git.rosy.net.cn/jx-callback/business/partner" + "git.rosy.net.cn/baseapi" + "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" + "git.rosy.net.cn/jx-callback/business/jxutils/excel" +) + +const ( + diffFileName = "export/京西和平台商品差异.xlsx" +) +var ( + vendorNameList = map[int]string { + // model.VendorIDMTWM: "美团", + // model.VendorIDEBAI: "饿百", + model.VendorIDJD: "京东", + } + titleList = []string { + "京西门店ID", + "平台门店ID", + "门店名", + "京西商品名", + "平台商品名", + "京西可售状态", + "平台可售状态", + } + diffData map[int][]DiffData + JdAllSkuInfoMap map[int]*partner.SkuNameInfo +) + +type DiffData struct { + JxStoreID string `json:"京西门店ID"` + VendorStoreID string `json:"平台门店ID"` + VendorStoreName string `json:"门店名"` + JxSkuName string `json:"京西商品名"` + VendorSkuName string `json:"平台商品名"` + JxStatus string `json:"京西可售状态"` + VendorStatus string `json:"平台可售状态"` +} + +func GetFilterJxSkuInfoMap(jxSkuInfoList []*StoreSkuNameExt) map[int]*StoreSkuNameExt { + filterJxSkuInfoMap := make(map[int]*StoreSkuNameExt) + for _, value := range jxSkuInfoList { + for _, skuInfo := range value.Skus2 { + filterJxSkuInfoMap[skuInfo.SkuID] = value + } + } + + return filterJxSkuInfoMap +} + +func GetFilterVendorSkuInfoMap(vendorSkuInfoList []*partner.SkuNameInfo) map[int]*partner.SkuNameInfo { + filterVendorSkuInfoMap := make(map[int]*partner.SkuNameInfo) + for _, value := range vendorSkuInfoList { + for _, skuInfo := range value.SkuList { + filterVendorSkuInfoMap[skuInfo.SkuID] = value + } + } + + return filterVendorSkuInfoMap +} + +func GetFilterJdSkuInfoMap(jdSkuInfoList []*partner.StoreSkuInfo) map[int]*partner.StoreSkuInfo { + filterJdSkuInfoMap := make(map[int]*partner.StoreSkuInfo) + for _, value := range jdSkuInfoList { + filterJdSkuInfoMap[value.SkuID] = value + } + + return filterJdSkuInfoMap +} + +func GetJdAllSkuInfoMap() map[int]*partner.SkuNameInfo { + if JdAllSkuInfoMap == nil { + JdAllSkuInfoMap = make(map[int]*partner.SkuNameInfo) + ctx := jxcontext.AdminCtx + vendorID := model.VendorIDJD + if multiHandler, ok := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler); ok { + jdAllSkuInfoList, err := multiHandler.GetSkus(ctx, 0, "", "") + if err != nil { + baseapi.SugarLogger.Errorf("GetJdAllSkuInfoMap error:%v", err) + } else { + for _, value := range jdAllSkuInfoList { + for _, skuInfo := range value.SkuList { + JdAllSkuInfoMap[skuInfo.SkuID] = value + } + } + } + } + } + + return JdAllSkuInfoMap +} + +func GetSkuStatusName(status int) string { + if status == 1 { + return "可售" + } else { + return "不可售" + } +} + +func CompareJxAndJd(vendorID int, storeIDStr, vendorStoreID, storeName string, + filterJxSkuInfoMap map[int]*StoreSkuNameExt, + filterJdSkuInfoMap map[int]*partner.StoreSkuInfo) { + JdAllSkuInfoMap := GetJdAllSkuInfoMap() + for skuID, jxSkuInfo := range filterJxSkuInfoMap { + jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, "", jxSkuInfo.SkuName.Unit, jxSkuInfo.SkuName.SpecQuality, jxSkuInfo.SkuName.SpecUnit, 0) + jxSkuStatusName := GetSkuStatusName(jxSkuInfo.Skus2[0].SkuStatus) + + vendorSkuInfo := filterJdSkuInfoMap[skuID] + if vendorSkuInfo != nil { + vendorSkuInfo := JdAllSkuInfoMap[vendorSkuInfo.SkuID] + vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName + vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) + if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, jxSkuStatusName} + diffData[vendorID] = append(diffData[vendorID], outPutData) + } + } else { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, "", jxSkuStatusName, ""} + diffData[vendorID] = append(diffData[vendorID], outPutData) + } + } + for skuID, _ := range filterJdSkuInfoMap { + vendorSkuInfo := JdAllSkuInfoMap[skuID] + vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName + vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) + + jxSkuInfo := filterJxSkuInfoMap[skuID] + if jxSkuInfo != nil { + jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, "", jxSkuInfo.SkuName.Unit, jxSkuInfo.SkuName.SpecQuality, jxSkuInfo.SkuName.SpecUnit, 0) + jxSkuStatusName := GetSkuStatusName(jxSkuInfo.Skus2[0].SkuStatus) + if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, jxSkuStatusName} + diffData[vendorID] = append(diffData[vendorID], outPutData) + } + } else { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, vendorSkuDetailName, "", vendorSkuStatusName, ""} + diffData[vendorID] = append(diffData[vendorID], outPutData) + } + } +} + +func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName string, + filterJxSkuInfoMap map[int]*StoreSkuNameExt, + filterVendorSkuInfoMap map[int]*partner.SkuNameInfo) { + for skuID, jxSkuInfo := range filterJxSkuInfoMap { + jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, "", jxSkuInfo.SkuName.Unit, jxSkuInfo.SkuName.SpecQuality, jxSkuInfo.SkuName.SpecUnit, 0) + jxSkuStatusName := GetSkuStatusName(jxSkuInfo.Skus2[0].SkuStatus) + + vendorSkuInfo := filterVendorSkuInfoMap[skuID] + if vendorSkuInfo != nil { + vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName + vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) + if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, jxSkuStatusName} + diffData[vendorID] = append(diffData[vendorID], outPutData) + } + } else { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, "", jxSkuStatusName, ""} + diffData[vendorID] = append(diffData[vendorID], outPutData) + } + } + for skuID, vendorSkuInfo := range filterVendorSkuInfoMap { + vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName + vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) + + jxSkuInfo := filterJxSkuInfoMap[skuID] + if jxSkuInfo != nil { + jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, "", jxSkuInfo.SkuName.Unit, jxSkuInfo.SkuName.SpecQuality, jxSkuInfo.SkuName.SpecUnit, 0) + jxSkuStatusName := GetSkuStatusName(jxSkuInfo.Skus2[0].SkuStatus) + if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, jxSkuStatusName} + diffData[vendorID] = append(diffData[vendorID], outPutData) + } + } else { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, vendorSkuDetailName, "", vendorSkuStatusName, ""} + diffData[vendorID] = append(diffData[vendorID], outPutData) + } + } +} + +func CheckSkuDiffBetweenJxAndVendor() { + startProcessTime := time.Now().Unix() + baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor start time: %v", time.Now()) + ctx := jxcontext.AdminCtx + 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 { + 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 + storeIDStr := utils.Int2Str(storeID) + storeName := jxStoreInfoListValue.Name + if jxStoreInfoListValue.StoreMaps != nil { + jxSkuInfoData, _ := GetStoreSkus(ctx, storeID, []int{}, true, "", true, map[string]interface{}{}, 0, -1) + filterJxSkuInfoMap := GetFilterJxSkuInfoMap(jxSkuInfoData.SkuNames) + for _, vendorListValue := range jxStoreInfoListValue.StoreMaps { + vendorID := int(utils.MustInterface2Int64(vendorListValue["vendorID"])) + if _, ok := vendorNameList[vendorID]; ok { + 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.ISingleStoreStoreSkuHandler) + jdSkuInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, nil, storeID, vendorStoreID, nil) + 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 + } + task := tasksch.NewParallelTask("CheckSkuDiffBetweenJxAndVendor", nil, 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) + } +} + +func WriteToExcel(data map[int][]DiffData) { + var sheetList []*excel.Obj2ExcelSheetConfig + for key, value := range data { + sheetName := vendorNameList[key] + excelConf := &excel.Obj2ExcelSheetConfig{ + Title: sheetName, + Data: value, + CaptionList: titleList, + } + sheetList = append(sheetList, excelConf) + baseapi.SugarLogger.Debugf("WriteToExcel:append:%s count:%d", sheetName, len(value)) + } + if len(sheetList) > 0 { + excelBin := excel.Obj2Excel(sheetList) + err := jxutils.WriteFile(diffFileName, excelBin) + if err != nil { + baseapi.SugarLogger.Errorf("WriteToExcel:save %s failed, error %v", diffFileName, err) + } else { + baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", diffFileName) + downloadURL, err := jxutils.UploadExportContent(excelBin, diffFileName) + if err != nil { + baseapi.SugarLogger.Errorf("WriteToExcel:upload %s failed error:%v", diffFileName, err) + } else { + baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL:%s", diffFileName, downloadURL) + } + } + } +} \ No newline at end of file diff --git a/business/jxstore/cms/store_sku_check_test.go b/business/jxstore/cms/store_sku_check_test.go new file mode 100644 index 000000000..033524de8 --- /dev/null +++ b/business/jxstore/cms/store_sku_check_test.go @@ -0,0 +1,33 @@ +package cms + +import ( + "testing" +) + +func TestCheckSkuDiffBetweenJxAndVendor(t *testing.T) { + CheckSkuDiffBetweenJxAndVendor() +} + +func TestTestExcel(t *testing.T) { + data1 := []DiffData{ + DiffData{"1", "1211", "aaa", "apple", "banna", "1", "0"}, + DiffData{"1", "1211", "aaa", "apple", "banna", "1", "0"}, + DiffData{"1", "1211", "aaa", "apple", "banna", "1", "0"}, + } + data2 := []DiffData{ + DiffData{"1", "1211", "aaa", "apple", "banna", "1", "0"}, + DiffData{"1", "1211", "aaa", "apple", "banna", "1", "0"}, + DiffData{"1", "1211", "aaa", "apple", "banna", "1", "0"}, + } + data3 := []DiffData{ + DiffData{"1", "1211", "aaa", "apple", "banna", "1", "0"}, + DiffData{"1", "1211", "aaa", "apple", "banna", "1", "0"}, + DiffData{"1", "1211", "aaa", "apple", "banna", "1", "0"}, + } + data := map[int][]DiffData{ + 0: data1, + 1: data2, + 3: data3, + } + WriteToExcel(data) +} diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index 19d56eebb..adb93c9c2 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -11,6 +11,7 @@ import ( "strings" "sync" "time" + "io/ioutil" "git.rosy.net.cn/baseapi/platformapi/autonavi" "git.rosy.net.cn/baseapi/utils" @@ -641,3 +642,8 @@ func GetEbaiOrderGetCode(order *model.GoodsOrder) (getCode string) { } return getCode } + +func WriteFile(fileName string, binData []byte) error { + err := ioutil.WriteFile(fileName, binData, 0666) + return err +} \ No newline at end of file diff --git a/controllers/temp_op.go b/controllers/temp_op.go index d2fc4d144..bb1d463da 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -11,6 +11,7 @@ import ( "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego" "git.rosy.net.cn/jx-callback/business/jxstore/misc" + "git.rosy.net.cn/jx-callback/business/jxstore/cms" ) type TempOpController struct { @@ -276,7 +277,7 @@ func (c *TempOpController) TestIt() { // @Title 开启或结束所有平台商店的额外时间 // @Description 开启或结束所有平台商店的额外时间,并且修改所有商品库存为0或99999(开启:0 , 结束:99999) // @Param token header string true "认证token" -// @Param startOrEndStore query bool true "开启或结束" +// @Param isStart query bool true "开启或结束门店" // @Param startTime query int false "开始营业时间(格式:930代表早上9点30分)" // @Param endTime query int false "结束营业时间" // @Success 200 {object} controllers.CallResult @@ -284,7 +285,20 @@ func (c *TempOpController) TestIt() { // @router /TestStartOrEndOpStore [get] func (c *TempOpController) TestStartOrEndOpStore() { c.callTestStartOrEndOpStore(func(params *tTempopTestStartOrEndOpStoreParams) (retVal interface{}, errCode string, err error) { - misc.StartOrEndOpStore(params.StartOrEndStore, int16(params.StartTime), int16(params.EndTime)) + misc.StartOrEndOpStore(params.IsStart, int16(params.StartTime), int16(params.EndTime)) + return retVal, "", err + }) +} + +// @Title 京西平台和其他平台商品的对比 +// @Description 京西平台和其他平台商品的对比 +// @Param token header string true "认证token" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /CheckSkuDiffBetweenJxAndVendor [get] +func (c *TempOpController) CheckSkuDiffBetweenJxAndVendor() { + c.callCheckSkuDiffBetweenJxAndVendor(func(params *tTempopCheckSkuDiffBetweenJxAndVendorParams) (retVal interface{}, errCode string, err error) { + cms.CheckSkuDiffBetweenJxAndVendor() return retVal, "", err }) } diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 1a31eaca4..320ce4c4f 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1654,6 +1654,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: "CheckSkuDiffBetweenJxAndVendor", + Router: `/CheckSkuDiffBetweenJxAndVendor`, + AllowHTTPMethods: []string{"get"}, + 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: "PrintMsg", From 06d564331e2d27e6efef475273900f06a652c84c Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Fri, 2 Aug 2019 15:33:28 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E4=BA=AC=E8=A5=BF=E5=92=8C=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E5=95=86=E5=93=81=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 127 ++++++++++++------- business/jxstore/cms/store_sku_check_test.go | 4 +- controllers/temp_op.go | 13 +- 3 files changed, 99 insertions(+), 45 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 8e7993abe..4c8ff1dd8 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -7,18 +7,23 @@ import ( "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/partner" + "git.rosy.net.cn/jx-callback/business/partner/putils" "git.rosy.net.cn/baseapi" "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" "git.rosy.net.cn/jx-callback/business/jxutils/excel" ) const ( - diffFileName = "export/京西和平台商品差异.xlsx" + canWriteTolocal = true + parallelCount = 10 + fileExt = ".xlsx" + diffFileName = "export/京西和平台商品差异" ) + var ( vendorNameList = map[int]string { - // model.VendorIDMTWM: "美团", - // model.VendorIDEBAI: "饿百", + model.VendorIDMTWM: "美团", + model.VendorIDEBAI: "饿百", model.VendorIDJD: "京东", } titleList = []string { @@ -31,7 +36,8 @@ var ( "平台可售状态", } diffData map[int][]DiffData - JdAllSkuInfoMap map[int]*partner.SkuNameInfo + jdAllSkuInfoMap map[int]*partner.SkuNameInfo + jdAllSkuInfoList []*partner.StoreSkuInfo ) type DiffData struct { @@ -69,53 +75,59 @@ func GetFilterVendorSkuInfoMap(vendorSkuInfoList []*partner.SkuNameInfo) map[int func GetFilterJdSkuInfoMap(jdSkuInfoList []*partner.StoreSkuInfo) map[int]*partner.StoreSkuInfo { filterJdSkuInfoMap := make(map[int]*partner.StoreSkuInfo) for _, value := range jdSkuInfoList { - filterJdSkuInfoMap[value.SkuID] = value + if value.Stock > 0 { + filterJdSkuInfoMap[value.SkuID] = value + } } return filterJdSkuInfoMap } -func GetJdAllSkuInfoMap() map[int]*partner.SkuNameInfo { - if JdAllSkuInfoMap == nil { - JdAllSkuInfoMap = make(map[int]*partner.SkuNameInfo) - ctx := jxcontext.AdminCtx - vendorID := model.VendorIDJD - if multiHandler, ok := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler); ok { - jdAllSkuInfoList, err := multiHandler.GetSkus(ctx, 0, "", "") - if err != nil { - baseapi.SugarLogger.Errorf("GetJdAllSkuInfoMap error:%v", err) - } else { - for _, value := range jdAllSkuInfoList { - for _, skuInfo := range value.SkuList { - JdAllSkuInfoMap[skuInfo.SkuID] = value +func GetJdAllSkuInfo() { + if _, ok := vendorNameList[model.VendorIDJD]; ok { + if jdAllSkuInfoMap == nil { + jdAllSkuInfoMap = make(map[int]*partner.SkuNameInfo) + ctx := jxcontext.AdminCtx + vendorID := model.VendorIDJD + if multiHandler, ok := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler); ok { + jdAllSkuNameInfoList, err := multiHandler.GetSkus(ctx, 0, "", "") + if err != nil { + baseapi.SugarLogger.Errorf("GetJdAllSkuInfo error:%v", err) + } else { + jdAllSkuInfoList = putils.StoreSkuFullList2Bare(jdAllSkuNameInfoList) + for _, value := range jdAllSkuNameInfoList { + for _, skuInfo := range value.SkuList { + jdAllSkuInfoMap[skuInfo.SkuID] = value + } } } } } } - - return JdAllSkuInfoMap } func GetSkuStatusName(status int) string { - if status == 1 { + if status == model.SkuStatusNormal { return "可售" - } else { + } else if status == model.SkuStatusDontSale { return "不可售" + } else if status == model.SkuStatusDeleted { + return "删除" } + + return "" } func CompareJxAndJd(vendorID int, storeIDStr, vendorStoreID, storeName string, filterJxSkuInfoMap map[int]*StoreSkuNameExt, filterJdSkuInfoMap map[int]*partner.StoreSkuInfo) { - JdAllSkuInfoMap := GetJdAllSkuInfoMap() for skuID, jxSkuInfo := range filterJxSkuInfoMap { jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, "", jxSkuInfo.SkuName.Unit, jxSkuInfo.SkuName.SpecQuality, jxSkuInfo.SkuName.SpecUnit, 0) jxSkuStatusName := GetSkuStatusName(jxSkuInfo.Skus2[0].SkuStatus) vendorSkuInfo := filterJdSkuInfoMap[skuID] if vendorSkuInfo != nil { - vendorSkuInfo := JdAllSkuInfoMap[vendorSkuInfo.SkuID] + vendorSkuInfo := jdAllSkuInfoMap[vendorSkuInfo.SkuID] vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { @@ -128,7 +140,7 @@ func CompareJxAndJd(vendorID int, storeIDStr, vendorStoreID, storeName string, } } for skuID, _ := range filterJdSkuInfoMap { - vendorSkuInfo := JdAllSkuInfoMap[skuID] + vendorSkuInfo := jdAllSkuInfoMap[skuID] vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) @@ -186,32 +198,59 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin } } -func CheckSkuDiffBetweenJxAndVendor() { +func CheckSkuDiffBetweenJxAndVendor(vendorIDList []string, storeIDList []string) { startProcessTime := time.Now().Unix() + vendorMap := make(map[int]bool) + for _, value := range vendorIDList { + vendorID := int(utils.Str2Int64(value)) + vendorMap[vendorID] = true + } + storeIDMap := make(map[int]bool) + for _, value := range storeIDList { + storeID := int(utils.Str2Int64(value)) + storeIDMap[storeID] = true + } baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor start time: %v", time.Now()) ctx := jxcontext.AdminCtx 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 { + 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 { - jxSkuInfoData, _ := GetStoreSkus(ctx, storeID, []int{}, true, "", true, map[string]interface{}{}, 0, -1) - filterJxSkuInfoMap := GetFilterJxSkuInfoMap(jxSkuInfoData.SkuNames) - for _, vendorListValue := range jxStoreInfoListValue.StoreMaps { + 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.ISingleStoreStoreSkuHandler) - jdSkuInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, nil, storeID, vendorStoreID, nil) + 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 { @@ -233,7 +272,7 @@ func CheckSkuDiffBetweenJxAndVendor() { } return retVal, err } - task := tasksch.NewParallelTask("CheckSkuDiffBetweenJxAndVendor", nil, ctx, taskFunc, jxStoreInfoList.Stores) + 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 { @@ -261,17 +300,19 @@ func WriteToExcel(data map[int][]DiffData) { } if len(sheetList) > 0 { excelBin := excel.Obj2Excel(sheetList) - err := jxutils.WriteFile(diffFileName, excelBin) - if err != nil { - baseapi.SugarLogger.Errorf("WriteToExcel:save %s failed, error %v", diffFileName, err) - } else { - baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", diffFileName) - downloadURL, err := jxutils.UploadExportContent(excelBin, diffFileName) - if err != nil { - baseapi.SugarLogger.Errorf("WriteToExcel:upload %s failed error:%v", diffFileName, err) - } else { - baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL:%s", diffFileName, downloadURL) - } + timeStr := utils.Int64ToStr(time.Now().Unix()) + diffFullFileName := diffFileName + 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) + } + } else { + baseapi.SugarLogger.Debug("WriteToExcel:No diff data!!!") } } \ No newline at end of file diff --git a/business/jxstore/cms/store_sku_check_test.go b/business/jxstore/cms/store_sku_check_test.go index ef06962e8..28250dc25 100644 --- a/business/jxstore/cms/store_sku_check_test.go +++ b/business/jxstore/cms/store_sku_check_test.go @@ -5,5 +5,7 @@ import ( ) func TestCheckSkuDiffBetweenJxAndVendor(t *testing.T) { - CheckSkuDiffBetweenJxAndVendor() + vendorIDList := []string{} + storeIDList := []string{} + CheckSkuDiffBetweenJxAndVendor(vendorIDList, storeIDList) } \ No newline at end of file diff --git a/controllers/temp_op.go b/controllers/temp_op.go index f92a2dcef..a5fc3f47f 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -1,6 +1,7 @@ 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,12 +296,22 @@ 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列表" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /CheckSkuDiffBetweenJxAndVendor [get] func (c *TempOpController) CheckSkuDiffBetweenJxAndVendor() { c.callCheckSkuDiffBetweenJxAndVendor(func(params *tTempopCheckSkuDiffBetweenJxAndVendorParams) (retVal interface{}, errCode string, err error) { - cms.CheckSkuDiffBetweenJxAndVendor() + var vendorIDList []string + if params.VendorIDList != "" { + vendorIDList = strings.Split(params.VendorIDList, ",") + } + var storeIDList []string + if params.StoreIDList != "" { + storeIDList = strings.Split(params.StoreIDList, ",") + } + cms.CheckSkuDiffBetweenJxAndVendor(vendorIDList, storeIDList) return retVal, "", err }) } From e3e57204f6a4c6d1572bfb8f6ca719eb5157c07d Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Fri, 2 Aug 2019 15:39:56 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=86=99=E6=96=87=E4=BB=B6=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 4c8ff1dd8..1b97bad84 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -14,7 +14,7 @@ import ( ) const ( - canWriteTolocal = true + canWriteTolocal = false parallelCount = 10 fileExt = ".xlsx" diffFileName = "export/京西和平台商品差异" From 876af999c38e21273d1a848cf61d28dcd400bc1d Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Fri, 2 Aug 2019 17:38:07 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E4=BA=AC=E8=A5=BF=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E5=92=8C=E5=85=B6=E4=BB=96=E5=B9=B3=E5=8F=B0=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 141 +++++++++++++----------- controllers/temp_op.go | 22 ++-- routers/commentsRouter_controllers.go | 2 +- 3 files changed, 86 insertions(+), 79 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 1b97bad84..cfe5d4aef 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -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 { diff --git a/controllers/temp_op.go b/controllers/temp_op.go index a5fc3f47f..6f7eb122f 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -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 }) } diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 320ce4c4f..93be9c30a 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -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}) From 9afb12ced7db3442565f34ceb0a9e75882ca24b1 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Mon, 5 Aug 2019 16:32:20 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=AF=94=E8=BE=83?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84BUG=EF=BC=8C=E6=B7=BB=E5=8A=A0SkuID?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=88=B0DiffData=E7=BB=93=E6=9E=84=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 59 +++++++++++-------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index cfe5d4aef..054fe5407 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -32,6 +32,7 @@ var ( "京西门店ID", "平台门店ID", "门店名", + "SkuID", "京西商品名", "平台商品名", "京西可售状态", @@ -46,6 +47,7 @@ type DiffData struct { JxStoreID string `json:"京西门店ID"` VendorStoreID string `json:"平台门店ID"` VendorStoreName string `json:"门店名"` + SkuID string `json:"SkuID"` JxSkuName string `json:"京西商品名"` VendorSkuName string `json:"平台商品名"` JxStatus string `json:"京西可售状态"` @@ -123,39 +125,34 @@ func GetSkuStatusName(status int) string { func CompareJxAndJd(vendorID int, storeIDStr, vendorStoreID, storeName string, filterJxSkuInfoMap map[int]*StoreSkuNameExt, filterJdSkuInfoMap map[int]*partner.StoreSkuInfo) { - for skuID, jxSkuInfo := range filterJxSkuInfoMap { - jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, "", jxSkuInfo.SkuName.Unit, jxSkuInfo.SkuName.SpecQuality, jxSkuInfo.SkuName.SpecUnit, 0) - jxSkuStatusName := GetSkuStatusName(jxSkuInfo.Skus2[0].SkuStatus) - + for skuID, jxSkuInfo := range filterJxSkuInfoMap { + skuIDStr := utils.Int2Str(skuID) + jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, jxSkuInfo.Skus2[0].Comment, jxSkuInfo.SkuName.Unit, jxSkuInfo.Skus2[0].SkuSpecQuality, jxSkuInfo.Skus2[0].SkuSpecUnit, 0) + jxSkuStatus := jxutils.MergeSkuStatus(jxSkuInfo.Skus2[0].SkuStatus, jxSkuInfo.Skus2[0].StoreSkuStatus) + jxSkuStatusName := GetSkuStatusName(jxSkuStatus) vendorSkuInfo := filterJdSkuInfoMap[skuID] if vendorSkuInfo != nil { vendorSkuInfo := jdAllSkuInfoMap[vendorSkuInfo.SkuID] vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, jxSkuStatusName} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, vendorSkuStatusName} diffData[vendorID] = append(diffData[vendorID], outPutData) } } else { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, "", jxSkuStatusName, ""} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, "", jxSkuStatusName, ""} diffData[vendorID] = append(diffData[vendorID], outPutData) } } for skuID, _ := range filterJdSkuInfoMap { + skuIDStr := utils.Int2Str(skuID) vendorSkuInfo := jdAllSkuInfoMap[skuID] vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) jxSkuInfo := filterJxSkuInfoMap[skuID] - if jxSkuInfo != nil { - jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, "", jxSkuInfo.SkuName.Unit, jxSkuInfo.SkuName.SpecQuality, jxSkuInfo.SkuName.SpecUnit, 0) - jxSkuStatusName := GetSkuStatusName(jxSkuInfo.Skus2[0].SkuStatus) - if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, jxSkuStatusName} - diffData[vendorID] = append(diffData[vendorID], outPutData) - } - } else { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, vendorSkuDetailName, "", vendorSkuStatusName, ""} + if jxSkuInfo == nil { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", vendorSkuDetailName, "", vendorSkuStatusName} diffData[vendorID] = append(diffData[vendorID], outPutData) } } @@ -164,37 +161,33 @@ func CompareJxAndJd(vendorID int, storeIDStr, vendorStoreID, storeName string, func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName string, filterJxSkuInfoMap map[int]*StoreSkuNameExt, filterVendorSkuInfoMap map[int]*partner.SkuNameInfo) { - for skuID, jxSkuInfo := range filterJxSkuInfoMap { - jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, "", jxSkuInfo.SkuName.Unit, jxSkuInfo.SkuName.SpecQuality, jxSkuInfo.SkuName.SpecUnit, 0) - jxSkuStatusName := GetSkuStatusName(jxSkuInfo.Skus2[0].SkuStatus) + for skuID, jxSkuInfo := range filterJxSkuInfoMap { + skuIDStr := utils.Int2Str(skuID) + jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, jxSkuInfo.Skus2[0].Comment, jxSkuInfo.SkuName.Unit, jxSkuInfo.Skus2[0].SkuSpecQuality, jxSkuInfo.Skus2[0].SkuSpecUnit, 0) + jxSkuStatus := jxutils.MergeSkuStatus(jxSkuInfo.Skus2[0].SkuStatus, jxSkuInfo.Skus2[0].StoreSkuStatus) + jxSkuStatusName := GetSkuStatusName(jxSkuStatus) vendorSkuInfo := filterVendorSkuInfoMap[skuID] if vendorSkuInfo != nil { vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, jxSkuStatusName} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, vendorSkuStatusName} diffData[vendorID] = append(diffData[vendorID], outPutData) } } else { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, "", jxSkuStatusName, ""} + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, "", jxSkuStatusName, ""} diffData[vendorID] = append(diffData[vendorID], outPutData) } } for skuID, vendorSkuInfo := range filterVendorSkuInfoMap { + skuIDStr := utils.Int2Str(skuID) vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) jxSkuInfo := filterJxSkuInfoMap[skuID] - if jxSkuInfo != nil { - jxSkuDetailName := jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, "", jxSkuInfo.SkuName.Unit, jxSkuInfo.SkuName.SpecQuality, jxSkuInfo.SkuName.SpecUnit, 0) - jxSkuStatusName := GetSkuStatusName(jxSkuInfo.Skus2[0].SkuStatus) - if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, jxSkuStatusName} - diffData[vendorID] = append(diffData[vendorID], outPutData) - } - } else { - outPutData := DiffData{storeIDStr, vendorStoreID, storeName, vendorSkuDetailName, "", vendorSkuStatusName, ""} + if jxSkuInfo == nil { + outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", vendorSkuDetailName, "", vendorSkuStatusName} diffData[vendorID] = append(diffData[vendorID], outPutData) } } @@ -233,17 +226,19 @@ func CheckSkuDiffBetweenJxAndVendor(vendorIDList []int, storeIDList []int) { storeIDStr := utils.Int2Str(storeID) storeName := jxStoreInfoListValue.Name if jxStoreInfoListValue.StoreMaps != nil { - for vendorListIndex, vendorListValue := range jxStoreInfoListValue.StoreMaps { + isGetJxSkuInfoData := false + for _, 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 + continue } } if _, ok := vendorNameList[vendorID]; ok { var filterJxSkuInfoMap map[int]*StoreSkuNameExt - if vendorListIndex == 0 { + 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) } From e64e0cc4fb1a943992c03d882ddcbb78909232e8 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Wed, 7 Aug 2019 15:18:10 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E7=BB=99=E6=95=B0=E6=8D=AE=E5=8A=A0?= =?UTF-8?q?=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 44 +++++++++++++++++++------ 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 054fe5407..39eda1a1f 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -3,6 +3,7 @@ package cms import ( "time" "fmt" + "sync" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" @@ -17,7 +18,7 @@ import ( const ( canWriteTolocal = false - parallelCount = 10 + parallelCount = 5 fileExt = ".xlsx" diffFileName = "export/京西和平台商品差异" ) @@ -38,11 +39,17 @@ var ( "京西可售状态", "平台可售状态", } - diffData map[int][]DiffData + //diffData map[int][]DiffData + diffData DiffDataLock jdAllSkuInfoMap map[int]*partner.SkuNameInfo jdAllSkuInfoList []*partner.StoreSkuInfo ) +type DiffDataLock struct { + diffDataMap map[int][]DiffData + locker sync.RWMutex +} + type DiffData struct { JxStoreID string `json:"京西门店ID"` VendorStoreID string `json:"平台门店ID"` @@ -54,6 +61,16 @@ type DiffData struct { VendorStatus string `json:"平台可售状态"` } +func (d *DiffDataLock) AppendData(vendorID int, diffData DiffData) { + d.locker.Lock() + defer d.locker.Unlock() + d.diffDataMap[vendorID] = append(d.diffDataMap[vendorID], diffData) +} + +func (d *DiffDataLock) InitData() { + d.diffDataMap = make(map[int][]DiffData) +} + func GetFilterJxSkuInfoMap(jxSkuInfoList []*StoreSkuNameExt) map[int]*StoreSkuNameExt { filterJxSkuInfoMap := make(map[int]*StoreSkuNameExt) for _, value := range jxSkuInfoList { @@ -137,11 +154,13 @@ func CompareJxAndJd(vendorID int, storeIDStr, vendorStoreID, storeName string, vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, vendorSkuStatusName} - diffData[vendorID] = append(diffData[vendorID], outPutData) + //diffData[vendorID] = append(diffData[vendorID], outPutData) + diffData.AppendData(vendorID, outPutData) } } else { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, "", jxSkuStatusName, ""} - diffData[vendorID] = append(diffData[vendorID], outPutData) + //diffData[vendorID] = append(diffData[vendorID], outPutData) + diffData.AppendData(vendorID, outPutData) } } for skuID, _ := range filterJdSkuInfoMap { @@ -153,7 +172,8 @@ func CompareJxAndJd(vendorID int, storeIDStr, vendorStoreID, storeName string, jxSkuInfo := filterJxSkuInfoMap[skuID] if jxSkuInfo == nil { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", vendorSkuDetailName, "", vendorSkuStatusName} - diffData[vendorID] = append(diffData[vendorID], outPutData) + //diffData[vendorID] = append(diffData[vendorID], outPutData) + diffData.AppendData(vendorID, outPutData) } } } @@ -173,11 +193,13 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, vendorSkuStatusName} - diffData[vendorID] = append(diffData[vendorID], outPutData) + //diffData[vendorID] = append(diffData[vendorID], outPutData) + diffData.AppendData(vendorID, outPutData) } } else { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, "", jxSkuStatusName, ""} - diffData[vendorID] = append(diffData[vendorID], outPutData) + //diffData[vendorID] = append(diffData[vendorID], outPutData) + diffData.AppendData(vendorID, outPutData) } } for skuID, vendorSkuInfo := range filterVendorSkuInfoMap { @@ -188,7 +210,8 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin jxSkuInfo := filterJxSkuInfoMap[skuID] if jxSkuInfo == nil { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", vendorSkuDetailName, "", vendorSkuStatusName} - diffData[vendorID] = append(diffData[vendorID], outPutData) + //diffData[vendorID] = append(diffData[vendorID], outPutData) + diffData.AppendData(vendorID, outPutData) } } } @@ -210,7 +233,8 @@ func CheckSkuDiffBetweenJxAndVendor(vendorIDList []int, storeIDList []int) { baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStores error:%v", err) } else { GetJdAllSkuInfo() - diffData = make(map[int][]DiffData) + //diffData = make(map[int][]DiffData) + diffData.InitData() taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { switch step { case 0: @@ -277,7 +301,7 @@ func CheckSkuDiffBetweenJxAndVendor(vendorIDList []int, storeIDList []int) { baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor taskParallel error:%v", err) } case 1: - WriteToExcel(task, diffData) + WriteToExcel(task, diffData.diffDataMap) endProcessTime := time.Now().Unix() diff := endProcessTime - startProcessTime baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor end time: %v", time.Now()) From 877566cc802d39d7aafc516690c8acfd7e3558a4 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Wed, 7 Aug 2019 15:19:29 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E6=9C=BA=E5=88=B6-=E7=BE=8E=E5=9B=A2?= =?UTF-8?q?=E5=92=8C=E9=A5=BF=E7=99=BE=E5=88=86=E6=97=B6=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/misc2.go | 134 ++++++++++++++++++++++------ business/jxstore/misc/misc2_test.go | 2 +- controllers/temp_op.go | 22 +++-- 3 files changed, 120 insertions(+), 38 deletions(-) diff --git a/business/jxstore/misc/misc2.go b/business/jxstore/misc/misc2.go index b55a57367..436a3f157 100644 --- a/business/jxstore/misc/misc2.go +++ b/business/jxstore/misc/misc2.go @@ -2,7 +2,7 @@ package misc import ( "time" - + "strings" "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxstore/cms" @@ -15,7 +15,8 @@ import ( ) const ( - specialSkuName = "温馨提示" + taskParallelCount = 4 + specialSkuNameKeyWord = "温馨提示" startOpStoreStockNumber = 0 endOpStoreStockNumber = model.MaxStoreSkuStockQty startOpStoreTimeDefaultMTWM = int16(2200) @@ -25,19 +26,34 @@ const ( ) var ( - startOpStoreTimeListJXCS = []string{ + //only for MTWM + startOpStoreTimeListJXGY_MTWM = []string{ + "22:00:00", + } + endOpStoreTimeListJXGY_MTWM = []string{ + "00:00:00", + } + startOpStoreTimeListJXCS_MTWM = []string { "22:10:00", } - endOpStoreTimeListJXCS = []string{ - "06:10:00", + endOpStoreTimeListJXCS_MTWM = []string{ + "00:10:00", } + //for other vendor startOpStoreTimeListJXGY = []string{ - "22:00:00", + "22:20:00", } endOpStoreTimeListJXGY = []string{ "06:00:00", } - vendorList = map[int]bool{ + startOpStoreTimeListJXCS = []string{ + "22:30:00", + } + endOpStoreTimeListJXCS = []string{ + "06:10:00", + } + + vendorList = map[int]bool { model.VendorIDMTWM: true, model.VendorIDEBAI: true, } @@ -71,17 +87,45 @@ func GetOpStoreTime(vendorID int) (startTime, endTime int16) { return 0, 0 } -func FilterSkuNameList(storeSkuNameList []*partner.SkuNameInfo) (filterStoreSkuNameList []*partner.SkuNameInfo) { - for _, skuNameInfo := range storeSkuNameList { - if skuNameInfo.Name != specialSkuName { - filterStoreSkuNameList = append(filterStoreSkuNameList, skuNameInfo) - } - } - return filterStoreSkuNameList +func IsSpecialSku(name string) bool { + return strings.Contains(name, specialSkuNameKeyWord) } -func StartOrEndOpStore(isStart bool, startTime, endTime int16, isAsync, isContinueWhenError bool) (retVal interface{}, err error) { +func SetSkuStock(isStart bool, storeSkuNameList []*partner.SkuNameInfo) { + for _, skuNameInfo := range storeSkuNameList { + for _, skuInfo := range skuNameInfo.SkuList { + if IsSpecialSku(skuNameInfo.Name) || IsSpecialSku(skuInfo.SkuName) { + skuInfo.Stock = endOpStoreStockNumber + } else { + skuInfo.Stock = GetStockValue(isStart) + } + } + } +} + +func SetSpecialSkuStatus(storeID, vendorID int, vendorStoreID string, storeSkuNameList []*partner.SkuNameInfo) { + ctx := jxcontext.AdminCtx + singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) + for _, skuNameInfo := range storeSkuNameList { + for _, skuInfo := range skuNameInfo.SkuList { + if IsSpecialSku(skuNameInfo.Name) || IsSpecialSku(skuInfo.SkuName) { + storeSkuList := []*partner.StoreSkuInfo{&skuInfo.StoreSkuInfo} + singleStoreHandler.UpdateStoreSkusStatus(ctx, storeID, vendorStoreID, storeSkuList, model.SkuStatusNormal) + } + } + } +} + +func StartOrEndOpStore(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 { + vendorMap[vendorID] = true + } + storeIDMap := make(map[int]bool) + for _, storeID := range storeIDList { + 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) @@ -92,9 +136,21 @@ func StartOrEndOpStore(isStart bool, startTime, endTime int16, isAsync, isContin taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { storeListValue := batchItemList[0].(*cms.StoreExt) storeID := storeListValue.ID + //filter for storeID + if len(storeIDMap) > 0 { + if _, ok := storeIDMap[storeID]; !ok { + return retVal, err + } + } if storeListValue.StoreMaps != nil { for _, vendorListValue := range storeListValue.StoreMaps { vendorID := int(utils.MustInterface2Int64(vendorListValue["vendorID"])) + //filter for vendorID + if len(vendorMap) > 0 { + if _, ok := vendorMap[vendorID]; !ok { + continue + } + } if _, ok := vendorList[vendorID]; ok { startOpStoreTime, endOpStoreTime := GetOpStoreTime(vendorID) if startTime != 0 && endTime != 0 { @@ -109,17 +165,15 @@ func StartOrEndOpStore(isStart bool, startTime, endTime int16, isAsync, isContin if err != nil { baseapi.SugarLogger.Errorf("StartOrEndOpStore GetStoreSkusFullInfo error:%v storeID:%d vendorID:%d vendorStoreID:%s", err, storeID, vendorID, vendorStoreID) } else { - filterStoreSkuNameList := FilterSkuNameList(storeSkuNameList) - storeSkuList := putils.StoreSkuFullList2Bare(filterStoreSkuNameList) + SetSkuStock(isStart, storeSkuNameList) + SetSpecialSkuStatus(storeID, vendorID, vendorStoreID,storeSkuNameList) + storeSkuList := putils.StoreSkuFullList2Bare(storeSkuNameList) if len(storeSkuList) > 0 { if !isStart { AddOrDelExtraStoreOptime(vendorID, storeID, vendorStoreID, &storeListValue.Store, startOpStoreTime, endOpStoreTime, false) } _, err = putils.FreeBatchStoreSkuInfo(func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { - for _, skuValue := range batchedStoreSkuList { - skuValue.Stock = GetStockValue(isStart) - } //var successList []*partner.StoreSkuInfo if _, err = singleStoreHandler.UpdateStoreSkusStock(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil { //successList = batchedStoreSkuList @@ -138,7 +192,7 @@ func StartOrEndOpStore(isStart bool, startTime, endTime int16, isAsync, isContin } return retVal, err } - task := tasksch.NewParallelTask("StartOrEndOpStore", tasksch.NewParallelConfig().SetParallelCount(4), ctx, taskFunc, storeInfo.Stores) + task := tasksch.NewParallelTask("StartOrEndOpStore", tasksch.NewParallelConfig().SetParallelCount(taskParallelCount), ctx, taskFunc, storeInfo.Stores) tasksch.HandleTask(task, nil, true).Run() if isAsync { retVal = task.ID @@ -158,21 +212,43 @@ func StartOrEndOpStore(isStart bool, startTime, endTime int16, isAsync, isContin return retVal, err } -func InitEx() { - startTimeList := startOpStoreTimeListJXCS - stopTimeList := endOpStoreTimeListJXCS - if !globals.IsMainProductEnv() { - startTimeList = startOpStoreTimeListJXGY - stopTimeList = endOpStoreTimeListJXGY +func StartDaemon(vendorID int) { + startTimeList := []string{} + stopTimeList := []string{} + if vendorID == model.VendorIDMTWM { + startTimeList = startOpStoreTimeListJXCS_MTWM + stopTimeList = endOpStoreTimeListJXCS_MTWM + if !globals.IsMainProductEnv() { + startTimeList = startOpStoreTimeListJXGY_MTWM + stopTimeList = endOpStoreTimeListJXGY_MTWM + } + } else { + startTimeList = startOpStoreTimeListJXCS + stopTimeList = endOpStoreTimeListJXCS + if !globals.IsMainProductEnv() { + startTimeList = startOpStoreTimeListJXGY + stopTimeList = endOpStoreTimeListJXGY + } } + + vendorIDList := []int{vendorID} + storeIDList := []int{} ScheduleTimerFunc("StartOpStore", func() { if !IsImportantTaskRunning(TaskNameSyncStoreSku) { - StartOrEndOpStore(true, 0, 0, false, true) + StartOrEndOpStore(true, vendorIDList, storeIDList, 0, 0, false, true) } }, startTimeList) ScheduleTimerFunc("EndOpStore", func() { if !IsImportantTaskRunning(TaskNameSyncStoreSku) { - StartOrEndOpStore(false, 0, 0, false, true) + StartOrEndOpStore(false, vendorIDList, storeIDList, 0, 0, false, true) } }, stopTimeList) } + +func InitEx() { + for index, value := range vendorList { + if value { + StartDaemon(index) + } + } +} diff --git a/business/jxstore/misc/misc2_test.go b/business/jxstore/misc/misc2_test.go index c683e0bb7..38d1a9be5 100644 --- a/business/jxstore/misc/misc2_test.go +++ b/business/jxstore/misc/misc2_test.go @@ -5,5 +5,5 @@ import ( ) func TestStartOrEndOpStore(t *testing.T) { - StartOrEndOpStore(true, 0, 0, false, true) + StartOrEndOpStore(1, true, 0, 0, false, true) } diff --git a/controllers/temp_op.go b/controllers/temp_op.go index 6f7eb122f..95d5001a6 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -276,18 +276,24 @@ func (c *TempOpController) TestIt() { // @Title 开启或结束所有平台商店的额外时间 // @Description 开启或结束所有平台商店的额外时间,并且修改所有商品库存为0或99999(开启:0 , 结束:99999) -// @Param token header string true "认证token" -// @Param startOrEndStore query bool true "开启或结束" -// @Param startTime query int false "开始营业时间(格式:930代表早上9点30分)" -// @Param endTime query int false "结束营业时间" -// @Param isAsync query bool false "是否异步操作" -// @Param isContinueWhenError query bool false "单个同步失败是否继续,缺省false" +// @Param token header string true "认证token" +// @Param vendorIDs formData string false "运营商ID列表(美团1 饿百3)" +// @Param storeIDs formData string false "京西门店ID列表" +// @Param startOrEndStore formData bool true "开启或结束" +// @Param startTime formData int false "开始营业时间(格式:930代表早上9点30分)" +// @Param endTime formData int false "结束营业时间" +// @Param isAsync formData bool false "是否异步操作" +// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult -// @router /TestStartOrEndOpStore [get] +// @router /TestStartOrEndOpStore [post] func (c *TempOpController) TestStartOrEndOpStore() { c.callTestStartOrEndOpStore(func(params *tTempopTestStartOrEndOpStoreParams) (retVal interface{}, errCode string, err error) { - retVal, err = misc.StartOrEndOpStore(params.StartOrEndStore, int16(params.StartTime), int16(params.EndTime), params.IsAsync, params.IsContinueWhenError) + 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) + } return retVal, "", err }) } From df40806734ffe45649498689517bd38fc7fe0100 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Thu, 8 Aug 2019 09:26:55 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 9 +-------- routers/commentsRouter_controllers.go | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 39eda1a1f..c97125bc1 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -39,7 +39,7 @@ var ( "京西可售状态", "平台可售状态", } - //diffData map[int][]DiffData + diffData DiffDataLock jdAllSkuInfoMap map[int]*partner.SkuNameInfo jdAllSkuInfoList []*partner.StoreSkuInfo @@ -154,12 +154,10 @@ func CompareJxAndJd(vendorID int, storeIDStr, vendorStoreID, storeName string, vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, vendorSkuStatusName} - //diffData[vendorID] = append(diffData[vendorID], outPutData) diffData.AppendData(vendorID, outPutData) } } else { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, "", jxSkuStatusName, ""} - //diffData[vendorID] = append(diffData[vendorID], outPutData) diffData.AppendData(vendorID, outPutData) } } @@ -172,7 +170,6 @@ func CompareJxAndJd(vendorID int, storeIDStr, vendorStoreID, storeName string, jxSkuInfo := filterJxSkuInfoMap[skuID] if jxSkuInfo == nil { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", vendorSkuDetailName, "", vendorSkuStatusName} - //diffData[vendorID] = append(diffData[vendorID], outPutData) diffData.AppendData(vendorID, outPutData) } } @@ -193,12 +190,10 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin vendorSkuStatusName := GetSkuStatusName(vendorSkuInfo.SkuList[0].Status) if jxSkuStatusName != vendorSkuStatusName || jxSkuDetailName != vendorSkuDetailName { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, vendorSkuDetailName, jxSkuStatusName, vendorSkuStatusName} - //diffData[vendorID] = append(diffData[vendorID], outPutData) diffData.AppendData(vendorID, outPutData) } } else { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, jxSkuDetailName, "", jxSkuStatusName, ""} - //diffData[vendorID] = append(diffData[vendorID], outPutData) diffData.AppendData(vendorID, outPutData) } } @@ -210,7 +205,6 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin jxSkuInfo := filterJxSkuInfoMap[skuID] if jxSkuInfo == nil { outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", vendorSkuDetailName, "", vendorSkuStatusName} - //diffData[vendorID] = append(diffData[vendorID], outPutData) diffData.AppendData(vendorID, outPutData) } } @@ -233,7 +227,6 @@ func CheckSkuDiffBetweenJxAndVendor(vendorIDList []int, storeIDList []int) { baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStores error:%v", err) } else { GetJdAllSkuInfo() - //diffData = make(map[int][]DiffData) diffData.InitData() taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { switch step { diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index d87168614..019edea3a 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1703,7 +1703,7 @@ func init() { beego.ControllerComments{ Method: "TestStartOrEndOpStore", Router: `/TestStartOrEndOpStore`, - AllowHTTPMethods: []string{"get"}, + AllowHTTPMethods: []string{"post"}, MethodParams: param.Make(), Filters: nil, Params: nil}) From 94f9a07519ba213d9f802a890e4d1b2bd96799cb Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Thu, 8 Aug 2019 12:03:25 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/misc2.go | 100 +++++++++++++++------------------ 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/business/jxstore/misc/misc2.go b/business/jxstore/misc/misc2.go index b8fb90dc4..4c21d844e 100644 --- a/business/jxstore/misc/misc2.go +++ b/business/jxstore/misc/misc2.go @@ -19,44 +19,42 @@ const ( specialSkuNameKeyWord = "温馨提示" startOpStoreStockNumber = 0 endOpStoreStockNumber = model.MaxStoreSkuStockQty - startOpStoreTimeDefaultMTWM = int16(2200) - endOpStoreTimeDefaultMTWM = int16(2355) - startOpStoreTimeDefaultEBAI = int16(5) - endOpStoreTimeDefaultEBAI = int16(2355) ) var ( - //only for MTWM - startOpStoreTimeListJXGY_MTWM = []string{ - "22:00:00", - } - endOpStoreTimeListJXGY_MTWM = []string{ - "00:00:00", - } - startOpStoreTimeListJXCS_MTWM = []string { - "22:10:00", - } - endOpStoreTimeListJXCS_MTWM = []string{ - "00:10:00", - } - //for other vendor - startOpStoreTimeListJXGY = []string{ - "22:20:00", - } - endOpStoreTimeListJXGY = []string{ - "06:00:00", - } - startOpStoreTimeListJXCS = []string{ - "22:30:00", - } - endOpStoreTimeListJXCS = []string{ - "06:10:00", - } - vendorList = map[int]bool { model.VendorIDMTWM: true, model.VendorIDEBAI: true, } + + vendorStoreRefreshTimeList = map[int][]string { + model.VendorIDMTWM: []string { + //start and end time for JXGY + "22:00:00", + "00:00:00", + //start and end time for JXCS + "22:10:00", + "00:10:00", + }, + model.VendorIDEBAI: []string { + "22:20:00", + "06:00:00", + + "22:30:00", + "06:10:00", + }, + } + + vendorStartEndStoreTime = map[int][]int16 { + model.VendorIDMTWM: []int16 { + int16(2200),//start time + int16(2355),//end time + }, + model.VendorIDEBAI: []int16 { + int16(5), + int16(2355), + }, + } ) func AddOrDelExtraStoreOptime(vendorID, storeID int, vendorStoreID string, storeInfo *model.Store, startOpStoreTime, endOpStoreTime int16, needAddTime bool) bool { @@ -78,13 +76,9 @@ func GetStockValue(isStart bool) int { } func GetOpStoreTime(vendorID int) (startTime, endTime int16) { - if vendorID == model.VendorIDMTWM { - return startOpStoreTimeDefaultMTWM, endOpStoreTimeDefaultMTWM - } else if vendorID == model.VendorIDEBAI { - return startOpStoreTimeDefaultEBAI, endOpStoreTimeDefaultEBAI - } - - return 0, 0 + startTime = vendorStartEndStoreTime[vendorID][0] + endTime = vendorStartEndStoreTime[vendorID][1] + return startTime, endTime } func IsSpecialSku(name string) bool { @@ -212,25 +206,21 @@ func StartOrEndOpStore(isStart bool, vendorIDList []int, storeIDList []int, star return retVal, err } -func StartDaemon(vendorID int) { - startTimeList := []string{} - stopTimeList := []string{} - if vendorID == model.VendorIDMTWM { - startTimeList = startOpStoreTimeListJXCS_MTWM - stopTimeList = endOpStoreTimeListJXCS_MTWM - if !globals.IsMainProductEnv() { - startTimeList = startOpStoreTimeListJXGY_MTWM - stopTimeList = endOpStoreTimeListJXGY_MTWM - } +func GetVendorStoreRefreshTime(vendorID int) (startTimeList, stopTimeList []string) { + isJXCS := globals.IsMainProductEnv() + refreshTimeList := vendorStoreRefreshTimeList[vendorID] + if isJXCS { + startTimeList = []string{refreshTimeList[2]} + stopTimeList = []string{refreshTimeList[3]} } else { - startTimeList = startOpStoreTimeListJXCS - stopTimeList = endOpStoreTimeListJXCS - if !globals.IsMainProductEnv() { - startTimeList = startOpStoreTimeListJXGY - stopTimeList = endOpStoreTimeListJXGY - } + startTimeList = []string{refreshTimeList[0]} + stopTimeList = []string{refreshTimeList[1]} } + return startTimeList, stopTimeList +} +func RefreshStore(vendorID int) { + startTimeList, stopTimeList := GetVendorStoreRefreshTime(vendorID) vendorIDList := []int{vendorID} storeIDList := []int{} ScheduleTimerFunc("StartOpStore", func() { @@ -248,7 +238,7 @@ func StartDaemon(vendorID int) { func InitEx() { for index, value := range vendorList { if value { - StartDaemon(index) + RefreshStore(index) } } }