From 91d7ca06128f996844aa7d2d691d083c944bdf1d Mon Sep 17 00:00:00 2001
From: lishihai <dslsh@dscom>
Date: 星期三, 03 七月 2024 17:22:16 +0800
Subject: [PATCH] 导入物料/产品->新模版BUG修复
---
controllers/product_controller.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index 0a0bc3f..56f6e68 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -7,6 +7,8 @@
"github.com/shopspring/decimal"
"github.com/spf13/cast"
"gorm.io/gorm"
+ "io"
+ "net/url"
"strconv"
"time"
"wms/constvar"
@@ -20,6 +22,7 @@
"wms/request"
"wms/response"
"wms/service"
+ "wms/utils/http"
)
type ProductController struct {
@@ -446,7 +449,16 @@
util.ResponseFormat(c, code.RequestParamError, "鏃犳晥id")
return
}
- err := models.NewMaterialSearch().SetID(id).Delete()
+ err := models.WithTransaction(func(tx *gorm.DB) error {
+ if err := models.NewMaterialSearch().SetOrm(tx).SetID(id).Delete(); err != nil {
+ return err
+ }
+ if err := models.NewAttributeValueSearch().SetOrm(tx).SetEntityID(id).Delete(); err != nil { //鍒犻櫎鐗╂枡瀵瑰簲鐨勫姩鎬佸睘鎬�
+ return err
+ }
+ return nil
+ })
+
if err != nil {
util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎澶辫触")
return
@@ -1036,8 +1048,8 @@
// InputProduct
//
-// @Tags 鐗╂枡绠$悊
-// @Summary 瀵煎叆鐗╂枡
+// @Tags 浜у搧
+// @Summary 瀵煎叆鐗╂枡/浜у搧
//
// @Accept multipart/form-data
// @Param file formData file true "file"
@@ -1063,3 +1075,40 @@
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(constvar.FileWarehouseCategory_JialianInput3).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
+ }
+
+ fileContentDisposition := "attachment;filename=\"" + url.QueryEscape("鐗╂枡瀵煎叆.xlsx") + "\""
+ w := c.Writer
+ w.Header().Set("Content-Type", "application/octet-stream")
+ w.Header().Set("Content-Disposition", fileContentDisposition)
+ w.Header().Set("Content-Transfer-Encoding", "binary")
+ w.Header().Set("Cache-Control", "no-cache")
+ _, err = io.Copy(w, readerCloser)
+ if err != nil {
+ util.ResponseFormat(c, code.NoTemplateError, "涓嬭浇澶辫触:"+err.Error())
+ return
+ }
+ w.Flush()
+ _ = readerCloser.Close()
+ util.ResponseFormat(c, code.Success, "")
+}
--
Gitblit v1.8.0