From fdf246661d8ce8d7845dae7a2167a960cc16bbc5 Mon Sep 17 00:00:00 2001 From: malik masis Date: Wed, 16 Mar 2022 18:31:33 +0300 Subject: [PATCH] Added GetPercentOfTotaPayment Added an action named GetPercentOfTotaPayment for sales by payment method (Paypal, demo, etc). Still need development --- .../Orders/IOrderAppService.cs | 1 + .../Orders/PaymentDto.cs | 10 +++++ .../Orders/PaymentInput.cs | 7 ++++ ...ringServiceApplicationAutoMapperProfile.cs | 5 ++- .../Orders/OrderAppService.cs | 12 ++++++ .../Orders/IOrderRepository.cs | 4 ++ .../Orders/EfCoreOrderRepository.cs | 15 ++++++++ .../OrderClientProxy.Generated.cs | 8 ++++ .../ordering-generate-proxy.json | 37 +++++++++++++++++++ 9 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentDto.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentInput.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs index 187bd82e..fc4a60c0 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs @@ -18,5 +18,6 @@ public interface IOrderAppService : IApplicationService Task SetAsShippedAsync(Guid id); Task> GetListPagedAsync(PagedAndSortedResultRequestDto input); Task> GetTopSellingAsync(TopSellingInput input); + Task> GetPercentOfTotalPaymentAsync(PaymentInput input); } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentDto.cs new file mode 100644 index 00000000..822f8701 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentDto.cs @@ -0,0 +1,10 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace EShopOnAbp.OrderingService.Orders; + +public class PaymentDto : EntityDto +{ + public int CountOfPaymentMethod { get; set; } + public string PaymentMethod { get; set; } +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentInput.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentInput.cs new file mode 100644 index 00000000..a8239960 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/PaymentInput.cs @@ -0,0 +1,7 @@ +namespace EShopOnAbp.OrderingService.Orders +{ + public class PaymentInput + { + public string Filter { 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 2746a0a8..34091272 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs @@ -11,9 +11,10 @@ namespace EShopOnAbp.OrderingService { CreateMap(); CreateMap(); - + CreateMap(); - 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 6eac463f..65523a36 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -78,6 +78,18 @@ public class OrderAppService : ApplicationService, IOrderAppService return ObjectMapper.Map, List>(orderItems); } + 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); + } + public async Task GetByOrderNoAsync(int orderNo) { var order = await _orderRepository.GetByOrderNoAsync(orderNo); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs index cdec07a6..3fd5f369 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs @@ -25,6 +25,10 @@ public interface IOrderRepository : IRepository bool includeDetails = true, CancellationToken cancellationToken = default); + Task> GetPercentOfTotalPayment( + ISpecification spec, + CancellationToken cancellationToken = default); + Task GetByOrderNoAsync(int orderNo, bool includeDetails = true, CancellationToken cancellationToken = default); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs index 28974037..01d1b7af 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs @@ -72,6 +72,21 @@ public class EfCoreOrderRepository : EfCoreRepository> GetPercentOfTotalPayment( + ISpecification spec, + CancellationToken cancellationToken = default) + { + 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(); + } + public async Task GetByOrderNoAsync( int orderNo, bool includeDetails = true, diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs index f4ddeb66..62328d80 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs @@ -57,6 +57,14 @@ public partial class OrderClientProxy : ClientProxyBase, IOrde }); } + public virtual async Task> GetPercentOfTotalPaymentAsync(PaymentInput input) + { + return await RequestAsync>(nameof(GetPercentOfTotalPaymentAsync), new ClientProxyRequestTypeValue + { + { typeof(PaymentInput), input } + }); + } + public virtual async Task GetByOrderNoAsync(int orderNo) { return await RequestAsync(nameof(GetByOrderNoAsync), new ClientProxyRequestTypeValue diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/ordering-generate-proxy.json b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/ordering-generate-proxy.json index 21aa866b..5be815d9 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/ordering-generate-proxy.json +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/ordering-generate-proxy.json @@ -232,6 +232,43 @@ "allowAnonymous": null, "implementFrom": "EShopOnAbp.OrderingService.Orders.IOrderAppService" }, + "GetPercentOfTotalPaymentAsyncByInput": { + "uniqueName": "GetPercentOfTotalPaymentAsyncByInput", + "name": "GetPercentOfTotalPaymentAsync", + "httpMethod": "GET", + "url": "api/ordering/order/percent-of-total-payment", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "input", + "typeAsString": "EShopOnAbp.OrderingService.Orders.PaymentInput, EShopOnAbp.OrderingService.Application.Contracts", + "type": "EShopOnAbp.OrderingService.Orders.PaymentInput", + "typeSimple": "EShopOnAbp.OrderingService.Orders.PaymentInput", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "input", + "name": "Filter", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": null, + "bindingSourceId": "ModelBinding", + "descriptorName": "input" + } + ], + "returnValue": { + "type": "System.Collections.Generic.List", + "typeSimple": "[EShopOnAbp.OrderingService.Orders.PaymentDto]" + }, + "allowAnonymous": null, + "implementFrom": "EShopOnAbp.OrderingService.Orders.IOrderAppService" + }, "GetByOrderNoAsyncByOrderNo": { "uniqueName": "GetByOrderNoAsyncByOrderNo", "name": "GetByOrderNoAsync",