| | |
| | | task.MonthStats() |
| | | util.ResponseFormat(c, code.Success, nil) |
| | | } |
| | | |
| | | // WarehouseMonthStats |
| | | // @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/warehouseMonthStats [post] |
| | | func (slf ReportFormsController) WarehouseMonthStats(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() |
| | | 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 |
| | | } |
| | | |
| | | now := time.Now().Local() |
| | | today := now.Day() |
| | | nowMonth := now.Format("2006-01") |
| | | |
| | | day, dateStr, _ := service.NewSystemConfigService().GetInventoryCutOffPoint() |
| | | if nowMonth == params.Date && today < day || today == day && now.Format("15:04") < dateStr { //本月未至结算时间点 |
| | | productIds := make([]string, 0, len(result)) |
| | | for _, item := range result { |
| | | productIds = append(productIds, item.ProductId) |
| | | } |
| | | statsRecords, err := service.GetCurrentWarehouseStats(params.Date, params.WarehouseID, productIds) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "内部错误") |
| | | return |
| | | } |
| | | statsMap := models.WarehouseMonthStatsMap(statsRecords) |
| | | for k, v := range result { |
| | | if statsMap[v.ProductId] == nil { |
| | | continue |
| | | } |
| | | |
| | | result[k].OutputAmount = statsMap[v.ProductId].OutputAmount |
| | | result[k].EndAmount = statsMap[v.ProductId].EndAmount |
| | | result[k].InputAmount = statsMap[v.ProductId].InputAmount |
| | | result[k].InputItems = statsMap[v.ProductId].InputItems |
| | | result[k].OutputItems = statsMap[v.ProductId].OutputItems |
| | | } |
| | | |
| | | } |
| | | |
| | | 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(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | if params.Token != constvar.DoMonthStatsToken { |
| | | return |
| | | } |
| | | |
| | | task.WarehouseMonthStats() |
| | | util.ResponseFormat(c, code.Success, nil) |
| | | } |