Add the dashboard entity.

This commit is contained in:
zicla 2018-12-01 20:21:32 +08:00
parent a197f51c6a
commit 439d23df2d
2 changed files with 44 additions and 14 deletions

View File

@ -12,37 +12,44 @@ type DashboardDao struct {
//过去七天调用量
func (this *DashboardDao) InvokeList() []*DashboardInvoke {
//过去几天
var dayNum = 15;
var tableName = Footprint{}.TableName()
now := time.Now()
startDate := now.AddDate(0, 0, -6)
rows, err := CONTEXT.DB.Raw("SELECT count(uuid) as invoke_num,dt FROM "+tableName+" where dt>= ? and dt <= ? group by dt",
startDate := now.AddDate(0, 0, 1-dayNum)
rows, err := CONTEXT.DB.Raw("SELECT COUNT(uuid) AS invoke_num,COUNT(DISTINCT(ip)) AS uv,dt FROM "+tableName+" WHERE dt>= ? AND dt <= ? GROUP BY dt",
ConvertTimeToDateString(startDate),
ConvertTimeToDateString(now)).Rows()
this.PanicError(err)
defer rows.Close()
var invokeMap = make(map[string]int64)
var invokeMap = make(map[string]*DashboardInvoke)
var dashboardInvokes []*DashboardInvoke
for rows.Next() {
var invokeNum int64 = 0;
var uv int64 = 0;
var dt string;
rows.Scan(&invokeNum, &dt)
invokeMap[dt] = invokeNum
rows.Scan(&invokeNum, &uv, &dt)
invokeMap[dt] = &DashboardInvoke{
InvokeNum: invokeNum,
Uv: uv,
Dt: dt,
}
for i := -6; i <= 0; i++ {
}
for i := 1 - dayNum; i <= 0; i++ {
date := now.AddDate(0, 0, i)
dt := ConvertTimeToDateString(date)
var invokeNum int64 = 0
v, ok := invokeMap[dt]
if ok {
invokeNum = v
}
dashboardInvokes = append(dashboardInvokes, v)
} else {
dashboardInvokes = append(dashboardInvokes, &DashboardInvoke{
InvokeNum: invokeNum,
InvokeNum: 0,
Uv: 0,
Dt: dt,
})
}
}
return dashboardInvokes
}

View File

@ -1,9 +1,32 @@
package rest
/**
* 系统的所有访问记录均记录在此
*/
type Dashboard struct {
Base
VisitNum int64 `json:"visitNum"`
TotalVisitNum int64 `json:"totalVisitNum"`
Uv int64 `json:"uv"`
TotalUv int64 `json:"totalUv"`
MatterNum int64 `json:"matterNum"`
TotalMatterNum int64 `json:"totalMatterNum"`
FileSize int64 `json:"fileSize"`
TotalFileSize int64 `json:"totalFileSize"`
AvgCost int64 `json:"avgCost"`
Dt string `json:"dt"`
}
// set File's table name to be `profiles`
func (Dashboard) TableName() string {
return TABLE_PREFIX + "dashboard"
}
/**
* 总调用量
*/
type DashboardInvoke struct {
InvokeNum int64 `json:"invokeNum"`
Uv int64 `json:"uv"`
Dt string `json:"dt"`
}