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