From 6dec2342316aecf4084c8f4efb43f33fbb72892f Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期二, 09 四月 2024 14:07:43 +0800
Subject: [PATCH] 更新计量单位字典

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

diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index b91d30f..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"
 )
 
@@ -777,3 +778,51 @@
 	}
 	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