feat(#IWYJR): 登录日志增加时间段过滤条件
#Comment comment #IWYJR #Issue close https://gitee.com/LongbowEnterprise/dashboard/issues?id=IWYJR
This commit is contained in:
parent
571b593e7b
commit
0391a20b57
|
@ -1,5 +1,6 @@
|
||||||
using Bootstrap.DataAccess;
|
using Bootstrap.DataAccess;
|
||||||
using Longbow.Web.Mvc;
|
using Longbow.Web.Mvc;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Bootstrap.Admin.Query
|
namespace Bootstrap.Admin.Query
|
||||||
{
|
{
|
||||||
|
@ -8,6 +9,16 @@ namespace Bootstrap.Admin.Query
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class QueryLoginOption : PaginationOption
|
public class QueryLoginOption : PaginationOption
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? StartTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? EndTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 登录IP地址
|
/// 登录IP地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -19,7 +30,7 @@ namespace Bootstrap.Admin.Query
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public QueryData<LoginUser> RetrieveData()
|
public QueryData<LoginUser> RetrieveData()
|
||||||
{
|
{
|
||||||
var data = LoginHelper.Retrieves(this, LoginIP);
|
var data = LoginHelper.RetrievePages(this, StartTime, EndTime, LoginIP);
|
||||||
return new QueryData<LoginUser>
|
return new QueryData<LoginUser>
|
||||||
{
|
{
|
||||||
total = data.TotalItems,
|
total = data.TotalItems,
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
}
|
}
|
||||||
@section css {
|
@section css {
|
||||||
<environment include="Development">
|
<environment include="Development">
|
||||||
|
<link href="~/lib/datetimepicker/css//bootstrap-datetimepicker.css" rel="stylesheet" />
|
||||||
<link href="~/lib/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
|
<link href="~/lib/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
|
||||||
</environment>
|
</environment>
|
||||||
<environment exclude="Development">
|
<environment exclude="Development">
|
||||||
|
<link href="~/lib/datetimepicker/css//bootstrap-datetimepicker.min.css" rel="stylesheet" />
|
||||||
<link href="~/lib/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
|
<link href="~/lib/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
|
||||||
</environment>
|
</environment>
|
||||||
}
|
}
|
||||||
|
@ -14,11 +16,14 @@
|
||||||
<environment include="Development">
|
<environment include="Development">
|
||||||
<script src="~/lib/bootstrap-table/bootstrap-table.js"></script>
|
<script src="~/lib/bootstrap-table/bootstrap-table.js"></script>
|
||||||
<script src="~/lib/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
|
<script src="~/lib/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
|
||||||
|
<script src="~/lib/datetimepicker/js/bootstrap-datetimepicker.js"></script>
|
||||||
</environment>
|
</environment>
|
||||||
<environment exclude="Development">
|
<environment exclude="Development">
|
||||||
<script src="~/lib/bootstrap-table/bootstrap-table.min.js"></script>
|
<script src="~/lib/bootstrap-table/bootstrap-table.min.js"></script>
|
||||||
<script src="~/lib/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
|
<script src="~/lib/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
|
||||||
|
<script src="~/lib/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
|
||||||
</environment>
|
</environment>
|
||||||
|
<script src="~/lib/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
|
||||||
<script src="~/js/logins.js" asp-append-version="true"></script>
|
<script src="~/js/logins.js" asp-append-version="true"></script>
|
||||||
}
|
}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
@ -26,11 +31,35 @@
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form class="form-inline">
|
<form class="form-inline">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-sm-6 col-md-auto">
|
<div class="form-group col-sm-auto">
|
||||||
|
<label class="control-label" for="txt_operate_start">起始时间</label>
|
||||||
|
<div class="input-group date">
|
||||||
|
<input id="txt_operate_start" class="form-control" size="16" type="text" value="" readonly>
|
||||||
|
<div class="input-group-append input-group-addon">
|
||||||
|
<div class="input-group-text"><span class="fa fa-times"></span></div>
|
||||||
|
</div>
|
||||||
|
<div class="input-group-append input-group-addon">
|
||||||
|
<div class="input-group-text"><span class="fa fa-calendar"></span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-sm-auto">
|
||||||
|
<label class="control-label" for="txt_operate_end">终止时间</label>
|
||||||
|
<div class="input-group date">
|
||||||
|
<input id="txt_operate_end" class="form-control" size="16" type="text" value="" readonly>
|
||||||
|
<div class="input-group-append input-group-addon">
|
||||||
|
<div class="input-group-text"><span class="fa fa-times"></span></div>
|
||||||
|
</div>
|
||||||
|
<div class="input-group-append input-group-addon">
|
||||||
|
<div class="input-group-text"><span class="fa fa-calendar"></span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-sm-auto">
|
||||||
<label class="control-label" for="txt_ip">请求IP</label>
|
<label class="control-label" for="txt_ip">请求IP</label>
|
||||||
<input type="text" class="form-control" id="txt_ip" />
|
<input type="text" class="form-control" id="txt_ip" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-sm-6 col-md-auto flex-md-fill justify-content-md-end">
|
<div class="form-group col-sm-auto flex-md-fill justify-content-md-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>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
// 登录日志
|
// 登录日志
|
||||||
$(function () {
|
$(function () {
|
||||||
var apiUrl = "api/Login";
|
var apiUrl = "api/Login";
|
||||||
var $table = $('table').smartTable({
|
var $table = $('.card-body table');
|
||||||
|
$table.smartTable({
|
||||||
url: apiUrl,
|
url: apiUrl,
|
||||||
showToggle: false,
|
showToggle: false,
|
||||||
showRefresh: false,
|
showRefresh: false,
|
||||||
showColumns: false,
|
showColumns: false,
|
||||||
queryParams: function (params) { return $.extend(params, { loginIp: $('#txt_ip').val() }); },
|
sortName: 'LoginTime',
|
||||||
|
sortOrder: "desc",
|
||||||
|
queryParams: function (params) { return $.extend(params, { startTime: $("#txt_operate_start").val(), endTime: $("#txt_operate_end").val(), loginIp: $('#txt_ip').val() }); },
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
title: "序号", formatter: function (value, row, index) {
|
title: "序号", formatter: function (value, row, index) {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess.MongoDB
|
namespace Bootstrap.DataAccess.MongoDB
|
||||||
|
@ -27,22 +28,35 @@ namespace Bootstrap.DataAccess.MongoDB
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="po"></param>
|
/// <param name="po"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Page<DataAccess.LoginUser> Retrieves(PaginationOption po, string ip)
|
public override Page<DataAccess.LoginUser> RetrieveByPages(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip)
|
||||||
{
|
{
|
||||||
var logs = DbManager.LoginUsers
|
var logs = Retrieves(startTime, endTime, ip);
|
||||||
.Find(Builders<DataAccess.LoginUser>.Filter.Eq("Ip", ip))
|
|
||||||
.Sort(Builders<DataAccess.LoginUser>.Sort.Descending(t => t.LoginTime))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
return new Page<DataAccess.LoginUser>()
|
return new Page<DataAccess.LoginUser>()
|
||||||
{
|
{
|
||||||
Context = logs,
|
Context = logs,
|
||||||
CurrentPage = po.PageIndex,
|
CurrentPage = po.PageIndex,
|
||||||
ItemsPerPage = po.Limit,
|
ItemsPerPage = po.Limit,
|
||||||
TotalItems = logs.Count,
|
TotalItems = logs.Count(),
|
||||||
TotalPages = (long)Math.Ceiling(logs.Count * 1.0 / po.Limit),
|
TotalPages = (long)Math.Ceiling(logs.Count() * 1.0 / po.Limit),
|
||||||
Items = logs.Skip(po.Offset).Take(po.Limit).ToList()
|
Items = logs.Skip(po.Offset).Take(po.Limit).ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取所有登录数据
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.LoginUser> Retrieves(DateTime? startTime, DateTime? endTime, string ip)
|
||||||
|
{
|
||||||
|
var filterBuilder = Builders<DataAccess.LoginUser>.Filter;
|
||||||
|
var filter = filterBuilder.Empty;
|
||||||
|
if (startTime.HasValue) filter = filterBuilder.Gte(l => l.LoginTime, startTime.Value);
|
||||||
|
if (endTime.HasValue) filter = filterBuilder.Lt(l => l.LoginTime, endTime.Value.AddDays(1));
|
||||||
|
if (!string.IsNullOrEmpty(ip)) filter = filterBuilder.Eq(l => l.Ip, ip);
|
||||||
|
|
||||||
|
return DbManager.LoginUsers
|
||||||
|
.Find(filter)
|
||||||
|
.Sort(Builders<DataAccess.LoginUser>.Sort.Descending(t => t.LoginTime)).ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using Longbow.Data;
|
using Longbow.Data;
|
||||||
using Longbow.Web.Mvc;
|
using Longbow.Web.Mvc;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
|
@ -17,10 +19,24 @@ namespace Bootstrap.DataAccess
|
||||||
public static bool Log(LoginUser user) => DbContextManager.Create<LoginUser>().Log(user);
|
public static bool Log(LoginUser user) => DbContextManager.Create<LoginUser>().Log(user);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询所有登录日志
|
/// 查询指定页码登录日志
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="po"></param>
|
/// <param name="po"></param>
|
||||||
|
/// <param name="startTime"></param>
|
||||||
|
/// <param name="endTime"></param>
|
||||||
/// <param name="ip"></param>
|
/// <param name="ip"></param>
|
||||||
public static Page<LoginUser> Retrieves(PaginationOption po, string ip) => DbContextManager.Create<LoginUser>().Retrieves(po, ip);
|
public static Page<LoginUser> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip) => DbContextManager.Create<LoginUser>().RetrieveByPages(po, startTime, endTime, ip);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有登录日志
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startTime"></param>
|
||||||
|
/// <param name="endTime"></param>
|
||||||
|
/// <param name="ip"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<LoginUser> RetrieveAll(DateTime? startTime, DateTime? endTime, string ip)
|
||||||
|
{
|
||||||
|
return DbContextManager.Create<LoginUser>().Retrieves(startTime, endTime, ip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using Longbow.Web.Mvc;
|
using Longbow.Web.Mvc;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
|
@ -71,14 +72,24 @@ namespace Bootstrap.DataAccess
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="po"></param>
|
/// <param name="po"></param>
|
||||||
|
/// <param name="startTime"></param>
|
||||||
|
/// <param name="endTime"></param>
|
||||||
/// <param name="ip"></param>
|
/// <param name="ip"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual Page<LoginUser> Retrieves(PaginationOption po, string ip)
|
public virtual Page<LoginUser> RetrieveByPages(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip)
|
||||||
{
|
{
|
||||||
var sql = new Sql("select UserName, LoginTime, Ip, Browser, OS, City, Result from LoginLogs");
|
var sql = new Sql("select UserName, LoginTime, Ip, Browser, OS, City, Result from LoginLogs");
|
||||||
|
if (startTime.HasValue) sql.Where("LoginTime >= @0", startTime.Value);
|
||||||
|
if (endTime.HasValue) sql.Where("LoginTime < @0", endTime.Value.AddDays(1));
|
||||||
if (!string.IsNullOrEmpty(ip)) sql.Where("ip = @0", ip);
|
if (!string.IsNullOrEmpty(ip)) sql.Where("ip = @0", ip);
|
||||||
sql.OrderBy("LoginTime desc");
|
sql.OrderBy($"{po.Sort} {po.Order}");
|
||||||
return DbManager.Create().Page<LoginUser>(po.PageIndex, po.Limit, sql);
|
return DbManager.Create().Page<LoginUser>(po.PageIndex, po.Limit, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取所有登录数据
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<LoginUser> Retrieves(DateTime? startTime, DateTime? endTime, string ip) => DbManager.Create().Fetch<LoginUser>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,11 +172,18 @@ namespace Bootstrap.DataAccess.SqlServer
|
||||||
Assert.True(UserHelper.ResetPassword(newUser.UserName, "123"));
|
Assert.True(UserHelper.ResetPassword(newUser.UserName, "123"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RetrievePageLoginUsers_Ok()
|
||||||
|
{
|
||||||
|
var data = LoginHelper.RetrievePages(new PaginationOption() { Limit = 20, Offset = 0 }, null, null, "");
|
||||||
|
Assert.NotNull(data.Items);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RetrieveLoginUsers_Ok()
|
public void RetrieveLoginUsers_Ok()
|
||||||
{
|
{
|
||||||
var data = LoginHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0 }, "");
|
var data = LoginHelper.RetrieveAll(null, null, "");
|
||||||
Assert.NotNull(data.Items);
|
Assert.NotNull(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue