Browse Source

Completed sales by payment method

pull/110/head
malik masis 5 years ago
parent
commit
ea3020474a
  1. 2
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentDto.cs
  2. 3
      services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs
  3. 22
      services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs
  4. 14
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs

2
services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentDto.cs

@ -5,6 +5,6 @@ namespace EShopOnAbp.OrderingService.Orders;
public class PaymentDto : EntityDto<Guid>
{
public int CountOfPaymentMethod { get; set; }
public decimal RateOfPaymentMethod { get; set; }
public string PaymentMethod { get; set; }
}

3
services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs

@ -1,6 +1,6 @@
using AutoMapper;
using EShopOnAbp.OrderingService.Orders;
using EShopOnAbp.OrderingService.OrderItems;
using EShopOnAbp.OrderingService.Orders;
using Volo.Abp.AutoMapper;
namespace EShopOnAbp.OrderingService
@ -14,7 +14,6 @@ namespace EShopOnAbp.OrderingService
CreateMap<OrderItem, OrderItemDto>();
CreateMap<OrderItem, TopSellingDto>();
CreateMap<Order, PaymentDto>();
CreateMap<Order, OrderDto>()
.Ignore(q => q.Address)

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

@ -81,13 +81,8 @@ public class OrderAppService : ApplicationService, IOrderAppService
public async Task<List<PaymentDto>> GetPercentOfTotalPaymentAsync(PaymentInput input)
{
ISpecification<Order> specification = SpecificationFactory.Create(input.Filter);
var orderItems = await _orderRepository.GetPercentOfTotalPayment(specification);
var paymentList = new List<PaymentDto>();
foreach (var item in orderItems)
{
paymentList.Add(new PaymentDto() { PaymentMethod = item.PaymentMethod, CountOfPaymentMethod = orderItems.Count });
}
return paymentList;//TODO ObjectMapper.Map<List<Order>, List<PaymentDto>>(orderItems);
var orders = await _orderRepository.GetPercentOfTotalPayment(specification);
return CreatePaymentDtoMapping(orders);
}
public async Task<OrderDto> GetByOrderNoAsync(int orderNo)
@ -175,4 +170,17 @@ public class OrderAppService : ApplicationService, IOrderAppService
PaymentMethod = order.PaymentMethod
};
}
private List<PaymentDto> CreatePaymentDtoMapping(List<Order> orders)
{
var payments = orders
.GroupBy(p => p.PaymentMethod)
.Select(p => new PaymentDto { RateOfPaymentMethod = p.Count(), PaymentMethod = p.Key })
.OrderBy(p => p.RateOfPaymentMethod)
.ToList();
decimal rate = 100 / payments.Sum(p => p.RateOfPaymentMethod);
payments.ForEach(p => p.RateOfPaymentMethod *= rate);
return payments;
}
}

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

@ -1,11 +1,11 @@
using System;
using EShopOnAbp.OrderingService.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using EShopOnAbp.OrderingService.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
@ -78,13 +78,7 @@ public class EfCoreOrderRepository : EfCoreRepository<OrderingServiceDbContext,
{
return await (await GetDbSetAsync())
.Where(spec.ToExpression())
.GroupBy(p => p.PaymentMethod)
.Select(p=>p.OrderBy(p=>p.Id).FirstOrDefault())//TODO list
//TODO
//.SelectMany(p=>p)
//.Select(p => new PaymentDto { CountOfPaymentMethod = p.Count(), PaymentMethod = p.Key })
//.OrderBy(p => p.CountOfPaymentMethod)
.ToListAsync();
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<Order> GetByOrderNoAsync(

Loading…
Cancel
Save