Merge pull request !15 from Vivian/dev-IW4W8

This commit is contained in:
Argo 2019-05-05 12:01:19 +08:00
commit d660480716
6 changed files with 22 additions and 11 deletions

View File

@ -19,13 +19,18 @@ namespace Bootstrap.Admin.Query
/// </summary>
public DateTime? OperateTimeEnd { get; set; }
/// <summary>
/// 请求IP地址
/// </summary>
public string AccessIP { get; set; }
/// <summary>
///
/// </summary>
/// <returns></returns>
public QueryData<Trace> RetrieveData()
{
var data = TraceHelper.Retrieves(this, OperateTimeStart, OperateTimeEnd);
var data = TraceHelper.Retrieves(this, OperateTimeStart, OperateTimeEnd, AccessIP);
var ret = new QueryData<Trace>();
ret.total = data.TotalItems;

View File

@ -59,6 +59,10 @@
</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">
<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>

View File

@ -1,13 +1,11 @@
$(function () {
var url = 'api/Traces';
var $data = $('#requestData');
var $dialog = $('#dialogRequestData');
$('.card-body table').smartTable({
url: url,
sortName: 'LogTime',
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: [
{ title: "用户名称", field: "UserName", sortable: true },
{ title: "操作时间", field: "LogTime", sortable: true },

View File

@ -15,13 +15,14 @@ namespace Bootstrap.DataAccess.MongoDB
///
/// </summary>
/// <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
var filterBuilder = Builders<DataAccess.Trace>.Filter;
var filter = filterBuilder.Empty;
if (startTime.HasValue) filter = filterBuilder.Gt("LogTime", startTime.Value);
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()));
// sort

View File

@ -42,7 +42,8 @@ namespace Bootstrap.DataAccess
/// <param name="po"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <param name="ip"></param>
/// <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);
}
}

View File

@ -72,14 +72,16 @@ namespace Bootstrap.DataAccess
/// <param name="po"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <param name="ip"></param>
/// <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");
if (startTime.HasValue) sql.Append("where LogTime > @0", startTime.Value);
if (endTime.HasValue) sql.Append("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()));
sql.Append($"order by {po.Sort} {po.Order}");
if (startTime.HasValue) sql.Where("LogTime > @0", startTime.Value);
if (endTime.HasValue) sql.Where("LogTime < @0", endTime.Value.AddDays(1).AddSeconds(-1));
if (startTime == null && endTime == null) sql.Where("LogTime > @0", DateTime.Today.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
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);
}