|
|
@@ -649,75 +649,24 @@ func GetCloudbrainsCreateHoursData(ctx *context.Context) { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
func GetCloudbrainsRunHoursData(ctx *context.Context) { |
|
|
|
|
|
runHourPeriodCount := make(map[string]interface{}) |
|
|
|
|
|
brainRecordBeginTime, err := getBrainRecordBeginTime() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetWaitTimeTop(ctx *context.Context) { |
|
|
|
|
|
|
|
|
|
|
|
cloudbrains, err := models.GetAllCloudBrain() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Error("Can not get brain record begin time", err) |
|
|
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.brain_record_begintime_get_err")) |
|
|
|
|
|
|
|
|
log.Error("Getcloudbrains failed:%v", err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
queryType := ctx.QueryTrim("type") |
|
|
|
|
|
beginTimeStr := ctx.QueryTrim("beginTime") |
|
|
|
|
|
endTimeStr := ctx.QueryTrim("endTime") |
|
|
|
|
|
now := time.Now() |
|
|
|
|
|
var beginTime time.Time |
|
|
|
|
|
var endTime time.Time |
|
|
|
|
|
if queryType != "" { |
|
|
|
|
|
if queryType == "all" { |
|
|
|
|
|
beginTime = brainRecordBeginTime |
|
|
|
|
|
endTime = now |
|
|
|
|
|
} else if queryType == "yesterday" { |
|
|
|
|
|
beginTime = now.AddDate(0, 0, -1) |
|
|
|
|
|
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()) |
|
|
|
|
|
} 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()) |
|
|
|
|
|
} 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()) |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
if beginTimeStr == "" || endTimeStr == "" { |
|
|
|
|
|
//如果查询类型和开始时间结束时间都未设置,按queryType=all处理 |
|
|
|
|
|
beginTime = brainRecordBeginTime |
|
|
|
|
|
endTime = now |
|
|
|
|
|
|
|
|
cloudBrainStatusResult := make(map[string]int) |
|
|
|
|
|
for _, cloudbrain := range cloudbrains { |
|
|
|
|
|
if _, ok := cloudBrainStatusResult[cloudbrain.Status]; !ok { |
|
|
|
|
|
cloudBrainStatusResult[cloudbrain.Status] = 1 |
|
|
} else { |
|
|
} else { |
|
|
beginTime, err = time.ParseInLocation("2006-01-02", beginTimeStr, time.Local) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Error("Can not ParseInLocation.", err) |
|
|
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("ParseInLocation_get_error")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
endTime, err = time.ParseInLocation("2006-01-02", endTimeStr, time.Local) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Error("Can not ParseInLocation.", err) |
|
|
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("ParseInLocation_get_error")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
cloudBrainStatusResult[cloudbrain.Status] += 1 |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
dateBeginTime := beginTime.Format("2006-01-02") |
|
|
|
|
|
dateEndTime := endTime.Format("2006-01-02") |
|
|
|
|
|
runHourPeriodCount, err = models.GetRunHourPeriodCount(dateBeginTime, dateEndTime) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Error("Can not query runHourPeriodCount.", err) |
|
|
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("runHourPeriodCount_get_error")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{ |
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{ |
|
|
"runHourPeriodCount": runHourPeriodCount, |
|
|
|
|
|
|
|
|
"cloudBrainStatusResult": cloudBrainStatusResult, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|