|
@@ -351,7 +351,7 @@ func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, g
|
|
|
sw := str2float64(row[44])
|
|
|
imageMat.SurfaceWeight = &sw
|
|
|
|
|
|
- imageName := row[42] // 不包含后缀 .jpg .png .jpeg
|
|
|
+ imageName := row[0] // 不包含后缀 .jpg .png .jpeg
|
|
|
// 根据图片名称检查goods和texture中是否存在,图片可能是.jpg .png .jpeg后缀
|
|
|
// 上传图片到oss 获取对应url,赋值到imageMat(Thumbnail, RawImage, ProductImage)
|
|
|
|
|
@@ -424,7 +424,7 @@ func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, g
|
|
|
// 复制原始表头并添加状态列
|
|
|
headers := append(rows[0], "导入状态", "失败原因", "数据库ID")
|
|
|
for i, header := range headers {
|
|
|
- colName := string(rune('A' + i))
|
|
|
+ colName := columnIndexToName(i)
|
|
|
resultExcel.SetCellValue(sheet, colName+"1", header)
|
|
|
}
|
|
|
|
|
@@ -445,14 +445,14 @@ func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, g
|
|
|
|
|
|
// 写入原始数据
|
|
|
for j, cell := range row {
|
|
|
- colName := string(rune('A' + j))
|
|
|
+ colName := columnIndexToName(j)
|
|
|
resultExcel.SetCellValue(sheet, colName+strconv.Itoa(i+1), cell)
|
|
|
}
|
|
|
|
|
|
// 添加状态和错误信息
|
|
|
- statusCol := string(rune('A' + len(row)))
|
|
|
- errorCol := string(rune('A' + len(row) + 1))
|
|
|
- idCol := string(rune('A' + len(row) + 2))
|
|
|
+ statusCol := columnIndexToName(len(row))
|
|
|
+ errorCol := columnIndexToName(len(row) + 1)
|
|
|
+ idCol := columnIndexToName(len(row) + 2)
|
|
|
|
|
|
resultExcel.SetCellValue(sheet, statusCol+strconv.Itoa(i+1), result.Status)
|
|
|
resultExcel.SetCellValue(sheet, errorCol+strconv.Itoa(i+1), result.ErrorMessage)
|
|
@@ -461,7 +461,7 @@ func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, g
|
|
|
|
|
|
// 设置列宽
|
|
|
for i := range headers {
|
|
|
- colName := string(rune('A' + i))
|
|
|
+ colName := columnIndexToName(i)
|
|
|
resultExcel.SetColWidth(sheet, colName, colName, 15)
|
|
|
}
|
|
|
|
|
@@ -511,7 +511,7 @@ func ZipImport(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
|
|
// 检查文件大小
|
|
|
if header.Size > 500*1024*1024 { // 限制100MB
|
|
|
- return nil, NewError("上传文件过大,请控制在100MB以内")
|
|
|
+ return nil, NewError("上传文件过大,请控制在500MB以内")
|
|
|
}
|
|
|
|
|
|
// 检查文件扩展名
|
|
@@ -828,13 +828,15 @@ func ZipExport(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
var goodsImagePath, textureImagePath string
|
|
|
if img.ProductImage != nil && img.ProductImage.Url != "" {
|
|
|
// 从URL中提取原始文件名
|
|
|
- productImageFileName := getFileNameFromUrl(img.ProductImage.Url)
|
|
|
+ // productImageFileName := getFileNameFromUrl(img.ProductImage.Url)
|
|
|
+ productImageFileName := img.CusNum
|
|
|
goodsImagePath = filepath.Join(goodsDir, productImageFileName)
|
|
|
downloadImage(img.ProductImage.Url, goodsImagePath)
|
|
|
}
|
|
|
if img.RawImage != nil && img.RawImage.Url != "" {
|
|
|
// 从URL中提取原始文件名
|
|
|
- rawImageFileName := getFileNameFromUrl(img.RawImage.Url)
|
|
|
+ rawImageFileName := img.CusNum
|
|
|
+ // rawImageFileName := getFileNameFromUrl(img.RawImage.Url)
|
|
|
textureImagePath = filepath.Join(textureDir, rawImageFileName)
|
|
|
downloadImage(img.RawImage.Url, textureImagePath)
|
|
|
}
|
|
@@ -1093,7 +1095,7 @@ func ZipExport(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
|
|
// 调整列宽
|
|
|
for i := range fixedHeaders {
|
|
|
- colName := string(rune('A' + i))
|
|
|
+ colName := columnIndexToName(i)
|
|
|
f.SetColWidth(sheet, colName, colName, 15)
|
|
|
}
|
|
|
|
|
@@ -1268,3 +1270,14 @@ func getFileNameFromUrl(url string) string {
|
|
|
fileName := path.Base(url)
|
|
|
return fileName
|
|
|
}
|
|
|
+
|
|
|
+// 工具函数 - 将列索引转换为Excel列名(支持多字母列名,如AA, AB等)
|
|
|
+func columnIndexToName(index int) string {
|
|
|
+ result := ""
|
|
|
+ for index >= 0 {
|
|
|
+ remainder := index % 26
|
|
|
+ result = string(rune('A'+remainder)) + result
|
|
|
+ index = index/26 - 1
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|