diff --git a/PARR.API/Contracts/V1/ApiRoutes.cs b/PARR.API/Contracts/V1/ApiRoutes.cs
index f3cfe01b..8a210088 100644
--- a/PARR.API/Contracts/V1/ApiRoutes.cs
+++ b/PARR.API/Contracts/V1/ApiRoutes.cs
@@ -182,6 +182,11 @@ namespace PARR.API.Contracts.V1
public const string Get = BaseStat + "/robot-histories/";
}
+ public static class StatTemplate
+ {
+ public const string Get = BaseStat + "/templates/";
+ }
+
#endregion
}
diff --git a/PARR.API/Contracts/V1/Responses/Statistics/StatTemplateResponse.cs b/PARR.API/Contracts/V1/Responses/Statistics/StatTemplateResponse.cs
new file mode 100644
index 00000000..af6b5bb7
--- /dev/null
+++ b/PARR.API/Contracts/V1/Responses/Statistics/StatTemplateResponse.cs
@@ -0,0 +1,17 @@
+namespace PARR.API.Contracts.V1.Responses.Statistics
+{
+ public class StatTemplateResponse
+ {
+ public int TemplateCount { get; set; }
+
+ public int ActivateTemplateCount { get; set; }
+
+ public int ActivateScheduleCount { get; set; }
+
+ public int TemplateAgentCount { get; set; }
+
+ public int SyncEsppTemplatesCount { get;set; }
+
+ public int SyncEsppScheduleCount { get; set; }
+ }
+}
diff --git a/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs b/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs
new file mode 100644
index 00000000..d0493017
--- /dev/null
+++ b/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs
@@ -0,0 +1,54 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using PARR.API.Contracts.V1;
+using PARR.API.Contracts.V1.Responses.Base;
+using PARR.API.Contracts.V1.Responses.Statistics;
+using PARR.API.Controllers.V1.Base;
+using PARR.Constants;
+using PARR.DAL.Contracts;
+using PARR.DAL.Services.Interfaces;
+
+namespace PARR.API.Controllers.V1.Statistics
+{
+ ///
+ /// Статистика по шаблонам
+ ///
+ [Authorize(Roles = ParrRoles.Administrator.Role)]
+ public class StatTemplateController : BaseApiController
+ {
+ private readonly ITemplateService templateService;
+
+ public StatTemplateController(
+ ITemplateService templateService
+ )
+ {
+ this.templateService = templateService;
+ }
+
+ ///
+ /// Статистика по шаблонам
+ ///
+ ///
+ [HttpGet(ApiRoutes.StatTemplate.Get)]
+ public async Task Get()
+ {
+ 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))
+ };
+
+ return Ok(new Response(response, true));
+ }
+ }
+}