From b361c50c9a0c9a35904a96e6a27ff1b609049071 Mon Sep 17 00:00:00 2001 From: zicla Date: Sun, 2 Dec 2018 21:06:06 +0800 Subject: [PATCH] Finish all the work of dashboard. --- rest/dashboard_controller.go | 7 +++++++ rest/dashboard_dao.go | 34 ++++++++++++++++++++++++++++++++++ rest/dashboard_model.go | 9 ++++----- rest/footprint_dao.go | 1 + rest/matter_controller.go | 17 +++++++++-------- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/rest/dashboard_controller.go b/rest/dashboard_controller.go index 7841a3f..0c5b28a 100644 --- a/rest/dashboard_controller.go +++ b/rest/dashboard_controller.go @@ -35,6 +35,7 @@ func (this *DashboardController) RegisterRoutes() map[string]func(writer http.Re //每个Controller需要主动注册自己的路由。 routeMap["/api/dashboard/page"] = this.Wrap(this.Page, USER_ROLE_ADMINISTRATOR) + routeMap["/api/dashboard/active/ip/top10"] = this.Wrap(this.ActiveIpTop10, USER_ROLE_ADMINISTRATOR) return routeMap } @@ -93,3 +94,9 @@ func (this *DashboardController) Page(writer http.ResponseWriter, request *http. return this.Success(pager) } + + +func (this *DashboardController) ActiveIpTop10(writer http.ResponseWriter, request *http.Request) *WebResult { + list := this.dashboardDao.ActiveIpTop10() + return this.Success(list) +} diff --git a/rest/dashboard_dao.go b/rest/dashboard_dao.go index 9c403e9..3ed2de9 100644 --- a/rest/dashboard_dao.go +++ b/rest/dashboard_dao.go @@ -77,3 +77,37 @@ func (this *DashboardDao) Page(page int, pageSize int, dt string, sortArray []Or return pager } + +//获取最活跃的前10个ip +func (this *DashboardDao) ActiveIpTop10() []*DashboardIpTimes { + + var dashboardIpTimes []*DashboardIpTimes + + sortArray := []OrderPair{ + { + key: "times", + value: "DESC", + }, + } + rows, err := CONTEXT.DB.Model(&Footprint{}). + Select("ip,COUNT(uuid) as times"). + Group("ip"). + Order(this.GetSortString(sortArray)). + Offset(0). + Limit(10). + Rows() + + this.PanicError(err) + for rows.Next() { + var ip string; + var times int64 = 0; + rows.Scan(&ip, ×) + item := &DashboardIpTimes{ + Ip: ip, + Times: times, + } + dashboardIpTimes = append(dashboardIpTimes, item) + } + + return dashboardIpTimes +} diff --git a/rest/dashboard_model.go b/rest/dashboard_model.go index 31b1e45..f9dfa65 100644 --- a/rest/dashboard_model.go +++ b/rest/dashboard_model.go @@ -23,10 +23,9 @@ func (Dashboard) TableName() string { } /** - * 总调用量 + * 统计IP活跃数的 */ -type DashboardInvoke struct { - InvokeNum int64 `json:"invokeNum"` - Uv int64 `json:"uv"` - Dt string `json:"dt"` +type DashboardIpTimes struct { + Ip string `json:"ip"` + Times int64 `json:"times"` } diff --git a/rest/footprint_dao.go b/rest/footprint_dao.go index aa6fbd2..5d2d5cd 100644 --- a/rest/footprint_dao.go +++ b/rest/footprint_dao.go @@ -117,3 +117,4 @@ func (this *FootprintDao) AvgCostBetweenTime(startTime time.Time, endTime time.T row.Scan(&cost) return int64(cost) } + diff --git a/rest/matter_controller.go b/rest/matter_controller.go index 9abcd56..4619f33 100644 --- a/rest/matter_controller.go +++ b/rest/matter_controller.go @@ -157,6 +157,7 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req orderCreateTime := request.FormValue("orderCreateTime") orderUpdateTime := request.FormValue("orderUpdateTime") orderSort := request.FormValue("orderSort") + orderTimes := request.FormValue("orderTimes") puuid := request.FormValue("puuid") userUuid := request.FormValue("userUuid") @@ -191,12 +192,12 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req extensions = strings.Split(extensionsStr, ",") } - //文件列表默认文件夹始终在文件的前面。 - if orderDir == "" { - orderDir = "DESC" - } sortArray := []OrderPair{ + { + key: "dir", + value: orderDir, + }, { key: "create_time", value: orderCreateTime, @@ -209,10 +210,6 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req key: "sort", value: orderSort, }, - { - key: "dir", - value: orderDir, - }, { key: "size", value: orderSize, @@ -221,6 +218,10 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req key: "name", value: orderName, }, + { + key: "times", + value: orderTimes, + }, } pager := this.matterDao.Page(page, pageSize, puuid, userUuid, name, dir, extensions, sortArray)