first commit
This commit is contained in:
54
repositories/com_repositories.go
Normal file
54
repositories/com_repositories.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"Quincy_admin/schemas"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type CommonRepository struct {
|
||||
db *sqlx.DB
|
||||
}
|
||||
|
||||
func NewCommonRepository(db *sqlx.DB) *CommonRepository {
|
||||
return &CommonRepository{db: db}
|
||||
}
|
||||
|
||||
// GetLoginLogList 获取登录日志列表
|
||||
func (r *CommonRepository) GetLoginLogList(req *schemas.LoginLogListRequest) ([]*schemas.LoginLog, int64, error) {
|
||||
offset := (req.PageIndex - 1) * req.PageSize
|
||||
|
||||
// 查询总数
|
||||
countQuery := `
|
||||
SELECT COUNT(*) FROM admin_login_logs WHERE isdel = 0 AND (? IS NULL OR create_time >= ?) AND (? IS NULL OR create_time < ?)
|
||||
`
|
||||
var total int64
|
||||
err := r.db.QueryRow(countQuery, req.StartDate.Time, req.StartDate.Time, req.EndDate.Time, req.EndDate.Time).Scan(&total)
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
tb1.id, tb1.username, tb1.user_id, tb1.ip_address, tb1.location, tb1.user_agent, tb1.status, tb1.failure_reason, tb1.login_time
|
||||
FROM
|
||||
admin_login_logs tb1
|
||||
WHERE
|
||||
tb1.isdel = 0
|
||||
AND (? IS NULL OR tb1.create_time >= ?)
|
||||
AND (? IS NULL OR tb1.create_time < ?)
|
||||
ORDER BY
|
||||
id DESC
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
|
||||
var items []*schemas.LoginLog
|
||||
err = r.db.Select(&items, query, req.StartDate.Time, req.StartDate.Time, req.EndDate.Time, req.EndDate.Time, req.PageSize, offset)
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return items, total, nil
|
||||
}
|
||||
Reference in New Issue
Block a user