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>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TableName("LoginLogs")]
|
|
|
|
|
public class LoginUser
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string UserName { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DateTime LoginTime { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Ip { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Browser { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string OS { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string City { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Result { get; set; }
|
|
|
|
|
|
2019-05-01 16:46:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
2019-04-27 20:39:24 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string UserAgent { get; set; }
|
|
|
|
|
|
2019-03-04 01:27:04 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </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>
|
|
|
|
|
///
|
|
|
|
|
/// </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
|
|
|
|
{
|
|
|
|
|
var sql = new Sql("select UserName, LoginTime, Ip, Browser, OS, City, Result 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>
|
|
|
|
|
public virtual IEnumerable<LoginUser> Retrieves(DateTime? startTime, DateTime? endTime, string ip) => DbManager.Create().Fetch<LoginUser>();
|
2019-03-04 01:27:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|