| | |
| | | attributeValueList = append(attributeValueList, attributeValue4) |
| | | } |
| | | */ |
| | | |
| | | materialList = append(materialList, material) |
| | | } |
| | | |
| | | //保存动态属性 |
| | | for attributesColumn := range attributesColumns { |
| | | if mapAttribute[insert[attributesColumn]] != 0 { |
| | | attributeValue2 := new(models.AttributeValue) |
| | | attributeValue2.EntityID = material.ID |
| | | attributeValue2.AttributeID = mapAttribute[insert[9]] |
| | | attributeValue2.Value = insert[9] |
| | | attributeValueList = append(attributeValueList, &models.AttributeValue{ |
| | | EntityID: material.ID, |
| | | AttributeID: mapAttribute[insert[attributesColumn]], |
| | | Value: insert[attributesColumn], |
| | | }) |
| | | } |
| | | for _, attributesColumn := range attributesColumns { |
| | | attributeValueList = append(attributeValueList, &models.AttributeValue{ |
| | | EntityID: material.ID, |
| | | //AttributeID: mapAttribute[insert[attributesColumn]], |
| | | AttributeID: mapAttribute[headers[attributesColumn]], |
| | | Value: insert[attributesColumn], |
| | | }) |
| | | } |
| | | |
| | | } |
| | | if len(materialList) == 0 { |
| | | return 0, errors.New("物料数据为空") |
| | | } |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | if err := models.NewMaterialSearch().SetOrm(db).CreateBatch(materialList); err != nil { |
| | | return err |
| | | } |
| | | if err := models.NewAttributeValueSearch().SetOrm(db).CreateBatch(attributeValueList); err != nil { |
| | | return err |
| | | if len(attributeValueList) != 0 { |
| | | if err := models.NewAttributeValueSearch().SetOrm(db).CreateBatch(attributeValueList); err != nil { |
| | | return err |
| | | } |
| | | } |
| | | return nil |
| | | }) |