From c4b9d130cb0aa98f4b65a987b11fc5c2bea3a1c7 Mon Sep 17 00:00:00 2001
From: yinbentan <yinbentan@live.com>
Date: 星期三, 03 七月 2024 10:37:25 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/jialian' into jialian

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

diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index b1233ec..6807a60 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -6,7 +6,9 @@
 	"github.com/gin-gonic/gin"
 	"github.com/shopspring/decimal"
 	"github.com/spf13/cast"
+	"github.com/xuri/excelize/v2"
 	"gorm.io/gorm"
+	"net/url"
 	"strconv"
 	"time"
 	"wms/constvar"
@@ -20,6 +22,7 @@
 	"wms/request"
 	"wms/response"
 	"wms/service"
+	"wms/utils/http"
 )
 
 type ProductController struct {
@@ -53,6 +56,13 @@
 	if params.Unit == "" {
 		util.ResponseFormat(c, code.RequestParamError, "鍗曚綅涓嶈兘涓虹┖")
 		return
+	}
+	if params.BarCode != "" {
+		m, err := models.NewMaterialSearch().SetBarCode(params.BarCode).First()
+		if err == nil && m.ID != "" { //鏌ュ嚭鐗╂枡琛ㄦ槸鐗╂枡宸插瓨鍦�
+			util.ResponseFormat(c, code.RequestParamError, "鏉″舰鐮佸凡缁忚浣跨敤")
+			return
+		}
 	}
 	//params.ID = utils.GetUUID()
 
@@ -352,6 +362,13 @@
 	if params.Unit == "" {
 		util.ResponseFormat(c, code.RequestParamError, "鍗曚綅涓嶈兘涓虹┖")
 		return
+	}
+	if params.BarCode != "" {
+		m, err := models.NewMaterialSearch().SetBarCode(params.BarCode).First()
+		if err == nil && m.ID != params.ID { //鏌ュ嚭鐗╂枡涓擨D涓嶄竴鏍�,
+			util.ResponseFormat(c, code.RequestParamError, "鏉″舰鐮佸凡缁忚浣跨敤")
+			return
+		}
 	}
 	err := models.NewMaterialSearch().SetID(params.ID).Save(&params)
 	if err != nil {
@@ -1022,8 +1039,8 @@
 
 // InputProduct
 //
-//	@Tags		鐗╂枡绠$悊
-//	@Summary	瀵煎叆鐗╂枡
+//	@Tags		浜у搧
+//	@Summary	瀵煎叆鐗╂枡/浜у搧
 //
 // @Accept multipart/form-data
 // @Param file formData file true "file"
@@ -1049,3 +1066,41 @@
 	resp.InputCount = insertCount
 	util.ResponseFormat(c, code.Success, resp)
 }
+
+// DownloadInputFormat
+//
+//	@Tags		浜у搧
+//	@Summary	涓嬭浇瀵煎叆鐗╂枡/浜у搧妯℃澘
+//
+// @Param     Authorization	header string true "token"
+//
+//	@Success	200		{object}	util.Response 	"鎴愬姛"
+//	@Router		/api-wms/v1/product/downloadInputFormat [get]
+func (slf ProductController) DownloadInputFormat(c *gin.Context) {
+	template, err := models.NewFileTemplateAttachmentSearch().SetCategory(7).First() //鐗╂枡瀵煎叆妯℃澘
+	if err != nil {
+		util.ResponseFormat(c, code.NoTemplateError, "鑾峰彇妯$増璁板綍澶辫触:"+err.Error())
+		return
+	}
+	readerCloser, err := http.HttpGetWithReadCloser(template.FileUrl)
+	if err != nil {
+		util.ResponseFormat(c, code.NoTemplateError, "鑾峰彇妯$増璁板綍澶辫触:"+err.Error())
+		return
+	}
+	f, err := excelize.OpenReader(readerCloser)
+	if err != nil {
+		util.ResponseFormat(c, code.NoTemplateError, "鑾峰彇妯$増璁板綍澶辫触:"+err.Error())
+		return
+	}
+	fileContentDisposition := "attachment;filename=\"" + url.QueryEscape("鐗╂枡瀵煎叆.xlsx") + "\""
+	c.Writer.Header().Add("Content-Disposition", fileContentDisposition)
+	c.Writer.Header().Add("Content-Type", "application/octet-stream")
+	//c.Writer.Header().Add("Content-Type", "application/xlsx")
+	if err = f.Write(c.Writer); err != nil {
+		util.ResponseFormat(c, code.NoTemplateError, "鏁版嵁瀵煎嚭寮傚父:"+err.Error())
+		return
+	}
+
+	readerCloser.Close()
+	util.ResponseFormat(c, code.Success, "")
+}

--
Gitblit v1.8.0