| | | 1 | | using OServices.FiltersServices.FilterModels; |
| | | 2 | | using OzonDomains.Models; |
| | | 3 | | using OzonDomains.Models.AccessControl; |
| | | 4 | | using OzonOrdersWeb.ViewModels.OrderViewModels; |
| | | 5 | | using Services.DataServices; |
| | | 6 | | using Services.OzonWebhookServices; |
| | | 7 | | |
| | | 8 | | namespace OzonOrdersWeb.WebServices.Orders; |
| | | 9 | | |
| | | 10 | | public interface IOrdersIndexPageDetailsService |
| | | 11 | | { |
| | | 12 | | Task LoadOrderDetailsForPageAsync( |
| | | 13 | | IReadOnlyList<Order> ordersForPage, |
| | | 14 | | AccessProfile? accessProfile, |
| | | 15 | | CancellationToken cancellationToken = default); |
| | | 16 | | |
| | | 17 | | Task PopulateUniqueCountsAsync( |
| | | 18 | | OrderPageViewModel<Order, OrderFilterModel> viewModel, |
| | | 19 | | IReadOnlyList<Order> ordersForPage, |
| | | 20 | | bool includeArchived, |
| | | 21 | | CancellationToken cancellationToken = default); |
| | | 22 | | |
| | | 23 | | void ApplyDbPagination( |
| | | 24 | | OrderPageViewModel<Order, OrderFilterModel> viewModel, |
| | | 25 | | int totalOrdersCount, |
| | | 26 | | int page, |
| | | 27 | | int pageSize, |
| | | 28 | | bool disablePagination = false); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | public sealed class OrdersIndexPageDetailsService : IOrdersIndexPageDetailsService |
| | | 32 | | { |
| | | 33 | | private readonly OrdersDataServices _orderServices; |
| | | 34 | | private readonly IOrderReturnInfoService _returnInfoService; |
| | | 35 | | private readonly IOzonPostingCancellationService _cancellationService; |
| | | 36 | | private readonly IOrderSupplierStateInfoService _supplierStateInfoService; |
| | | 37 | | private readonly IOrderProblemInfoService _problemInfoService; |
| | | 38 | | |
| | 0 | 39 | | public OrdersIndexPageDetailsService( |
| | 0 | 40 | | OrdersDataServices orderServices, |
| | 0 | 41 | | IOrderReturnInfoService returnInfoService, |
| | 0 | 42 | | IOzonPostingCancellationService cancellationService, |
| | 0 | 43 | | IOrderSupplierStateInfoService supplierStateInfoService, |
| | 0 | 44 | | IOrderProblemInfoService problemInfoService) |
| | | 45 | | { |
| | 0 | 46 | | _orderServices = orderServices; |
| | 0 | 47 | | _returnInfoService = returnInfoService; |
| | 0 | 48 | | _cancellationService = cancellationService; |
| | 0 | 49 | | _supplierStateInfoService = supplierStateInfoService; |
| | 0 | 50 | | _problemInfoService = problemInfoService; |
| | 0 | 51 | | } |
| | | 52 | | |
| | | 53 | | public async Task LoadOrderDetailsForPageAsync( |
| | | 54 | | IReadOnlyList<Order> ordersForPage, |
| | | 55 | | AccessProfile? accessProfile, |
| | | 56 | | CancellationToken cancellationToken = default) |
| | | 57 | | { |
| | 0 | 58 | | if (ordersForPage.Count == 0) |
| | | 59 | | { |
| | 0 | 60 | | return; |
| | | 61 | | } |
| | | 62 | | |
| | 0 | 63 | | await _orderServices.LoadOrderExtensionsForOrders(ordersForPage.ToList()); |
| | 0 | 64 | | await _orderServices.LoadOrderItemsForOrders(ordersForPage.ToList()); |
| | | 65 | | |
| | 0 | 66 | | if (accessProfile?.AvailableOrderColumns?.Contains("Себестоимость") == true) |
| | | 67 | | { |
| | 0 | 68 | | await _orderServices.LoadExtraExpensesForOrders(ordersForPage.ToList()); |
| | | 69 | | } |
| | | 70 | | |
| | 0 | 71 | | await _returnInfoService.PopulateForOrdersAsync(ordersForPage, cancellationToken); |
| | 0 | 72 | | await _cancellationService.PopulateLatestForOrdersAsync(ordersForPage, cancellationToken); |
| | 0 | 73 | | await _supplierStateInfoService.PopulateForOrdersAsync(ordersForPage, cancellationToken); |
| | 0 | 74 | | await _problemInfoService.PopulateForOrdersAsync(ordersForPage, cancellationToken); |
| | 0 | 75 | | } |
| | | 76 | | |
| | | 77 | | public async Task PopulateUniqueCountsAsync( |
| | | 78 | | OrderPageViewModel<Order, OrderFilterModel> viewModel, |
| | | 79 | | IReadOnlyList<Order> ordersForPage, |
| | | 80 | | bool includeArchived, |
| | | 81 | | CancellationToken cancellationToken = default) |
| | | 82 | | { |
| | | 83 | | _ = cancellationToken; |
| | 0 | 84 | | viewModel.UniqueArticles = await _orderServices.GetArticleCountsForOrdersAsync( |
| | 0 | 85 | | ordersForPage.ToList(), includeArchived); |
| | 0 | 86 | | viewModel.UniqueDeliveryCitys = await _orderServices.GetDeliveryCityCountsForOrdersAsync( |
| | 0 | 87 | | ordersForPage.ToList(), includeArchived); |
| | 0 | 88 | | viewModel.UniqueNumbers = await _orderServices.GetShipmentBaseCountsForOrdersAsync( |
| | 0 | 89 | | ordersForPage.ToList(), includeArchived); |
| | 0 | 90 | | } |
| | | 91 | | |
| | | 92 | | public void ApplyDbPagination( |
| | | 93 | | OrderPageViewModel<Order, OrderFilterModel> viewModel, |
| | | 94 | | int totalOrdersCount, |
| | | 95 | | int page, |
| | | 96 | | int pageSize, |
| | | 97 | | bool disablePagination = false) |
| | | 98 | | { |
| | 0 | 99 | | if (totalOrdersCount <= 0) |
| | | 100 | | { |
| | 0 | 101 | | viewModel.PageNumber = 1; |
| | 0 | 102 | | viewModel.TotalPages = 1; |
| | 0 | 103 | | return; |
| | | 104 | | } |
| | | 105 | | |
| | 0 | 106 | | viewModel.PageNumber = page; |
| | 0 | 107 | | viewModel.TotalPages = disablePagination |
| | 0 | 108 | | ? 1 |
| | 0 | 109 | | : (int)Math.Ceiling(totalOrdersCount / (double)pageSize); |
| | 0 | 110 | | } |
| | | 111 | | } |