From f4f348f98a262b2826ead0c723d0922e1f95ee71 Mon Sep 17 00:00:00 2001 From: malik masis Date: Wed, 24 Aug 2022 16:12:51 +0300 Subject: [PATCH] Fixed grouping --- .../Orders/OrderAppService.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs index 63b84cb2..91e46d3e 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -76,21 +76,21 @@ public class OrderAppService : ApplicationService, IOrderAppService private async Task> GetTopSellingAsync(string filter) { ISpecification specification = SpecificationFactory.Create(filter); - var orderItems = await _orderRepository.GetTopSelling(specification, true); - return ObjectMapper.Map, List>(orderItems); + var orderItems = await _orderRepository.GetDashboardAsync(specification); + return CreateTopSellingDtoMapping(orderItems); } private async Task> GetPercentOfTotalPaymentAsync(string filter) { ISpecification specification = SpecificationFactory.Create(filter); - var orders = await _orderRepository.GetPercentOfTotalPayment(specification); + var orders = await _orderRepository.GetDashboardAsync(specification, false); return CreatePaymentDtoMapping(orders); } private async Task> GetCountOfTotalOrderStatusAsync(string filter) { ISpecification specification = SpecificationFactory.Create(filter); - var orders = await _orderRepository.GetCountOfTotalOrderStatus(specification, true); + var orders = await _orderRepository.GetDashboardAsync(specification); return CreateOrderStatusDtoMapping(orders); } @@ -200,11 +200,24 @@ public class OrderAppService : ApplicationService, IOrderAppService return payments; } + private List CreateTopSellingDtoMapping(List orders) + { + var orderItems = orders.Select(p => p.OrderItems).SelectMany(p => p).ToList(); + + var topSetlling = orderItems + .GroupBy(p => new { p.ProductName, p.PictureUrl }) + .Select(p => new TopSellingDto { Units = p.Count(), ProductName = p.Key.ProductName, PictureUrl = p.Key.PictureUrl }) + .OrderByDescending(p => p.Units) + .Take(OrderConstants.Top10).ToList(); + + return topSetlling; + } + private List CreateOrderStatusDtoMapping(List orders) { var orderStatus = orders .GroupBy(p => p.OrderStatus) - .Select(p => new OrderStatusDto { CountOfStatusOrder = p.Count(), OrderStatus = p.Key.ToString(), }) + .Select(p => new OrderStatusDto { CountOfStatusOrder = p.Count(), OrderStatus = p.Key.ToString() }) .OrderBy(p => p.CountOfStatusOrder) .ToList();