读取永辉excel文件
This commit is contained in:
125
business/jxstore/yonghui/yonghui.go
Normal file
125
business/jxstore/yonghui/yonghui.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package yonghui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mime/multipart"
|
||||
"unicode"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
)
|
||||
|
||||
var (
|
||||
sheetNames = []string{"蔬菜", "水果", "肉禽", "净配", "水产", "干货", "MINI肉禽价格"}
|
||||
)
|
||||
|
||||
//sheet1 蔬菜
|
||||
var (
|
||||
sheet1SkuIdCol = 0
|
||||
sheet1SkuPriceCol = 14
|
||||
sheet1OrgSkuIdCol = 5
|
||||
sheet1OrgSkuPriceCol = 8
|
||||
)
|
||||
|
||||
func SendFilesToStores(ctx *jxcontext.Context, files []*multipart.FileHeader) (hint string, err error) {
|
||||
var (
|
||||
// skuId string
|
||||
// skuPrice string
|
||||
skuMap = make(map[string]string)
|
||||
)
|
||||
param := &weimobapi.QueryGoodsListParam{
|
||||
PageNum: 1,
|
||||
PageSize: jdapi.MaxSkuIDsCount4QueryListBySkuIds,
|
||||
}
|
||||
// if len(files) == 0 {
|
||||
// return "", errors.New("没有文件上传!")
|
||||
// }
|
||||
xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
for _, v := range sheetNames {
|
||||
// goodsParam := &weimobapi.GoodsParameter{}
|
||||
rows, _ := xlsx.GetRows(v)
|
||||
switch v {
|
||||
case "蔬菜":
|
||||
for _, row := range rows {
|
||||
for k, _ := range row {
|
||||
if k == sheet1SkuIdCol {
|
||||
|
||||
}
|
||||
// if !IsChineseChar(colCell) {
|
||||
|
||||
// }
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// xlFile, err := xlsx.OpenFile("111.xlsx")
|
||||
// if err != nil {
|
||||
// errors.New(err.Error())
|
||||
// }
|
||||
// excelize
|
||||
// for _, sheet := range xlFile.Sheets {
|
||||
// if sheet.Name == "蔬菜" {
|
||||
// for j := 0; j < len(sheet.Rows); j++ {
|
||||
// cells := sheet.Rows[j].Cells
|
||||
// for i := 0; i < len(cells); i++ {
|
||||
// cell := cells[i]
|
||||
// if i == 0 {
|
||||
// if _, err := strconv.Atoi(cell.String()); err != nil || cell.String() == "" {
|
||||
// continue
|
||||
// }
|
||||
// skuId = cell.String()
|
||||
// }
|
||||
// if i == 14 {
|
||||
// skuPrice = cell.String()
|
||||
// }
|
||||
// skuMap[skuId] = skuPrice
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for k, v := range skuMap {
|
||||
fmt.Println(k)
|
||||
fmt.Println(v)
|
||||
}
|
||||
|
||||
GetWeiMoGoodsList(param)
|
||||
return "", err
|
||||
}
|
||||
|
||||
func GetWeiMoGoodsList(param *weimobapi.QueryGoodsListParam) {
|
||||
// for {
|
||||
// skuList, _, err2 := getAPI("").QuerySkuInfos(param)
|
||||
// if err = err2; err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if len(skuList) > 0 {
|
||||
// batchSkuNameList := make([]*partner.SkuNameInfo, len(skuList))
|
||||
// for k, v := range skuList {
|
||||
// batchSkuNameList[k] = vendorSku2Jx(v)
|
||||
// }
|
||||
// setSkuNameListPic(batchSkuNameList)
|
||||
// skuNameList = append(skuNameList, batchSkuNameList...)
|
||||
// }
|
||||
// if len(skuList) < param.PageSize {
|
||||
// break
|
||||
// }
|
||||
// param.PageNum++
|
||||
// }
|
||||
}
|
||||
|
||||
func IsChineseChar(str string) bool {
|
||||
for _, r := range str {
|
||||
if unicode.Is(unicode.Scripts["Han"], r) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
27
controllers/yonghui.go
Normal file
27
controllers/yonghui.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/yonghui"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
//读取永辉excelAPI
|
||||
type YongHuiController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title 读取永辉excel文件
|
||||
// @Description 读取永辉excel文件
|
||||
// @Param token header string true "认证token"
|
||||
// @Param isAsync query bool false "是否异步,缺省是同步"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /LoadExcelByYongHui [post]
|
||||
func (c *YongHuiController) LoadExcelByYongHui() {
|
||||
c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) {
|
||||
r := c.Ctx.Request
|
||||
files := r.MultipartForm.File["userfiles"]
|
||||
retVal, err = yonghui.SendFilesToStores(params.Ctx, files)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -1998,4 +1998,13 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:YongHuiController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:YongHuiController"],
|
||||
beego.ControllerComments{
|
||||
Method: "LoadExcelByYongHui",
|
||||
Router: `/LoadExcelByYongHui`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
}
|
||||
|
||||
@@ -126,6 +126,11 @@ func init() {
|
||||
&controllers.ReportController{},
|
||||
),
|
||||
),
|
||||
beego.NSNamespace("/yonghui",
|
||||
beego.NSInclude(
|
||||
&controllers.YongHuiController{},
|
||||
),
|
||||
),
|
||||
)
|
||||
beego.AddNamespace(ns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user