diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentDto.cs index 822f8701..9dc3cd1c 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentDto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentDto.cs @@ -5,6 +5,6 @@ namespace EShopOnAbp.OrderingService.Orders; public class PaymentDto : EntityDto { - public int CountOfPaymentMethod { get; set; } + public decimal RateOfPaymentMethod { get; set; } public string PaymentMethod { get; set; } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs index 34091272..3209fded 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs +++ b/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(); CreateMap(); - CreateMap(); CreateMap() .Ignore(q => q.Address) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs index 65523a36..da4dbf99 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -81,13 +81,8 @@ public class OrderAppService : ApplicationService, IOrderAppService public async Task> GetPercentOfTotalPaymentAsync(PaymentInput input) { ISpecification specification = SpecificationFactory.Create(input.Filter); - var orderItems = await _orderRepository.GetPercentOfTotalPayment(specification); - var paymentList = new List(); - foreach (var item in orderItems) - { - paymentList.Add(new PaymentDto() { PaymentMethod = item.PaymentMethod, CountOfPaymentMethod = orderItems.Count }); - } - return paymentList;//TODO ObjectMapper.Map, List>(orderItems); + var orders = await _orderRepository.GetPercentOfTotalPayment(specification); + return CreatePaymentDtoMapping(orders); } public async Task GetByOrderNoAsync(int orderNo) @@ -175,4 +170,17 @@ public class OrderAppService : ApplicationService, IOrderAppService PaymentMethod = order.PaymentMethod }; } + + private List CreatePaymentDtoMapping(List 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; + } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs index 01d1b7af..e7f6a8be 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs +++ b/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 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 GetByOrderNoAsync(