zhangqian
2024-07-01 73b6baf6af3d88cdcb0e2df7932a9bd96b0b85c5
service/material.go
@@ -190,25 +190,31 @@
               attributeValueList = append(attributeValueList, attributeValue4)
            }
         */
         materialList = append(materialList, material)
      }
      //保存动态属性
      for attributesColumn := range attributesColumns {
      for _, attributesColumn := range attributesColumns {
         attributeValueList = append(attributeValueList, &models.AttributeValue{
            EntityID:    material.ID,
            AttributeID: mapAttribute[insert[attributesColumn]],
            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
   })