Browse Source

fix-bug

tags/v1.22.6.1^2
liuzx 3 years ago
parent
commit
69167f3660
1 changed files with 18 additions and 13 deletions
  1. +18
    -13
      routers/api/v1/repo/cloudbrain_dashboard.go

+ 18
- 13
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -745,44 +745,45 @@ func GetCloudbrainsCreateHoursData(ctx *context.Context) {
if queryType != "" {
if queryType == "all" {
beginTime = recordBeginTime
endTime = now
endTime = now.AddDate(0, 0, 1)
} else if queryType == "today" {
beginTime = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
endTime = now.AddDate(0, 0, 1)
} else if queryType == "yesterday" {
beginTime = now.AddDate(0, 0, -1)
beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location())
endTime = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
} else if queryType == "current_week" {
beginTime = now.AddDate(0, 0, -int(time.Now().Weekday())+1) //begin from monday
endTime = now
} else if queryType == "current_month" {
endTime = now
beginTime = time.Date(endTime.Year(), endTime.Month(), 1, 0, 0, 0, 0, now.Location())
beginTime = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
endTime = now.AddDate(0, 0, 1)
} else if queryType == "monthly" {
endTime = now
beginTime = now.AddDate(0, -1, 0)
beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location())
} else if queryType == "current_year" {
endTime = now
beginTime = time.Date(endTime.Year(), 1, 1, 0, 0, 0, 0, now.Location())
beginTime = time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location())
endTime = now.AddDate(0, 0, 1)
} else if queryType == "last_month" {
lastMonthTime := now.AddDate(0, -1, 0)
beginTime = time.Date(lastMonthTime.Year(), lastMonthTime.Month(), 1, 0, 0, 0, 0, now.Location())
endTime = time.Date(now.Year(), now.Month(), 2, 0, 0, 0, 0, now.Location())
endTime = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
} else if queryType == "last_7day" {
lastMonthTime := now.AddDate(0, 0, -7)
beginTime = time.Date(lastMonthTime.Year(), lastMonthTime.Month(), 1, 0, 0, 0, 0, now.Location())
endTime = time.Date(now.Year(), now.Month(), 2, 0, 0, 0, 0, now.Location())
beginTime = now.AddDate(0, 0, -6)
beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location())
endTime = now.AddDate(0, 0, 1)
} else if queryType == "last_30day" {
lastMonthTime := now.AddDate(0, 0, -30)
beginTime = time.Date(lastMonthTime.Year(), lastMonthTime.Month(), 1, 0, 0, 0, 0, now.Location())
endTime = time.Date(now.Year(), now.Month(), 2, 0, 0, 0, 0, now.Location())
beginTime := now.AddDate(0, 0, -29)
beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location())
endTime = now.AddDate(0, 0, 1)
}
} else {
if beginTimeStr == "" || endTimeStr == "" {
//如果查询类型和开始时间结束时间都未设置,按queryType=all处理
beginTime = recordBeginTime
endTime = now
endTime = now.AddDate(0, 0, 1)
} else {
beginTime, err = time.ParseInLocation("2006-01-02", beginTimeStr, time.Local)
if err != nil {
@@ -798,8 +799,12 @@ func GetCloudbrainsCreateHoursData(ctx *context.Context) {
}
}
}
log.Info("begintimehour:", beginTime)
log.Info("endTimehour:", endTime)
dateBeginTime := beginTime.Format("2006-01-02")
dateEndTime := endTime.Format("2006-01-02")
log.Info("dateBeginTime:", dateBeginTime)
log.Info("dateBeginTime:", dateEndTime)
createHourPeriodCount, err = models.GetCreateHourPeriodCount(dateBeginTime, dateEndTime)
if err != nil {
log.Error("Can not query hourPeriodCount.", err)


Loading…
Cancel
Save