From 462071ca05c30354057a6eb3839a4dc6ac6f659a Mon Sep 17 00:00:00 2001
From: dsmzx <dsmzx@123.com>
Date: 星期一, 24 六月 2024 11:33:16 +0800
Subject: [PATCH] 出库/入库 打印

---
 controllers/product_controller.go |   89 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 80 insertions(+), 9 deletions(-)

diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index cb0e7fc..86f4178 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -181,6 +181,37 @@
 			product.MaxInventoryRule = reorderRules[0].MaxInventory
 		}
 		product.ReorderRuleNum = rulesTotal
+		attributeValues, err := models.NewAttributeValueSearch().SetEntityID(product.ID).FindNotTotal()
+		aids := make([]uint, 0)
+		for _, v := range attributeValues {
+			aids = append(aids, v.AttributeID)
+		}
+		attributes, err := models.NewAttributeSearch().SetIDs(aids).FindNotTotal()
+		attributesMap := make(map[uint]*models.Attribute, len(attributes))
+		for _, v := range attributes {
+			attributesMap[v.ID] = v
+		}
+		if err != nil {
+			util.ResponseFormat(c, code.RequestParamError, "鏈煡鍔ㄦ�佸睘鎬�")
+		}
+		for _, v1 := range attributeValues {
+			attribute := attributesMap[v1.AttributeID]
+			if attribute == nil {
+				continue
+			}
+			//product.Attributes = append(product.Attributes,v1)
+			product.Attributes = append(product.Attributes, models.Attribute{
+				Model:        gorm.Model{ID: v1.ID, CreatedAt: v1.CreatedAt, UpdatedAt: v1.UpdatedAt, DeletedAt: v1.DeletedAt},
+				Name:         attribute.Name,
+				DataType:     attribute.DataType,
+				EntityType:   attribute.EntityType,
+				SelectValues: attribute.SelectValues,
+				SelectValue:  attribute.SelectValue,
+				//Value:        v1.Value,
+				Value: v1.Value,
+			})
+		}
+
 	}
 	util.ResponseFormatList(c, code.Success, products, int(total))
 }
@@ -189,6 +220,7 @@
 // @Tags      浜у搧
 // @Summary   鑾峰彇浜у搧璇︽儏
 // @Produce   application/json
+// @Param     Authorization	header string true "token"
 // @Param		id	path		string			true	"id"  "鏌ヨ鍙傛暟"
 // @Success   200 {object} util.Response{data=models.Material}	"鎴愬姛"
 // @Router    /api-wms/v1/product/getProductDetails/{id} [get]
@@ -202,6 +234,40 @@
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
 		return
+	}
+	attributeValues, err := models.NewAttributeValueSearch().SetEntityID(material.ID).FindNotTotal()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
+		return
+	}
+	aids := make([]uint, 0)
+	for _, v := range attributeValues {
+		aids = append(aids, v.AttributeID)
+	}
+	attributes, err := models.NewAttributeSearch().SetIDs(aids).FindNotTotal()
+	attributesMap := make(map[uint]*models.Attribute, len(attributes))
+	for _, v := range attributes {
+		attributesMap[v.ID] = v
+	}
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏈煡鍔ㄦ�佸睘鎬�")
+	}
+	for _, v1 := range attributeValues {
+		attribute := attributesMap[v1.AttributeID]
+		if attribute == nil {
+			continue
+		}
+		//product.Attributes = append(product.Attributes,v1)
+		material.Attributes = append(material.Attributes, models.Attribute{
+			Model:        gorm.Model{ID: v1.ID, CreatedAt: v1.CreatedAt, UpdatedAt: v1.UpdatedAt, DeletedAt: v1.DeletedAt},
+			Name:         attribute.Name,
+			DataType:     attribute.DataType,
+			EntityType:   attribute.EntityType,
+			SelectValues: attribute.SelectValues,
+			SelectValue:  attribute.SelectValue,
+			//Value:        v1.Value,
+			Value: v1.Value,
+		})
 	}
 	util.ResponseFormat(c, code.Success, material)
 }
@@ -268,25 +334,25 @@
 			}
 		}
 
-		attributeValueSearch := models.NewAttributeValueSearch()
+		/*attributeValueSearch := models.NewAttributeValueSearch()
 		//鍒犻櫎浠庢柊鎻掑叆
 		if err := attributeValueSearch.SetOrm(tx).SetEntityID(params.ID).Delete(); err != nil {
 			return err
-		}
-		avs := make([]*models.AttributeValue, 0)
+		}*/
+		//avs := make([]*models.AttributeValue, 0)
 		for _, v := range params.Attributes {
 			av := models.AttributeValue{
-				Model:       gorm.Model{},
+				Model:       gorm.Model{ID: v.ID},
 				EntityID:    params.ID,
 				AttributeID: v.ID,
 				Value:       v.Value,
 			}
-			avs = append(avs, &av)
+			//avs = append(avs, &av)
+			if err := models.NewAttributeValueSearch().SetOrm(tx).Save(&av); err != nil {
+				return err
+			}
+		}
 
-		}
-		if err := models.NewAttributeValueSearch().SetOrm(tx).CreateBatch(avs); err != nil {
-			return err
-		}
 		return nil
 	})
 	if err != nil {
@@ -881,6 +947,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]

--
Gitblit v1.8.0