管理端全部功能跑通
This commit is contained in:
101
EdgeAPI/internal/db/models/httpdns_access_log_dao.go
Normal file
101
EdgeAPI/internal/db/models/httpdns_access_log_dao.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
type HTTPDNSAccessLogDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSAccessLogDAO() *HTTPDNSAccessLogDAO {
|
||||
return dbs.NewDAO(&HTTPDNSAccessLogDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSAccessLogs",
|
||||
Model: new(HTTPDNSAccessLog),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSAccessLogDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSAccessLogDAO *HTTPDNSAccessLogDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSAccessLogDAO = NewHTTPDNSAccessLogDAO()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAccessLogDAO) CreateLog(tx *dbs.Tx, log *HTTPDNSAccessLog) error {
|
||||
var op = NewHTTPDNSAccessLogOperator()
|
||||
op.RequestId = log.RequestId
|
||||
op.ClusterId = log.ClusterId
|
||||
op.NodeId = log.NodeId
|
||||
op.AppId = log.AppId
|
||||
op.AppName = log.AppName
|
||||
op.Domain = log.Domain
|
||||
op.QType = log.QType
|
||||
op.ClientIP = log.ClientIP
|
||||
op.ClientRegion = log.ClientRegion
|
||||
op.Carrier = log.Carrier
|
||||
op.SDKVersion = log.SDKVersion
|
||||
op.OS = log.OS
|
||||
op.ResultIPs = log.ResultIPs
|
||||
op.Status = log.Status
|
||||
op.ErrorCode = log.ErrorCode
|
||||
op.CostMs = log.CostMs
|
||||
op.CreatedAt = log.CreatedAt
|
||||
op.Day = log.Day
|
||||
op.Summary = log.Summary
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAccessLogDAO) BuildListQuery(tx *dbs.Tx, day string, clusterId int64, nodeId int64, appId string, domain string, status string, keyword string) *dbs.Query {
|
||||
query := this.Query(tx).DescPk()
|
||||
if len(day) > 0 {
|
||||
query = query.Attr("day", day)
|
||||
}
|
||||
if clusterId > 0 {
|
||||
query = query.Attr("clusterId", clusterId)
|
||||
}
|
||||
if nodeId > 0 {
|
||||
query = query.Attr("nodeId", nodeId)
|
||||
}
|
||||
if len(appId) > 0 {
|
||||
query = query.Attr("appId", appId)
|
||||
}
|
||||
if len(domain) > 0 {
|
||||
query = query.Attr("domain", domain)
|
||||
}
|
||||
if len(status) > 0 {
|
||||
query = query.Attr("status", status)
|
||||
}
|
||||
if len(keyword) > 0 {
|
||||
query = query.Where("(summary LIKE :kw OR appName LIKE :kw OR clientIP LIKE :kw OR resultIPs LIKE :kw)").Param("kw", "%"+keyword+"%")
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAccessLogDAO) CountLogs(tx *dbs.Tx, day string, clusterId int64, nodeId int64, appId string, domain string, status string, keyword string) (int64, error) {
|
||||
return this.BuildListQuery(tx, day, clusterId, nodeId, appId, domain, status, keyword).Count()
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAccessLogDAO) ListLogs(tx *dbs.Tx, day string, clusterId int64, nodeId int64, appId string, domain string, status string, keyword string, offset int64, size int64) (result []*HTTPDNSAccessLog, err error) {
|
||||
_, err = this.BuildListQuery(tx, day, clusterId, nodeId, appId, domain, status, keyword).
|
||||
Offset(offset).
|
||||
Limit(size).
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAccessLogDAO) DeleteLogsWithAppId(tx *dbs.Tx, appId string) error {
|
||||
if len(appId) == 0 {
|
||||
return nil
|
||||
}
|
||||
_, err := this.Query(tx).
|
||||
Attr("appId", appId).
|
||||
Delete()
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user