79 lines
2.8 KiB
C#
79 lines
2.8 KiB
C#
|
|
using CMSMicroservice.Protobuf.Protos.Commission;
|
|
|
|
namespace BackOffice.BFF.Application.CommissionCQ.Queries.GetWithdrawalReports;
|
|
|
|
public class GetWithdrawalReportsQueryHandler : IRequestHandler<GetWithdrawalReportsQuery, GetWithdrawalReportsResponseDto>
|
|
{
|
|
private readonly IApplicationContractContext _context;
|
|
|
|
public GetWithdrawalReportsQueryHandler(IApplicationContractContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<GetWithdrawalReportsResponseDto> Handle(GetWithdrawalReportsQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var grpcRequest = new GetWithdrawalReportsRequest
|
|
{
|
|
PeriodType = (int)request.PeriodType
|
|
};
|
|
|
|
// تنظیم بازه زمانی
|
|
if (request.StartDate.HasValue)
|
|
{
|
|
grpcRequest.StartDate = Timestamp.FromDateTime(request.StartDate.Value.ToUniversalTime());
|
|
}
|
|
|
|
if (request.EndDate.HasValue)
|
|
{
|
|
grpcRequest.EndDate = Timestamp.FromDateTime(request.EndDate.Value.ToUniversalTime());
|
|
}
|
|
|
|
// فیلتر وضعیت
|
|
if (request.Status.HasValue)
|
|
{
|
|
grpcRequest.Status = request.Status.Value;
|
|
}
|
|
|
|
// فیلتر کاربر
|
|
if (request.UserId.HasValue)
|
|
{
|
|
grpcRequest.UserId = request.UserId.Value;
|
|
}
|
|
|
|
var response = await _context.Commissions.GetWithdrawalReportsAsync(grpcRequest, cancellationToken: cancellationToken);
|
|
|
|
// تبدیل به DTO
|
|
return new GetWithdrawalReportsResponseDto
|
|
{
|
|
PeriodReports = response.PeriodReports.Select(p => new PeriodReportDto
|
|
{
|
|
PeriodLabel = p.PeriodLabel,
|
|
StartDate = p.StartDate.ToDateTime(),
|
|
EndDate = p.EndDate.ToDateTime(),
|
|
TotalRequests = p.TotalRequests,
|
|
PendingCount = p.PendingCount,
|
|
ApprovedCount = p.ApprovedCount,
|
|
RejectedCount = p.RejectedCount,
|
|
CompletedCount = p.CompletedCount,
|
|
FailedCount = p.FailedCount,
|
|
TotalAmount = p.TotalAmount,
|
|
PaidAmount = p.PaidAmount,
|
|
PendingAmount = p.PendingAmount
|
|
}).ToList(),
|
|
Summary = new WithdrawalSummaryDto
|
|
{
|
|
TotalRequests = response.Summary.TotalRequests,
|
|
TotalAmount = response.Summary.TotalAmount,
|
|
TotalPaid = response.Summary.TotalPaid,
|
|
TotalPending = response.Summary.TotalPending,
|
|
TotalRejected = response.Summary.TotalRejected,
|
|
AverageAmount = response.Summary.AverageAmount,
|
|
UniqueUsers = response.Summary.UniqueUsers,
|
|
SuccessRate = (decimal)response.Summary.SuccessRate
|
|
}
|
|
};
|
|
}
|
|
}
|