From 7468b67542954eb9b2a2bae35a86be091690d9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 12 Dec 2019 15:38:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AEExcel=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BA=AC=E8=A5=BF=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 39 +++++++++++++++++++++++------ business/jxstore/yonghui/yonghui.go | 18 +++---------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 89b2338e3..8e4ca1062 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -11,6 +11,7 @@ import ( "strings" "sync" "time" + "unicode" "git.rosy.net.cn/baseapi" @@ -2179,6 +2180,8 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io. storeSkuNamePriceListUpdate []*model.StoreSkuNamePrice skuBindInfosInter []interface{} skuBindInfoList []*StoreSkuBindInfo + errMsg string + isErr bool = false ) dataLock.dataFailedList = dataLock.dataFailedList[0:0] dataLock.dataSuccessList = dataLock.dataSuccessList[0:0] @@ -2194,7 +2197,6 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io. switch step { case 0: xlsx, err := excelize.OpenReader(reader) - // xlsx, err := excelize.OpenFile("111.xlsx") if err != nil { return "", err } @@ -2204,9 +2206,14 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io. continue } storeSkuNamePrice := &model.StoreSkuNamePrice{} - GetCellIntoStruct(rowNum, row, sheetParam, storeSkuNamePrice) + errMsg += GetCellIntoStruct(rowNum, row, sheetParam, storeSkuNamePrice) storeSkuNamePriceList = append(storeSkuNamePriceList, storeSkuNamePrice) } + if errMsg != "" { + return "", errors.New(errMsg) + } else { + isErr = true + } case 1: db := dao.GetDB() storeSkuNamePriceListOrg, _ := dao.GetStoreSkuNamePrice(db) @@ -2244,9 +2251,9 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io. NameID: nameID, Name: skuList[0].Name, Unit: storeSkuNamePrice.Unit, - OrgPrice: utils.Str2Float64(utils.Int64ToStr(skuList[0].UnitPrice / 100)), - NowPrice: utils.Str2Float64(utils.Int64ToStr(int64(unitPrice / 100))), - MixPrice: utils.Str2Float64(utils.Int64ToStr(int64(unitPrice) - skuList[0].UnitPrice)), + OrgPrice: utils.Str2Float64(utils.Int64ToStr(skuList[0].UnitPrice)) / 100, + NowPrice: utils.Str2Float64(utils.Int64ToStr(int64(unitPrice))) / 100, + MixPrice: utils.Str2Float64(utils.Int64ToStr(int64(unitPrice)-skuList[0].UnitPrice)) / 100, } dataLock.AppendDataSuccess(outSuccess) } else { @@ -2280,7 +2287,9 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io. for _, v := range skuBindInfosInter { skuBindInfoList = append(skuBindInfoList, v.(*StoreSkuBindInfo)) } - UpdateStoresSkus(ctx, storeIDs, skuBindInfoList, false, isAsync, isContinueWhenError) + if isErr { + UpdateStoresSkus(ctx, storeIDs, skuBindInfoList, false, isAsync, isContinueWhenError) + } case 3: //写Excel WriteToExcelJx(task, dataLock.dataSuccessList, dataLock.dataFailedList) @@ -2367,9 +2376,12 @@ func StoreSkuNamePriceList2Map(ctx *jxcontext.Context, storeSkuNamePriceList []* return result } -func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSkuNamePrice *model.StoreSkuNamePrice) { +func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSkuNamePrice *model.StoreSkuNamePrice) (errMsg string) { for k, cell := range row { if k == sheetParam.OutSkuIDCol { + if IsChineseChar(cell) { + return fmt.Sprintf("Excel格式排版发生了变化!在[%v]列,[%v]行附近可能增加或减少了一列", k+1, rowNum+1) + } storeSkuNamePrice.OutSkuID = cell } if k == sheetParam.SkuNameCol { @@ -2385,12 +2397,16 @@ func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSk storeSkuNamePrice.NameIDGroup = cellReplace } if k == sheetParam.SkuPriceCol { + if IsChineseChar(cell) { + return fmt.Sprintf("Excel格式排版发生了变化!在[%v]列,[%v]行附近可能增加或减少了一列", k+1, rowNum+1) + } storeSkuNamePrice.Price = int(utils.Float64TwoInt64(utils.Str2Float64(cell) * 100)) } if k == sheetParam.SkuUnitCol { storeSkuNamePrice.Unit = cell } } + return errMsg } func (d *DataLock) AppendDataSuccess(dataSuccess DataSuccess) { @@ -2404,3 +2420,12 @@ func (d *DataLock) AppendDataFailed(dataFailed DataFailed) { defer d.locker.Unlock() d.dataFailedList = append(d.dataFailedList, dataFailed) } + +func IsChineseChar(str string) bool { + for _, r := range str { + if unicode.Is(unicode.Scripts["Han"], r) { + return true + } + } + return false +} diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index f3f8a4562..f838d4b2c 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -9,7 +9,6 @@ import ( "strings" "sync" "time" - "unicode" "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/utils" @@ -555,15 +554,6 @@ func GetWeiMobGoodsList(param *weimobapi.QueryGoodsListParam) (goodsList []*weim return goodsList, err } -func IsChineseChar(str string) bool { - for _, r := range str { - if unicode.Is(unicode.Scripts["Han"], r) { - return true - } - } - return false -} - func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row []string, sheetName string, rowNum int) (errMsg string) { var ( skuID string @@ -613,10 +603,8 @@ func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row [ } if rowNum >= sheetParam.SkuRow { if rowNum == sheetParam.SkuRow { - if IsChineseChar(skuID) { - if IsChineseChar(skuID) { - errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]行附近可能增加了一行,请确认!", sheetName, rowNum) - } + if cms.IsChineseChar(skuID) { + errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]行附近可能增加了一行,请确认!", sheetName, rowNum) } } if len(skuMap) > 0 { @@ -649,7 +637,7 @@ func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row [ delete(skuMap, "") } else { for i := rowNum; i < sheetParam.SkuRow; i++ { - if !IsChineseChar(skuID) { + if !cms.IsChineseChar(skuID) { errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]行附近可能减少了一行,请确认!", sheetName, rowNum) } }