修改BUG:程序异常后台清理过期日志配置项程序异常保留时长未生效 closed #ITUOK

#Issue
https://gitee.com/LongbowEnterprise/dashboard/issues?id=ITUOK
This commit is contained in:
Argo Zhang 2019-03-18 17:49:28 +08:00
parent ac8bc82978
commit 72729e577c
3 changed files with 124 additions and 124 deletions

View File

@ -1,4 +1,4 @@
using Longbow.Web.Mvc;
using Longbow.Web.Mvc;
using MongoDB.Driver;
using PetaPoco;
using System;
@ -17,7 +17,7 @@ namespace Bootstrap.DataAccess.MongoDB
{
System.Threading.Tasks.Task.Run(() =>
{
DbManager.Exceptions.DeleteMany(ex => ex.LogTime < DateTime.Now.AddDays(-7));
DbManager.Exceptions.DeleteMany(ex => ex.LogTime < DateTime.Now.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod()));
});
}
@ -27,7 +27,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// <returns></returns>
public override IEnumerable<DataAccess.Exceptions> Retrieves()
{
return DbManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList();
return DbManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Today.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod())).ToList();
}
/// <summary>
@ -71,7 +71,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.RetrieveExceptionsLogPeriod()));
// sort
var sortBuilder = Builders<DataAccess.Exceptions>.Sort;

View File

@ -1,4 +1,4 @@
using Longbow.Web.Mvc;
using Longbow.Web.Mvc;
using PetaPoco;
using System;
using System.Collections.Generic;
@ -96,7 +96,7 @@ namespace Bootstrap.DataAccess
/// 查询一周内所有异常
/// </summary>
/// <returns></returns>
public virtual IEnumerable<Exceptions> Retrieves() => DbManager.Create().Fetch<Exceptions>("select * from Exceptions where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7));
public virtual IEnumerable<Exceptions> Retrieves() => DbManager.Create().Fetch<Exceptions>("select * from Exceptions where LogTime > @0 order by LogTime desc", DateTime.Now.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod()));
/// <summary>
///
@ -110,7 +110,7 @@ namespace Bootstrap.DataAccess
var sql = new Sql("select * from Exceptions");
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.RetrieveExceptionsLogPeriod()));
sql.Append($"order by {po.Sort} {po.Order}");
return DbManager.Create().Page<Exceptions>(po.PageIndex, po.Limit, sql);

View File

@ -117,7 +117,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<KeyValuePair<string, string>> RetrieveApps() => DbContextManager.Create<Dict>().RetrieveApps();
/// <summary>
///
/// 程序异常时长 默认1月
/// </summary>
/// <returns></returns>
public static int RetrieveExceptionsLogPeriod() => DbContextManager.Create<Dict>().RetrieveExceptionsLogPeriod();