Merge pull request !15 from Vivian/dev-IW4W8
This commit is contained in:
commit
d660480716
|
@ -19,13 +19,18 @@ namespace Bootstrap.Admin.Query
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? OperateTimeEnd { get; set; }
|
public DateTime? OperateTimeEnd { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求IP地址
|
||||||
|
/// </summary>
|
||||||
|
public string AccessIP { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public QueryData<Trace> RetrieveData()
|
public QueryData<Trace> RetrieveData()
|
||||||
{
|
{
|
||||||
var data = TraceHelper.Retrieves(this, OperateTimeStart, OperateTimeEnd);
|
var data = TraceHelper.Retrieves(this, OperateTimeStart, OperateTimeEnd, AccessIP);
|
||||||
|
|
||||||
var ret = new QueryData<Trace>();
|
var ret = new QueryData<Trace>();
|
||||||
ret.total = data.TotalItems;
|
ret.total = data.TotalItems;
|
||||||
|
|
|
@ -59,6 +59,10 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group col-sm-auto">
|
||||||
|
<label class="control-label" for="txt_ip">请求IP</label>
|
||||||
|
<input type="text" class="form-control" id="txt_ip" />
|
||||||
|
</div>
|
||||||
<div class="form-group col-sm-auto flex-sm-fill justify-content-sm-end">
|
<div class="form-group col-sm-auto flex-sm-fill justify-content-sm-end">
|
||||||
<button type="button" id="btn_query" class="btn btn-primary btn-fill"><i class="fa fa-search" aria-hidden="true"></i><span>查询</span></button>
|
<button type="button" id="btn_query" class="btn btn-primary btn-fill"><i class="fa fa-search" aria-hidden="true"></i><span>查询</span></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
$(function () {
|
$(function () {
|
||||||
var url = 'api/Traces';
|
var url = 'api/Traces';
|
||||||
var $data = $('#requestData');
|
|
||||||
var $dialog = $('#dialogRequestData');
|
|
||||||
|
|
||||||
$('.card-body table').smartTable({
|
$('.card-body table').smartTable({
|
||||||
url: url,
|
url: url,
|
||||||
sortName: 'LogTime',
|
sortName: 'LogTime',
|
||||||
sortOrder: 'desc',
|
sortOrder: 'desc',
|
||||||
queryParams: function (params) { return $.extend(params, { OperateTimeStart: $("#txt_operate_start").val(), OperateTimeEnd: $("#txt_operate_end").val() }); },
|
queryParams: function (params) { return $.extend(params, { OperateTimeStart: $("#txt_operate_start").val(), OperateTimeEnd: $("#txt_operate_end").val(), AccessIP: $('#txt_ip').val() }); },
|
||||||
columns: [
|
columns: [
|
||||||
{ title: "用户名称", field: "UserName", sortable: true },
|
{ title: "用户名称", field: "UserName", sortable: true },
|
||||||
{ title: "操作时间", field: "LogTime", sortable: true },
|
{ title: "操作时间", field: "LogTime", sortable: true },
|
||||||
|
|
|
@ -15,13 +15,14 @@ namespace Bootstrap.DataAccess.MongoDB
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Page<DataAccess.Trace> Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime)
|
public override Page<DataAccess.Trace> Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip)
|
||||||
{
|
{
|
||||||
// filter
|
// filter
|
||||||
var filterBuilder = Builders<DataAccess.Trace>.Filter;
|
var filterBuilder = Builders<DataAccess.Trace>.Filter;
|
||||||
var filter = filterBuilder.Empty;
|
var filter = filterBuilder.Empty;
|
||||||
if (startTime.HasValue) filter = filterBuilder.Gt("LogTime", startTime.Value);
|
if (startTime.HasValue) filter = filterBuilder.Gt("LogTime", startTime.Value);
|
||||||
if (endTime.HasValue) filter = filterBuilder.Lt("LogTime", endTime.Value.AddDays(1).AddSeconds(-1));
|
if (endTime.HasValue) filter = filterBuilder.Lt("LogTime", endTime.Value.AddDays(1).AddSeconds(-1));
|
||||||
|
if (!string.IsNullOrEmpty(ip)) filter = filterBuilder.Eq("Ip", ip);
|
||||||
if (startTime == null && endTime == null) filter = filterBuilder.Gt("LogTime", DateTime.Today.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
if (startTime == null && endTime == null) filter = filterBuilder.Gt("LogTime", DateTime.Today.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
||||||
|
|
||||||
// sort
|
// sort
|
||||||
|
|
|
@ -42,7 +42,8 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="po"></param>
|
/// <param name="po"></param>
|
||||||
/// <param name="startTime"></param>
|
/// <param name="startTime"></param>
|
||||||
/// <param name="endTime"></param>
|
/// <param name="endTime"></param>
|
||||||
|
/// <param name="ip"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Page<Trace> Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime) => DbContextManager.Create<Trace>().Retrieves(po, startTime, endTime);
|
public static Page<Trace> Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip) => DbContextManager.Create<Trace>().Retrieves(po, startTime, endTime, ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,14 +72,16 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="po"></param>
|
/// <param name="po"></param>
|
||||||
/// <param name="startTime"></param>
|
/// <param name="startTime"></param>
|
||||||
/// <param name="endTime"></param>
|
/// <param name="endTime"></param>
|
||||||
|
/// <param name="ip"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual Page<Trace> Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime)
|
public virtual Page<Trace> Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip)
|
||||||
{
|
{
|
||||||
var sql = new Sql("select UserName, LogTime, IP, Browser, OS, City, RequestUrl from Traces");
|
var sql = new Sql("select UserName, LogTime, IP, Browser, OS, City, RequestUrl from Traces");
|
||||||
if (startTime.HasValue) sql.Append("where LogTime > @0", startTime.Value);
|
if (startTime.HasValue) sql.Where("LogTime > @0", startTime.Value);
|
||||||
if (endTime.HasValue) sql.Append("where LogTime < @0", endTime.Value.AddDays(1).AddSeconds(-1));
|
if (endTime.HasValue) sql.Where("LogTime < @0", endTime.Value.AddDays(1).AddSeconds(-1));
|
||||||
if (startTime == null && endTime == null) sql.Append("where LogTime > @0", DateTime.Today.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
if (startTime == null && endTime == null) sql.Where("LogTime > @0", DateTime.Today.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
||||||
sql.Append($"order by {po.Sort} {po.Order}");
|
if (!string.IsNullOrEmpty(ip)) sql.Where("IP = @0", ip);
|
||||||
|
sql.OrderBy($"{po.Sort} {po.Order}");
|
||||||
|
|
||||||
return DbManager.Create().Page<Trace>(po.PageIndex, po.Limit, sql);
|
return DbManager.Create().Page<Trace>(po.PageIndex, po.Limit, sql);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue