| | |
| | | // @Tags 报表 |
| | | // @Summary 获取位置报表 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body request.GetLocationForms true "查询参数" |
| | | // @Success 200 {object} util.ResponseList{data=[]response.LocationForms} "成功" |
| | | // @Router /api-wms/v1/forms/getLocationForms [post] |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | ids := make([]int, 0) |
| | | if params.LocationId != 0 { |
| | | ids = append(ids, params.LocationId) |
| | | } else { |
| | | //查询位置 |
| | | locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).SetType(3).FindAll() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询位置失败") |
| | | return |
| | | } |
| | | for _, location := range locations { |
| | | ids = append(ids, location.Id) |
| | | } |
| | | } |
| | | var ( |
| | | amounts []*models.LocationProductAmount |
| | | total uint64 |
| | | totalInt64 int64 |
| | | err error |
| | | ) |
| | | if params.KeyWord != "" { |
| | | amounts, total, err = service.SearchLocationReport(params.KeyWord, params.Page, params.PageSize) |
| | | } else { |
| | | amounts, totalInt64, err = models.NewLocationProductAmountSearch().SetPage(params.Page, params.PageSize).SetPreload(true).SetKeyword(params.KeyWord).SetProductId(params.ProductId).SetLocationIds(ids).FindByPage() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询数量失败") |
| | | return |
| | | } |
| | | total = uint64(totalInt64) |
| | | } |
| | | |
| | | var result []response.LocationForms |
| | | for _, amount := range amounts { |
| | | var resp response.LocationForms |
| | | resp.Amount = amount.Amount |
| | | resp.LocationId = amount.LocationId |
| | | resp.LocationName = amount.Location.Name |
| | | resp.ProduceId = amount.Product.ID |
| | | resp.ProductName = amount.Product.Name |
| | | resp.ProductTypeName = amount.ProductCategory.Name |
| | | resp.Unit = amount.Product.Unit |
| | | resp.Value = resp.Amount.Mul(amount.Product.Cost) |
| | | result = append(result, resp) |
| | | locationFormsService := service.NewLocationFormsService() |
| | | total, err := locationFormsService.Count(params) |
| | | if err != nil { |
| | | logx.Errorf("GetLocationForms count err:%v", err) |
| | | util.ResponseFormat(c, code.InternalError, "查询总数失败") |
| | | return |
| | | } |
| | | result, err := locationFormsService.Query(params) |
| | | if err != nil { |
| | | logx.Errorf("GetLocationForms query err:%v", err) |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormatList(c, code.Success, result, int(total)) |
| | | } |
| | | |
| | | // DownloadLocationForms |
| | | // @Tags 报表 |
| | | // @Summary 下载位置报表 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body request.GetLocationForms true "查询参数" |
| | | // @Success 200 {object} util.ResponseList{data=[]response.LocationForms} "成功" |
| | | // @Router /api-wms/v1/forms/downloadLocationForms [post] |
| | | func (slf ReportFormsController) DownloadLocationForms(c *gin.Context) { |
| | | var params request.GetLocationForms |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | locationFormsService := service.NewLocationFormsService() |
| | | list, err := locationFormsService.FetchAll(params) |
| | | if err != nil { |
| | | logx.Errorf("DownloadLocationForms FetchAll err:%v", err) |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | filename, err := locationFormsService.Export(list) |
| | | if err != nil { |
| | | logx.Errorf("DownloadLocationForms Export err:%v", err) |
| | | util.ResponseFormat(c, code.InternalError, "导出数据到文件失败") |
| | | 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) |
| | | c.File(filename) |
| | | defer os.Remove(filename) |
| | | } |
| | | |
| | | // MonthStats |
| | | // @Tags 报表 |
| | | // @Summary 月度统计库存报表 |