From 52c7dec820e88e4e3466a03b0f68796805ebbe28 Mon Sep 17 00:00:00 2001
From: lishihai <dslsh@dscom>
Date: 星期三, 03 七月 2024 10:21:59 +0800
Subject: [PATCH] 下载导入物料/产品模板

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

diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index 0a0bc3f..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 {
@@ -1036,8 +1039,8 @@
 
 // InputProduct
 //
-//	@Tags		鐗╂枡绠$悊
-//	@Summary	瀵煎叆鐗╂枡
+//	@Tags		浜у搧
+//	@Summary	瀵煎叆鐗╂枡/浜у搧
 //
 // @Accept multipart/form-data
 // @Param file formData file true "file"
@@ -1063,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