491520313@qq.com 3 هفته پیش
والد
کامیت
30ef25fe2a
1فایلهای تغییر یافته به همراه39 افزوده شده و 33 حذف شده
  1. 39 33
      sku3d/sku3d/api/a-excel.go

+ 39 - 33
sku3d/sku3d/api/a-excel.go

@@ -46,7 +46,7 @@ func RegExcelRouter(router *GinRouter) {
 	router.POSTJWT("/zip/export", ZipExport)
 }
 
-func ParseMatObject(row []string, headers []string, cates []*model.Category) (model.MatImage, error) {
+func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates []*model.Category) (model.MatImage, error) {
 	imageMat := model.MatImage{}
 	// 构建基础数据
 	imageMat.CusNum = row[0]
@@ -143,7 +143,7 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 	}
 
 	//分类rootId
-	imageMat.Categories = append(imageMat.Categories, row3Cate.IdStr)
+	imageMat.Categories = append(imageMat.Categories, rootCate.IdStr)
 
 	//5 单位包材毛重(KG)
 	PackageGrossWeightIndex := -1
@@ -160,11 +160,13 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 		if len(s) == 0 {
 			return nil
 		}
+		f := 0.0
 		f, err := strconv.ParseFloat(s, 64)
 		if err != nil {
-			return 0 // 或 math.NaN() 表示无效值
+			log.Errorf("解析浮点数失败: %v", err)
+			return &f // 或 math.NaN() 表示无效值
 		}
-		return f
+		return &f
 	}
 
 	row5 := str2float64(row[PackageGrossWeightIndex])
@@ -264,10 +266,6 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 		}
 	}
 	if len(row11Cate.IdStr) <= 0 {
-		// 记录日志跳过
-		result.Status = "失败"
-		result.ErrorMessage = "首选供应商未找到"
-		importResults = append(importResults, result)
 		return imageMat, fmt.Errorf("%s的首选供应商未找到定义", row[MainSupplierIndex])
 	}
 	//添加首先供应商
