/// <summary> /// The GetPaged /// </summary> /// <param name="model">The model<see cref="AuditLogPagedFilteringModel"/></param> /// <returns>The <see cref="Task{PagedResultDto{AuditLogPagedModel}}"/></returns> public async Task <PagedResultDto <AuditLogPagedModel> > GetPaged(AuditLogPagedFilteringModel model) { var query = CreateAuditLogQuery(model); var count = await query.CountAsync(); var result = await query.AsNoTracking() .OrderBy(model.Sorting) .PageBy(model) .ToListAsync(); return(new PagedResultDto <AuditLogPagedModel>(count, result)); }
/// <summary> /// 构建审计日志查询语句 /// </summary> /// <param name="model"></param> /// <returns></returns> private IQueryable <AuditLogPagedModel> CreateAuditLogQuery(AuditLogPagedFilteringModel model) { IQueryable <AuditLogPagedModel> query; query = from auditLog in _auditLog.GetAll().AsNoTracking() join user in _user.GetAll().AsNoTracking() on auditLog.UserId equals user.Id into userJoin from joinedUser in userJoin.DefaultIfEmpty() select new AuditLogPagedModel { BrowserInfo = auditLog.BrowserInfo, ClientIPAddress = auditLog.ClientIpAddress, ClientName = auditLog.ClientName, CustomData = auditLog.CustomData, Exception = auditLog.Exception, ExecutionDuration = auditLog.ExecutionDuration, ExecutionTime = auditLog.ExecutionTime, MethodName = auditLog.MethodName, Parameters = auditLog.Parameters, ServiceName = auditLog.ServiceName, UserName = joinedUser.UserName }; query = query .WhereIf(model.StartDate.HasValue, item => item.ExecutionTime >= model.StartDate) .WhereIf(model.EndDate.HasValue, item => item.ExecutionTime <= model.EndDate) .WhereIf(!model.UserName.IsNullOrWhiteSpace(), item => item.UserName.Contains(model.UserName)) .WhereIf(!model.ServiceName.IsNullOrWhiteSpace(), item => item.ServiceName.Contains(model.ServiceName)) .WhereIf(!model.MethodName.IsNullOrWhiteSpace(), item => item.MethodName.Contains(model.MethodName)) .WhereIf(!model.BrowserInfo.IsNullOrWhiteSpace(), item => item.BrowserInfo.Contains(model.BrowserInfo)) .WhereIf(model.MinExecutionDuration.HasValue && model.MinExecutionDuration > 0, item => item.ExecutionDuration >= model.MinExecutionDuration.Value) .WhereIf(model.MaxExecutionDuration.HasValue && model.MaxExecutionDuration < int.MaxValue, item => item.ExecutionDuration <= model.MaxExecutionDuration.Value) .WhereIf(model.HasException == true, item => item.Exception != null && item.Exception != "") .WhereIf(model.HasException == false, item => item.Exception == null || item.Exception == ""); return(query); }