| @@ -16,19 +16,17 @@ import ( | |||||
| func CloudbrainDurationStatisticHour() { | func CloudbrainDurationStatisticHour() { | ||||
| var statisticTime time.Time | var statisticTime time.Time | ||||
| var count int64 | var count int64 | ||||
| recordBeginTime, _ := time.ParseInLocation("2006-01-02 15:04:05", setting.Grampus.UsageRateBeginTime, time.Local) | |||||
| recordDurationUpdateTime, err := models.GetDurationRecordUpdateTime() | recordDurationUpdateTime, err := models.GetDurationRecordUpdateTime() | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("Can not get GetDurationRecordBeginTime", err) | log.Error("Can not get GetDurationRecordBeginTime", err) | ||||
| return | |||||
| } | |||||
| if recordDurationUpdateTime == nil { | |||||
| statisticTime = recordBeginTime | |||||
| } else { | |||||
| statisticTime = time.Unix(int64(recordDurationUpdateTime[0].DateTime), 0) | |||||
| } | } | ||||
| now := time.Now() | now := time.Now() | ||||
| currentTime := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location()) | currentTime := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location()) | ||||
| if err == nil && len(recordDurationUpdateTime) > 0 { | |||||
| statisticTime = time.Unix(int64(recordDurationUpdateTime[0].DateTime), 0) | |||||
| } else { | |||||
| statisticTime = currentTime.Add(-1 * time.Hour) | |||||
| } | |||||
| for statisticTime.Before(currentTime) || statisticTime.Equal(currentTime) { | for statisticTime.Before(currentTime) || statisticTime.Equal(currentTime) { | ||||
| countEach := summaryDurationStat(statisticTime) | countEach := summaryDurationStat(statisticTime) | ||||