From 39a8a6ca76c13c4014732441c6c73cc3c2243e19 Mon Sep 17 00:00:00 2001
From: lishihai <dslsh@dscom>
Date: 星期三, 26 六月 2024 11:27:25 +0800
Subject: [PATCH] 库存盘点应用按钮记录创建人,创建时间,应用时间、应用人员等信息;根据条形码查询产品详情;新增编辑产品增加条形码字段

---
 controllers/product_controller.go |   81 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index 86f4178..b1233ec 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -218,7 +218,7 @@
 
 // GetProductDetails
 // @Tags      浜у搧
-// @Summary   鑾峰彇浜у搧璇︽儏
+// @Summary   閫氳繃浜у搧/鍟嗗搧/鐗╂枡 ID鑾峰彇浜у搧璇︽儏
 // @Produce   application/json
 // @Param     Authorization	header string true "token"
 // @Param		id	path		string			true	"id"  "鏌ヨ鍙傛暟"
@@ -231,6 +231,62 @@
 		return
 	}
 	material, err := models.NewMaterialSearch().SetID(id).SetPreload(true).First()
+	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)
+}
+
+// GetProductDetailsByBarCode
+// @Tags      浜у搧
+// @Summary   閫氳繃浜у搧/鍟嗗搧/鐗╂枡 鏉″舰鐮� 鑾峰彇浜у搧璇︽儏
+// @Produce   application/json
+// @Param     Authorization	header string true "token"
+// @Param		barCode	path		string			true	"barCode"  "鏌ヨ鍙傛暟"
+// @Success   200 {object} util.Response{data=models.Material}	"鎴愬姛"
+// @Router    /api-wms/v1/product/getProductDetailsByBarCode/{barCode} [get]
+func (slf ProductController) GetProductDetailsByBarCode(c *gin.Context) {
+	barCode := c.Param("barCode")
+	if barCode == "" {
+		util.ResponseFormat(c, code.RequestParamError, "鏃犳晥鏉″舰鐮�")
+		return
+	}
+	material, err := models.NewMaterialSearch().SetBarCode(barCode).SetPreload(true).First()
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
 		return
@@ -365,7 +421,7 @@
 
 // DeleteProduct
 // @Tags      浜у搧
-// @Summary   鍒犻櫎浜у搧
+// @Summary   閫氳繃浜у搧/鍟嗗搧/鐗╂枡 ID鍒犻櫎浜у搧
 // @Produce   application/json
 // @Param		id	path		string			true	"id"  "鏌ヨ鍙傛暟"
 // @Success   200 {object} util.Response "鎴愬姛"
@@ -384,6 +440,27 @@
 	util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛")
 }
 
+// DeleteProductByBarCode
+// @Tags      浜у搧
+// @Summary    閫氳繃浜у搧/鍟嗗搧/鐗╂枡 鏉″舰鐮佸垹闄や骇鍝�
+// @Produce   application/json
+// @Param		barCode	path		string			true	"barCode"  "鏌ヨ鍙傛暟"
+// @Success   200 {object} util.Response "鎴愬姛"
+// @Router    /api-wms/v1/product/deleteProductByBarCode/{barCode} [delete]
+func (slf ProductController) DeleteProductByBarCode(c *gin.Context) {
+	barCode := c.Param("barCode")
+	if barCode == "" {
+		util.ResponseFormat(c, code.RequestParamError, "鏃犳晥id")
+		return
+	}
+	err := models.NewMaterialSearch().SetBarCode(barCode).Delete()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎澶辫触")
+		return
+	}
+	util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛")
+}
+
 // AddProductCategory
 // @Tags      浜у搧绫诲瀷
 // @Summary   娣诲姞浜у搧绫诲瀷

--
Gitblit v1.8.0