From 9effa1fd02fcfb17a2726415efa830575ef45822 Mon Sep 17 00:00:00 2001
From: lishihai <dslsh@dscom>
Date: 星期一, 24 六月 2024 10:40:21 +0800
Subject: [PATCH] report物料导入BUG

---
 controllers/product_controller.go |    5 +++++
 service/material.go               |   13 +++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index dea98e2..1549251 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -912,6 +912,11 @@
 //
 //	@Tags		鐗╂枡绠$悊
 //	@Summary	瀵煎叆鐗╂枡
+//
+// @Accept multipart/form-data
+// @Param file formData file true "file"
+// @Param     Authorization	header string true "token"
+//
 //	@Produce	application/xlsx
 //	@Success	200		{object}	util.Response 	"鎴愬姛"
 //	@Router		/api-wms/v1/product/inputProduct [post]
diff --git a/service/material.go b/service/material.go
index 5ae63e5..1a32f8e 100644
--- a/service/material.go
+++ b/service/material.go
@@ -190,11 +190,11 @@
 					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]],
@@ -203,12 +203,17 @@
 		}
 
 	}
+	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
 	})

--
Gitblit v1.8.0