123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using YBEE.EQM.Core;
- namespace YBEE.EQM.Application
- {
- /// <summary>
- /// 日志管理服务
- /// </summary>
- public class SysLogService : ISysLogService, ITransient
- {
- private readonly IRepository _rep; // 操作日志表仓储
- public SysLogService(IRepository rep)
- {
- _rep = rep;
- }
- #region 异常日志
- /// <summary>
- /// 分页查询异常日志
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- //[HttpGet("sysExLog/page")]
- public async Task<PageResult<SysLogExOutput>> 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<SysLogEx>().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<SysLogExOutput>()
- .ToADPagedListAsync(input.PageIndex, input.PageSize);
- return exLogs;
- }
- /// <summary>
- /// 清空异常日志
- /// </summary>
- /// <returns></returns>
- public async Task ClearLogEx()
- {
- var rep = _rep.Change<SysLogEx>();
- await rep.SqlNonQueryAsync("TRUNCATE TABLE sys_log_ex");
- await rep.SaveNowAsync();
- }
- #endregion
- #region 操作日志
- /// <summary>
- /// 分页查询操作日志
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<PageResult<SysLogOpOutput>> 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<SysLogOp>().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<SysLogOpOutput>()
- .ToADPagedListAsync(input.PageIndex, input.PageSize);
- return opLogs;
- }
- /// <summary>
- /// 清空操作日志
- /// </summary>
- /// <returns></returns>
- public async Task ClearLogOp()
- {
- var rep = _rep.Change<SysLogOp>();
- await rep.SqlNonQueryAsync("TRUNCATE TABLE sys_log_op");
- await rep.SaveNowAsync();
- }
- #endregion
- #region 访问日志
- /// <summary>
- /// 分页查询访问日志
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<PageResult<SysLogVisOutput>> QueryLogVisPageList(SysLogVisPageInput input)
- {
- var name = !string.IsNullOrEmpty(input.Name?.Trim());
- var searchBeginTime = !string.IsNullOrEmpty(input.SearchBeginTime?.Trim());
- var visLogs = await _rep.Change<SysLogVis>().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<SysLogVisOutput>()
- .ToADPagedListAsync(input.PageIndex, input.PageSize);
- return visLogs;
- }
- /// <summary>
- /// 清空访问日志
- /// </summary>
- /// <returns></returns>
- public async Task ClearLogVis()
- {
- var rep = _rep.Change<SysLogVis>();
- await rep.SqlNonQueryAsync("TRUNCATE TABLE sys_log_vis");
- await rep.SaveNowAsync();
- }
- #endregion
- }
- }
|