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 | 42 +++++++++++++++++++++++++-----------------
service/material.go | 14 ++++++++------
2 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index 6807a60..56f6e68 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -6,8 +6,8 @@
"github.com/gin-gonic/gin"
"github.com/shopspring/decimal"
"github.com/spf13/cast"
- "github.com/xuri/excelize/v2"
"gorm.io/gorm"
+ "io"
"net/url"
"strconv"
"time"
@@ -449,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
@@ -1077,7 +1086,7 @@
// @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() //鐗╂枡瀵煎叆妯℃澘
+ template, err := models.NewFileTemplateAttachmentSearch().SetCategory(constvar.FileWarehouseCategory_JialianInput3).First() //鐗╂枡瀵煎叆妯℃澘
if err != nil {
util.ResponseFormat(c, code.NoTemplateError, "鑾峰彇妯$増璁板綍澶辫触:"+err.Error())
return
@@ -1087,20 +1096,19 @@
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()
+ 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, "")
}
diff --git a/service/material.go b/service/material.go
index 8fbf56b..f4f302c 100644
--- a/service/material.go
+++ b/service/material.go
@@ -156,12 +156,14 @@
//淇濆瓨鍔ㄦ�佸睘鎬�
for _, attributesColumn := range attributesColumns {
- attributeValueList = append(attributeValueList, &models.AttributeValue{
- EntityID: material.ID,
- //AttributeID: mapAttribute[insert[attributesColumn]],
- AttributeID: mapAttribute[headers[attributesColumn]],
- Value: insert[attributesColumn],
- })
+ if len(insert) > attributesColumn {
+ attributeValueList = append(attributeValueList, &models.AttributeValue{
+ EntityID: material.ID,
+ //AttributeID: mapAttribute[insert[attributesColumn]],
+ AttributeID: mapAttribute[headers[attributesColumn]],
+ Value: insert[attributesColumn],
+ })
+ }
}
}
--
Gitblit v1.8.0