| | | 1 | | using OzonOrdersWeb.Areas.Studio2.ViewModels.TransactionTimeTracking; |
| | | 2 | | using Services.DataServices; |
| | | 3 | | |
| | | 4 | | namespace OzonOrdersWeb.WebServices.TransactionTimeTracking; |
| | | 5 | | |
| | | 6 | | /// <summary>Собирает единый срез трекинга времени для отдельного отчёта и вкладки JobLogs.</summary> |
| | | 7 | | public interface ITransactionTimeTrackingReportQueryService |
| | | 8 | | { |
| | | 9 | | Task<TransactionTimeTrackingReportViewModel> GetAsync( |
| | | 10 | | DateTime? dateFromUtc, |
| | | 11 | | DateTime? dateToUtc, |
| | | 12 | | string? userName, |
| | | 13 | | string? transactionType, |
| | | 14 | | CancellationToken cancellationToken = default); |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | public sealed class TransactionTimeTrackingReportQueryService : ITransactionTimeTrackingReportQueryService |
| | | 18 | | { |
| | | 19 | | private readonly TransactionTimeTrackingDataServices _dataServices; |
| | | 20 | | |
| | 0 | 21 | | public TransactionTimeTrackingReportQueryService(TransactionTimeTrackingDataServices dataServices) |
| | | 22 | | { |
| | 0 | 23 | | _dataServices = dataServices; |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | public async Task<TransactionTimeTrackingReportViewModel> GetAsync( |
| | | 27 | | DateTime? dateFromUtc, |
| | | 28 | | DateTime? dateToUtc, |
| | | 29 | | string? userName, |
| | | 30 | | string? transactionType, |
| | | 31 | | CancellationToken cancellationToken = default) |
| | | 32 | | { |
| | 0 | 33 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 34 | | var normalizedDateTo = dateToUtc?.Date.AddDays(1).AddTicks(-1); |
| | 0 | 35 | | var filterBaseResults = await _dataServices.GetReport(dateFromUtc, normalizedDateTo, null, transactionType); |
| | 0 | 36 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 37 | | var results = await _dataServices.GetReport(dateFromUtc, normalizedDateTo, userName, transactionType); |
| | | 38 | | |
| | 0 | 39 | | return new TransactionTimeTrackingReportViewModel |
| | 0 | 40 | | { |
| | 0 | 41 | | DateFromUtc = dateFromUtc, |
| | 0 | 42 | | DateToUtc = dateToUtc, |
| | 0 | 43 | | UserName = userName, |
| | 0 | 44 | | TransactionType = transactionType, |
| | 0 | 45 | | TotalCount = results.Count, |
| | 0 | 46 | | Results = results, |
| | 0 | 47 | | AvailableTransactionTypes = filterBaseResults |
| | 0 | 48 | | .Select(x => x.TransactionType) |
| | 0 | 49 | | .Where(x => !string.IsNullOrWhiteSpace(x)) |
| | 0 | 50 | | .Distinct() |
| | 0 | 51 | | .OrderBy(x => x) |
| | 0 | 52 | | .ToList(), |
| | 0 | 53 | | AvailableUsers = filterBaseResults |
| | 0 | 54 | | .Select(x => x.UserName) |
| | 0 | 55 | | .Where(x => !string.IsNullOrWhiteSpace(x)) |
| | 0 | 56 | | .Distinct() |
| | 0 | 57 | | .OrderBy(x => x) |
| | 0 | 58 | | .ToList(), |
| | 0 | 59 | | Summary = TransactionTimeTrackingReportBuilder.BuildSummary(results), |
| | 0 | 60 | | ChartData = TransactionTimeTrackingReportBuilder.BuildChartData(results) |
| | 0 | 61 | | }; |
| | 0 | 62 | | } |
| | | 63 | | } |