Browse Source

fixed: 导入优化

infish2018 6 days ago
parent
commit
290bd9955d
1 changed files with 206 additions and 169 deletions
  1. 206 169
      sku3d/sku3d/api/a-excel.go

+ 206 - 169
sku3d/sku3d/api/a-excel.go

@@ -132,7 +132,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		rootCate = cat
 		for _, cate := range cates {
 			if cate.Name == "商品分类" {
-				cat.Children = append(cate.Children, cat)
+				cate.Children = append(cate.Children, cat)
 				break
 			}
 		}
@@ -171,7 +171,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 		inserted := false
 		for _, cate := range rootCate.Children {
-			if cate.Name == "种类分类" {
+			if cate.Name == pName {
 				cate.Children = append(cate.Children, c)
 				inserted = true
 				break
@@ -181,7 +181,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			oid2 := primitive.NewObjectID()
 			r := &model.Category{
 				Id:     oid2,
-				Name:   "种类分类",
+				Name:   pName,
 				IdStr:  oid2.Hex(),
 				CusNum: "0000",
 				Children: []*model.Category{
@@ -190,6 +190,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			}
 			rootCate.Children = append(rootCate.Children, r)
 		}
+		catDirty = true
 		return c
 	}
 
@@ -204,9 +205,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if PackageGrossWeightIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("单位包材毛重(KG)列未找到")
-	}
+
 	var str2float64 = func(s string) *float64 {
 		if len(s) == 0 {
 			return nil
@@ -219,9 +218,11 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 		return &f
 	}
-
-	row5 := str2float64(row[PackageGrossWeightIndex])
-	imageMat.PackageGrossWeight = row5
+	if PackageGrossWeightIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("单位包材毛重(KG)列未找到")
+		row5 := str2float64(row[PackageGrossWeightIndex])
+		imageMat.PackageGrossWeight = row5
+	}
 
 	//6.单位包材体积(CBM)
 	PackageVolumeIndex := -1
@@ -231,11 +232,11 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if PackageVolumeIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("单位包材体积(CBM)列未找到")
+	if PackageVolumeIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("单位包材体积(CBM)列未找到")
+		row6 := str2float64(row[PackageVolumeIndex])
+		imageMat.PackageVolume = row6
 	}
-	row6 := str2float64(row[PackageVolumeIndex])
-	imageMat.PackageVolume = row6
 
 	//7.长度(MM)
 	PhyHeightIndex := -1
@@ -245,11 +246,11 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if PhyHeightIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("长度(MM)列未找到")
+	if PhyHeightIndex != -1 {
+		//return imageMat, catDirty, fmt.Errorf("长度(MM)列未找到")
+		row7 := str2float64(row[PhyHeightIndex])
+		imageMat.PhyHeight = row7
 	}
-	row7 := str2float64(row[PhyHeightIndex])
-	imageMat.PhyHeight = row7
 
 	//8.门幅/宽(MM)
 	PhyWidthIndex := -1
@@ -260,10 +261,10 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if PhyWidthIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("门幅/宽(MM)列未找到")
+		//return imageMat, catDirty, fmt.Errorf("门幅/宽(MM)列未找到")
+		row8 := str2float64(row[PhyWidthIndex])
+		imageMat.PhyWidth = row8
 	}
-	row8 := str2float64(row[PhyWidthIndex])
-	imageMat.PhyWidth = row8
 
 	//9.厚度/高(MM)
 	ThicknessIndex := -1
@@ -273,11 +274,11 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if ThicknessIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("厚度/高(MM)列未找到")
+	if ThicknessIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("厚度/高(MM)列未找到")
+		row9 := str2float64(row[ThicknessIndex])
+		imageMat.Thickness = row9
 	}
-	row9 := str2float64(row[ThicknessIndex])
-	imageMat.Thickness = row9
 
 	//10.备注
 	RemarksIndex := -1
@@ -288,9 +289,10 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if RemarksIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("备注列未找到")
+		// return imageMat, catDirty, fmt.Errorf("备注列未找到")
+		imageMat.Remarks = row[RemarksIndex]
 	}
-	imageMat.Remarks = row[RemarksIndex]
+	// imageMat.Remarks = row[RemarksIndex]
 
 	//11.首选供应商
 	MainSupplierIndex := -1
