fix(api): Статистика хостам, приложениям, хостам в шаблонах
This commit is contained in:
@@ -187,6 +187,17 @@ namespace PARR.API.Contracts.V1
|
|||||||
public const string Get = BaseStat + "/templates/";
|
public const string Get = BaseStat + "/templates/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class StatHost
|
||||||
|
{
|
||||||
|
public const string Get = BaseStat + "/hosts/";
|
||||||
|
public const string GetWithTemplates = BaseStat + "/hosts/templates";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class StatApplication
|
||||||
|
{
|
||||||
|
public const string Get = BaseStat + "/applications/";
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Responses.Statistics
|
||||||
|
{
|
||||||
|
public class StatApplicationResponse
|
||||||
|
{
|
||||||
|
public int AllApplications { get; set; }
|
||||||
|
|
||||||
|
public int CreatedLastDay { get; set; }
|
||||||
|
|
||||||
|
public int UpdatedLastDay { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Responses.Statistics
|
||||||
|
{
|
||||||
|
public class StatHostResponse
|
||||||
|
{
|
||||||
|
public int AllHosts { get; set; }
|
||||||
|
|
||||||
|
public int CreatedLastDay { get; set; }
|
||||||
|
|
||||||
|
public int UpdatedLastDay { get; set;}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Responses.Statistics
|
||||||
|
{
|
||||||
|
public class StatHostTemplateResponse
|
||||||
|
{
|
||||||
|
public int AllHosts { get; set; }
|
||||||
|
public int HostsInTemplates { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
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.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace PARR.API.Controllers.V1.Statistics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Статистика по приложениям
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||||
|
public class StatApplicationController : BaseApiController
|
||||||
|
{
|
||||||
|
private readonly IApplicationService applicationService;
|
||||||
|
|
||||||
|
public StatApplicationController(IApplicationService applicationService)
|
||||||
|
{
|
||||||
|
this.applicationService = applicationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статистика синхронизации приложений с АИХИТ за последние сутки
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet(ApiRoutes.StatApplication.Get)]
|
||||||
|
public async Task<IActionResult> Get()
|
||||||
|
{
|
||||||
|
var queryDate = DateTimeOffset.UtcNow.AddDays(-1);
|
||||||
|
|
||||||
|
var response = new StatApplicationResponse
|
||||||
|
{
|
||||||
|
AllApplications = await applicationService.Get().CountAsync(),
|
||||||
|
CreatedLastDay = await applicationService.Get().CountAsync(t => t.DateCreated >= queryDate),
|
||||||
|
UpdatedLastDay = await applicationService.Get().CountAsync(t => t.DateModified.HasValue && t.DateModified.Value >= queryDate),
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(new Response<StatApplicationResponse>(response, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
PARR.API/Controllers/V1/Statistics/StatHostController.cs
Normal file
64
PARR.API/Controllers/V1/Statistics/StatHostController.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
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.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace PARR.API.Controllers.V1.Statistics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Статистика по хостам
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||||
|
public class StatHostController : BaseApiController
|
||||||
|
{
|
||||||
|
private readonly IHostService hostService;
|
||||||
|
|
||||||
|
public StatHostController(IHostService hostService)
|
||||||
|
{
|
||||||
|
this.hostService = hostService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статистика синхронизации хостов с АИХИТ за последние сутки
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet(ApiRoutes.StatHost.Get)]
|
||||||
|
public async Task<IActionResult> Get()
|
||||||
|
{
|
||||||
|
var queryDate = DateTimeOffset.UtcNow.AddDays(-1);
|
||||||
|
|
||||||
|
var response = new StatHostResponse
|
||||||
|
{
|
||||||
|
AllHosts = await hostService.Get().CountAsync(),
|
||||||
|
CreatedLastDay = await hostService.Get().CountAsync(t => t.DateCreated >= queryDate),
|
||||||
|
UpdatedLastDay = await hostService.Get().CountAsync(t => t.DateModified.HasValue && t.DateModified.Value >= queryDate)
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(new Response<StatHostResponse>(response, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Количество хостов в шаблонах
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet(ApiRoutes.StatHost.GetWithTemplates)]
|
||||||
|
public async Task<IActionResult> GetWithTemplates()
|
||||||
|
{
|
||||||
|
//считаем именно хосты в шаблонах, т е один хост может быть в нескольких шаблонах
|
||||||
|
|
||||||
|
var response = new StatHostTemplateResponse
|
||||||
|
{
|
||||||
|
AllHosts = await hostService.Get().CountAsync(),
|
||||||
|
HostsInTemplates = await hostService.Get().Include(t => t.Templates).CountAsync(t =>t.Templates.Any())
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(new Response<StatHostTemplateResponse>(response, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user