fix api日志增加时间筛选
This commit is contained in:
@@ -1,14 +1,27 @@
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.Core.CustomClass;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Common.ApiLog.Request
|
||||
namespace Dlhis.Common.ApiLog.Request;
|
||||
|
||||
public class ApiLogRequest : PageDto, IValidatableObject
|
||||
{
|
||||
public class ApiLogRequest : PageDto
|
||||
/// <summary>
|
||||
/// 日志级别 LogLevel
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(LogLevel))]
|
||||
public LogLevel? Level { get; set; }
|
||||
|
||||
|
||||
public DateTimePeriod SearchDateTimePeriod { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志级别 LogLevel
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(LogLevel))]
|
||||
public LogLevel? Level { get; set; }
|
||||
if (SearchDateTimePeriod != null && SearchDateTimePeriod.End.HasValue)
|
||||
{
|
||||
SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.AddDays(1).AddSeconds(-1);
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace Dlhis.Common.ApiLog.Services
|
||||
public async Task<Pagination<ApiLogResponse>> GetLogsAsync(ApiLogRequest request)
|
||||
{
|
||||
var logs = await _dbContext.ChangeDb("log").Queryable<ApiLogEntity>()
|
||||
.WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true && request.SearchDateTimePeriod?.End.HasValue == true,
|
||||
x => x._ts >= request.SearchDateTimePeriod.Start && x._ts <= request.SearchDateTimePeriod.End)
|
||||
.WhereIF(request.Search.IsPresent(), x => x.Message.Contains(request.Search))
|
||||
.WhereIF(request.Level.HasValue, x => x.Level == request.Level)
|
||||
.OrderBy(x => x.Timestamp, OrderByType.Desc)
|
||||
|
||||
Reference in New Issue
Block a user