Remove get best agent
This commit is contained in:
@@ -662,35 +662,6 @@ public class DataController : ControllerBase
|
||||
return Ok(balances);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a paginated list of the best performing agents based on their total value
|
||||
/// </summary>
|
||||
/// <param name="startDate">The start date for calculating agent performance</param>
|
||||
/// <param name="endDate">Optional end date for calculating agent performance (defaults to current time)</param>
|
||||
/// <param name="page">Page number (defaults to 1)</param>
|
||||
/// <param name="pageSize">Number of items per page (defaults to 10)</param>
|
||||
/// <returns>A paginated list of agent balances and total count</returns>
|
||||
[HttpGet("GetBestAgents")]
|
||||
public async Task<ActionResult<BestAgentsResponse>> GetBestAgents(
|
||||
DateTime startDate,
|
||||
DateTime? endDate = null,
|
||||
int page = 1,
|
||||
int pageSize = 10)
|
||||
{
|
||||
var (agents, totalCount) = await _agentService.GetBestAgents(startDate, endDate, page, pageSize);
|
||||
|
||||
var response = new BestAgentsResponse
|
||||
{
|
||||
Agents = agents,
|
||||
TotalCount = totalCount,
|
||||
CurrentPage = page,
|
||||
PageSize = pageSize,
|
||||
TotalPages = (int)Math.Ceiling(totalCount / (double)pageSize)
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an array of online agent names
|
||||
/// </summary>
|
||||
|
||||
@@ -6,7 +6,4 @@ public interface IAgentBalanceRepository
|
||||
{
|
||||
void InsertAgentBalance(AgentBalance balance);
|
||||
Task<IList<AgentBalance>> GetAgentBalancesByUserId(int userId, DateTime start, DateTime? end = null);
|
||||
|
||||
Task<(IList<AgentBalanceHistory> result, int totalCount)> GetAllAgentBalancesWithHistory(DateTime start,
|
||||
DateTime? end);
|
||||
}
|
||||
@@ -7,10 +7,6 @@ public interface IAgentService
|
||||
Task<AgentBalanceHistory> GetAgentBalances(string agentName, DateTime start, DateTime? end = null);
|
||||
Task<AgentBalanceHistory> GetAgentBalancesByUserId(int userId, DateTime start, DateTime? end = null);
|
||||
|
||||
Task<(IList<AgentBalanceHistory> Agents, int TotalCount)> GetBestAgents(DateTime start, DateTime? end = null,
|
||||
int page = 1,
|
||||
int pageSize = 10);
|
||||
|
||||
Task SaveOrUpdateAgentSummary(AgentSummary agentSummary);
|
||||
|
||||
Task<IEnumerable<AgentSummary>> GetAllAgentSummaries();
|
||||
|
||||
@@ -90,45 +90,6 @@ public class AgentService : IAgentService
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<(IList<AgentBalanceHistory> Agents, int TotalCount)> GetBestAgents(
|
||||
DateTime start,
|
||||
DateTime? end = null,
|
||||
int page = 1,
|
||||
int pageSize = 10)
|
||||
{
|
||||
var effectiveEnd = end ?? DateTime.UtcNow;
|
||||
string cacheKey = $"BestAgents_{start:yyyyMMdd}_{effectiveEnd:yyyyMMdd}";
|
||||
|
||||
// Check if the results are already cached
|
||||
var cachedResult = _cacheService.GetValue<(IList<AgentBalanceHistory>, int)>(cacheKey);
|
||||
|
||||
if (cachedResult != default)
|
||||
{
|
||||
// Apply pagination to cached results
|
||||
var (cachedAgents, cachedTotalCount) = cachedResult;
|
||||
var paginatedAgents = cachedAgents
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
return (paginatedAgents, cachedTotalCount);
|
||||
}
|
||||
|
||||
// Get all agents with their balance history
|
||||
var (fetchedAgents, fetchedTotalCount) =
|
||||
await _agentBalanceRepository.GetAllAgentBalancesWithHistory(start, end);
|
||||
|
||||
// Cache all results for 5 minutes
|
||||
_cacheService.SaveValue(cacheKey, (fetchedAgents, fetchedTotalCount), TimeSpan.FromMinutes(5));
|
||||
|
||||
// Apply pagination
|
||||
var result = fetchedAgents
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
|
||||
return (result, fetchedTotalCount);
|
||||
}
|
||||
|
||||
public async Task SaveOrUpdateAgentSummary(AgentSummary agentSummary)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user