From 06cfcc6391e6a6b3e718a6381c04f8df8786aa21 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 4 May 2019 17:13:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(#IW4W8):=20=E8=AE=BF=E9=97=AE=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=A2=9E=E5=8A=A0IP=E5=9C=B0=E5=9D=80=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Comment comment #IW4W8 #Issue close https://gitee.com/LongbowEnterprise/dashboard/issues?id=IW4W8 --- Bootstrap.Admin/Query/QueryTraceOptions.cs | 7 ++++++- Bootstrap.Admin/Views/Admin/Traces.cshtml | 4 ++++ Bootstrap.Admin/wwwroot/js/traces.js | 4 +--- Bootstrap.DataAccess.MongoDB/Trace.cs | 3 ++- Bootstrap.DataAccess/Helper/TraceHelper.cs | 3 ++- Bootstrap.DataAccess/Trace.cs | 12 +++++++----- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Bootstrap.Admin/Query/QueryTraceOptions.cs b/Bootstrap.Admin/Query/QueryTraceOptions.cs index abf70168..37793641 100644 --- a/Bootstrap.Admin/Query/QueryTraceOptions.cs +++ b/Bootstrap.Admin/Query/QueryTraceOptions.cs @@ -19,13 +19,18 @@ namespace Bootstrap.Admin.Query /// public DateTime? OperateTimeEnd { get; set; } + /// + /// 请求IP地址 + /// + public string AccessIP { get; set; } + /// /// /// /// public QueryData RetrieveData() { - var data = TraceHelper.Retrieves(this, OperateTimeStart, OperateTimeEnd); + var data = TraceHelper.Retrieves(this, OperateTimeStart, OperateTimeEnd, AccessIP); var ret = new QueryData(); ret.total = data.TotalItems; diff --git a/Bootstrap.Admin/Views/Admin/Traces.cshtml b/Bootstrap.Admin/Views/Admin/Traces.cshtml index 384dfc37..92fc80e0 100644 --- a/Bootstrap.Admin/Views/Admin/Traces.cshtml +++ b/Bootstrap.Admin/Views/Admin/Traces.cshtml @@ -59,6 +59,10 @@ +
+ + +
diff --git a/Bootstrap.Admin/wwwroot/js/traces.js b/Bootstrap.Admin/wwwroot/js/traces.js index 0694b6c8..44061abb 100644 --- a/Bootstrap.Admin/wwwroot/js/traces.js +++ b/Bootstrap.Admin/wwwroot/js/traces.js @@ -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 }, diff --git a/Bootstrap.DataAccess.MongoDB/Trace.cs b/Bootstrap.DataAccess.MongoDB/Trace.cs index 89d2e7b5..8ccb292c 100644 --- a/Bootstrap.DataAccess.MongoDB/Trace.cs +++ b/Bootstrap.DataAccess.MongoDB/Trace.cs @@ -15,13 +15,14 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override Page Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime) + public override Page Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip) { // filter var filterBuilder = Builders.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 diff --git a/Bootstrap.DataAccess/Helper/TraceHelper.cs b/Bootstrap.DataAccess/Helper/TraceHelper.cs index 1c54eaa4..6c019993 100644 --- a/Bootstrap.DataAccess/Helper/TraceHelper.cs +++ b/Bootstrap.DataAccess/Helper/TraceHelper.cs @@ -42,7 +42,8 @@ namespace Bootstrap.DataAccess /// /// /// + /// /// - public static Page Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime) => DbContextManager.Create().Retrieves(po, startTime, endTime); + public static Page Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip) => DbContextManager.Create().Retrieves(po, startTime, endTime, ip); } } diff --git a/Bootstrap.DataAccess/Trace.cs b/Bootstrap.DataAccess/Trace.cs index 7e3d4c4f..f7b1ba14 100644 --- a/Bootstrap.DataAccess/Trace.cs +++ b/Bootstrap.DataAccess/Trace.cs @@ -72,14 +72,16 @@ namespace Bootstrap.DataAccess /// /// /// + /// /// - public virtual Page Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime) + public virtual Page 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(po.PageIndex, po.Limit, sql); }