| | |
| | | "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" |
| | |
| | | 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 |
| | |
| | | // @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 |
| | |
| | | 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, "") |
| | | } |