读取永辉excel
This commit is contained in:
@@ -133,12 +133,12 @@ var (
|
|||||||
SkuRow: 1,
|
SkuRow: 1,
|
||||||
}, "净配": &SheetParam{
|
}, "净配": &SheetParam{
|
||||||
SkuIDCol: 0,
|
SkuIDCol: 0,
|
||||||
SkuPriceCol: 12,
|
SkuPriceCol: 14,
|
||||||
SkuNameCol: 1,
|
SkuNameCol: 1,
|
||||||
OrgSkuIdCol: 4,
|
OrgSkuIdCol: 4,
|
||||||
OrgSkuPriceCol: 7,
|
OrgSkuPriceCol: 7,
|
||||||
OrgSkuNameCol: 5,
|
OrgSkuNameCol: 5,
|
||||||
SkuRow: 1,
|
SkuRow: 2,
|
||||||
}, "水产": &SheetParam{
|
}, "水产": &SheetParam{
|
||||||
SkuIDCol: 1,
|
SkuIDCol: 1,
|
||||||
SkuPriceCol: 15,
|
SkuPriceCol: 15,
|
||||||
@@ -239,43 +239,37 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
costPrice float64 //成本价
|
costPrice float64 //成本价
|
||||||
goodsList []*weimobapi.GoodsInfo
|
goodsList []*weimobapi.GoodsInfo
|
||||||
goodsIDListForPutAway []interface{}
|
goodsIDListForPutAway []interface{}
|
||||||
// isCompare bool
|
isCompare bool
|
||||||
)
|
)
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
//读取excel文件
|
|
||||||
xlsx, err := excelize.OpenReader(reader)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
for k := range sheetMap {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//修改分组名
|
|
||||||
// 分类名格式为:可定XX日
|
|
||||||
// XX为上传永辉 提供的 价格表时间 +2天
|
|
||||||
// isCompare, err = UpdateClassifyAndGetLastClassify()
|
|
||||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
switch step {
|
switch step {
|
||||||
case 0:
|
case 0:
|
||||||
|
//读取excel文件
|
||||||
|
xlsx, err := excelize.OpenReader(reader)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
for k := range sheetMap {
|
||||||
|
sheetParam := sheetMap[k]
|
||||||
|
rows, _ := xlsx.GetRows(k)
|
||||||
|
for rowNum, row := range rows {
|
||||||
|
errMsg += GetCellIntoMap(sheetParam, skuMap, row, k, rowNum)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//修改分组名
|
||||||
|
// 分类名格式为:可定XX日
|
||||||
|
// XX为上传永辉 提供的 价格表时间 +2天
|
||||||
|
if errMsg == "" {
|
||||||
|
isCompare, err = UpdateClassifyAndGetLastClassify()
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
//获取微盟所有商品
|
//获取微盟所有商品
|
||||||
// param := &weimobapi.QueryGoodsListParam{
|
param := &weimobapi.QueryGoodsListParam{
|
||||||
// PageNum: 1,
|
PageNum: 1,
|
||||||
// PageSize: jdapi.MaxSkuIDsCount4QueryListBySkuIds,
|
PageSize: jdapi.MaxSkuIDsCount4QueryListBySkuIds,
|
||||||
// }
|
}
|
||||||
// goodsList, err = GetWeiMobGoodsList(param)
|
goodsList, err = GetWeiMobGoodsList(param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
baseapi.SugarLogger.Errorf("GetWeiMobGoodsList error:%v", err)
|
baseapi.SugarLogger.Errorf("GetWeiMobGoodsList error:%v", err)
|
||||||
}
|
}
|
||||||
@@ -302,10 +296,9 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
Comment: "在微盟上未找到该商品",
|
Comment: "在微盟上未找到该商品",
|
||||||
}
|
}
|
||||||
dataFailed.AppendData2(outPutData)
|
dataFailed.AppendData2(outPutData)
|
||||||
// errMsg += fmt.Sprintf("在微盟上未找到该商品xxx", xxx)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 1:
|
case 2:
|
||||||
//找出微盟上有,excel上没有的,有就更新,没有就下架
|
//找出微盟上有,excel上没有的,有就更新,没有就下架
|
||||||
taskFunc3 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
taskFunc3 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
goods := batchItemList[0].(*weimobapi.GoodsInfo)
|
goods := batchItemList[0].(*weimobapi.GoodsInfo)
|
||||||
@@ -323,7 +316,6 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
Comment: "在京西库中未找到该商品",
|
Comment: "在京西库中未找到该商品",
|
||||||
}
|
}
|
||||||
dataFailed.AppendData2(outPutData)
|
dataFailed.AppendData2(outPutData)
|
||||||
// return "", errors.New(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 {
|
||||||
@@ -334,9 +326,9 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
} else {
|
} else {
|
||||||
costPrice = skuMap[spuCode].Price
|
costPrice = skuMap[spuCode].Price
|
||||||
}
|
}
|
||||||
// if errMsg == "" {
|
if errMsg == "" {
|
||||||
// _, _, _ = updateWeiMobGoods(costPrice, skuMap[spuCode].Price, skuList[0].Unit, isCompare, goodsDetail)
|
_, _, _ = updateWeiMobGoods(costPrice, skuMap[spuCode].Price, skuList[0].Unit, isCompare, goodsDetail)
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//下架微盟商品
|
//下架微盟商品
|
||||||
@@ -352,30 +344,30 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
goodsIDListForPutAway = goodsIDListForPutAwayInterface
|
goodsIDListForPutAway = goodsIDListForPutAwayInterface
|
||||||
case 2:
|
case 3:
|
||||||
// 批量下架微盟商品
|
// 批量下架微盟商品
|
||||||
taskFunc4 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
taskFunc4 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
int64Slice := []int64{}
|
int64Slice := []int64{}
|
||||||
for _, v := range batchItemList {
|
for _, v := range batchItemList {
|
||||||
int64Slice = append(int64Slice, v.(int64))
|
int64Slice = append(int64Slice, v.(int64))
|
||||||
}
|
}
|
||||||
// if errMsg == "" {
|
if errMsg == "" {
|
||||||
// PutAwayWeiMobSku(int64Slice)
|
PutAwayWeiMobSku(int64Slice)
|
||||||
// }
|
}
|
||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway)
|
taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway)
|
||||||
tasksch.HandleTask(taskParallel4, task, true).Run()
|
tasksch.HandleTask(taskParallel4, task, true).Run()
|
||||||
_, err = taskParallel4.GetResult(0)
|
_, err = taskParallel4.GetResult(0)
|
||||||
case 3:
|
case 4:
|
||||||
WriteToExcel(task, dataSuccess.dataSuccessList, dataFailed.dataFailedList)
|
WriteToExcel(task, dataSuccess.dataSuccessList, dataFailed.dataFailedList)
|
||||||
}
|
}
|
||||||
// if errMsg != "" {
|
if errMsg != "" {
|
||||||
// return result, errors.New(errMsg)
|
return result, errors.New(errMsg)
|
||||||
// }
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
taskSeq := tasksch.NewSeqTask2("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, isContinueWhenError, taskSeqFunc, 4)
|
taskSeq := tasksch.NewSeqTask2("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, isContinueWhenError, taskSeqFunc, 5)
|
||||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||||
if !isAsync {
|
if !isAsync {
|
||||||
_, err = taskSeq.GetResult(0)
|
_, err = taskSeq.GetResult(0)
|
||||||
@@ -404,17 +396,6 @@ func GetGoodsInfoAndDetailMap(goodsList []*weimobapi.GoodsInfo) (goodsMap map[st
|
|||||||
return goodsMap
|
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) {
|
func updateWeiMobGoods(costPrice, salePrice float64, unit string, isCompare bool, goodsDetail *weimobapi.GoodsDetailInfo) (goodsID int64, skuMap map[string]int64, err error) {
|
||||||
var (
|
var (
|
||||||
categoryList []*weimobapi.CategoryList
|
categoryList []*weimobapi.CategoryList
|
||||||
@@ -580,7 +561,7 @@ func IsChineseChar(str string) bool {
|
|||||||
return false
|
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 (
|
var (
|
||||||
skuID string
|
skuID string
|
||||||
orgSkuID string
|
orgSkuID string
|
||||||
@@ -597,19 +578,27 @@ func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row [
|
|||||||
)
|
)
|
||||||
for k, cell := range row {
|
for k, cell := range row {
|
||||||
if cell != "" {
|
if cell != "" {
|
||||||
if !IsChineseChar(cell) {
|
if k == skuIDCol && skuIDCol >= 0 {
|
||||||
if k == skuIDCol && skuIDCol >= 0 {
|
skuID = cell
|
||||||
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))
|
||||||
skuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0))
|
}
|
||||||
}
|
if k == orgSkuIDCol && orgSkuIDCol >= 0 {
|
||||||
if k == orgSkuIDCol && orgSkuIDCol >= 0 {
|
orgSkuID = "0" + cell
|
||||||
orgSkuID = "0" + cell
|
}
|
||||||
}
|
if k == orgSkuPriceCol && orgSkuPriceCol >= 0 {
|
||||||
if k == orgSkuPriceCol && orgSkuPriceCol >= 0 {
|
if rowNum == sheetParam.SkuRow-1 {
|
||||||
orgSkuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0))
|
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 {
|
if k == skuNameCol && skuNameCol >= 0 {
|
||||||
skuName = cell
|
skuName = cell
|
||||||
@@ -619,34 +608,50 @@ func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(skuMap) > 0 {
|
if rowNum >= sheetParam.SkuRow {
|
||||||
if skuMap[skuID] != nil {
|
if rowNum == sheetParam.SkuRow {
|
||||||
if skuMap[skuID].Price != 0 && skuMap[skuID].Price != skuPrice && skuPrice != 0 {
|
if IsChineseChar(skuID) {
|
||||||
if skuPrice > skuMap[skuID].Price {
|
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)
|
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||||
}
|
}
|
||||||
} else {
|
} else if skuPrice != 0 {
|
||||||
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||||
}
|
}
|
||||||
} else if skuPrice != 0 {
|
if skuMap[orgSkuID] != nil {
|
||||||
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
if skuMap[orgSkuID].Price != 0 && skuMap[orgSkuID].Price != orgSkuPrice && orgSkuPrice != 0 {
|
||||||
}
|
if orgSkuPrice > skuMap[orgSkuID].Price {
|
||||||
if skuMap[orgSkuID] != nil {
|
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||||
if skuMap[orgSkuID].Price != 0 && skuMap[orgSkuID].Price != orgSkuPrice && orgSkuPrice != 0 {
|
}
|
||||||
if orgSkuPrice > skuMap[orgSkuID].Price {
|
} else if orgSkuPriceCol >= 0 && orgSkuIDCol >= 0 && orgSkuNameCol >= 0 {
|
||||||
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||||
}
|
}
|
||||||
} else if orgSkuPriceCol >= 0 && orgSkuIDCol >= 0 && orgSkuNameCol >= 0 {
|
} else if orgSkuPrice != 0 {
|
||||||
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||||
}
|
}
|
||||||
} else if orgSkuPrice != 0 {
|
} else {
|
||||||
|
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||||
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||||
}
|
}
|
||||||
|
delete(skuMap, "")
|
||||||
} else {
|
} else {
|
||||||
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
for i := rowNum; i < sheetParam.SkuRow; i++ {
|
||||||
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
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) {
|
func BuildSkuMap(id, name string, price float64, skuMap map[string]*ExcelParam) {
|
||||||
excelParam := &ExcelParam{
|
excelParam := &ExcelParam{
|
||||||
|
|||||||
Reference in New Issue
Block a user