fix
zhangqian
2024-07-04 f0786e779666d67a50cd57d82cfe1e278b47d397
controllers/report_forms_controller.go
@@ -444,7 +444,7 @@
// @Produce   application/json
// @Param     object  body  request.GetMonthStats true  "查询参数"
// @Param     Authorization   header string true "token"
// @Success   200 {object} util.ResponseList{data=[]models.MonthStats}   "成功"
// @Success   200 {object} util.ResponseList{data=[]models.WarehouseMonthStats}   "成功"
// @Router    /api-wms/v1/forms/warehouseMonthStats [post]
func (slf ReportFormsController) WarehouseMonthStats(c *gin.Context) {
   var params request.GetMonthStats
@@ -465,6 +465,8 @@
      util.ResponseFormat(c, code.InternalError, "查询总数失败")
      return
   }
   params.Preload = true
   result, err := monthFormsService.Query(params)
   if err != nil {
@@ -505,3 +507,68 @@
   util.ResponseFormatList(c, code.Success, result, int(total))
}
// DoWareHouseMonthStats
// @Tags      报表
// @Summary   手动跑月度统计库存报表
// @Produce   application/json
// @Param     object  body  request.DoWarehouseMonthStats true  "查询参数"
// @Param     Authorization   header string true "token"
// @Success   200 {object} util.ResponseList{data=[]models.MonthStats}   "成功"
// @Router    /api-wms/v1/forms/doWarehouseMonthStats [post]
func (slf ReportFormsController) DoWareHouseMonthStats(c *gin.Context) {
   var params request.DoMonthStats
   if err := c.BindJSON(&params); err != nil {
      util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
      return
   }
   if params.Token != constvar.DoMonthStatsToken {
      return
   }
   task.WarehouseMonthStats()
   util.ResponseFormat(c, code.Success, nil)
}
// DownloadWarehouseMonthStats
// @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/downloadWarehouseMonthStats [post]
func (slf ReportFormsController) DownloadWarehouseMonthStats(c *gin.Context) {
   var params request.GetMonthStats
   if err := c.BindJSON(&params); err != nil {
      util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
      return
   }
   if params.WarehouseID == 0 {
      util.ResponseFormat(c, code.RequestParamError, "仓库ID参数缺失")
      return
   }
   params.Preload = true
   monthFormsService := service.NewWarehouseMonthFormsService()
   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)
}