From 7ac81ca54ca0cf89982e06c5fd2f56df5f7af8e0 Mon Sep 17 00:00:00 2001 From: Mikhail Trubnikov Date: Tue, 30 Jul 2024 11:03:47 +1000 Subject: [PATCH] =?UTF-8?q?refactor(api):=20=D0=9E=D0=BF=D1=82=D0=B8=D0=BC?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B7=D0=B0=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D0=B0=20StatTemplateController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../V1/Statistics/StatTemplateController.cs | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs b/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs index d0493017..f01f9fbc 100644 --- a/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs +++ b/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs @@ -33,19 +33,29 @@ namespace PARR.API.Controllers.V1.Statistics [HttpGet(ApiRoutes.StatTemplate.Get)] public async Task 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(response, true));