@@ -300,43 +302,43 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if MainSupplierIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("首选供应商列未找到")
-	}
-	row11Cate := &model.Category{}
-	for _, cate := range cates {
-		if cate.Name == "首选供应商" {
-			for _, c := range cate.Children {
-				if c.Name == row[MainSupplierIndex] {
-					// 记录该分类为其他自动做准备
-					row11Cate = c
-					break
-				}
-			}
-			break
-		}
-	}
-	if len(row11Cate.IdStr) <= 0 && len(row[MainSupplierIndex]) > 0 {
-		oid := primitive.NewObjectID()
-		super := &model.Category{
-			Id:       oid,
-			Name:     row[MainSupplierIndex],
-			IdStr:    oid.Hex(),
-			CusNum:   "0000",
-			Children: []*model.Category{},
-		}
+	if MainSupplierIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("首选供应商列未找到")
+		row11Cate := &model.Category{}
 		for _, cate := range cates {
 			if cate.Name == "首选供应商" {
-				cate.Children = append(cate.Children, super)
+				for _, c := range cate.Children {
+					if c.Name == row[MainSupplierIndex] {
+						// 记录该分类为其他自动做准备
+						row11Cate = c
+						break
+					}
+				}
 				break
 			}
 		}
-		catDirty = true
-		row11Cate = super
-	}
-	//添加首先供应商
-	if len(row11Cate.IdStr) > 0 {
-		imageMat.Categories = append(imageMat.Categories, row11Cate.IdStr)
+		if len(row11Cate.IdStr) <= 0 && len(row[MainSupplierIndex]) > 0 {
+			oid := primitive.NewObjectID()
+			super := &model.Category{
+				Id:       oid,
+				Name:     row[MainSupplierIndex],
+				IdStr:    oid.Hex(),
+				CusNum:   "0000",
+				Children: []*model.Category{},
+			}
+			for _, cate := range cates {
+				if cate.Name == "首选供应商" {
+					cate.Children = append(cate.Children, super)
+					break
+				}
+			}
+			catDirty = true
+			row11Cate = super
+		}
+		//添加首先供应商
+		if len(row11Cate.IdStr) > 0 {
+			imageMat.Categories = append(imageMat.Categories, row11Cate.IdStr)
+		}
 	}
 
 	//12.默认采购单价
@@ -348,10 +350,10 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 		}
 	}
 	if PriceIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("默认采购单价列未找到")
+		// return imageMat, catDirty, fmt.Errorf("默认采购单价列未找到")
+		row12 := str2float64(row[PriceIndex])
+		imageMat.Price = row12
 	}
-	row12 := str2float64(row[PriceIndex])
-	imageMat.Price = row12
 
 	//13.样品搜集人
 	FromIndex := -1
@@ -364,21 +366,28 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if FromIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("样品搜集人列未找到")
-	}
-	staffName := row[FromIndex]
-	if len(staffName) > 0 {
-		staff := model.StaffUser{}
-		// 验证样品收集人是否预设
-		found, _ := repo.RepoSeachDoc(ctx, &repo.DocSearchOptions{
-			CollectName: repo.CollectionStaffUser,
-			Query:       repo.Map{"name": staffName},
-		}, &staff)
-		if found {
-			imageMat.From = staffName
-		} else {
-			return imageMat, catDirty, fmt.Errorf("样品搜集人未配置")
+	if FromIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("样品搜集人列未找到")
+		staffName := row[FromIndex]
+		if len(staffName) > 0 {
+			staff := model.StaffUser{}
+			// 验证样品收集人是否预设
+			found, _ := repo.RepoSeachDoc(ctx, &repo.DocSearchOptions{
+				CollectName: repo.CollectionStaffUser,
+				Query:       repo.Map{"name": staffName},
+			}, &staff)
+			if found {
+				imageMat.From = staffName
+			} else {
+				staff.Name = staffName
+				staff.CreateTime = time.Now()
+				uid, err := repo.RepoAddDoc(ctx, repo.CollectionStaffUser, &staff)
+				if err != nil {
+					return imageMat, catDirty, fmt.Errorf("自动添加添加样品搜集人失败: %v", err)
+				}
+				staff.Id, _ = primitive.ObjectIDFromHex(uid)
+				imageMat.From = staff.Name
+			}
 		}
 	}
 
@@ -390,15 +399,16 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if DevTimeIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("开发日期列未找到")
-	}
-	if len(row[DevTimeIndex]) > 0 {
-		layout := "2006/1/2"
-		// 解析字符串
-		devTime, _ := time.Parse(layout, row[DevTimeIndex])
-		imageMat.DevTime = &devTime
+	if DevTimeIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("开发日期列未找到")
+		if len(row[DevTimeIndex]) > 0 {
+			layout := "2006/1/2"
+			// 解析字符串
+			devTime, _ := time.Parse(layout, row[DevTimeIndex])
+			imageMat.DevTime = &devTime
+		}
 	}
+
 	//15.出口属性
 	ExportPropertyIndex := -1
 	for i, header := range headers {
@@ -407,11 +417,11 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if ExportPropertyIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("出口属性列未找到")
+	if ExportPropertyIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("出口属性列未找到")
+		row15 := str2bool(row[ExportPropertyIndex])
+		imageMat.ExportProperty = row15
 	}
