46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package model
|
|
|
|
import (
|
|
"SciencesServer/app/common/model"
|
|
"SciencesServer/serve/orm"
|
|
"fmt"
|
|
)
|
|
|
|
type SysUserLoginLog struct {
|
|
*model.SysUserLoginLog
|
|
}
|
|
|
|
type SysUserLoginLogInfo struct {
|
|
*model.SysUserLoginLog
|
|
TenantName string `json:"tenant_name"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
// Logs 日志信息
|
|
func (m *SysUserLoginLog) Logs(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysUserLoginLogInfo, error) {
|
|
db := orm.GetDB().Table(m.TableName()+" AS l").
|
|
Select("l.*, t.name AS tenant_name, u.name AS username").
|
|
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON l.tenant_id = t.id", NewSysTenant().TableName())).
|
|
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON l.uid = u.uuid", NewSysUser().TableName())).
|
|
Where("l.is_deleted = ?", model.DeleteStatusForNot)
|
|
|
|
if len(where) > 0 {
|
|
for _, wo := range where {
|
|
db = db.Where(wo.Condition, wo.Value)
|
|
}
|
|
}
|
|
out := make([]*SysUserLoginLogInfo, 0)
|
|
|
|
if err := db.Count(count).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := db.Order("l.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func NewSysUserLoginLog() *SysUserLoginLog {
|
|
return &SysUserLoginLog{SysUserLoginLog: model.NewSysUserLoginLog()}
|
|
}
|