From 79aef24a785581d95343ccd99e9cb362b2bc9c97 Mon Sep 17 00:00:00 2001 From: yinbentan <yinbentan@live.com> Date: 星期六, 06 七月 2024 21:31:59 +0800 Subject: [PATCH] 调整库存商品位置错误 --- controllers/product_controller.go | 69 +++++++++++++++++++++++++++++++++- 1 files changed, 66 insertions(+), 3 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index b1233ec..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 { @@ -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() @@ -353,6 +363,13 @@ 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(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "浜у搧淇℃伅鏇存柊澶辫触") @@ -432,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 @@ -1022,8 +1048,8 @@ // InputProduct // -// @Tags 鐗╂枡绠$悊 -// @Summary 瀵煎叆鐗╂枡 +// @Tags 浜у搧 +// @Summary 瀵煎叆鐗╂枡/浜у搧 // // @Accept multipart/form-data // @Param file formData file true "file" @@ -1049,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