Finish all the work of dashboard.

This commit is contained in:
zicla 2018-12-02 21:06:06 +08:00
parent 927427f353
commit b361c50c9a
5 changed files with 55 additions and 13 deletions

View File

@ -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)
}

View File

@ -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, &times)
item := &DashboardIpTimes{
Ip: ip,
Times: times,
}
dashboardIpTimes = append(dashboardIpTimes, item)
}
return dashboardIpTimes
}

View File

@ -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"`
}

View File

@ -117,3 +117,4 @@ func (this *FootprintDao) AvgCostBetweenTime(startTime time.Time, endTime time.T
row.Scan(&cost)
return int64(cost)
}

View File

@ -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)