From 1e4b9b31e3a0b634f6faa741e0d8815a6cab6391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=A4=A7=E5=85=A8?= Date: Tue, 4 Jul 2017 17:44:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=BB=E5=8A=A1=E7=BB=84+?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/main.go | 29 +++++++++++++++++++++++++++-- controllers/task.go | 13 +++++++++---- views/main/index.html | 24 ++++++++++++------------ views/task/add.html | 2 +- views/task/list.html | 4 +++- 5 files changed, 52 insertions(+), 20 deletions(-) diff --git a/controllers/main.go b/controllers/main.go index 492fd05..ebf674a 100644 --- a/controllers/main.go +++ b/controllers/main.go @@ -25,22 +25,35 @@ type MainController struct { // 首页 func (this *MainController) Index() { this.Data["pageTitle"] = "系统概况" - + // 分组列表 + groups, _ := models.TaskGroupGetList(1, 100) + groups_map := make(map[int]string) + for _,gname := range groups { + groups_map[gname.Id] = gname.GroupName + } + //计算总任务数量 + _, count := models.TaskGetList(1, 200) // 即将执行的任务 entries := jobs.GetEntries(30) jobList := make([]map[string]interface{}, len(entries)) + startJob := 0 //即将执行的任务 for k, v := range entries { row := make(map[string]interface{}) job := v.Job.(*jobs.Job) + task, _ := models.TaskGetById(job.GetId()) row["task_id"] = job.GetId() row["task_name"] = job.GetName() + row["task_group"] = groups_map[task.GroupId] row["next_time"] = beego.Date(v.Next, "Y-m-d H:i:s") jobList[k] = row + startJob++ } // 最近执行的日志 logs, _ := models.TaskLogGetList(1, 20) recentLogs := make([]map[string]interface{}, len(logs)) + failJob := 0 //最近失败的数量 + okJob:=0 //最近成功的数量 for k, v := range logs { task, err := models.TaskGetById(v.TaskId) taskName := "" @@ -56,17 +69,24 @@ func (this *MainController) Index() { row["output"] = beego.Substr(v.Output, 0, 100) row["status"] = v.Status recentLogs[k] = row + if v.Status!=0 { + failJob++ + }else { + okJob++ + } } // 最近执行失败的日志 logs, _ = models.TaskLogGetList(1, 20, "status__lt", 0) errLogs := make([]map[string]interface{}, len(logs)) + for k, v := range logs { task, err := models.TaskGetById(v.TaskId) taskName := "" if err == nil { taskName = task.TaskName } + row := make(map[string]interface{}) row["task_name"] = taskName row["id"] = v.Id @@ -76,9 +96,14 @@ func (this *MainController) Index() { row["error"] = beego.Substr(v.Error, 0, 100) row["status"] = v.Status errLogs[k] = row + } - this.Data["okTotal"] = 13 + this.Data["startJob"] = startJob + this.Data["okJob"] = okJob + this.Data["failJob"] = failJob + this.Data["totalJob"] = count + this.Data["recentLogs"] = recentLogs // this.Data["errLogs"] = errLogs this.Data["jobs"] = jobList diff --git a/controllers/task.go b/controllers/task.go index 900de18..f502fcc 100644 --- a/controllers/task.go +++ b/controllers/task.go @@ -36,6 +36,12 @@ func (this *TaskController) List() { result, count := models.TaskGetList(page, this.pageSize, filters...) list := make([]map[string]interface{}, len(result)) + // 分组列表 + groups, _ := models.TaskGroupGetList(1, 100) + groups_map := make(map[int]string) + for _,gname := range groups { + groups_map[gname.Id] = gname.GroupName + } for k, v := range result { row := make(map[string]interface{}) row["id"] = v.Id @@ -43,6 +49,9 @@ func (this *TaskController) List() { row["cron_spec"] = v.CronSpec row["status"] = v.Status row["description"] = v.Description + row["group_id"] = v.GroupId + row["group_name"] = groups_map[v.GroupId] + e := jobs.GetEntryById(v.Id) if e != nil { row["next_time"] = beego.Date(e.Next, "Y-m-d H:i:s") @@ -64,10 +73,6 @@ func (this *TaskController) List() { } list[k] = row } - - // 分组列表 - groups, _ := models.TaskGroupGetList(1, 100) - this.Data["pageTitle"] = "任务列表" this.Data["list"] = list this.Data["groups"] = groups diff --git a/views/main/index.html b/views/main/index.html index 9a70a0b..e7f0115 100644 --- a/views/main/index.html +++ b/views/main/index.html @@ -16,7 +16,7 @@
- +
@@ -122,7 +122,7 @@ {{range $k, $v := .jobs}} diff --git a/views/task/add.html b/views/task/add.html index 6a63c55..458ace8 100644 --- a/views/task/add.html +++ b/views/task/add.html @@ -23,7 +23,7 @@
- +
* diff --git a/views/task/list.html b/views/task/list.html index 0aad1f5..1c99f85 100644 --- a/views/task/list.html +++ b/views/task/list.html @@ -79,7 +79,9 @@ {{end}}   - {{$v.name}} + {{$v.name}}-{{$v.group_name}} + + {{$v.cron_spec}} {{$v.description}}