2019-05-01 16:46:24 +08:00
|
|
|
|
using Longbow.Web.Mvc;
|
2019-05-01 12:07:00 +08:00
|
|
|
|
using PetaPoco;
|
2019-03-04 01:27:04 +08:00
|
|
|
|
using System;
|
2019-05-24 12:27:14 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-03-04 01:27:04 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 登录用户信息实体类
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
[TableName("LoginLogs")]
|
|
|
|
|
public class LoginUser
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 获得/设置 Id
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 获得/设置 用户名
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string UserName { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 获得/设置 登录时间
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public DateTime LoginTime { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 获得/设置 登录IP地址
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string Ip { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 获得/设置 登录浏览器
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string Browser { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 获得/设置 登录操作系统
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string OS { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 获得/设置 登录地点
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string City { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 获得/设置 登录是否成功
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string Result { get; set; }
|
|
|
|
|
|
2019-05-01 16:46:24 +08:00
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 获得/设置 用户 UserAgent
|
2019-04-27 20:39:24 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string UserAgent { get; set; }
|
|
|
|
|
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 保存登录用户数据
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public virtual bool Log(LoginUser user)
|
|
|
|
|
{
|
|
|
|
|
var db = DbManager.Create();
|
|
|
|
|
db.Save(user);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-03-04 13:21:04 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-07-27 16:17:33 +08:00
|
|
|
|
/// 获得登录用户的分页数据
|
2019-03-04 13:21:04 +08:00
|
|
|
|
/// </summary>
|
2019-05-01 12:07:00 +08:00
|
|
|
|
/// <param name="po"></param>
|
2019-05-24 12:27:14 +08:00
|
|
|
|
/// <param name="startTime"></param>
|
|
|
|
|
/// <param name="endTime"></param>
|
2019-05-04 16:44:30 +08:00
|
|
|
|
/// <param name="ip"></param>
|
2019-03-04 13:21:04 +08:00
|
|
|
|
/// <returns></returns>
|
2019-05-24 12:27:14 +08:00
|
|
|
|
public virtual Page<LoginUser> RetrieveByPages(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip)
|
2019-05-04 16:44:30 +08:00
|
|
|
|
{
|
2019-07-27 16:17:33 +08:00
|
|
|
|
var sql = new Sql("select * from LoginLogs");
|
2019-05-24 12:27:14 +08:00
|
|
|
|
if (startTime.HasValue) sql.Where("LoginTime >= @0", startTime.Value);
|
|
|
|
|
if (endTime.HasValue) sql.Where("LoginTime < @0", endTime.Value.AddDays(1));
|
2019-05-04 16:44:30 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(ip)) sql.Where("ip = @0", ip);
|
2019-05-24 12:27:14 +08:00
|
|
|
|
sql.OrderBy($"{po.Sort} {po.Order}");
|
2019-05-04 16:44:30 +08:00
|
|
|
|
return DbManager.Create().Page<LoginUser>(po.PageIndex, po.Limit, sql);
|
|
|
|
|
}
|
2019-05-24 12:27:14 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有登录数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-05-25 14:52:14 +08:00
|
|
|
|
public virtual IEnumerable<LoginUser> RetrieveAll(DateTime? startTime, DateTime? endTime, string ip)
|
|
|
|
|
{
|
|
|
|
|
var sql = new Sql("select UserName, LoginTime, Ip, Browser, OS, City, Result from LoginLogs");
|
|
|
|
|
if (startTime.HasValue) sql.Where("LoginTime >= @0", startTime.Value);
|
|
|
|
|
if (endTime.HasValue) sql.Where("LoginTime < @0", endTime.Value.AddDays(1));
|
|
|
|
|
if (!string.IsNullOrEmpty(ip)) sql.Where("ip = @0", ip);
|
|
|
|
|
sql.OrderBy($"LoginTime");
|
|
|
|
|
return DbManager.Create().Fetch<LoginUser>(sql);
|
|
|
|
|
}
|
2019-03-04 01:27:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|