Refine the context and Try to fix the nil issue.

This commit is contained in:
zicla
2019-04-28 00:36:21 +08:00
parent fa28bbb83f
commit 3ffc4090e0
34 changed files with 246 additions and 167 deletions

View File

@ -1,6 +1,7 @@
package rest
import (
"github.com/eyebluecn/tank/code/core"
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/jinzhu/gorm"
"github.com/nu7hatch/gouuid"
@ -19,7 +20,7 @@ func (this *DashboardDao) Create(dashboard *Dashboard) *Dashboard {
dashboard.CreateTime = time.Now()
dashboard.UpdateTime = time.Now()
dashboard.Sort = time.Now().UnixNano() / 1e6
db := CONTEXT.GetDB().Create(dashboard)
db := core.CONTEXT.GetDB().Create(dashboard)
this.PanicError(db.Error)
return dashboard
@ -29,7 +30,7 @@ func (this *DashboardDao) Create(dashboard *Dashboard) *Dashboard {
func (this *DashboardDao) Save(dashboard *Dashboard) *Dashboard {
dashboard.UpdateTime = time.Now()
db := CONTEXT.GetDB().Save(dashboard)
db := core.CONTEXT.GetDB().Save(dashboard)
this.PanicError(db.Error)
return dashboard
@ -38,7 +39,7 @@ func (this *DashboardDao) Save(dashboard *Dashboard) *Dashboard {
//删除一条记录
func (this *DashboardDao) Delete(dashboard *Dashboard) {
db := CONTEXT.GetDB().Delete(&dashboard)
db := core.CONTEXT.GetDB().Delete(&dashboard)
this.PanicError(db.Error)
}
@ -47,7 +48,7 @@ func (this *DashboardDao) FindByDt(dt string) *Dashboard {
// Read
var dashboard Dashboard
db := CONTEXT.GetDB().Where(&Dashboard{Dt: dt}).First(&dashboard)
db := core.CONTEXT.GetDB().Where(&Dashboard{Dt: dt}).First(&dashboard)
if db.Error != nil {
return nil
}
@ -64,7 +65,7 @@ func (this *DashboardDao) Page(page int, pageSize int, dt string, sortArray []bu
}
var conditionDB *gorm.DB
conditionDB = CONTEXT.GetDB().Model(&Dashboard{}).Where(wp.Query, wp.Args...)
conditionDB = core.CONTEXT.GetDB().Model(&Dashboard{}).Where(wp.Query, wp.Args...)
count := 0
db := conditionDB.Count(&count)
@ -89,7 +90,7 @@ func (this *DashboardDao) ActiveIpTop10() []*DashboardIpTimes {
Value: "DESC",
},
}
rows, err := CONTEXT.GetDB().Model(&Footprint{}).
rows, err := core.CONTEXT.GetDB().Model(&Footprint{}).
Select("ip,COUNT(uuid) as times").
Group("ip").
Order(this.GetSortString(sortArray)).
@ -115,6 +116,6 @@ func (this *DashboardDao) ActiveIpTop10() []*DashboardIpTimes {
//执行清理操作
func (this *DashboardDao) Cleanup() {
this.logger.Info("[DashboardDao]执行清理清除数据库中所有Dashboard记录。")
db := CONTEXT.GetDB().Where("uuid is not null").Delete(Dashboard{})
db := core.CONTEXT.GetDB().Where("uuid is not null").Delete(Dashboard{})
this.PanicError(db.Error)
}