From bbb14ee4ea136327f0f84336de09aed7bc2e985a Mon Sep 17 00:00:00 2001 From: Mikhail Trubnikov Date: Fri, 17 Jul 2026 15:35:46 +1000 Subject: [PATCH] =?UTF-8?q?feat(api):=20=D0=A1=D1=82=D0=B0=D1=82=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D0=B8=D0=BA=D0=B0:=20=D0=9F=D0=BE=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D0=B8=D1=82=D1=8C=20=D0=BA=D0=BE=D0=BB-=D0=B2=D0=BE=20?= =?UTF-8?q?=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=BE=D0=B2=20=D1=83=20?= =?UTF-8?q?=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D1=85=20=D0=98=D0=94=20?= =?UTF-8?q?=D1=80=D0=B0=D1=81=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?null=20=D0=B8=20=D0=BD=D0=B5=D1=82=20=D0=B7=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D1=81=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PARR.API/Contracts/V1/ApiRoutes.cs | 1 + .../StatTemplatesWithoutScheduleResponse.cs | 5 ++ .../V1/Statistics/StatTemplateController.cs | 49 ++++++++++++++----- 3 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 PARR.API/Contracts/V1/Responses/Statistics/StatTemplatesWithoutScheduleResponse.cs diff --git a/PARR.API/Contracts/V1/ApiRoutes.cs b/PARR.API/Contracts/V1/ApiRoutes.cs index a6d4d22b..b52b7878 100644 --- a/PARR.API/Contracts/V1/ApiRoutes.cs +++ b/PARR.API/Contracts/V1/ApiRoutes.cs @@ -226,6 +226,7 @@ namespace PARR.API.Contracts.V1 { public const string Get = BaseStat + "/templates/"; public const string GetForPeriod = BaseStat + "/templates/period"; + public const string GetTemplatesWithoutScheduleAndTaskCount = BaseStat + "/templates/without-schedule"; } public static class StatStatusTypeTemplates diff --git a/PARR.API/Contracts/V1/Responses/Statistics/StatTemplatesWithoutScheduleResponse.cs b/PARR.API/Contracts/V1/Responses/Statistics/StatTemplatesWithoutScheduleResponse.cs new file mode 100644 index 00000000..10913c6f --- /dev/null +++ b/PARR.API/Contracts/V1/Responses/Statistics/StatTemplatesWithoutScheduleResponse.cs @@ -0,0 +1,5 @@ +namespace PARR.API.Contracts.V1.Responses.Statistics +{ + public record StatTemplatesWithoutScheduleResponse(int Count); + +} diff --git a/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs b/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs index 4863e6ec..edcacc37 100644 --- a/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs +++ b/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs @@ -10,6 +10,7 @@ using PARR.API.Helpers; using PARR.Core.Repositories.Interfaces; using PARR.Core.Services.NextRunServices; using PARR.Domain.Common.Roles; +using PARR.Domain.Entities; using PARR.Domain.Enums; namespace PARR.API.Controllers.V1.Statistics @@ -20,16 +21,16 @@ namespace PARR.API.Controllers.V1.Statistics [Authorize(Roles = ParrRoles.Administrator.Role)] public class StatTemplateController : BaseApiController { - private readonly ITemplateRepository templateService; - private readonly INextRunService nextRunService; + private readonly ITemplateRepository _templateRepository; + private readonly INextRunService _nextRunService; public StatTemplateController( - ITemplateRepository templateService, + ITemplateRepository templateRepository, INextRunService nextRunService ) { - this.templateService = templateService; - this.nextRunService = nextRunService; + _templateRepository = templateRepository; + _nextRunService = nextRunService; } /// @@ -41,12 +42,12 @@ namespace PARR.API.Controllers.V1.Statistics { var response = new StatTemplateResponse { - ActivateScheduleCount = await templateService.Get().AsNoTracking().CountAsync(t => t.IsActiveSchedule), - ActivateTemplateCount = await templateService.Get().AsNoTracking().CountAsync(t => t.IsActiveTemplate), - TemplateAgentCount = await templateService.Get().AsNoTracking().CountAsync(t => t.Job!.Group!.IsAgent), - TemplateCount = await templateService.Get().AsNoTracking().CountAsync(), - SyncEsppScheduleCount = await templateService.Get().AsNoTracking().CountAsync(t => t.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.ScheduleOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)), - SyncEsppTemplatesCount = await templateService.Get().AsNoTracking().CountAsync(t => t.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.TemplateOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)) + ActivateScheduleCount = await _templateRepository.Get().AsNoTracking().CountAsync(t => t.IsActiveSchedule), + ActivateTemplateCount = await _templateRepository.Get().AsNoTracking().CountAsync(t => t.IsActiveTemplate), + TemplateAgentCount = await _templateRepository.Get().AsNoTracking().CountAsync(t => t.Job!.Group!.IsAgent), + TemplateCount = await _templateRepository.Get().AsNoTracking().CountAsync(), + SyncEsppScheduleCount = await _templateRepository.Get().AsNoTracking().CountAsync(t => t.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.ScheduleOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)), + SyncEsppTemplatesCount = await _templateRepository.Get().AsNoTracking().CountAsync(t => t.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.TemplateOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)) }; return Ok(new Response(response, true)); @@ -71,7 +72,7 @@ namespace PARR.API.Controllers.V1.Statistics userEnd.AddDays(1), timeZoneQuery.TimeZoneOffset); - var allRecords = await templateService.Get() + var allRecords = await _templateRepository.Get() .AsNoTracking() .FilterByDateRangeUtc(t => t.DateCreated, utcStart, utcEnd) .Select(t => new { t.Id, t.DateCreated }) @@ -80,7 +81,7 @@ namespace PARR.API.Controllers.V1.Statistics var resultDict = allRecords.GroupByUserDate(t => t.DateCreated, timeZoneQuery.TimeZoneOffset); - var daysList = await nextRunService.GetWorkDaysAsync(userStart, userEnd, false); + var daysList = await _nextRunService.GetWorkDaysAsync(userStart, userEnd, false); var response = daysList.Select(date => new StatTemplatePeriodResponse { @@ -92,5 +93,27 @@ namespace PARR.API.Controllers.V1.Statistics } + /// + /// Получить кол-во шаблонов у которых ИД расписания null и нет задания на создание расписания + /// + /// + [HttpGet(ApiRoutes.StatTemplate.GetTemplatesWithoutScheduleAndTaskCount)] + public async Task GetTemplatesWithoutScheduleAndTaskCount() + { + var count = await _templateRepository.Get() + .CountAsync(t => + t.ScheduleEsppId == null + && !t.RobotConfigurations.Any(x => + x.RobotCode == (int)RobotsEnum.ScheduleOrder + && x.TaskStatusCode == (int)TaskStatusEnum.Creating + ) + ); + + var resposne = new StatTemplatesWithoutScheduleResponse(count); + + return Ok(new Response(resposne, true)); + } + + } }