读取永辉excel
This commit is contained in:
@@ -84,18 +84,18 @@ const (
|
|||||||
UpdateGoodsShelfStatusCount = 50 //微盟下架商品api限制一次50个
|
UpdateGoodsShelfStatusCount = 50 //微盟下架商品api限制一次50个
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync bool) (hint string, err error) {
|
func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync, IsContinueWhenError bool) (hint string, err error) {
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
return "", errors.New("没有文件上传!")
|
return "", errors.New("没有文件上传!")
|
||||||
}
|
}
|
||||||
fileHeader := files[0]
|
fileHeader := files[0]
|
||||||
file, err := fileHeader.Open()
|
file, err := fileHeader.Open()
|
||||||
hint, err = LoadExcelBinByYongHui(ctx, file, isAsync)
|
hint, err = LoadExcelBinByYongHui(ctx, file, true, true)
|
||||||
file.Close()
|
file.Close()
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync bool) (hint string, err error) {
|
func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, IsContinueWhenError bool) (hint string, err error) {
|
||||||
var (
|
var (
|
||||||
skuMap = make(map[string]float64)
|
skuMap = make(map[string]float64)
|
||||||
errMsg string
|
errMsg string
|
||||||
@@ -163,13 +163,14 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync boo
|
|||||||
goods := batchItemList[0].(*weimobapi.GoodsInfo)
|
goods := batchItemList[0].(*weimobapi.GoodsInfo)
|
||||||
goodsDetail := goods.GoodsDetailInfo
|
goodsDetail := goods.GoodsDetailInfo
|
||||||
spuCode := goodsDetail.OuterGoodsCode
|
spuCode := goodsDetail.OuterGoodsCode
|
||||||
|
errTmp := ""
|
||||||
if spuCode != "" {
|
if spuCode != "" {
|
||||||
//如果微盟商品里找得到excel中的商品
|
//如果微盟商品里找得到excel中的商品
|
||||||
if skuMap[spuCode] != 0 {
|
if skuMap[spuCode] != 0 {
|
||||||
//获取京西库商品
|
//获取京西库商品
|
||||||
skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil)
|
skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil)
|
||||||
if len(skuList) == 0 {
|
if len(skuList) == 0 {
|
||||||
errMsg += fmt.Sprintf("在京西库中未找到该商品!name_id : [%v] \n", goodsDetail.SkuMap.SingleSku.OuterSkuCode)
|
errTmp += fmt.Sprintf("在京西库中未找到该商品!name_id : [%v] \n", goodsDetail.SkuMap.SingleSku.OuterSkuCode)
|
||||||
} else {
|
} else {
|
||||||
if skuList[0].Unit == "份" {
|
if skuList[0].Unit == "份" {
|
||||||
if goodsDetail.SkuMap.SingleSku.B2CSku.Weight == 0 {
|
if goodsDetail.SkuMap.SingleSku.B2CSku.Weight == 0 {
|
||||||
@@ -189,9 +190,12 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync boo
|
|||||||
retVal = []int64{goodsDetail.GoodsID}
|
retVal = []int64{goodsDetail.GoodsID}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err == nil {
|
||||||
|
return retVal, errors.New(errTmp)
|
||||||
|
}
|
||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
taskParallel3 := tasksch.NewParallelTask("根据获取的微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc3, goodsList)
|
taskParallel3 := tasksch.NewParallelTask("根据获取的微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetIsContinueWhenError(IsContinueWhenError), ctx, taskFunc3, goodsList)
|
||||||
tasksch.HandleTask(taskParallel3, task, true).Run()
|
tasksch.HandleTask(taskParallel3, task, true).Run()
|
||||||
goodsIDListForPutAwayInterface, err2 := taskParallel3.GetResult(0)
|
goodsIDListForPutAwayInterface, err2 := taskParallel3.GetResult(0)
|
||||||
if err = err2; err != nil {
|
if err = err2; err != nil {
|
||||||
@@ -224,10 +228,6 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync boo
|
|||||||
} else {
|
} else {
|
||||||
hint = taskSeq.GetID()
|
hint = taskSeq.GetID()
|
||||||
}
|
}
|
||||||
if errMsg != "" {
|
|
||||||
baseapi.SugarLogger.Debugf(errMsg)
|
|
||||||
return "", errors.New(errMsg)
|
|
||||||
}
|
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func (c *FinancialController) SendFilesToStores() {
|
|||||||
if params.Title != "永辉" {
|
if params.Title != "永辉" {
|
||||||
retVal, err = financial.SendFilesToStores(params.Ctx, files, params.Title, params.ShopName, params.IsAsync, params.Ctx.GetUserName())
|
retVal, err = financial.SendFilesToStores(params.Ctx, files, params.Title, params.ShopName, params.IsAsync, params.Ctx.GetUserName())
|
||||||
} else {
|
} else {
|
||||||
retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync)
|
retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync, true)
|
||||||
}
|
}
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ type YongHuiController struct {
|
|||||||
// @Title 读取永辉excel文件
|
// @Title 读取永辉excel文件
|
||||||
// @Description 读取永辉excel文件
|
// @Description 读取永辉excel文件
|
||||||
// @Param token header string false "认证token"
|
// @Param token header string false "认证token"
|
||||||
// @Param isAsync query bool false "是否异步,缺省是同步"
|
// @Param isAsync query bool true "是否异步,缺省是同步"
|
||||||
|
// @Param isContinueWhenError query bool true "单个同步失败是否继续,缺省false"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /LoadExcelByYongHui [post,get]
|
// @router /LoadExcelByYongHui [post,get]
|
||||||
@@ -36,7 +37,7 @@ func (c *YongHuiController) LoadExcelByYongHui() {
|
|||||||
c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) {
|
c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) {
|
||||||
r := c.Ctx.Request
|
r := c.Ctx.Request
|
||||||
files := r.MultipartForm.File["userfiles"]
|
files := r.MultipartForm.File["userfiles"]
|
||||||
retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync)
|
retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync, params.IsContinueWhenError)
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user