Browse Source

Merge pull request #125 from abpframework/eshop-dashboard-grouping-issue-13805

Eshop dashboard grouping issue 13805
pull/127/head
Galip Tolga Erdem 4 years ago
committed by GitHub
parent
commit
84fdc67dc6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs
  2. 12
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs
  3. 31
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs

23
services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs

@ -76,21 +76,21 @@ public class OrderAppService : ApplicationService, IOrderAppService
private async Task<List<TopSellingDto>> GetTopSellingAsync(string filter)
{
ISpecification<Order> specification = SpecificationFactory.Create(filter);
var orderItems = await _orderRepository.GetTopSelling(specification, true);
return ObjectMapper.Map<List<OrderItem>, List<TopSellingDto>>(orderItems);
var orderItems = await _orderRepository.GetDashboardAsync(specification);
return CreateTopSellingDtoMapping(orderItems);
}
private async Task<List<PaymentDto>> GetPercentOfTotalPaymentAsync(string filter)
{
ISpecification<Order> specification = SpecificationFactory.Create(filter);
var orders = await _orderRepository.GetPercentOfTotalPayment(specification);
var orders = await _orderRepository.GetDashboardAsync(specification, false);
return CreatePaymentDtoMapping(orders);
}
private async Task<List<OrderStatusDto>> GetCountOfTotalOrderStatusAsync(string filter)
{
ISpecification<Order> 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<TopSellingDto> CreateTopSellingDtoMapping(List<Order> orders)
{
var orderItems = orders.Select(p => p.OrderItems).SelectMany(p => p).ToList();
var topSetlling = orderItems
.GroupBy(p => p.ProductId)
.Select(p => new TopSellingDto { Units = p.Count(), ProductName = p.First().ProductName , PictureUrl = p.First().PictureUrl })
.OrderByDescending(p => p.Units)
.Take(OrderConstants.Top10).ToList();
return topSetlling;
}
private List<OrderStatusDto> CreateOrderStatusDtoMapping(List<Order> 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();

12
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -20,16 +21,7 @@ public interface IOrderRepository : IRepository<Order, Guid>
bool includeDetails = true,
CancellationToken cancellationToken = default);
Task<List<OrderItem>> GetTopSelling(
ISpecification<Order> spec,
bool includeDetails = true,
CancellationToken cancellationToken = default);
Task<List<Order>> GetPercentOfTotalPayment(
ISpecification<Order> spec,
CancellationToken cancellationToken = default);
Task<List<Order>> GetCountOfTotalOrderStatus(
Task<List<Order>> GetDashboardAsync(
ISpecification<Order> spec,
bool includeDetails = true,
CancellationToken cancellationToken = default);

31
services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs

@ -45,35 +45,8 @@ public class EfCoreOrderRepository : EfCoreRepository<OrderingServiceDbContext,
.OrderByDescending(o => o.OrderDate)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OrderItem>> GetTopSelling(
ISpecification<Order> spec,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return (await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(spec.ToExpression())
.SelectMany(oi => oi.OrderItems)
.GroupBy(p => p.ProductCode)
.OrderByDescending(o => o.Sum(p => p.Units))
.Select(o => o.ToList())
.ToListAsync())
.SelectMany(t => t)
.Take(OrderConstants.Top10)
.ToList();
}
public async Task<List<Order>> GetPercentOfTotalPayment(
ISpecification<Order> spec,
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(spec.ToExpression())
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<Order>> GetCountOfTotalOrderStatus(
public async Task<List<Order>> GetDashboardAsync(
ISpecification<Order> spec,
bool includeDetails = true,
CancellationToken cancellationToken = default)

Loading…
Cancel
Save