/
afanasevn
/
MaxSystems
Обзор
Документация
Войти
/
afanasevn
/
MaxSystems
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/MaxSystems.Infrastructure/Services/IntegrationDeliveryQueryService.cs
106 строк
4 KB
IBS\NAfanasev
Integration delivery UI
22 июн 2026, 18:55
22 июн 2026, 18:55
ff9f4c2
Код
Авторство
О чём код?
using MaxSystems.Application.Abstractions; using MaxSystems.Application.Contracts.Admin; using MaxSystems.Domain.Entities; using MaxSystems.Infrastructure.Data; using Microsoft.EntityFrameworkCore; namespace MaxSystems.Infrastructure.Services; /// <summary>EF-реализация чтения журнала доставки интеграционных событий.</summary> public sealed class IntegrationDeliveryQueryService(AppDbContext db) : IIntegrationDeliveryQueryService { private const int DefaultPageSize = 20; private const int MaxPageSize = 100; /// <inheritdoc /> public async Task<PagedIntegrationDeliveriesDto> ListAsync( IntegrationDeliveryListQuery query, CancellationToken ct = default) { var page = Math.Max(1, query.Page); var pageSize = Math.Clamp(query.PageSize <= 0 ? DefaultPageSize : query.PageSize, 1, MaxPageSize); var filtered = ApplyFilters(db.IntegrationDeliveryLogs.AsNoTracking(), query); var totalCount = await filtered.CountAsync(ct); var items = await filtered .OrderByDescending(x => x.UpdatedAt) .Skip((page - 1) * pageSize) .Take(pageSize) .Select(x => new IntegrationDeliveryListItemDto( x.Id, x.EventType, x.RoutingKey, x.QueueName, x.Status, x.WorkId, x.EquipmentId, x.MaintenanceRegulationId, x.MessageId, x.AttemptCount, x.PayloadSummary, x.CreatedAt, x.UpdatedAt, x.ProcessedAt)) .ToListAsync(ct); return new PagedIntegrationDeliveriesDto(items, page, pageSize, totalCount); } /// <inheritdoc /> public async Task<IntegrationDeliveryDetailDto?> GetByIdAsync( Guid id, CancellationToken ct = default) { return await db.IntegrationDeliveryLogs .AsNoTracking() .Where(x => x.Id == id) .Select(x => new IntegrationDeliveryDetailDto( x.Id, x.EventType, x.RoutingKey, x.QueueName, x.Status, x.WorkId, x.EquipmentId, x.MaintenanceRegulationId, x.MessageId, x.AttemptCount, x.ErrorMessage, x.PayloadSummary, x.CreatedAt, x.UpdatedAt, x.ProcessedAt)) .FirstOrDefaultAsync(ct); } /// <summary>Применяет фильтры запроса к IQueryable журнала.</summary> private static IQueryable<IntegrationDeliveryLog> ApplyFilters( IQueryable<IntegrationDeliveryLog> source, IntegrationDeliveryListQuery query) { if (query.Status.HasValue) source = source.Where(x => x.Status == query.Status.Value); if (!string.IsNullOrWhiteSpace(query.QueueName)) source = source.Where(x => x.QueueName == query.QueueName); if (!string.IsNullOrWhiteSpace(query.EventType)) source = source.Where(x => x.EventType == query.EventType); if (query.WorkId.HasValue) source = source.Where(x => x.WorkId == query.WorkId.Value); if (query.EquipmentId.HasValue) source = source.Where(x => x.EquipmentId == query.EquipmentId.Value); if (query.DateFrom.HasValue) source = source.Where(x => x.UpdatedAt >= query.DateFrom.Value); if (query.DateTo.HasValue) source = source.Where(x => x.UpdatedAt <= query.DateTo.Value); return source; } }