-	row15 := str2bool(row[ExportPropertyIndex])
-	imageMat.ExportProperty = row15
 
 	//16.内销属性
 	DomesticPropertyIndex := -1
@@ -421,11 +431,11 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if DomesticPropertyIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("内销属性列未找到")
+	if DomesticPropertyIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("内销属性列未找到")
+		row16 := str2bool(row[DomesticPropertyIndex])
+		imageMat.DomesticProperty = row16
 	}
-	row16 := str2bool(row[DomesticPropertyIndex])
-	imageMat.DomesticProperty = row16
 
 	//17.内购属性
 	InpurchasePropertyIndex := -1
@@ -435,11 +445,11 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if InpurchasePropertyIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("内购属性列未找到")
+	if InpurchasePropertyIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("内购属性列未找到")
+		row17 := str2bool(row[InpurchasePropertyIndex])
+		imageMat.InpurchaseProperty = row17
 	}
-	row17 := str2bool(row[InpurchasePropertyIndex])
-	imageMat.InpurchaseProperty = row17
 
 	//18.委外属性
 	OutsourcedPropertyIndex := -1
@@ -449,20 +459,23 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if OutsourcedPropertyIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("委外属性列未找到")
+	if OutsourcedPropertyIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("委外属性列未找到")
+		row18 := str2bool(row[OutsourcedPropertyIndex])
+		imageMat.OutsourcedProperty = row18
 	}
-	row18 := str2bool(row[OutsourcedPropertyIndex])
-	imageMat.OutsourcedProperty = row18
 
 	//19.报关助记符
-	MnemonicSignIndex := -1
-	for i, header := range headers {
-		if header == "报关商品编码" {
-			MnemonicSignIndex = i
-			break
-		}
-	}
+	// MnemonicSignIndex := -1
+	// for i, header := range headers {
+	// 	if header == "报关商品编码" {
+	// 		MnemonicSignIndex = i
+	// 		break
+	// 	}
+	// }
+	// if MnemonicSignIndex == -1 {
+	// 	return imageMat, catDirty, fmt.Errorf("报关商品编码列未找到")
+	// }
 
 	TaxNameCNIndex := -1
 	for i, header := range headers {
@@ -471,9 +484,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if MnemonicSignIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("报关商品编码列未找到")
-	}
+
 	if TaxNameCNIndex != -1 && len(row[TaxNameCNIndex]) > 0 {
 		imageMat.TaxNameCN = row[TaxNameCNIndex]
 		row15Cate := &model.Category{}
@@ -520,10 +531,12 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if RecordUserIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("录入人名称列未找到")
+	if RecordUserIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("录入人名称列未找到")
+		if rowLenth > RecordUserIndex {
+			imageMat.RecordUser = row[RecordUserIndex]
+		}
 	}
-	imageMat.RecordUser = row[RecordUserIndex]
 
 	//22.适合的市场
 	FitMarketIndex := -1
@@ -533,10 +546,10 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if FitMarketIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("适合的市场列未找到")
+	if FitMarketIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("适合的市场列未找到")
+		imageMat.FitMarket = row[FitMarketIndex]
 	}
-	imageMat.FitMarket = row[FitMarketIndex]
 
 	//23.种类分类
 	TypeCategoryIndex := -1
@@ -599,6 +612,7 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 	baseClothObj := getRootCate2(rootCate, "基布", baseClothName, baseCloth)
 	if baseClothObj == nil {
 		baseClothObj = insertRootCate2(rootCate, "基布", baseClothName, baseCloth)
+
 	}
 	imageMat.Categories = append(imageMat.Categories, baseClothObj.IdStr)
 
@@ -643,11 +657,11 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if ProductWeightIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("产品克重(KG)列未找到")
+	if ProductWeightIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("产品克重(KG)列未找到")
+		pw := str2float64(row[ProductWeightIndex])
+		imageMat.ProductWeight = pw
 	}
-	pw := str2float64(row[ProductWeightIndex])
-	imageMat.ProductWeight = pw
 
 	//30.运营周期
 	OperationCycleIndex := -1
@@ -657,10 +671,10 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if OperationCycleIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("运营周期列未找到")
+	if OperationCycleIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("运营周期列未找到")
+		imageMat.OperationCycle = row[OperationCycleIndex]
 	}
-	imageMat.OperationCycle = row[OperationCycleIndex]
 
 	//31.商品单位体积
 	ProductVolumeIndex := -1
@@ -670,11 +684,11 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if ProductVolumeIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("商品单位体积列未找到")
+	if ProductVolumeIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("商品单位体积列未找到")
+		pv := str2float64(row[ProductVolumeIndex])
+		imageMat.ProductVolume = pv
 	}
-	pv := str2float64(row[ProductVolumeIndex])
-	imageMat.ProductVolume = pv
 
 	//32.商品分类代码
 	// ProductCategoryIndex := -1
