From 73b6baf6af3d88cdcb0e2df7932a9bd96b0b85c5 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期一, 01 七月 2024 22:32:34 +0800
Subject: [PATCH] 月度统计出入库按类型汇总报表定时任务和手动跑任务接口

---
 service/material.go |   30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/service/material.go b/service/material.go
index 7513d30..920fa36 100644
--- a/service/material.go
+++ b/service/material.go
@@ -190,31 +190,31 @@
 					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
 	})

--
Gitblit v1.8.0