feat:完善项目
This commit is contained in:
57
app/api/controller/logs.go
Normal file
57
app/api/controller/logs.go
Normal file
@ -0,0 +1,57 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/tools/ip"
|
||||
)
|
||||
|
||||
type Log struct{ *Platform }
|
||||
|
||||
type LogHandle func(session *service.Session) *Log
|
||||
|
||||
type (
|
||||
// LogForLogin 登录日志
|
||||
LogForLogin struct {
|
||||
*model.SysUserLoginLogInfo
|
||||
IPAddress string `json:"ip_address"`
|
||||
}
|
||||
)
|
||||
|
||||
// Login 登录日志
|
||||
func (c *Log) Login(name string, page, pageSize int) (*ReturnPages, error) {
|
||||
mSysUserLoginLogs := model.NewSysUserLoginLog()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("l.tenant_id", c.TenantID))
|
||||
}
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("u.name", name))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mSysUserLoginLogs.Logs(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*LogForLogin, 0)
|
||||
|
||||
for _, v := range out {
|
||||
ipAddress, _ := ip.Find(v.IP)
|
||||
|
||||
list = append(list, &LogForLogin{
|
||||
SysUserLoginLogInfo: v, IPAddress: string(ipAddress),
|
||||
})
|
||||
}
|
||||
return &ReturnPages{Data: list, Page: page, TotalCount: count}, nil
|
||||
}
|
||||
|
||||
func NewLog() LogHandle {
|
||||
return func(session *service.Session) *Log {
|
||||
return &Log{Platform: &Platform{Session: session}}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user