Files
EdgeAPI/internal/db/models/log_dao.go

56 lines
1.1 KiB
Go
Raw Normal View History

2020-07-22 22:17:53 +08:00
package models
import (
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
)
type LogDAO dbs.DAO
func NewLogDAO() *LogDAO {
return dbs.NewDAO(&LogDAO{
DAOObject: dbs.DAOObject{
DB: Tea.Env,
Table: "edgeLogs",
Model: new(Log),
PkName: "id",
},
}).(*LogDAO)
}
2020-10-13 20:05:13 +08:00
var SharedLogDAO *LogDAO
func init() {
dbs.OnReady(func() {
SharedLogDAO = NewLogDAO()
})
}
2020-07-22 22:17:53 +08:00
// 创建管理员日志
2020-11-10 20:30:55 +08:00
func (this *LogDAO) CreateLog(adminType string, adminId int64, level string, description string, action string, ip string) error {
2020-07-22 22:17:53 +08:00
op := NewLogOperator()
2020-11-10 20:30:55 +08:00
op.Type = adminType
2020-07-22 22:17:53 +08:00
op.AdminId, op.Level, op.Description, op.Action, op.Ip = adminId, level, description, action, ip
op.Type = LogTypeAdmin
_, err := this.Save(op)
return err
}
2020-11-10 20:30:55 +08:00
// 计算所有日志数量
func (this *LogDAO) CountAllLogs() (int64, error) {
return this.Query().
Count()
}
// 列出单页日志
func (this *LogDAO) ListLogs(offset int64, size int64) (result []*Log, err error) {
_, err = this.Query().
Offset(offset).
Limit(size).
Slice(&result).
DescPk().
FindAll()
return
}