mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-11 22:00:27 +08:00
修复查看服务24小时流量统计会产生panic的问题
This commit is contained in:
@@ -834,11 +834,6 @@ func (this *ServerBandwidthStatDAO) HasFullData(tx *dbs.Tx, serverId int64, mont
|
|||||||
return false, errors.New("invalid month '" + month + "'")
|
return false, errors.New("invalid month '" + month + "'")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仅供调试
|
|
||||||
if Tea.IsTesting() {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
fullDataLocker.Lock()
|
fullDataLocker.Lock()
|
||||||
hasData, ok := fullDataMap[monthKey]
|
hasData, ok := fullDataMap[monthKey]
|
||||||
fullDataLocker.Unlock()
|
fullDataLocker.Unlock()
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ func (this *ServerDailyStatDAO) compatFindDailyStats(tx *dbs.Tx, serverId int64,
|
|||||||
|
|
||||||
dayMap := map[string]*ServerDailyStat{} // day => Stat
|
dayMap := map[string]*ServerDailyStat{} // day => Stat
|
||||||
for _, one := range ones {
|
for _, one := range ones {
|
||||||
stat := one.(*ServerDailyStat)
|
var stat = one.(*ServerDailyStat)
|
||||||
dayMap[stat.Day] = stat
|
dayMap[stat.Day] = stat
|
||||||
}
|
}
|
||||||
days, err := utils.RangeDays(dayFrom, dayTo)
|
days, err := utils.RangeDays(dayFrom, dayTo)
|
||||||
@@ -656,9 +656,11 @@ func (this *ServerDailyStatDAO) compatFindHourlyStats(tx *dbs.Tx, serverId int64
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hourMap := map[string]*ServerDailyStat{} // hour => Stat
|
var hourMap = map[string]*ServerDailyStat{} // hour => Stat
|
||||||
for _, one := range ones {
|
for _, one := range ones {
|
||||||
stat := one.(*ServerDailyStat)
|
var stat = one.(*ServerDailyStat)
|
||||||
|
stat.Day = stat.Hour[:8]
|
||||||
|
stat.TimeFrom = stat.Hour[8:] + "00"
|
||||||
hourMap[stat.Hour] = stat
|
hourMap[stat.Hour] = stat
|
||||||
}
|
}
|
||||||
hours, err := utils.RangeHours(hourFrom, hourTo)
|
hours, err := utils.RangeHours(hourFrom, hourTo)
|
||||||
@@ -670,7 +672,11 @@ func (this *ServerDailyStatDAO) compatFindHourlyStats(tx *dbs.Tx, serverId int64
|
|||||||
if ok {
|
if ok {
|
||||||
result = append(result, stat)
|
result = append(result, stat)
|
||||||
} else {
|
} else {
|
||||||
result = append(result, &ServerDailyStat{Hour: hour})
|
result = append(result, &ServerDailyStat{
|
||||||
|
Hour: hour,
|
||||||
|
Day: hour[:8],
|
||||||
|
TimeFrom: hour[8:] + "00",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
func (this *ServerDailyStat) AsUserBandwidthStat() *UserBandwidthStat {
|
func (this *ServerDailyStat) AsUserBandwidthStat() *UserBandwidthStat {
|
||||||
|
var timeAt = "0000"
|
||||||
|
if len(this.TimeFrom) >= 4 {
|
||||||
|
timeAt = this.TimeFrom[:4]
|
||||||
|
} else if len(this.Hour) > 8 {
|
||||||
|
timeAt = this.Hour[8:] + "00"
|
||||||
|
}
|
||||||
return &UserBandwidthStat{
|
return &UserBandwidthStat{
|
||||||
Id: 0,
|
Id: 0,
|
||||||
UserId: uint64(this.UserId),
|
UserId: uint64(this.UserId),
|
||||||
RegionId: this.RegionId,
|
RegionId: this.RegionId,
|
||||||
Day: this.Day,
|
Day: this.Day,
|
||||||
TimeAt: this.TimeFrom[:4],
|
TimeAt: timeAt,
|
||||||
Bytes: this.Bytes / 300,
|
Bytes: this.Bytes / 300,
|
||||||
TotalBytes: this.Bytes,
|
TotalBytes: this.Bytes,
|
||||||
AvgBytes: this.Bytes / 300,
|
AvgBytes: this.Bytes / 300,
|
||||||
@@ -19,13 +25,19 @@ func (this *ServerDailyStat) AsUserBandwidthStat() *UserBandwidthStat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *ServerDailyStat) AsServerBandwidthStat() *ServerBandwidthStat {
|
func (this *ServerDailyStat) AsServerBandwidthStat() *ServerBandwidthStat {
|
||||||
|
var timeAt = "0000"
|
||||||
|
if len(this.TimeFrom) >= 4 {
|
||||||
|
timeAt = this.TimeFrom[:4]
|
||||||
|
} else if len(this.Hour) > 8 {
|
||||||
|
timeAt = this.Hour[8:] + "00"
|
||||||
|
}
|
||||||
return &ServerBandwidthStat{
|
return &ServerBandwidthStat{
|
||||||
Id: 0,
|
Id: 0,
|
||||||
UserId: uint64(this.UserId),
|
UserId: uint64(this.UserId),
|
||||||
ServerId: uint64(this.ServerId),
|
ServerId: uint64(this.ServerId),
|
||||||
RegionId: this.RegionId,
|
RegionId: this.RegionId,
|
||||||
Day: this.Day,
|
Day: this.Day,
|
||||||
TimeAt: this.TimeFrom[:4],
|
TimeAt: timeAt,
|
||||||
Bytes: this.Bytes / 300,
|
Bytes: this.Bytes / 300,
|
||||||
TotalBytes: this.Bytes,
|
TotalBytes: this.Bytes,
|
||||||
AvgBytes: this.Bytes / 300,
|
AvgBytes: this.Bytes / 300,
|
||||||
|
|||||||
@@ -523,11 +523,6 @@ func (this *UserBandwidthStatDAO) HasFullData(tx *dbs.Tx, userId int64, month st
|
|||||||
return false, errors.New("invalid month '" + month + "'")
|
return false, errors.New("invalid month '" + month + "'")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仅供调试
|
|
||||||
if Tea.IsTesting() {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
fullDataLocker.Lock()
|
fullDataLocker.Lock()
|
||||||
hasData, ok := fullDataMap[month]
|
hasData, ok := fullDataMap[month]
|
||||||
fullDataLocker.Unlock()
|
fullDataLocker.Unlock()
|
||||||
|
|||||||
Reference in New Issue
Block a user