读取永辉Excel文件
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
|
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
)
|
)
|
||||||
@@ -99,11 +100,11 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i
|
|||||||
var (
|
var (
|
||||||
skuMap = make(map[string]float64)
|
skuMap = make(map[string]float64)
|
||||||
errMsg string
|
errMsg string
|
||||||
// costPrice float64 //成本价
|
costPrice float64 //成本价
|
||||||
// goodsIDListForPutAway []int64
|
goodsIDListForPutAway []int64
|
||||||
// goodsList []*weimobapi.GoodsInfo
|
goodsList []*weimobapi.GoodsInfo
|
||||||
)
|
)
|
||||||
// db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
return "", errors.New("没有文件上传!")
|
return "", errors.New("没有文件上传!")
|
||||||
}
|
}
|
||||||
@@ -127,117 +128,141 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
GetCellIntoMap(sheet1SkuIDCol, sheet1SkuPriceCol, sheet1OrgSkuIdCol, sheet1OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
GetCellIntoMap(sheet1SkuIDCol, sheet1SkuPriceCol, sheet1OrgSkuIdCol, sheet1OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
||||||
|
if len(skuMap) < 1 {
|
||||||
|
errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v)
|
||||||
|
}
|
||||||
case sheet2Name:
|
case sheet2Name:
|
||||||
if rowNum < sheet2SkuRow {
|
if rowNum < sheet2SkuRow {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
GetCellIntoMap(sheet2SkuIDCol, sheet2SkuPriceCol, sheet2OrgSkuIdCol, sheet2OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
GetCellIntoMap(sheet2SkuIDCol, sheet2SkuPriceCol, sheet2OrgSkuIdCol, sheet2OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
||||||
|
if len(skuMap) < 1 {
|
||||||
|
errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v)
|
||||||
|
}
|
||||||
case sheet3Name:
|
case sheet3Name:
|
||||||
if rowNum < sheet3SkuRow {
|
if rowNum < sheet3SkuRow {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
GetCellIntoMap(sheet3SkuIDCol, sheet3SkuPriceCol, sheet3OrgSkuIdCol, sheet3OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
GetCellIntoMap(sheet3SkuIDCol, sheet3SkuPriceCol, sheet3OrgSkuIdCol, sheet3OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
||||||
|
if len(skuMap) < 1 {
|
||||||
|
errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v)
|
||||||
|
}
|
||||||
case sheet4Name:
|
case sheet4Name:
|
||||||
if rowNum < sheet4SkuRow {
|
if rowNum < sheet4SkuRow {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
GetCellIntoMap(sheet4SkuIDCol, sheet4SkuPriceCol, sheet4OrgSkuIdCol, sheet4OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
GetCellIntoMap(sheet4SkuIDCol, sheet4SkuPriceCol, sheet4OrgSkuIdCol, sheet4OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
||||||
|
if len(skuMap) < 1 {
|
||||||
|
errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v)
|
||||||
|
}
|
||||||
case sheet5Name:
|
case sheet5Name:
|
||||||
if rowNum < sheet5SkuRow {
|
if rowNum < sheet5SkuRow {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
GetCellIntoMap(sheet5SkuIDCol, sheet5SkuPriceCol, sheet5OrgSkuIdCol, sheet5OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
GetCellIntoMap(sheet5SkuIDCol, sheet5SkuPriceCol, sheet5OrgSkuIdCol, sheet5OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
||||||
|
if len(skuMap) < 1 {
|
||||||
|
errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v)
|
||||||
|
}
|
||||||
case sheet6Name:
|
case sheet6Name:
|
||||||
if rowNum < sheet6SkuRow {
|
if rowNum < sheet6SkuRow {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
GetCellIntoMap(sheet6SkuIDCol, sheet6SkuPriceCol, sheet6OrgSkuIdCol, sheet6OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
GetCellIntoMap(sheet6SkuIDCol, sheet6SkuPriceCol, sheet6OrgSkuIdCol, sheet6OrgSkuPriceCol, skuMap, true, row, v, rowNum)
|
||||||
|
if len(skuMap) < 1 {
|
||||||
|
errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v)
|
||||||
|
}
|
||||||
case sheet7Name:
|
case sheet7Name:
|
||||||
if rowNum < sheet7SkuRow {
|
if rowNum < sheet7SkuRow {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
GetCellIntoMap(sheet7SkuIDCol, sheet7SkuPriceCol, 0, 0, skuMap, false, row, v, rowNum)
|
GetCellIntoMap(sheet7SkuIDCol, sheet7SkuPriceCol, 0, 0, skuMap, false, row, v, rowNum)
|
||||||
|
if len(skuMap) < 1 {
|
||||||
|
errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return retVal, errors.New("未找到配置的sheet页,请检查excel内容排版格式是否发生变化!\n")
|
return retVal, errors.New("未找到配置的sheet页,请检查excel内容排版格式是否发生变化!\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if errMsg != "" {
|
||||||
|
return "", errors.New(errMsg)
|
||||||
|
}
|
||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
taskParallel1 := tasksch.NewParallelTask("读取Excel", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc1, sheetNames)
|
taskParallel1 := tasksch.NewParallelTask("读取Excel", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc1, sheetNames)
|
||||||
tasksch.HandleTask(taskParallel1, task, true).Run()
|
tasksch.HandleTask(taskParallel1, task, true).Run()
|
||||||
_, err = taskParallel1.GetResult(0)
|
_, err = taskParallel1.GetResult(0)
|
||||||
// case 1:
|
case 1:
|
||||||
// //获取微盟所有商品
|
//获取微盟所有商品
|
||||||
// goodsList = GetGoodsInfoAndDetail()
|
goodsList = GetGoodsInfoAndDetail()
|
||||||
// //找出excel上有,微盟没有的,有就列出报错,不进行更新
|
//找出excel上有,微盟没有的,有就列出报错,不进行更新
|
||||||
// goodsInfoAndDetailMap := GetGoodsInfoAndDetailMap(goodsList)
|
goodsInfoAndDetailMap := GetGoodsInfoAndDetailMap(goodsList)
|
||||||
// for k, _ := range skuMap {
|
delete(skuMap, "")
|
||||||
// //表示excel上有,微盟上没有
|
for k, v := range skuMap {
|
||||||
// if goodsInfoAndDetailMap[k] == nil {
|
fmt.Printf("key %v, value %v\n", k, v)
|
||||||
// errMsg += fmt.Sprintf("在微盟上未找到该商品!excel商品ID : [%v]\n", k)
|
//表示excel上有,微盟上没有
|
||||||
// }
|
if goodsInfoAndDetailMap[k] == nil {
|
||||||
// }
|
errMsg += fmt.Sprintf("在微盟上未找到该商品!excel商品ID : [%v]\n", k)
|
||||||
// if errMsg != "" {
|
}
|
||||||
// return "", errors.New(errMsg)
|
}
|
||||||
// }
|
fmt.Println(len(skuMap))
|
||||||
// case 2:
|
if errMsg != "" {
|
||||||
// //找出微盟上有,excel上没有的,有就更新,没有就下架
|
return "", errors.New(errMsg)
|
||||||
// taskFunc2 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
}
|
||||||
// goods := batchItemList[0].(*weimobapi.GoodsInfo)
|
case 2:
|
||||||
// goodsDetail := goods.GoodsDetailInfo
|
//找出微盟上有,excel上没有的,有就更新,没有就下架
|
||||||
// spuCode := goodsDetail.OuterGoodsCode
|
taskFunc2 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
// if spuCode != "" {
|
goods := batchItemList[0].(*weimobapi.GoodsInfo)
|
||||||
// //如果微盟商品里找得到excel中的商品
|
goodsDetail := goods.GoodsDetailInfo
|
||||||
// if skuMap[spuCode] != 0 {
|
spuCode := goodsDetail.OuterGoodsCode
|
||||||
// //获取京西库商品
|
if spuCode != "" {
|
||||||
// skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil)
|
//如果微盟商品里找得到excel中的商品
|
||||||
// if len(skuList) == 0 {
|
if skuMap[spuCode] != 0 {
|
||||||
// errMsg += fmt.Sprintf("在京西库中未找到该商品!name_id : [%v] \n", goodsDetail.SkuMap.SingleSku.OuterSkuCode)
|
//获取京西库商品
|
||||||
// } else {
|
skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil)
|
||||||
// if skuList[0].Unit != "份" {
|
if len(skuList) == 0 {
|
||||||
// costPrice = Float64Round(0.5 / goodsDetail.SkuMap.SingleSku.B2CSku.Weight * skuMap[spuCode])
|
errMsg += fmt.Sprintf("在京西库中未找到该商品!name_id : [%v] \n", goodsDetail.SkuMap.SingleSku.OuterSkuCode)
|
||||||
// } else {
|
} else {
|
||||||
// costPrice = skuMap[spuCode]
|
if skuList[0].Unit != "份" {
|
||||||
// }
|
costPrice = Float64Round(0.5 / goodsDetail.SkuMap.SingleSku.B2CSku.Weight * skuMap[spuCode])
|
||||||
// if errMsg == "" {
|
} else {
|
||||||
// _, _, err = updateWeiMobGoods(costPrice, skuMap[spuCode], goodsDetail)
|
costPrice = skuMap[spuCode]
|
||||||
// }
|
}
|
||||||
// }
|
if errMsg == "" {
|
||||||
// } else {
|
_, _, err = updateWeiMobGoods(costPrice, skuMap[spuCode], goodsDetail)
|
||||||
// //下架微盟商品
|
}
|
||||||
// goodsIDListForPutAway = append(goodsIDListForPutAway, goodsDetail.GoodsID)
|
}
|
||||||
// }
|
} else {
|
||||||
// }
|
//下架微盟商品
|
||||||
// return retVal, err
|
goodsIDListForPutAway = append(goodsIDListForPutAway, goodsDetail.GoodsID)
|
||||||
// }
|
}
|
||||||
// taskParallel2 := tasksch.NewParallelTask("获取微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc2, goodsList)
|
}
|
||||||
// tasksch.HandleTask(taskParallel2, task, true).Run()
|
return retVal, err
|
||||||
// _, err = taskParallel2.GetResult(0)
|
}
|
||||||
// case 3:
|
taskParallel2 := tasksch.NewParallelTask("获取微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc2, goodsList)
|
||||||
// //批量下架微盟商品
|
tasksch.HandleTask(taskParallel2, task, true).Run()
|
||||||
// if errMsg == "" {
|
_, err = taskParallel2.GetResult(0)
|
||||||
// if len(goodsIDListForPutAway) <= 50 { //api要求最多传50个
|
case 3:
|
||||||
// PutAwayWeiMobSku(goodsIDListForPutAway)
|
//批量下架微盟商品
|
||||||
// } else {
|
if errMsg == "" {
|
||||||
// for i := 0; i < len(goodsIDListForPutAway)/50+1; i++ {
|
if len(goodsIDListForPutAway) <= 50 { //api要求最多传50个
|
||||||
// var int64Slice []int64
|
PutAwayWeiMobSku(goodsIDListForPutAway)
|
||||||
// if len(goodsIDListForPutAway) > 50*(i+1) {
|
} else {
|
||||||
// int64Slice = goodsIDListForPutAway[i*50 : (i+1)*50+1]
|
for i := 0; i < len(goodsIDListForPutAway)/50+1; i++ {
|
||||||
// } else {
|
var int64Slice []int64
|
||||||
// int64Slice = goodsIDListForPutAway[i*50 : len(goodsIDListForPutAway)]
|
if len(goodsIDListForPutAway) > 50*(i+1) {
|
||||||
// }
|
int64Slice = goodsIDListForPutAway[i*50 : (i+1)*50+1]
|
||||||
// PutAwayWeiMobSku(int64Slice)
|
} else {
|
||||||
// }
|
int64Slice = goodsIDListForPutAway[i*50 : len(goodsIDListForPutAway)]
|
||||||
// }
|
}
|
||||||
// }
|
PutAwayWeiMobSku(int64Slice)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 4)
|
taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 2)
|
||||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||||
for k, v := range skuMap {
|
|
||||||
fmt.Println(k, v)
|
|
||||||
}
|
|
||||||
if errMsg != "" {
|
if errMsg != "" {
|
||||||
baseapi.SugarLogger.Debugf(errMsg)
|
baseapi.SugarLogger.Debugf(errMsg)
|
||||||
}
|
}
|
||||||
@@ -401,7 +426,7 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if skuMap[skuID] != 0 && skuMap[skuID] != skuPrice {
|
if skuMap[skuID] != 0 && skuMap[skuID] != skuPrice && skuID != "" {
|
||||||
if skuPrice > skuMap[skuID] {
|
if skuPrice > skuMap[skuID] {
|
||||||
skuMap[skuID] = skuPrice
|
skuMap[skuID] = skuPrice
|
||||||
}
|
}
|
||||||
@@ -410,7 +435,7 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM
|
|||||||
skuMap[skuID] = skuPrice
|
skuMap[skuID] = skuPrice
|
||||||
}
|
}
|
||||||
if isHaveOrg {
|
if isHaveOrg {
|
||||||
if skuMap[orgSkuID] != 0 && skuMap[orgSkuID] != orgSkuPrice {
|
if skuMap[orgSkuID] != 0 && skuMap[orgSkuID] != orgSkuPrice && orgSkuID != "" {
|
||||||
if orgSkuPrice > skuMap[orgSkuID] {
|
if orgSkuPrice > skuMap[orgSkuID] {
|
||||||
skuMap[orgSkuID] = orgSkuPrice
|
skuMap[orgSkuID] = orgSkuPrice
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/yonghui"
|
"git.rosy.net.cn/jx-callback/business/jxstore/yonghui"
|
||||||
@@ -36,8 +35,6 @@ func (c *YongHuiController) LoadExcelByYongHui() {
|
|||||||
} else if c.Ctx.Input.IsPost() {
|
} else if c.Ctx.Input.IsPost() {
|
||||||
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
|
||||||
fmt.Println(r)
|
|
||||||
fmt.Println(r.MultipartForm)
|
|
||||||
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)
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
|
|||||||
Reference in New Issue
Block a user