Explorar o código

添加row index索引错误的bug

491520313@qq.com hai 1 semana
pai
achega
1465ad6005
Modificáronse 1 ficheiros con 167 adicións e 68 borrados
  1. 167 68
      sku3d/sku3d/api/a-excel.go

+ 167 - 68
sku3d/sku3d/api/a-excel.go

@@ -46,12 +46,14 @@ func RegExcelRouter(router *GinRouter) {
 	router.POSTJWT("/zip/export", ZipExport)
 }
 
-func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates []*model.Category) (model.MatImage, error) {
+func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates []*model.Category) (model.MatImage, bool, error) {
 	imageMat := model.MatImage{}
 	// 构建基础数据
 	imageMat.CusNum = row[0]
 	imageMat.NameCN = row[1]
 	imageMat.NameEN = row[2]
+	catDirty := false
+	rowLenth := len(row)
 
 	//1.商品编号
 	CusNumIndex := -1
@@ -62,7 +64,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if CusNumIndex == -1 {
-		return imageMat, fmt.Errorf("公司商品编号列未找到")
+		return imageMat, catDirty, fmt.Errorf("公司商品编号列未找到")
 	}
 	imageMat.CusNum = row[CusNumIndex]
 
@@ -75,7 +77,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if NameCNIndex == -1 {
-		return imageMat, fmt.Errorf("商品中文名列未找到")
+		return imageMat, catDirty, fmt.Errorf("商品中文名列未找到")
 	}
 	imageMat.NameCN = row[NameCNIndex]
 
@@ -88,7 +90,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if NameENIndex == -1 {
-		return imageMat, fmt.Errorf("商品英文名列未找到")
+		return imageMat, catDirty, fmt.Errorf("商品英文名列未找到")
 	}
 	imageMat.NameEN = row[NameENIndex]
 
@@ -101,7 +103,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if CategoryIndex == -1 {
-		return imageMat, fmt.Errorf("分类列未找到")
+		return imageMat, catDirty, fmt.Errorf("分类列未找到")
 	}
 	//imageMat.Categories = append(imageMat.Categories, row[CategoryIndex])
 	// 根据分类层级一的名字获取对应id,遍历一层获取对应数据
@@ -118,8 +120,23 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if len(rootCate.IdStr) <= 0 {
-		return imageMat, fmt.Errorf("%s的商品分类未找到定义", row[CategoryIndex])
+	if len(rootCate.IdStr) <= 0 && len(row[CategoryIndex]) > 0 {
+		oid := primitive.NewObjectID()
+		cat := &model.Category{
+			Id:       oid,
+			IdStr:    oid.Hex(),
+			CusNum:   "0000",
+			Name:     row[CategoryIndex],
+			Children: []*model.Category{},
+		}
+		rootCate = cat
+		for _, cate := range cates {
+			if cate.Name == "商品分类" {
+				cat.Children = append(cate.Children, cat)
+				break
+			}
+		}
+		catDirty = true
 	}
 
 	// 获取rootCate下的二级分类
@@ -142,6 +159,40 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		return nil
 	}
 
+	var insertRootCate2 = func(rootCate *model.Category, pName string, name string, cusNum string) *model.Category {
+		// 如果没有找到种类分类定义,则创建一个新的种类分类
+		oid := primitive.NewObjectID()
+		c := &model.Category{
+			Id:       oid,
+			Name:     name,
+			IdStr:    oid.Hex(),
+			CusNum:   cusNum,
+			Children: []*model.Category{},
+		}
+		inserted := false
+		for _, cate := range rootCate.Children {
+			if cate.Name == "种类分类" {
+				cate.Children = append(cate.Children, c)
+				inserted = true
+				break
+			}
+		}
+		if !inserted {
+			oid2 := primitive.NewObjectID()
+			r := &model.Category{
+				Id:     oid2,
+				Name:   "种类分类",
+				IdStr:  oid2.Hex(),
+				CusNum: "0000",
+				Children: []*model.Category{
+					c,
+				},
+			}
+			rootCate.Children = append(rootCate.Children, r)
+		}
+		return c
+	}
+
 	//分类rootId
 	imageMat.Categories = append(imageMat.Categories, rootCate.IdStr)
 
@@ -154,7 +205,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if PackageGrossWeightIndex == -1 {
-		return imageMat, fmt.Errorf("单位包材毛重(KG)列未找到")
+		return imageMat, catDirty, fmt.Errorf("单位包材毛重(KG)列未找到")
 	}
 	var str2float64 = func(s string) *float64 {
 		if len(s) == 0 {
@@ -181,7 +232,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if PackageVolumeIndex == -1 {
-		return imageMat, fmt.Errorf("单位包材体积(CBM)列未找到")
+		return imageMat, catDirty, fmt.Errorf("单位包材体积(CBM)列未找到")
 	}
 	row6 := str2float64(row[PackageVolumeIndex])
 	imageMat.PackageVolume = row6
@@ -195,7 +246,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if PhyHeightIndex == -1 {
-		return imageMat, fmt.Errorf("长度(MM)列未找到")
+		return imageMat, catDirty, fmt.Errorf("长度(MM)列未找到")
 	}
 	row7 := str2float64(row[PhyHeightIndex])
 	imageMat.PhyHeight = row7
@@ -209,7 +260,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if PhyWidthIndex == -1 {
-		return imageMat, fmt.Errorf("门幅/宽(MM)列未找到")
+		return imageMat, catDirty, fmt.Errorf("门幅/宽(MM)列未找到")
 	}
 	row8 := str2float64(row[PhyWidthIndex])
 	imageMat.PhyWidth = row8
@@ -223,7 +274,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if ThicknessIndex == -1 {
-		return imageMat, fmt.Errorf("厚度/高(MM)列未找到")
+		return imageMat, catDirty, fmt.Errorf("厚度/高(MM)列未找到")
 	}
 	row9 := str2float64(row[ThicknessIndex])
 	imageMat.Thickness = row9
@@ -237,7 +288,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if RemarksIndex == -1 {
-		return imageMat, fmt.Errorf("备注列未找到")
+		return imageMat, catDirty, fmt.Errorf("备注列未找到")
 	}
 	imageMat.Remarks = row[RemarksIndex]
 
@@ -250,7 +301,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if MainSupplierIndex == -1 {
-		return imageMat, fmt.Errorf("首选供应商列未找到")
+		return imageMat, catDirty, fmt.Errorf("首选供应商列未找到")
 	}
 	row11Cate := &model.Category{}
 	for _, cate := range cates {
@@ -265,7 +316,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if len(row11Cate.IdStr) <= 0 {
+	if len(row11Cate.IdStr) <= 0 && len(row[MainSupplierIndex]) > 0 {
 		oid := primitive.NewObjectID()
 		super := &model.Category{
 			Id:       oid,
@@ -280,10 +331,13 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 				break
 			}
 		}
+		catDirty = true
 		row11Cate = super
 	}
 	//添加首先供应商
-	imageMat.Categories = append(imageMat.Categories, row11Cate.IdStr)
+	if len(row11Cate.IdStr) > 0 {
+		imageMat.Categories = append(imageMat.Categories, row11Cate.IdStr)
+	}
 
 	//12.默认采购单价
 	PriceIndex := -1
@@ -294,7 +348,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if PriceIndex == -1 {
-		return imageMat, fmt.Errorf("默认采购单价列未找到")
+		return imageMat, catDirty, fmt.Errorf("默认采购单价列未找到")
 	}
 	row12 := str2float64(row[PriceIndex])
 	imageMat.Price = row12
@@ -311,7 +365,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if FromIndex == -1 {
-		return imageMat, fmt.Errorf("样品搜集人列未找到")
+		return imageMat, catDirty, fmt.Errorf("样品搜集人列未找到")
 	}
 	staffName := row[FromIndex]
 	if len(staffName) > 0 {
@@ -324,7 +378,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		if found {
 			imageMat.From = staffName
 		} else {
-			return imageMat, fmt.Errorf("样品搜集人未配置")
+			return imageMat, catDirty, fmt.Errorf("样品搜集人未配置")
 		}
 	}
 
@@ -337,7 +391,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if DevTimeIndex == -1 {
-		return imageMat, fmt.Errorf("开发日期列未找到")
+		return imageMat, catDirty, fmt.Errorf("开发日期列未找到")
 	}
 	if len(row[DevTimeIndex]) > 0 {
 		layout := "2006/1/2"
@@ -354,7 +408,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if ExportPropertyIndex == -1 {
-		return imageMat, fmt.Errorf("出口属性列未找到")
+		return imageMat, catDirty, fmt.Errorf("出口属性列未找到")
 	}
 	row15 := str2bool(row[ExportPropertyIndex])
 	imageMat.ExportProperty = row15
@@ -368,7 +422,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if DomesticPropertyIndex == -1 {
-		return imageMat, fmt.Errorf("内销属性列未找到")
+		return imageMat, catDirty, fmt.Errorf("内销属性列未找到")
 	}
 	row16 := str2bool(row[DomesticPropertyIndex])
 	imageMat.DomesticProperty = row16
@@ -382,7 +436,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if InpurchasePropertyIndex == -1 {
-		return imageMat, fmt.Errorf("内购属性列未找到")
+		return imageMat, catDirty, fmt.Errorf("内购属性列未找到")
 	}
 	row17 := str2bool(row[InpurchasePropertyIndex])
 	imageMat.InpurchaseProperty = row17
@@ -396,7 +450,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if OutsourcedPropertyIndex == -1 {
-		return imageMat, fmt.Errorf("委外属性列未找到")
+		return imageMat, catDirty, fmt.Errorf("委外属性列未找到")
 	}
 	row18 := str2bool(row[OutsourcedPropertyIndex])
 	imageMat.OutsourcedProperty = row18
@@ -418,7 +472,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if MnemonicSignIndex == -1 {
-		return imageMat, fmt.Errorf("报关商品编码列未找到")
+		return imageMat, catDirty, fmt.Errorf("报关商品编码列未找到")
 	}
 	if TaxNameCNIndex != -1 && len(row[TaxNameCNIndex]) > 0 {
 		imageMat.TaxNameCN = row[TaxNameCNIndex]
@@ -434,8 +488,26 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 				break
 			}
 		}
+
 		if len(row15Cate.IdStr) <= 0 {
-			return imageMat, fmt.Errorf("%s的报关助记符未找到定义", row[TaxNameCNIndex])
+			oid := primitive.NewObjectID()
+			r := &model.Category{
+				Id:       oid,
+				Name:     row[TaxNameCNIndex],
+				IdStr:    oid.Hex(),
+				CusNum:   "0000",
+				Children: []*model.Category{},
+			}
+
+			for _, cate := range cates {
+				if cate.Name == "报关助记符" {
+					cate.Children = append(cate.Children, r)
+					break
+				}
+			}
+			catDirty = true
+			row15Cate = r
+			//return imageMat, catDirty, fmt.Errorf("%s的报关助记符未找到定义", row[TaxNameCNIndex])
 		}
 		imageMat.Categories = append(imageMat.Categories, row15Cate.IdStr)
 	}
@@ -449,7 +521,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if RecordUserIndex == -1 {
-		return imageMat, fmt.Errorf("录入人名称列未找到")
+		return imageMat, catDirty, fmt.Errorf("录入人名称列未找到")
 	}
 	imageMat.RecordUser = row[RecordUserIndex]
 
@@ -462,7 +534,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if FitMarketIndex == -1 {
-		return imageMat, fmt.Errorf("适合的市场列未找到")
+		return imageMat, catDirty, fmt.Errorf("适合的市场列未找到")
 	}
 	imageMat.FitMarket = row[FitMarketIndex]
 
@@ -475,7 +547,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if TypeCategoryIndex == -1 {
-		return imageMat, fmt.Errorf("种类分类列未找到")
+		return imageMat, catDirty, fmt.Errorf("种类分类列未找到")
 	}
 
 	//24.种类分类名称
@@ -487,14 +559,14 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if TypeCategoryNameIndex == -1 {
-		return imageMat, fmt.Errorf("种类分类名称列未找到")
+		return imageMat, catDirty, fmt.Errorf("种类分类名称列未找到")
 	}
 
 	typeCate := row[TypeCategoryIndex]
 	typeCateName := row[TypeCategoryNameIndex]
 	typeCateObj := getRootCate2(rootCate, "种类分类", typeCateName, typeCate)
 	if typeCateObj == nil {
-		return imageMat, fmt.Errorf("%s / %s 的种类分类未找到定义", typeCate, typeCateName)
+		typeCateObj = insertRootCate2(rootCate, "种类分类", typeCateName, typeCate)
 	}
 	imageMat.Categories = append(imageMat.Categories, typeCateObj.IdStr)
 
@@ -507,7 +579,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if BaseClothIndex == -1 {
-		return imageMat, fmt.Errorf("基布列未找到")
+		return imageMat, catDirty, fmt.Errorf("基布列未找到")
 	}
 
 	//26.基布名称
@@ -519,14 +591,14 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if BaseClothNameIndex == -1 {
-		return imageMat, fmt.Errorf("基布名称列未找到")
+		return imageMat, catDirty, fmt.Errorf("基布名称列未找到")
 	}
 
 	baseCloth := row[BaseClothIndex]
 	baseClothName := row[BaseClothNameIndex]
 	baseClothObj := getRootCate2(rootCate, "基布", baseClothName, baseCloth)
 	if baseClothObj == nil {
-		return imageMat, fmt.Errorf("%s / %s 的基布未找到定义", baseCloth, baseClothName)
+		baseClothObj = insertRootCate2(rootCate, "基布", baseClothName, baseCloth)
 	}
 	imageMat.Categories = append(imageMat.Categories, baseClothObj.IdStr)
 
@@ -539,7 +611,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if SurfaceProcessIndex == -1 {
-		return imageMat, fmt.Errorf("表面工艺列未找到")
+		return imageMat, catDirty, fmt.Errorf("表面工艺列未找到")
 	}
 
 	//28.表面工艺名称
@@ -551,14 +623,15 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if SurfaceProcessNameIndex == -1 {
-		return imageMat, fmt.Errorf("表面工艺名称列未找到")
+		return imageMat, catDirty, fmt.Errorf("表面工艺名称列未找到")
 	}
 
 	surfaceProcess := row[SurfaceProcessIndex]
 	surfaceProcessName := row[SurfaceProcessNameIndex]
 	surfaceProcessObj := getRootCate2(rootCate, "表面工艺", surfaceProcessName, surfaceProcess)
 	if surfaceProcessObj == nil {
-		return imageMat, fmt.Errorf("%s / %s 的表面工艺未找到定义", surfaceProcess, surfaceProcessName)
+		surfaceProcessObj = insertRootCate2(rootCate, "表面工艺", surfaceProcessName, surfaceProcess)
+		//return imageMat, catDirty, fmt.Errorf("%s / %s 的表面工艺未找到定义", surfaceProcess, surfaceProcessName)
 	}
 	imageMat.Categories = append(imageMat.Categories, surfaceProcessObj.IdStr)
 
@@ -571,7 +644,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if ProductWeightIndex == -1 {
-		return imageMat, fmt.Errorf("产品克重(KG)列未找到")
+		return imageMat, catDirty, fmt.Errorf("产品克重(KG)列未找到")
 	}
 	pw := str2float64(row[ProductWeightIndex])
 	imageMat.ProductWeight = pw
@@ -585,7 +658,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if OperationCycleIndex == -1 {
-		return imageMat, fmt.Errorf("运营周期列未找到")
+		return imageMat, catDirty, fmt.Errorf("运营周期列未找到")
 	}
 	imageMat.OperationCycle = row[OperationCycleIndex]
 
@@ -598,7 +671,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if ProductVolumeIndex == -1 {
-		return imageMat, fmt.Errorf("商品单位体积列未找到")
+		return imageMat, catDirty, fmt.Errorf("商品单位体积列未找到")
 	}
 	pv := str2float64(row[ProductVolumeIndex])
 	imageMat.ProductVolume = pv
@@ -630,20 +703,25 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if ProductSeriesIndex == -1 {
-		return imageMat, fmt.Errorf("产品系列列未找到")
+		return imageMat, catDirty, fmt.Errorf("产品系列列未找到")
+	}
+	if rowLenth > ProductSeriesIndex {
+		imageMat.ProductSeries = row[ProductSeriesIndex]
 	}
-	imageMat.ProductSeries = row[ProductSeriesIndex]
 
 	if ProductSeriesCodeIndex == -1 {
-		return imageMat, fmt.Errorf("产品系列代码列未找到")
+		return imageMat, catDirty, fmt.Errorf("产品系列代码列未找到")
 	}
-	productSeriesCode := row[ProductSeriesCodeIndex]
-	productSeriesCodeName := row[ProductSeriesCodeIndex+1]
-	productSeriesCodeObj := getRootCate2(rootCate, "产品系列", productSeriesCodeName, productSeriesCode)
-	if productSeriesCodeObj == nil {
-		return imageMat, fmt.Errorf("%s / %s 的产品系列代码未找到定义", productSeriesCode, productSeriesCodeName)
+	if rowLenth > (ProductSeriesCodeIndex + 1) {
+		productSeriesCode := row[ProductSeriesCodeIndex]
+		productSeriesCodeName := row[ProductSeriesCodeIndex+1]
+		productSeriesCodeObj := getRootCate2(rootCate, "产品系列", productSeriesCodeName, productSeriesCode)
+		if productSeriesCodeObj == nil {
+			productSeriesCodeObj = insertRootCate2(rootCate, "产品系列", productSeriesCodeName, productSeriesCode)
+			// return imageMat, catDirty, fmt.Errorf("%s / %s 的产品系列代码未找到定义", productSeriesCode, productSeriesCodeName)
+		}
+		imageMat.Categories = append(imageMat.Categories, productSeriesCodeObj.IdStr)
 	}
-	imageMat.Categories = append(imageMat.Categories, productSeriesCodeObj.IdStr)
 
 	//35.产品用途
 	ProductUsageIndex := -1
@@ -659,21 +737,23 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 	}
 
 	if ProductUsageIndex == -1 {
-		return imageMat, fmt.Errorf("产品用途列未找到")
+		return imageMat, catDirty, fmt.Errorf("产品用途列未找到")
 	}
 	if ProductUsageNameIndex == -1 {
-		return imageMat, fmt.Errorf("产品用途名称列未找到")
+		return imageMat, catDirty, fmt.Errorf("产品用途名称列未找到")
 	}
+	if rowLenth > ProductUsageIndex {
 
-	imageMat.ProductUsage = row[ProductUsageIndex]
-
-	ProductUsageCode := row[ProductUsageIndex]
-	ProductUsageCodeName := row[ProductUsageNameIndex]
-	ProductUsageObj := getRootCate2(rootCate, "产品用途", ProductUsageCodeName, ProductUsageCode)
-	if ProductUsageObj == nil {
-		return imageMat, fmt.Errorf("%s / %s 产品用途未找到定义", ProductUsageCode, ProductUsageCodeName)
+		imageMat.ProductUsage = row[ProductUsageIndex]
+		ProductUsageCode := row[ProductUsageIndex]
+		ProductUsageCodeName := row[ProductUsageNameIndex]
+		ProductUsageObj := getRootCate2(rootCate, "产品用途", ProductUsageCodeName, ProductUsageCode)
+		if ProductUsageObj == nil {
+			ProductUsageObj = insertRootCate2(rootCate, "产品用途", ProductUsageCodeName, ProductUsageCode)
+			// return imageMat, catDirty, fmt.Errorf("%s / %s 产品用途未找到定义", ProductUsageCode, ProductUsageCodeName)
+		}
+		imageMat.Categories = append(imageMat.Categories, ProductUsageObj.IdStr)
 	}
-	imageMat.Categories = append(imageMat.Categories, ProductUsageObj.IdStr)
 
 	//36.原命名编号
 	OriginalNumberIndex := -1
@@ -684,9 +764,13 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if OriginalNumberIndex == -1 {
-		return imageMat, fmt.Errorf("原命名编号列未找到")
+		return imageMat, catDirty, fmt.Errorf("原命名编号列未找到")
 	}
-	imageMat.OriginalNumber = row[OriginalNumberIndex]
+
+	if rowLenth > OriginalNumberIndex {
+		imageMat.OriginalNumber = row[OriginalNumberIndex]
+	}
+	// imageMat.OriginalNumber = row[OriginalNumberIndex]
 
 	//37.底布克重
 	BackingWeightIndex := -1
@@ -697,9 +781,12 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if BackingWeightIndex == -1 {
-		return imageMat, fmt.Errorf("底布克重列未找到")
+		return imageMat, catDirty, fmt.Errorf("底布克重列未找到")
+	}
+	bw := Float64Value(0.0)
+	if len(row) > BackingWeightIndex {
+		bw = str2float64(row[BackingWeightIndex])
 	}
-	bw := str2float64(row[BackingWeightIndex])
 	imageMat.BackingWeight = bw
 
 	//38.面布克重
@@ -711,12 +798,14 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if SurfaceWeightIndex == -1 {
-		return imageMat, fmt.Errorf("面布克重列未找到")
+		return imageMat, catDirty, fmt.Errorf("面布克重列未找到")
+	}
+	sw := Float64Value(0.0)
+	if len(row) > SurfaceWeightIndex {
+		sw = str2float64(row[SurfaceWeightIndex])
 	}
-	sw := str2float64(row[SurfaceWeightIndex])
 	imageMat.SurfaceWeight = sw
-
-	return imageMat, nil
+	return imageMat, catDirty, nil
 }
 
 func str2bool(s string) *bool {
@@ -781,6 +870,7 @@ func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, g
 	headers := rows[0]
 
 	// 根据模板解析每列数据
+	updateCate := false
 	for i, row := range rows {
 		// 跳过表头
 		if i == 0 {
@@ -793,7 +883,11 @@ func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, g
 			Status:   "成功",
 		}
 
-		imageMat, err := ParseMatObject(apictx.CreateRepoCtx(), row, headers, cates)
+		imageMat, dirty, err := ParseMatObject(apictx.CreateRepoCtx(), row, headers, cates)
+		if dirty {
+			updateCate = true
+		}
+		fmt.Printf("parsed imageMat: %s\n %d / %d", imageMat.CusNum, i, len(rows))
 		if err != nil {
 			result.Status = "失败"
 			result.ErrorMessage = err.Error()
@@ -877,6 +971,11 @@ func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, g
 		importResults = append(importResults, result)
 	}
 
+	if updateCate {
+		// 更新分类配置
+		repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionCategory, cat[0].Id.Hex(), repo.Map{"children": cates})
+	}
+
 	// 创建一个新的Excel文件用于导出结果
 	resultExcel := excelize.NewFile()
 	sheet := "Sheet1"