@@ -702,25 +716,25 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if ProductSeriesIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("产品系列列未找到")
-	}
-	if rowLenth > ProductSeriesIndex {
-		imageMat.ProductSeries = row[ProductSeriesIndex]
+	if ProductSeriesIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("产品系列列未找到")
+		if rowLenth > ProductSeriesIndex {
+			imageMat.ProductSeries = row[ProductSeriesIndex]
+		}
 	}
 
-	if ProductSeriesCodeIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("产品系列代码列未找到")
-	}
-	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)
+	if ProductSeriesCodeIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("产品系列代码列未找到")
+		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.产品用途
@@ -763,14 +777,12 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if OriginalNumberIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("原命名编号列未找到")
-	}
-
-	if rowLenth > OriginalNumberIndex {
-		imageMat.OriginalNumber = row[OriginalNumberIndex]
+	if OriginalNumberIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("原命名编号列未找到")
+		if rowLenth > OriginalNumberIndex {
+			imageMat.OriginalNumber = row[OriginalNumberIndex]
+		}
 	}
-	// imageMat.OriginalNumber = row[OriginalNumberIndex]
 
 	//37.底布克重
 	BackingWeightIndex := -1
@@ -780,14 +792,14 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if BackingWeightIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("底布克重列未找到")
-	}
-	bw := Float64Value(0.0)
-	if len(row) > BackingWeightIndex {
-		bw = str2float64(row[BackingWeightIndex])
+	if BackingWeightIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("底布克重列未找到")
+		bw := Float64Value(0.0)
+		if len(row) > BackingWeightIndex {
+			bw = str2float64(row[BackingWeightIndex])
+		}
+		imageMat.BackingWeight = bw
 	}
-	imageMat.BackingWeight = bw
 
 	//38.面布克重
 	SurfaceWeightIndex := -1
@@ -797,14 +809,15 @@ func ParseMatObject(ctx *repo.RepoSession, row []string, headers []string, cates
 			break
 		}
 	}
-	if SurfaceWeightIndex == -1 {
-		return imageMat, catDirty, fmt.Errorf("面布克重列未找到")
-	}
-	sw := Float64Value(0.0)
-	if len(row) > SurfaceWeightIndex {
-		sw = str2float64(row[SurfaceWeightIndex])
+	if SurfaceWeightIndex != -1 {
+		// return imageMat, catDirty, fmt.Errorf("面布克重列未找到")
+		sw := Float64Value(0.0)
+		if len(row) > SurfaceWeightIndex {
+			sw = str2float64(row[SurfaceWeightIndex])
+		}
+		imageMat.SurfaceWeight = sw
 	}
-	imageMat.SurfaceWeight = sw
+
 	return imageMat, catDirty, nil
 }
 
@@ -981,13 +994,37 @@ func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, g
 	sheet := "Sheet1"
 
 	// 复制原始表头并添加状态列
-	headers2 := append(rows[0], "导入状态", "失败原因", "数据库ID")
+	statusColumn := -1
+	reasonColumn := -1
+	ObjIdColumn := -1
+
+	for i, header := range rows[0] {
+		if header == "导入状态" {
+			statusColumn = i
+		} else if header == "失败原因" {
+			reasonColumn = i
+		} else if header == "数据库ID" {
+			ObjIdColumn = i
+		}
+	}
+	headers2 := rows[0]
+	if statusColumn < 0 {
+		headers2 = append(headers2, "导入状态")
+		statusColumn = len(headers2) - 1
+	}
+	if reasonColumn < 0 {
+		headers2 = append(headers2, "失败原因")
+		reasonColumn = len(headers2) - 1
+	}
+	if ObjIdColumn < 0 {
+		headers2 = append(headers2, "数据库ID")
+		ObjIdColumn = len(headers2) - 1
+	}
 	for i, header := range headers2 {
 		colName := columnIndexToName(i)
 		resultExcel.SetCellValue(sheet, colName+"1", header)
 	}
 
-	// 写入每行数据和导入结果
 	for i, row := range rows {
 		if i == 0 {
 			continue // 跳过表头
@@ -1009,9 +1046,9 @@ func ExcelImportWithImages(c *gin.Context, apictx *ApiSession, file io.Reader, g
 		}
 
 		// 添加状态和错误信息
-		statusCol := columnIndexToName(len(row))
-		errorCol := columnIndexToName(len(row) + 1)
-		idCol := columnIndexToName(len(row) + 2)
+		statusCol := columnIndexToName(statusColumn)
+		errorCol := columnIndexToName(reasonColumn)
+		idCol := columnIndexToName(ObjIdColumn)
 
 		resultExcel.SetCellValue(sheet, statusCol+strconv.Itoa(i+1), result.Status)
 		resultExcel.SetCellValue(sheet, errorCol+strconv.Itoa(i+1), result.ErrorMessage)