@@ -305,7 +303,7 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 	if len(staffName) > 0 {
 		staff := model.StaffUser{}
 		// 验证样品收集人是否预设
-		found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		found, _ := repo.RepoSeachDoc(ctx, &repo.DocSearchOptions{
 			CollectName: repo.CollectionStaffUser,
 			Query:       repo.Map{"name": staffName},
 		}, &staff)
@@ -392,20 +390,31 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 	//19.报关助记符
 	MnemonicSignIndex := -1
 	for i, header := range headers {
-		if header == "报关助记符" {
+		if header == "报关商品编码" {
 			MnemonicSignIndex = i
 			break
 		}
 	}
 	if MnemonicSignIndex == -1 {
-		return imageMat, fmt.Errorf("报关助记符列未找到")
+		return imageMat, fmt.Errorf("报关商品编码列未找到")
+	}
+	TaxNameCNIndex := -1
+	for i, header := range headers {
+		if header == "报关商品中文名" {
+			TaxNameCNIndex = i
+			break
+		}
+	}
+	if TaxNameCNIndex == -1 {
+		return imageMat, fmt.Errorf("报关商品中文名列未找到")
 	}
+	imageMat.TaxNameCN = row[TaxNameCNIndex]
 
 	row15Cate := &model.Category{}
 	for _, cate := range cates {
 		if cate.Name == "报关助记符" {
 			for _, c := range cate.Children {
-				if c.Name == row[MnemonicSignIndex] {
+				if c.Name == row[TaxNameCNIndex] {
 					row15Cate = c
 					break
 				}
@@ -414,24 +423,10 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 		}
 	}
 	if len(row15Cate.IdStr) <= 0 {
-		return imageMat, fmt.Errorf("%s的报关助记符未找到定义", row[MnemonicSignIndex])
+		return imageMat, fmt.Errorf("%s的报关助记符未找到定义", row[TaxNameCNIndex])
 	}
-	//添加报关助记符
 	imageMat.Categories = append(imageMat.Categories, row15Cate.IdStr)
 
-	//20.报关商品中文名
-	TaxNameCNIndex := -1
-	for i, header := range headers {
-		if header == "报关商品中文名" {
-			TaxNameCNIndex = i
-			break
-		}
-	}
-	if TaxNameCNIndex == -1 {
-		return imageMat, fmt.Errorf("报关商品中文名列未找到")
-	}
-	imageMat.TaxNameCN = row[TaxNameCNIndex]
-
 	//21.录入人名称
 	RecordUserIndex := -1
 	for i, header := range headers {
@@ -484,7 +479,7 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 
 	typeCate := row[TypeCategoryIndex]
 	typeCateName := row[TypeCategoryNameIndex]
-	typeCateObj := getRootCate2(rootCate, "种类分类", typeCate, typeCateName)
+	typeCateObj := getRootCate2(rootCate, "种类分类", typeCateName, typeCate)
 	if typeCateObj == nil {
 		return imageMat, fmt.Errorf("%s / %s 的种类分类未找到定义", typeCate, typeCateName)
 	}
@@ -516,7 +511,7 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 
 	baseCloth := row[BaseClothIndex]
 	baseClothName := row[BaseClothNameIndex]
-	baseClothObj := getRootCate2(rootCate, "基布", baseCloth, baseClothName)
+	baseClothObj := getRootCate2(rootCate, "基布", baseClothName, baseCloth)
 	if baseClothObj == nil {
 		return imageMat, fmt.Errorf("%s / %s 的基布未找到定义", baseCloth, baseClothName)
 	}
@@ -548,7 +543,7 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 
 	surfaceProcess := row[SurfaceProcessIndex]
 	surfaceProcessName := row[SurfaceProcessNameIndex]
-	surfaceProcessObj := getRootCate2(rootCate, "表面工艺", surfaceProcess, surfaceProcessName)
+	surfaceProcessObj := getRootCate2(rootCate, "表面工艺", surfaceProcessName, surfaceProcess)
 	if surfaceProcessObj == nil {
 		return imageMat, fmt.Errorf("%s / %s 的表面工艺未找到定义", surfaceProcess, surfaceProcessName)
 	}
@@ -630,7 +625,7 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 	}
 	productSeriesCode := row[ProductSeriesCodeIndex]
 	productSeriesCodeName := row[ProductSeriesCodeIndex+1]
-	productSeriesCodeObj := getRootCate2(rootCate, "产品系列", productSeriesCode, productSeriesCodeName)
+	productSeriesCodeObj := getRootCate2(rootCate, "产品系列", productSeriesCodeName, productSeriesCode)
 	if productSeriesCodeObj == nil {
 		return imageMat, fmt.Errorf("%s / %s 的产品系列代码未找到定义", productSeriesCode, productSeriesCodeName)
 	}
@@ -660,7 +655,7 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 
 	ProductUsageCode := row[ProductUsageIndex]
 	ProductUsageCodeName := row[ProductUsageNameIndex]
-	ProductUsageObj := getRootCate2(rootCate, "产品用途", ProductUsageCode, ProductUsageCodeName)
+	ProductUsageObj := getRootCate2(rootCate, "产品用途", ProductUsageCodeName, ProductUsageCode)
 	if ProductUsageObj == nil {
 		return imageMat, fmt.Errorf("%s / %s 产品用途未找到定义", ProductUsageCode, ProductUsageCodeName)
 	}
@@ -710,6 +705,16 @@ func ParseMatObject(row []string, headers []string, cates []*model.Category) (mo
 	return imageMat, nil
 }
 
+func str2bool(s string) *bool {
+	s = strings.TrimSpace(strings.ToLower(s))
+	if s == "true" || s == "1" || s == "yes" || s == "y" {
+		return BoolValue(true)
+	} else if s == "false" || s == "0" || s == "no" || s == "n" || s == "" {
+		return BoolValue(false)
+	}
+	return nil
+}
+
 func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, goodsDir, textureDir string) (interface{}, error) {
 	// 读取Excel文件
 	xlsx, err := excelize.OpenReader(file)
@@ -774,10 +779,11 @@ func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, g
 			Status:   "成功",
 		}
 
-		imageMat, err := ParseMatObject(row, headers, cates)
+		imageMat, err := ParseMatObject(apictx.CreateRepoCtx(), row, headers, cates)
 		if err != nil {
 			result.Status = "失败"
 			result.ErrorMessage = err.Error()
+			fmt.Println(result.ErrorMessage)
 			importResults = append(importResults, result)
 			continue
 		}