using YBEE.EQM.Core;
namespace YBEE.EQM.Application
{
///
/// 日志管理服务
///
public class SysLogService : ISysLogService, ITransient
{
private readonly IRepository _rep; // 操作日志表仓储
public SysLogService(IRepository rep)
{
_rep = rep;
}
#region 异常日志
///
/// 分页查询异常日志
///
///
///
//[HttpGet("sysExLog/page")]
public async Task> QueryLogExPageList(SysLogExPageInput input)
{
var name = !string.IsNullOrEmpty(input.Name?.Trim());
var className = !string.IsNullOrEmpty(input.ClassName?.Trim());
var methodName = !string.IsNullOrEmpty(input.MethodName?.Trim());
var exceptionMsg = !string.IsNullOrEmpty(input.ExceptionMsg?.Trim());
var searchBeginTime = !string.IsNullOrEmpty(input.SearchBeginTime?.Trim());
var exLogs = await _rep.Change().DetachedEntities
.Where((name, u => EF.Functions.Like(u.Name, $"%{input.Name.Trim()}%")))
.Where(className, u => u.ClassName == input.ClassName)
.Where(methodName, u => u.MethodName == input.MethodName)
.Where(exceptionMsg, u => EF.Functions.Like(u.ExceptionMsg, $"%{input.ExceptionMsg.Trim()}%"))
.Where(searchBeginTime, u => u.ExceptionTime >= DateTime.Parse(input.SearchBeginTime.Trim()) &&
u.ExceptionTime <= DateTime.Parse(input.SearchEndTime.Trim()))
.OrderByDescending(u => u.Id)
.ProjectToType()
.ToADPagedListAsync(input.PageIndex, input.PageSize);
return exLogs;
}
///
/// 清空异常日志
///
///
public async Task ClearLogEx()
{
var rep = _rep.Change();
await rep.SqlNonQueryAsync("TRUNCATE TABLE sys_log_ex");
await rep.SaveNowAsync();
}
#endregion
#region 操作日志
///
/// 分页查询操作日志
///
///
///
public async Task> QueryLogOpPageList(SysLogOpPageInput input)
{
var name = !string.IsNullOrEmpty(input.Name?.Trim());
var searchBeginTime = !string.IsNullOrEmpty(input.SearchBeginTime?.Trim());
var searchEndTime = !string.IsNullOrEmpty(input.SearchEndTime?.Trim());
var ReqMethod = !string.IsNullOrEmpty(input.ReqMethod?.Trim());
var opLogs = await _rep.Change().DetachedEntities
.Where((name, u => EF.Functions.Like(u.Name, $"%{input.Name.Trim()}%")))
.Where(input.Success.HasValue, u => u.Success == input.Success)
.Where(ReqMethod, u => u.ReqMethod == input.ReqMethod)
.Where(searchBeginTime, u => u.OpTime >= DateTime.Parse(input.SearchBeginTime.Trim()))
.Where(searchEndTime, u => u.OpTime <= DateTime.Parse(input.SearchEndTime.Trim()))
.OrderByDescending(u => u.Id)
.ProjectToType()
.ToADPagedListAsync(input.PageIndex, input.PageSize);
return opLogs;
}
///
/// 清空操作日志
///
///
public async Task ClearLogOp()
{
var rep = _rep.Change();
await rep.SqlNonQueryAsync("TRUNCATE TABLE sys_log_op");
await rep.SaveNowAsync();
}
#endregion
#region 访问日志
///
/// 分页查询访问日志
///
///
///
public async Task> QueryLogVisPageList(SysLogVisPageInput input)
{
var name = !string.IsNullOrEmpty(input.Name?.Trim());
var searchBeginTime = !string.IsNullOrEmpty(input.SearchBeginTime?.Trim());
var visLogs = await _rep.Change().DetachedEntities
.Where((name, u => EF.Functions.Like(u.Name, $"%{input.Name.Trim()}%")))
.Where(input.VisType >= 0, u => u.VisType == input.VisType)
.Where(input.Success.HasValue, u => u.Success == input.Success)
.Where(searchBeginTime, u => u.VisTime >= DateTime.Parse(input.SearchBeginTime.Trim()) &&
u.VisTime <= DateTime.Parse(input.SearchEndTime.Trim()))
.OrderByDescending(u => u.Id)
.ProjectToType()
.ToADPagedListAsync(input.PageIndex, input.PageSize);
return visLogs;
}
///
/// 清空访问日志
///
///
public async Task ClearLogVis()
{
var rep = _rep.Change();
await rep.SqlNonQueryAsync("TRUNCATE TABLE sys_log_vis");
await rep.SaveNowAsync();
}
#endregion
}
}