yinbentan
2024-07-03 c4b9d130cb0aa98f4b65a987b11fc5c2bea3a1c7
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, "")
}