| | |
| | | return |
| | | } |
| | | |
| | | params.Preload = true |
| | | |
| | | result, err := monthFormsService.Query(params) |
| | | if err != nil { |
| | | logx.Errorf("MonthStats query err:%v", err) |
| | |
| | | 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(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | if params.WarehouseID == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "仓库ID参数缺失") |
| | | return |
| | | } |
| | | |
| | | 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) |
| | | } |