| | |
| | | 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) |
| | |
| | | |
| | | nowMonth := time.Now().Local().Format("2006-01") |
| | | if nowMonth == params.Date { |
| | | productIds := make([]string, 0, len(result)) |
| | | for _, item := range result { |
| | | productIds = append(productIds, item.ProductId) |
| | | } |
| | | statsRecords, err := service.GetCurrentWarehouseStats(params.Date, params.WarehouseID, productIds, true) |
| | | 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)) |
| | |
| | | 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) |
| | |
| | | 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 |
| | | } |