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();