From c4b9d130cb0aa98f4b65a987b11fc5c2bea3a1c7 Mon Sep 17 00:00:00 2001 From: yinbentan <yinbentan@live.com> Date: 星期三, 03 七月 2024 10:37:25 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/jialian' into jialian --- controllers/product_controller.go | 45 +++++++++++++++++++++- controllers/operation.go | 32 +++++---------- router/router.go | 1 service/warehouse_month_forms.go | 6 ++ 4 files changed, 60 insertions(+), 24 deletions(-) diff --git a/controllers/operation.go b/controllers/operation.go index fb1285d..d4c32c5 100644 --- a/controllers/operation.go +++ b/controllers/operation.go @@ -9,7 +9,6 @@ "github.com/shopspring/decimal" "github.com/xuri/excelize/v2" "gorm.io/gorm" - "io/ioutil" "sort" "strconv" "strings" @@ -847,22 +846,19 @@ return } - if warehouse.FileTemplateCategoryIn == constvar.FileTemplateCategory_JialianInput1 { - fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryIn, operation) - if err != nil { - util.ResponseFormat(c, code.RequestParamError, err.Error()) - return - } - - } else if warehouse.FileTemplateCategoryIn == constvar.FileWarehouseCategory_JialianInput2 { + if warehouse.FileTemplateCategoryIn == constvar.FileWarehouseCategory_JialianInput2 { fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryIn, operation) if err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) return } - + } else { + fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryIn, operation) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } } - } else if companyName == "geruimi" { fileUrl, err = ExportInputSelfmade(constvar.FileTemplateCategory_Selfmade, operation) if err != nil { @@ -887,15 +883,15 @@ return } - if warehouse.FileTemplateCategoryOut == constvar.FileTemplateCategory_JialianOutput1 { - fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryOut, operation) + if warehouse.FileTemplateCategoryOut == constvar.FileWarehouseCategory_JialianOutput2 { + fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryOut, operation) if err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) return } - } else if warehouse.FileTemplateCategoryOut == constvar.FileWarehouseCategory_JialianOutput2 { - fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryOut, operation) + } else { + fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryOut, operation) if err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) return @@ -935,8 +931,6 @@ // 璇诲彇妯℃澘鍐呭 f, err := excelize.OpenReader(readerCloser) - //fl, err := os.Open("E:\\瀹剁汉鍑哄叆搴撳崟.xlsx") - //f, err := excelize.OpenReader(fl) if err != nil { return "", errors.New("璇诲彇excel妯$増澶辫触锛�" + err.Error()) } @@ -1063,9 +1057,7 @@ } fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes()) - ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644) if err != nil { - //ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644) logx.Errorf("file upload err: %v", err) return "", err } @@ -1183,7 +1175,6 @@ } fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes()) - ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644) if err != nil { logx.Errorf("file upload err: %v", err) return "", err @@ -1267,7 +1258,6 @@ logx.Errorf("file upload err: %v", err) return "", err } - return fileUrl, nil } 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, "") +} diff --git a/router/router.go b/router/router.go index a540f4f..edf34ef 100644 --- a/router/router.go +++ b/router/router.go @@ -122,6 +122,7 @@ productAPI.POST("updateProduct", productController.UpdateProduct) // 淇敼浜у搧璇︽儏 productAPI.DELETE("deleteProduct/:id", productController.DeleteProduct) // 閫氳繃ID鑾峰垹闄や骇鍝� productAPI.DELETE("deleteProductByBarCode/:barCode", productController.DeleteProductByBarCode) // 閫氳繃鏉″舰鐮佸垹闄や骇鍝� + productAPI.GET("downloadInputFormat", productController.DownloadInputFormat) // 涓嬭浇瀵煎叆鐗╂枡妯℃澘 productAPI.POST("addProductCategory", productController.AddProductCategory) //娣诲姞浜у搧绫诲瀷 productAPI.POST("getProductCategoryList", productController.GetProductCategoryList) //鑾峰彇浜у搧绫诲瀷鍒楄〃 diff --git a/service/warehouse_month_forms.go b/service/warehouse_month_forms.go index 9edf8c4..a4d4838 100644 --- a/service/warehouse_month_forms.go +++ b/service/warehouse_month_forms.go @@ -243,8 +243,12 @@ func GetDealerItems(m map[string]decimal.Decimal) (items []*models.WarehouseStatsItems) { for k, v := range m { + name := k + if name == "" { + name = "鍏朵粬" + } items = append(items, &models.WarehouseStatsItems{ - Name: k, + Name: name, Amount: v, }) } -- Gitblit v1.8.0