From 216c9e49dafdb7a5bd025f6d6fa899a33befc38c Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期三, 17 四月 2024 10:33:01 +0800
Subject: [PATCH] 产品添加字段

---
 controllers/product_controller.go |   65 ++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index 84d970e..a99ac83 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -16,6 +16,7 @@
 	"wms/models"
 	"wms/pkg/logx"
 	"wms/pkg/mysqlx"
+	"wms/pkg/structx"
 	"wms/request"
 )
 
@@ -761,3 +762,67 @@
 	m["userName"] = userInfo.Username
 	util.ResponseFormat(c, code.Success, m)
 }
+
+// GetUnitInfo
+//
+//	@Tags		浜у搧
+//	@Summary	鑾峰彇鍗曚綅淇℃伅
+//	@Produce	application/json
+//	@Success	200	{object}	util.ResponseList{data=[]models.UnitDict}	"鎴愬姛"
+//	@Router		/api-wms/v1/product/getUnitInfo [get]
+func (slf ProductController) GetUnitInfo(c *gin.Context) {
+	dicts, total, err := models.NewUnitDictSearch().Find()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍑洪敊")
+		return
+	}
+	util.ResponseFormatList(c, code.Success, dicts, int(total))
+}
+
+// SaveUnitDict
+//
+//	@Tags		鏁版嵁瀛楀吀
+//	@Summary	鏇存柊璁¢噺鍗曚綅瀛楀吀
+//	@Produce	application/json
+//	@Param		object	body		request.SaveUnitDict	true	"鍙傛暟"
+//	@Success	200		{object}	util.Response			"鎴愬姛"
+//	@Router		/api-wms/v1/product/saveUnitDict [post]
+func (slf ProductController) SaveUnitDict(c *gin.Context) {
+	var reqParams request.SaveUnitDict
+	var params []*models.UnitDict
+	if err := c.BindJSON(&reqParams); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+		return
+	}
+	if err := structx.AssignTo(reqParams.Data, &params); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鏁版嵁杞崲閿欒")
+		return
+	}
+
+	for i, v := range params {
+		if len(v.Name) == 0 {
+			util.ResponseFormat(c, code.RequestParamError, "鍚嶇О涓虹┖")
+			return
+		}
+		v.Sort = i + 1
+	}
+
+	err := models.WithTransaction(func(tx *gorm.DB) error {
+		err := models.NewUnitDictSearch().SetOrm(tx).Delete()
+		if err != nil {
+			return err
+		}
+
+		err = models.NewUnitDictSearch().SetOrm(tx).CreateBatch(params)
+		if err != nil {
+			return err
+		}
+		return nil
+	})
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎澶辫触")
+		return
+	}
+
+	util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛")
+}

--
Gitblit v1.8.0