refactor(api): Оптимизация запроса StatTemplateController
This commit is contained in:
@@ -33,19 +33,29 @@ namespace PARR.API.Controllers.V1.Statistics
|
||||
[HttpGet(ApiRoutes.StatTemplate.Get)]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
var templates = await templateService.Get()
|
||||
.Include(t => t.ApplicationsInWork)
|
||||
.Include(t => t.RobotConfigurations)
|
||||
.ToListAsync();
|
||||
//var templates = await templateService.Get()
|
||||
// .Include(t => t.ApplicationsInWork)
|
||||
// .Include(t => t.RobotConfigurations)
|
||||
// .ToListAsync();
|
||||
|
||||
//var response = new StatTemplateResponse
|
||||
//{
|
||||
// ActivateScheduleCount = templates.Count(x => x.IsActiveSchedule),
|
||||
// ActivateTemplateCount = templates.Count(x => x.IsActiveTemplate),
|
||||
// TemplateAgentCount = templates.Count(x => x.ApplicationsInWork!.IsAgent),
|
||||
// TemplateCount = templates.Count(),
|
||||
// SyncEsppScheduleCount = templates.Count(x => x.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.ScheduleOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)),
|
||||
// SyncEsppTemplatesCount = templates.Count(x => x.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.TemplateOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok))
|
||||
//};
|
||||
|
||||
var response = new StatTemplateResponse
|
||||
{
|
||||
ActivateScheduleCount = templates.Count(x => x.IsActiveSchedule),
|
||||
ActivateTemplateCount = templates.Count(x => x.IsActiveTemplate),
|
||||
TemplateAgentCount = templates.Count(x => x.ApplicationsInWork!.IsAgent),
|
||||
TemplateCount = templates.Count(),
|
||||
SyncEsppScheduleCount = templates.Count(x => x.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.ScheduleOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)),
|
||||
SyncEsppTemplatesCount = templates.Count(x => x.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.TemplateOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok))
|
||||
ActivateScheduleCount = await templateService.Get().CountAsync(t => t.IsActiveSchedule),
|
||||
ActivateTemplateCount = await templateService.Get().CountAsync(t => t.IsActiveTemplate),
|
||||
TemplateAgentCount = await templateService.Get().Include(t => t.ApplicationsInWork).CountAsync(t => t.ApplicationsInWork!.IsAgent),
|
||||
TemplateCount = await templateService.Get().CountAsync(),
|
||||
SyncEsppScheduleCount = await templateService.Get().Include(t => t.RobotConfigurations).CountAsync(t => t.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.ScheduleOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)),
|
||||
SyncEsppTemplatesCount = await templateService.Get().Include(t => t.RobotConfigurations).CountAsync(t => t.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.TemplateOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok))
|
||||
};
|
||||
|
||||
return Ok(new Response<StatTemplateResponse>(response, true));
|
||||
|
||||
Reference in New Issue
Block a user