| | |
| | | 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.GetCurrentStats(params.Date, productIds) |
| | | nowMonth := time.Now().Local().Format("2006-01") |
| | | if nowMonth == params.Date { //实时查询 |
| | | result, err = MonthStatsReplaceRealtimeOperation(result, params.Date) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "内部错误") |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | statsMap := models.MonthStatsMap(statsRecords) |
| | | for k, v := range result { |
| | | if statsMap[v.ProductId] == nil { |
| | | continue |
| | | } |
| | | |
| | | result[k].OutputAmount = statsMap[v.ProductId].OutputAmount |
| | | result[k].OutputMoreUnits = statsMap[v.ProductId].OutputMoreUnits |
| | | result[k].EndAmount = statsMap[v.ProductId].EndAmount |
| | | result[k].EndMoreUnits = statsMap[v.ProductId].EndMoreUnits |
| | | result[k].InputAmount = statsMap[v.ProductId].InputAmount |
| | | result[k].InputMoreUnits = statsMap[v.ProductId].InputMoreUnits |
| | | } |
| | | |
| | | } |
| | | |
| | | util.ResponseFormatList(c, code.Success, result, int(total)) |
| | | } |
| | | |
| | | func MonthStatsReplaceRealtimeOperation(result []*models.MonthStats, date string) ([]*models.MonthStats, error) { |
| | | productIds := make([]string, 0, len(result)) |
| | | for _, item := range result { |
| | | productIds = append(productIds, item.ProductId) |
| | | } |
| | | statsRecords, err := service.GetCurrentStats(date, productIds) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | statsMap := models.MonthStatsMap(statsRecords) |
| | | for k, v := range result { |
| | | if statsMap[v.ProductId] == nil { |
| | | continue |
| | | } |
| | | |
| | | result[k].OutputAmount = statsMap[v.ProductId].OutputAmount |
| | | result[k].OutputMoreUnits = statsMap[v.ProductId].OutputMoreUnits |
| | | result[k].EndAmount = statsMap[v.ProductId].EndAmount |
| | | result[k].EndMoreUnits = statsMap[v.ProductId].EndMoreUnits |
| | | result[k].InputAmount = statsMap[v.ProductId].InputAmount |
| | | result[k].InputMoreUnits = statsMap[v.ProductId].InputMoreUnits |
| | | } |
| | | return result, nil |
| | | } |
| | | |
| | | // DownloadMonthStats |
| | |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | |
| | | nowMonth := time.Now().Local().Format("2006-01") |
| | | if nowMonth == params.Date { //实时查询 |
| | | list, err = MonthStatsReplaceRealtimeOperation(list, params.Date) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "查询失败") |
| | | return |
| | | } |
| | | } |
| | | |
| | | filename, err := monthFormsService.Export(list) |
| | | if err != nil { |
| | | logx.Errorf("DownloadMonthStats Export err:%v", err) |
| | |
| | | // @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 |
| | |
| | | return |
| | | } |
| | | |
| | | params.Preload = true |
| | | |
| | | result, err := monthFormsService.Query(params) |
| | | if err != nil { |
| | | logx.Errorf("MonthStats query err:%v", err) |
| | |
| | | return |
| | | } |
| | | |
| | | now := time.Now().Local() |
| | | today := now.Day() |
| | | nowMonth := now.Format("2006-01") |
| | | if len(result) == 0 { |
| | | util.ResponseFormatList(c, code.Success, result, int(total)) |
| | | return |
| | | } |
| | | |
| | | 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) |
| | | nowMonth := time.Now().Local().Format("2006-01") |
| | | if nowMonth == params.Date { |
| | | result, err = WarehouseMonthStatsReplaceRealtimeOperation(result, params.Date, params.WarehouseID) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "内部错误") |
| | | 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) |
| | | } |
| | | |
| | | // 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 |
| | | } |
| | | |
| | | 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 |
| | | } |
| | | |
| | | nowMonth := time.Now().Local().Format("2006-01") |
| | | if nowMonth == params.Date { |
| | | list, err = WarehouseMonthStatsReplaceRealtimeOperation(list, params.Date, params.WarehouseID) |
| | | if err != nil { |
| | | 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) |
| | | } |
| | | |
| | | func WarehouseMonthStatsReplaceRealtimeOperation(list []*models.WarehouseMonthStats, date string, warehouseId int) (newList []*models.WarehouseMonthStats, err error) { |
| | | productIds := make([]string, 0, len(list)) |
| | | for _, item := range list { |
| | | productIds = append(productIds, item.ProductId) |
| | | } |
| | | statsRecords, err := service.GetCurrentWarehouseStats(date, warehouseId, productIds, true) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | statsMap := models.WarehouseMonthStatsMap(statsRecords) |
| | | for k, v := range list { |
| | | if statsMap[v.ProductId] == nil { |
| | | continue |
| | | } |
| | | |
| | | list[k].OutputAmount = statsMap[v.ProductId].OutputAmount |
| | | list[k].EndAmount = statsMap[v.ProductId].EndAmount |
| | | list[k].InputAmount = statsMap[v.ProductId].InputAmount |
| | | list[k].InputItems = statsMap[v.ProductId].InputItems |
| | | list[k].OutputItems = statsMap[v.ProductId].OutputItems |
| | | } |
| | | return list, nil |
| | | } |