fix(api): Статистика по шаблонам
This commit is contained in:
54
PARR.API/Controllers/V1/Statistics/StatTemplateController.cs
Normal file
54
PARR.API/Controllers/V1/Statistics/StatTemplateController.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Статистика по шаблонам
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class StatTemplateController : BaseApiController
|
||||
{
|
||||
private readonly ITemplateService templateService;
|
||||
|
||||
public StatTemplateController(
|
||||
ITemplateService templateService
|
||||
)
|
||||
{
|
||||
this.templateService = templateService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Статистика по шаблонам
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.StatTemplate.Get)]
|
||||
public async Task<IActionResult> 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<StatTemplateResponse>(response, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user