zhangqian
2024-06-07 e718c2568e9712ab40dc4d2d4d20cf3635dc4c34
controllers/report_forms_controller.go
@@ -8,7 +8,6 @@
   "wms/constvar"
   "wms/extend/code"
   "wms/extend/util"
   "wms/models"
   "wms/pkg/logx"
   "wms/request"
   "wms/service"
@@ -83,11 +82,6 @@
   if err != nil {
      logx.Errorf("DownloadInventoryForms Export err:%v", err)
      util.ResponseFormat(c, code.InternalError, "导出数据到文件失败")
      return
   }
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "导出失败")
      return
   }
@@ -306,11 +300,6 @@
      return
   }
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "导出失败")
      return
   }
   fileContentDisposition := "attachment;filename=\"" + url.QueryEscape(filename) + "\""
   c.Header("Content-Type", "application/xlsx")
   c.Header("Content-Disposition", fileContentDisposition)
@@ -333,13 +322,57 @@
      return
   }
   list, total, err := models.NewMonthStatsSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetDate(params.Date).Find()
   monthFormsService := service.NewMonthFormsService()
   total, err := monthFormsService.Count(params)
   if err != nil {
      logx.Errorf("MonthStats count err:%v", err)
      util.ResponseFormat(c, code.InternalError, "查询总数失败")
      return
   }
   result, err := monthFormsService.Query(params)
   if err != nil {
      logx.Errorf("MonthStats query err:%v", err)
      util.ResponseFormat(c, code.InternalError, "查询失败")
      return
   }
   util.ResponseFormatList(c, code.Success, list, int(total))
   util.ResponseFormatList(c, code.Success, result, int(total))
}
// DownloadMonthStats
// @Tags      报表
// @Summary   下载月度统计库存报表
// @Produce   application/json
// @Param     object  body  request.GetMonthStats true  "查询参数"
// @Param     Authorization   header string true "token"
// @Success   200 {object} util.ResponseList{data=[]models.MonthStats}   "成功"
// @Router    /api-wms/v1/forms/downloadMonthStats [post]
func (slf ReportFormsController) DownloadMonthStats(c *gin.Context) {
   var params request.GetMonthStats
   if err := c.BindJSON(&params); err != nil {
      util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
      return
   }
   monthFormsService := service.NewMonthFormsService()
   list, err := monthFormsService.FetchAll(params)
   if err != nil {
      logx.Errorf("DownloadMonthStats FetchAll err:%v", err)
      util.ResponseFormat(c, code.InternalError, "查询失败")
      return
   }
   filename, err := monthFormsService.Export(list)
   if err != nil {
      logx.Errorf("DownloadMonthStats Export err:%v", err)
      util.ResponseFormat(c, code.InternalError, "导出数据到文件失败")
      return
   }
   fileContentDisposition := "attachment;filename=\"" + url.QueryEscape(filename) + "\""
   c.Header("Content-Type", "application/xlsx")
   c.Header("Content-Disposition", fileContentDisposition)
   c.File(filename)
   defer os.Remove(filename)
}
// DoMonthStats