diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 817eda93a..fd9eccd86 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -133,12 +133,12 @@ var ( SkuRow: 1, }, "净配": &SheetParam{ SkuIDCol: 0, - SkuPriceCol: 12, + SkuPriceCol: 14, SkuNameCol: 1, OrgSkuIdCol: 4, OrgSkuPriceCol: 7, OrgSkuNameCol: 5, - SkuRow: 1, + SkuRow: 2, }, "水产": &SheetParam{ SkuIDCol: 1, SkuPriceCol: 15, @@ -254,22 +254,15 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is sheetParam := sheetMap[k] rows, _ := xlsx.GetRows(k) for rowNum, row := range rows { - if rowNum < sheetParam.SkuRow { - continue - } - GetCellIntoMap(sheetParam, skuMap, row, k, rowNum) - if len(skuMap) < 1 { - errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]\n", k) - } - } - if errMsg != "" { - return "", errors.New(errMsg) + errMsg += GetCellIntoMap(sheetParam, skuMap, row, k, rowNum) } } //修改分组名 // 分类名格式为:可定XX日 // XX为上传永辉 提供的 价格表时间 +2天 - isCompare, err = UpdateClassifyAndGetLastClassify() + if errMsg == "" { + isCompare, err = UpdateClassifyAndGetLastClassify() + } case 1: //获取微盟所有商品 param := &weimobapi.QueryGoodsListParam{ @@ -303,7 +296,6 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is Comment: "在微盟上未找到该商品", } dataFailed.AppendData2(outPutData) - // errMsg += fmt.Sprintf("在微盟上未找到该商品xxx", xxx) } } case 2: @@ -324,7 +316,6 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is Comment: "在京西库中未找到该商品", } dataFailed.AppendData2(outPutData) - // return "", errors.New(fmt.Sprintf("在京西库中未找到该商品!name_id : [%v]\n", goodsDetail.SkuMap.SingleSku.OuterSkuCode)) } else { if skuList[0].Unit == "份" { if goodsDetail.SkuMap.SingleSku.B2CSku.Weight == 0 { @@ -335,7 +326,9 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is } else { costPrice = skuMap[spuCode].Price } - _, _, _ = updateWeiMobGoods(costPrice, skuMap[spuCode].Price, skuList[0].Unit, isCompare, goodsDetail) + if errMsg == "" { + _, _, _ = updateWeiMobGoods(costPrice, skuMap[spuCode].Price, skuList[0].Unit, isCompare, goodsDetail) + } } } else { //下架微盟商品 @@ -358,7 +351,9 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is for _, v := range batchItemList { int64Slice = append(int64Slice, v.(int64)) } - PutAwayWeiMobSku(int64Slice) + if errMsg == "" { + PutAwayWeiMobSku(int64Slice) + } return retVal, err } taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway) @@ -367,9 +362,9 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is case 4: WriteToExcel(task, dataSuccess.dataSuccessList, dataFailed.dataFailedList) } - // if errMsg != "" { - // return result, errors.New(errMsg) - // } + if errMsg != "" { + return result, errors.New(errMsg) + } return result, err } taskSeq := tasksch.NewSeqTask2("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, isContinueWhenError, taskSeqFunc, 5) @@ -401,17 +396,6 @@ func GetGoodsInfoAndDetailMap(goodsList []*weimobapi.GoodsInfo) (goodsMap map[st return goodsMap } -// func getSelectedClassifyLeafList(l []weimobapi.SelectedClassifyList) (list []int64) { -// for _, v := range l { -// if v.ChildrenClassify == nil { -// list = append(list, v.ClassifyID) -// } else { -// subList := getSelectedClassifyLeafList(v.ChildrenClassify) -// } -// } -// return list -// } - func updateWeiMobGoods(costPrice, salePrice float64, unit string, isCompare bool, goodsDetail *weimobapi.GoodsDetailInfo) (goodsID int64, skuMap map[string]int64, err error) { var ( categoryList []*weimobapi.CategoryList @@ -577,7 +561,7 @@ func IsChineseChar(str string) bool { return false } -func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row []string, sheetName string, rowNum int) { +func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row []string, sheetName string, rowNum int) (errMsg string) { var ( skuID string orgSkuID string @@ -594,19 +578,27 @@ func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row [ ) for k, cell := range row { if cell != "" { - if !IsChineseChar(cell) { - if k == skuIDCol && skuIDCol >= 0 { - skuID = cell + if k == skuIDCol && skuIDCol >= 0 { + skuID = cell + } + if k == skuPriceCol && skuPriceCol >= 0 { + if rowNum == sheetParam.SkuRow-1 { + if !strings.Contains(cell, "今日供价") && !strings.Contains(cell, "单价") { + errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]列今日供价附近可能增加或减少了一列,请确认!", sheetName, k+1) + } } - if k == skuPriceCol && skuPriceCol >= 0 { - skuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0)) - } - if k == orgSkuIDCol && orgSkuIDCol >= 0 { - orgSkuID = "0" + cell - } - if k == orgSkuPriceCol && orgSkuPriceCol >= 0 { - orgSkuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0)) + skuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0)) + } + if k == orgSkuIDCol && orgSkuIDCol >= 0 { + orgSkuID = "0" + cell + } + if k == orgSkuPriceCol && orgSkuPriceCol >= 0 { + if rowNum == sheetParam.SkuRow-1 { + if !strings.Contains(cell, "进价") { + errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]列进价附近可能增加或减少了一列,请确认!", sheetName, k+1) + } } + orgSkuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0)) } if k == skuNameCol && skuNameCol >= 0 { skuName = cell @@ -616,34 +608,50 @@ func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row [ } } } - if len(skuMap) > 0 { - if skuMap[skuID] != nil { - if skuMap[skuID].Price != 0 && skuMap[skuID].Price != skuPrice && skuPrice != 0 { - if skuPrice > skuMap[skuID].Price { + if rowNum >= sheetParam.SkuRow { + if rowNum == sheetParam.SkuRow { + if IsChineseChar(skuID) { + if IsChineseChar(skuID) { + errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]行附近可能增加了一行,请确认!", sheetName, rowNum) + } + } + } + if len(skuMap) > 0 { + if skuMap[skuID] != nil { + if skuMap[skuID].Price != 0 && skuMap[skuID].Price != skuPrice && skuPrice != 0 { + if skuPrice > skuMap[skuID].Price { + BuildSkuMap(skuID, skuName, skuPrice, skuMap) + } + } else { BuildSkuMap(skuID, skuName, skuPrice, skuMap) } - } else { + } else if skuPrice != 0 { BuildSkuMap(skuID, skuName, skuPrice, skuMap) } - } else if skuPrice != 0 { - BuildSkuMap(skuID, skuName, skuPrice, skuMap) - } - if skuMap[orgSkuID] != nil { - if skuMap[orgSkuID].Price != 0 && skuMap[orgSkuID].Price != orgSkuPrice && orgSkuPrice != 0 { - if orgSkuPrice > skuMap[orgSkuID].Price { + if skuMap[orgSkuID] != nil { + if skuMap[orgSkuID].Price != 0 && skuMap[orgSkuID].Price != orgSkuPrice && orgSkuPrice != 0 { + if orgSkuPrice > skuMap[orgSkuID].Price { + BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap) + } + } else if orgSkuPriceCol >= 0 && orgSkuIDCol >= 0 && orgSkuNameCol >= 0 { BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap) } - } else if orgSkuPriceCol >= 0 && orgSkuIDCol >= 0 && orgSkuNameCol >= 0 { + } else if orgSkuPrice != 0 { BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap) } - } else if orgSkuPrice != 0 { + } else { + BuildSkuMap(skuID, skuName, skuPrice, skuMap) BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap) } + delete(skuMap, "") } else { - BuildSkuMap(skuID, skuName, skuPrice, skuMap) - BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap) + for i := rowNum; i < sheetParam.SkuRow; i++ { + if !IsChineseChar(skuID) { + errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]行附近可能减少了一行,请确认!", sheetName, rowNum) + } + } } - delete(skuMap, "") + return errMsg } func BuildSkuMap(id, name string, price float64, skuMap map[string]*ExcelParam) { excelParam := &ExcelParam{ @@ -751,7 +759,7 @@ func WriteToExcel(task *tasksch.SeqTask, dataSuccess []DataSuccess, dataFailed [ if err != nil { baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName1, fileName2, err) } else { - noticeMsg := fmt.Sprintf("[详情点我]path1=%s, path2=%s \n", globals.BackstageHost, downloadURL1, downloadURL2) + noticeMsg := fmt.Sprintf("[详情点我]path1=%s, path2=%s \n", downloadURL1, downloadURL2) task.SetNoticeMsg(noticeMsg) baseapi.SugarLogger.Debugf("WriteToExcel:upload %s ,%s success, downloadURL1:%s ,downloadURL2:%s", fileName1, fileName2, downloadURL1, downloadURL2) } @@ -907,7 +915,7 @@ func WriteToExcel3(task *tasksch.SeqTask, dataSuccess []DataStoreSkusSuccess, da if err != nil { baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName1, fileName2, err) } else { - noticeMsg := fmt.Sprintf("[详情点我]path1=%s, path2=%s \n", globals.BackstageHost, downloadURL1, downloadURL2) + noticeMsg := fmt.Sprintf("[详情点我]path1=%s, path2=%s \n", downloadURL1, downloadURL2) task.SetNoticeMsg(noticeMsg) baseapi.SugarLogger.Debugf("WriteToExcel:upload %s ,%s success, downloadURL1:%s ,downloadURL2:%s", fileName1, fileName2, downloadURL1, downloadURL2) }