增加功能:访问日志增加保存时长设置 closed #ITRQL
#Issue https://gitee.com/LongbowEnterprise/dashboard/issues?id=ITRQL
This commit is contained in:
parent
106c77a26c
commit
ac8bc82978
|
@ -13,13 +13,11 @@ namespace Bootstrap.Client.DataAccess
|
|||
/// </summary>
|
||||
public static class DictHelper
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// 缓存索引,BootstrapAdmin后台清理缓存时使用
|
||||
/// </summary>
|
||||
public const string RetrieveDictsDataKey = "BootstrapDict-RetrieveDicts";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -28,6 +26,7 @@ namespace Bootstrap.Client.DataAccess
|
|||
{
|
||||
return RetrieveAppName("个人中心地址");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -36,6 +35,7 @@ namespace Bootstrap.Client.DataAccess
|
|||
{
|
||||
return RetrieveAppName("系统设置地址");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -44,6 +44,7 @@ namespace Bootstrap.Client.DataAccess
|
|||
{
|
||||
return RetrieveAppName("网站标题");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -52,6 +53,7 @@ namespace Bootstrap.Client.DataAccess
|
|||
{
|
||||
return RetrieveAppName("网站页脚");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
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 (startTime == null && endTime == null) filter = filterBuilder.Gt("LogTime", DateTime.Today.AddDays(-7));
|
||||
if (startTime == null && endTime == null) filter = filterBuilder.Gt("LogTime", DateTime.Today.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
||||
|
||||
// sort
|
||||
var sortBuilder = Builders<DataAccess.Trace>.Sort;
|
||||
|
@ -73,7 +73,16 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
{
|
||||
p.Id = null;
|
||||
DbManager.Traces.InsertOne(p);
|
||||
ClearTraces();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void ClearTraces()
|
||||
{
|
||||
System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
DbManager.Traces.DeleteMany(t => t.LogTime < DateTime.Now.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,30 +132,36 @@ namespace Bootstrap.DataAccess
|
|||
/// 程序异常时长 默认1月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveExceptionsLogPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "程序异常保留时长" && d.Define == 0).FirstOrDefault()?.Code, 1);
|
||||
public int RetrieveExceptionsLogPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "系统设置" && d.Name == "程序异常保留时长" && d.Define == 0)?.Code, 1);
|
||||
|
||||
/// <summary>
|
||||
/// 操作日志时长 默认12月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "操作日志保留时长" && d.Define == 0).FirstOrDefault()?.Code, 12);
|
||||
public int RetrieveLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "系统设置" && d.Name == "操作日志保留时长" && d.Define == 0)?.Code, 12);
|
||||
|
||||
/// <summary>
|
||||
/// 登录日志时长 默认12月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveLoginLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "登录日志保留时长" && d.Define == 0).FirstOrDefault()?.Code, 12);
|
||||
public int RetrieveLoginLogsPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "系统设置" && d.Name == "登录日志保留时长" && d.Define == 0)?.Code, 12);
|
||||
|
||||
/// <summary>
|
||||
/// Cookie保存时长 默认7天
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveCookieExpiresPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "Cookie保留时长" && d.Define == 0).FirstOrDefault()?.Code, 7);
|
||||
public int RetrieveCookieExpiresPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "系统设置" && d.Name == "Cookie保留时长" && d.Define == 0)?.Code, 7);
|
||||
|
||||
/// <summary>
|
||||
/// 获得 项目是否获取登录地点 默认为false
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveLocaleIP() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().Where(d => d.Category == "系统设置" && d.Name == "获取IP地点" && d.Define == 0).FirstOrDefault()?.Code, 0);
|
||||
public int RetrieveLocaleIP() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "系统设置" && d.Name == "获取IP地点" && d.Define == 0)?.Code, 0);
|
||||
|
||||
/// <summary>
|
||||
/// 获得 访问日志保留时长 默认为1个月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int RetrieveAccessLogPeriod() => LgbConvert.ReadValue(DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "系统设置" && d.Name == "访问日志保留时长" && d.Define == 0)?.Code, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.Security;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Data;
|
||||
using System.Collections.Generic;
|
||||
|
@ -145,5 +145,11 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int RetrieveLocaleIP() => DbContextManager.Create<Dict>().RetrieveLocaleIP();
|
||||
|
||||
/// <summary>
|
||||
/// 访问日志保留时长 默认一个月
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int RetrieveAccessLogPeriod() => DbContextManager.Create<Dict>().RetrieveAccessLogPeriod();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using Longbow.Web.Mvc;
|
||||
using Longbow.Web.Mvc;
|
||||
using PetaPoco;
|
||||
using System;
|
||||
|
||||
|
@ -57,6 +57,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
if (p == null) throw new ArgumentNullException(nameof(p));
|
||||
DbManager.Create().Save(p);
|
||||
ClearTraces();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -70,10 +71,15 @@ namespace Bootstrap.DataAccess
|
|||
var sql = new Sql("select * 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.AddDays(-7));
|
||||
if (startTime == null && endTime == null) sql.Append("where LogTime > @0", DateTime.Today.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
||||
sql.Append($"order by {po.Sort} {po.Order}");
|
||||
|
||||
return DbManager.Create().Page<Trace>(po.PageIndex, po.Limit, sql);
|
||||
}
|
||||
|
||||
private static void ClearTraces() => System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
DbManager.Create().Execute("delete from Traces where LogTime < @0", DateTime.Now.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
USE [BootstrapAdmin]
|
||||
USE [BootstrapAdmin]
|
||||
GO
|
||||
|
||||
DELETE From Users where ID = 1
|
||||
|
@ -35,6 +35,7 @@ INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'网站设
|
|||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'程序异常保留时长', '1', 0)
|
||||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'操作日志保留时长', '12', 0)
|
||||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'登录日志保留时长', '12', 0)
|
||||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'访问日志保留时长', '1', 0)
|
||||
|
||||
-- 时长单位 天
|
||||
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统设置', N'Cookie保留时长', '7', 0)
|
||||
|
|
|
@ -313,5 +313,12 @@
|
|||
"Name": "获取IP地点",
|
||||
"Code": "0",
|
||||
"Define": NumberInt(0)
|
||||
},
|
||||
{
|
||||
"_id": ObjectId("5bd6c73d5fa31256f77e4a45"),
|
||||
"Category": "系统设置",
|
||||
"Name": "访问日志保留时长",
|
||||
"Code": "1",
|
||||
"Define": NumberInt(0)
|
||||
}
|
||||
]
|
|
@ -32,6 +32,7 @@ INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '网站设置
|
|||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '程序异常保留时长', '1', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '操作日志保留时长', '12', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '登录日志保留时长', '12', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '访问日志保留时长', '1', 0);
|
||||
|
||||
-- 时长单位 天
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', 'Cookie保留时长', '7', 0);
|
||||
|
|
|
@ -32,6 +32,7 @@ INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('网站设置', '前台
|
|||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '程序异常保留时长', '1', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '操作日志保留时长', '12', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '登录日志保留时长', '12', 0);
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', '访问日志保留时长', '1', 0);
|
||||
|
||||
-- 时长单位 天
|
||||
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统设置', 'Cookie保留时长', '7', 0);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
DELETE From Users where ID = 1;
|
||||
DELETE From Users where ID = 1;
|
||||
-- ADMIN/123789
|
||||
INSERT INTO Users (ID, UserName, [Password], PassSalt, DisplayName, RegisterTime, ApprovedTime,ApprovedBy, [Description]) values (1, 'Admin', 'Es7WVgNsJuELwWK8daCqufUBknCsSC0IYDphQZAiGOo=', 'W5vpBEOYRGHkQXatN0t+ECM/U8cHDuEgrq56+zZBk4J481xH', 'Administrator', datetime(CURRENT_TIMESTAMP, 'localtime'), datetime(CURRENT_TIMESTAMP, 'localtime'), 'system', '系统默认创建');
|
||||
|
||||
|
@ -30,6 +30,7 @@ INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '
|
|||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', '程序异常保留时长', '1', 0);
|
||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', '操作日志保留时长', '12', 0);
|
||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', '登录日志保留时长', '12', 0);
|
||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', '访问日志保留时长', '1', 0);
|
||||
|
||||
-- 时长单位 天
|
||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统设置', 'Cookie保留时长', '7', 0);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Linq;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
|
@ -131,5 +131,12 @@ namespace Bootstrap.DataAccess
|
|||
var dict = new Dict();
|
||||
Assert.Equal(0, dict.RetrieveLocaleIP());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrieveAccessLogPeriod_Ok()
|
||||
{
|
||||
var dict = new Dict();
|
||||
Assert.Equal(1, dict.RetrieveAccessLogPeriod());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue