2016-11-05 15:26:42 +08:00
|
|
|
|
using Bootstrap.DataAccess;
|
|
|
|
|
using Longbow.Web.Mvc;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Models
|
|
|
|
|
{
|
|
|
|
|
public class QueryLogOption : PaginationOption
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string OperateType { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2016-11-29 12:59:37 +08:00
|
|
|
|
public DateTime OperateTimeStart { get; set; }
|
2016-11-05 15:26:42 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2016-11-29 12:59:37 +08:00
|
|
|
|
public DateTime OperateTimeEnd { get; set; }
|
2016-11-10 12:20:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2016-11-05 15:26:42 +08:00
|
|
|
|
public QueryData<Log> RetrieveData()
|
|
|
|
|
{
|
2016-11-10 12:20:26 +08:00
|
|
|
|
var data = LogHelper.RetrieveLogs();
|
2016-11-05 15:26:42 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(OperateType))
|
|
|
|
|
{
|
|
|
|
|
data = data.Where(t => t.CRUD.ToString().Contains(OperateType));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-29 12:59:37 +08:00
|
|
|
|
if (OperateTimeStart > DateTime.MinValue)
|
2016-11-05 15:26:42 +08:00
|
|
|
|
{
|
2016-11-29 12:59:37 +08:00
|
|
|
|
data = data.Where(t => t.LogTime > OperateTimeStart);
|
2016-11-05 15:26:42 +08:00
|
|
|
|
}
|
2016-11-29 12:59:37 +08:00
|
|
|
|
if (OperateTimeEnd > DateTime.MinValue)
|
2016-11-05 15:26:42 +08:00
|
|
|
|
{
|
2016-11-29 12:59:37 +08:00
|
|
|
|
data = data.Where(t => t.LogTime < OperateTimeEnd.AddDays(1));
|
2016-11-05 15:26:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ret = new QueryData<Log>();
|
|
|
|
|
ret.total = data.Count();
|
2016-11-29 12:59:37 +08:00
|
|
|
|
switch (Sort)
|
|
|
|
|
{
|
|
|
|
|
case "CRUD":
|
|
|
|
|
data = Order == "asc" ? data.OrderBy(t => t.CRUD) : data.OrderByDescending(t => t.CRUD);
|
|
|
|
|
break;
|
|
|
|
|
case "UserName":
|
|
|
|
|
data = Order == "asc" ? data.OrderBy(t => t.UserName) : data.OrderByDescending(t => t.UserName);
|
|
|
|
|
break;
|
|
|
|
|
case "LogTime":
|
|
|
|
|
data = Order == "asc" ? data.OrderBy(t => t.LogTime) : data.OrderByDescending(t => t.LogTime);
|
|
|
|
|
break;
|
|
|
|
|
case "ClientIp":
|
|
|
|
|
data = Order == "asc" ? data.OrderBy(t => t.ClientIp) : data.OrderByDescending(t => t.ClientIp);
|
|
|
|
|
break;
|
|
|
|
|
case "RequestUrl":
|
|
|
|
|
data = Order == "asc" ? data.OrderBy(t => t.RequestUrl) : data.OrderByDescending(t => t.RequestUrl);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-11-05 15:26:42 +08:00
|
|
|
|
ret.rows = data.Skip(Offset).Take(Limit);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-02 15:35:25 +08:00
|
|
|
|
}
|