diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 35d4f9568..1bbb1da35 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -146,31 +146,34 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, Is taskParallel2 := tasksch.NewParallelTask("获取微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc2, goodsList) tasksch.HandleTask(taskParallel2, task, true).Run() _, err = taskParallel2.GetResult(0) + case 2: //找出excel上有,微盟没有的,有就列出报错,不进行更新 goodsInfoAndDetailMap := GetGoodsInfoAndDetailMap(goodsList) - for k, _ := range skuMap { + skuMapList := GetSkuMapList(skuMap) + taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + k := batchItemList[0].(string) //表示excel上有,微盟上没有 if goodsInfoAndDetailMap[k] == nil { - errMsg += fmt.Sprintf("在微盟上未找到该商品!excel商品ID : [%v]\n", k) + return "", errors.New(fmt.Sprintf("在微盟上未找到该商品!excel商品ID : [%v]\n", k)) } + return retVal, err } - // if errMsg != "" { - // return "", errors.New(errMsg) - // } - case 2: + taskParallel := tasksch.NewParallelTask("对比Excel上有微盟上没有的商品", tasksch.NewParallelConfig().SetIsContinueWhenError(IsContinueWhenError), ctx, taskFunc, skuMapList) + tasksch.HandleTask(taskParallel, task, true).Run() + _, err = taskParallel.GetResult(0) + case 3: //找出微盟上有,excel上没有的,有就更新,没有就下架 taskFunc3 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { goods := batchItemList[0].(*weimobapi.GoodsInfo) goodsDetail := goods.GoodsDetailInfo spuCode := goodsDetail.OuterGoodsCode - errTmp := "" if spuCode != "" { //如果微盟商品里找得到excel中的商品 if skuMap[spuCode] != 0 { //获取京西库商品 skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil) if len(skuList) == 0 { - errTmp += fmt.Sprintf("在京西库中未找到该商品!name_id : [%v]\n", goodsDetail.SkuMap.SingleSku.OuterSkuCode) + 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 { @@ -190,9 +193,6 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, Is retVal = []int64{goodsDetail.GoodsID} } } - if errTmp != "" { - return retVal, errors.New(errTmp) - } return retVal, err } taskParallel3 := tasksch.NewParallelTask("根据获取的微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetIsContinueWhenError(IsContinueWhenError), ctx, taskFunc3, goodsList) @@ -202,7 +202,7 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, Is return "", err } goodsIDListForPutAway = goodsIDListForPutAwayInterface - case 3: + case 4: // 批量下架微盟商品 // if errMsg == "" { taskFunc4 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { @@ -218,12 +218,9 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, Is _, err = taskParallel4.GetResult(0) // } } - if errMsg != "" { - return result, errors.New(errMsg) - } return result, err } - taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 4) + taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 5) tasksch.HandleTask(taskSeq, nil, true).Run() if !isAsync { _, err = taskSeq.GetResult(0) @@ -244,6 +241,13 @@ func PutAwayWeiMobSku(goodsIDListForPutAway []int64) (err error) { return err } +func GetSkuMapList(skuMap map[string]float64) (skuMapList []string) { + for k, _ := range skuMap { + skuMapList = append(skuMapList, k) + } + return skuMapList +} + func GetGoodsInfoAndDetailMap(goodsList []*weimobapi.GoodsInfo) (goodsMap map[string]*weimobapi.GoodsInfo) { goodsMap = make(map[string]*weimobapi.GoodsInfo) for _, v := range goodsList {