feat: Implement Approve and Reject Withdrawal commands with handlers
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using CMSMicroservice.Application.Common.Models;
|
||||
|
||||
namespace CMSMicroservice.Application.CommissionCQ.Queries.GetWorkerExecutionLogs;
|
||||
|
||||
public record GetWorkerExecutionLogsQuery : IRequest<GetWorkerExecutionLogsResponseDto>
|
||||
{
|
||||
public string? WeekNumber { get; init; }
|
||||
public string? ExecutionId { get; init; }
|
||||
public bool? SuccessOnly { get; init; }
|
||||
public bool? FailedOnly { get; init; }
|
||||
public string? SortBy { get; init; }
|
||||
public PaginationState? PaginationState { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Application.Common.Models;
|
||||
|
||||
namespace CMSMicroservice.Application.CommissionCQ.Queries.GetWorkerExecutionLogs;
|
||||
|
||||
public class GetWorkerExecutionLogsQueryHandler : IRequestHandler<GetWorkerExecutionLogsQuery, GetWorkerExecutionLogsResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetWorkerExecutionLogsQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetWorkerExecutionLogsResponseDto> Handle(
|
||||
GetWorkerExecutionLogsQuery request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// TODO: این باید از یک entity واقعی لاگها را بگیرد
|
||||
// فعلاً mock data برمیگرداند
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
var mockLogs = new List<WorkerExecutionLogModel>
|
||||
{
|
||||
new WorkerExecutionLogModel
|
||||
{
|
||||
ExecutionId = Guid.NewGuid().ToString(),
|
||||
WeekNumber = "2025-W48",
|
||||
Step = "Full",
|
||||
Success = true,
|
||||
ErrorMessage = null,
|
||||
StartedAt = DateTime.UtcNow.AddHours(-24),
|
||||
CompletedAt = DateTime.UtcNow.AddHours(-24).AddMinutes(15),
|
||||
DurationMs = 900000, // 15 minutes
|
||||
RecordsProcessed = 1523,
|
||||
Details = "محاسبات کامل هفته 2025-W48 با موفقیت انجام شد"
|
||||
},
|
||||
new WorkerExecutionLogModel
|
||||
{
|
||||
ExecutionId = Guid.NewGuid().ToString(),
|
||||
WeekNumber = "2025-W47",
|
||||
Step = "Full",
|
||||
Success = true,
|
||||
ErrorMessage = null,
|
||||
StartedAt = DateTime.UtcNow.AddDays(-7),
|
||||
CompletedAt = DateTime.UtcNow.AddDays(-7).AddMinutes(12),
|
||||
DurationMs = 720000,
|
||||
RecordsProcessed = 1489,
|
||||
Details = "محاسبات کامل هفته 2025-W47 با موفقیت انجام شد"
|
||||
},
|
||||
new WorkerExecutionLogModel
|
||||
{
|
||||
ExecutionId = Guid.NewGuid().ToString(),
|
||||
WeekNumber = "2025-W46",
|
||||
Step = "Pool",
|
||||
Success = false,
|
||||
ErrorMessage = "خطا در محاسبه استخر کمیسیون",
|
||||
StartedAt = DateTime.UtcNow.AddDays(-14),
|
||||
CompletedAt = DateTime.UtcNow.AddDays(-14).AddSeconds(30),
|
||||
DurationMs = 30000,
|
||||
RecordsProcessed = 0,
|
||||
Details = "محاسبه استخر با خطا مواجه شد"
|
||||
}
|
||||
};
|
||||
|
||||
// Apply filters
|
||||
if (!string.IsNullOrEmpty(request.WeekNumber))
|
||||
{
|
||||
mockLogs = mockLogs.Where(x => x.WeekNumber == request.WeekNumber).ToList();
|
||||
}
|
||||
|
||||
if (request.SuccessOnly == true)
|
||||
{
|
||||
mockLogs = mockLogs.Where(x => x.Success).ToList();
|
||||
}
|
||||
|
||||
if (request.FailedOnly == true)
|
||||
{
|
||||
mockLogs = mockLogs.Where(x => !x.Success).ToList();
|
||||
}
|
||||
|
||||
var totalCount = mockLogs.Count;
|
||||
var pageSize = request.PaginationState?.PageSize ?? 10;
|
||||
var pageNumber = request.PaginationState?.PageNumber ?? 1;
|
||||
|
||||
var pagedLogs = mockLogs
|
||||
.Skip((pageNumber - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
|
||||
return new GetWorkerExecutionLogsResponseDto
|
||||
{
|
||||
MetaData = new MetaData
|
||||
{
|
||||
CurrentPage = pageNumber,
|
||||
TotalPage = (int)Math.Ceiling(totalCount / (double)pageSize),
|
||||
PageSize = pageSize,
|
||||
TotalCount = totalCount,
|
||||
HasPrevious = pageNumber > 1,
|
||||
HasNext = pageNumber < (int)Math.Ceiling(totalCount / (double)pageSize)
|
||||
},
|
||||
Models = pagedLogs
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using CMSMicroservice.Application.Common.Models;
|
||||
|
||||
namespace CMSMicroservice.Application.CommissionCQ.Queries.GetWorkerExecutionLogs;
|
||||
|
||||
public class GetWorkerExecutionLogsResponseDto
|
||||
{
|
||||
public MetaData? MetaData { get; set; }
|
||||
public List<WorkerExecutionLogModel> Models { get; set; } = new();
|
||||
}
|
||||
|
||||
public class WorkerExecutionLogModel
|
||||
{
|
||||
public string ExecutionId { get; set; } = string.Empty;
|
||||
public string WeekNumber { get; set; } = string.Empty;
|
||||
public string Step { get; set; } = string.Empty; // "Balances" | "Pool" | "Payouts" | "Full"
|
||||
public bool Success { get; set; }
|
||||
public string? ErrorMessage { get; set; }
|
||||
public DateTime StartedAt { get; set; }
|
||||
public DateTime? CompletedAt { get; set; }
|
||||
public long DurationMs { get; set; }
|
||||
public int RecordsProcessed { get; set; }
|
||||
public string? Details { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user