2023-12-20 13:43:03 +10:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using PARR.API.Contracts.V1;
|
2024-08-30 16:40:06 +10:00
|
|
|
|
using PARR.API.Contracts.V1.Requests.BaseRequests;
|
2023-12-20 13:43:03 +10:00
|
|
|
|
using PARR.API.Contracts.V1.Responses.Base;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Responses.Statistics;
|
|
|
|
|
|
using PARR.API.Controllers.V1.Base;
|
2024-08-30 16:40:06 +10:00
|
|
|
|
using PARR.BLL.Services.Interfaces;
|
2023-12-20 13:43:03 +10:00
|
|
|
|
using PARR.Constants;
|
|
|
|
|
|
using PARR.DAL.Services.Interfaces;
|
2025-08-26 14:04:49 +10:00
|
|
|
|
using PARR.DAL.Services.Interfaces.Unit;
|
2023-12-20 13:43:03 +10:00
|
|
|
|
|
|
|
|
|
|
namespace PARR.API.Controllers.V1.Statistics
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2025-08-26 14:04:49 +10:00
|
|
|
|
/// Статистика по значениям unit.FieldValues полученных из АИХИТ
|
2023-12-20 13:43:03 +10:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
2025-08-26 14:04:49 +10:00
|
|
|
|
public class StatUnitFieldValuesController : BaseApiController
|
2023-12-20 13:43:03 +10:00
|
|
|
|
{
|
|
|
|
|
|
private readonly IApplicationService applicationService;
|
2025-08-26 14:04:49 +10:00
|
|
|
|
private readonly IUnitFieldValueService unitFieldValueService;
|
2024-08-30 16:40:06 +10:00
|
|
|
|
private readonly ICalendarService calendarService;
|
2023-12-20 13:43:03 +10:00
|
|
|
|
|
2025-08-26 14:04:49 +10:00
|
|
|
|
public StatUnitFieldValuesController(
|
|
|
|
|
|
IApplicationService applicationService,
|
|
|
|
|
|
IUnitFieldValueService unitFieldValueService,
|
|
|
|
|
|
ICalendarService calendarService
|
|
|
|
|
|
)
|
2023-12-20 13:43:03 +10:00
|
|
|
|
{
|
|
|
|
|
|
this.applicationService = applicationService;
|
2025-08-26 14:04:49 +10:00
|
|
|
|
this.unitFieldValueService = unitFieldValueService;
|
2024-08-30 16:40:06 +10:00
|
|
|
|
this.calendarService = calendarService;
|
2023-12-20 13:43:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-08-26 14:04:49 +10:00
|
|
|
|
/// Статистика синхронизации полей юнитов (ЭК) с АИХИТ за последние сутки
|
2023-12-20 13:43:03 +10:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2025-08-26 14:04:49 +10:00
|
|
|
|
[HttpGet(ApiRoutes.StatUnitFieldValues.Get)]
|
2023-12-20 13:43:03 +10:00
|
|
|
|
public async Task<IActionResult> Get()
|
|
|
|
|
|
{
|
|
|
|
|
|
var queryDate = DateTimeOffset.UtcNow.AddDays(-1);
|
|
|
|
|
|
|
2025-08-26 14:04:49 +10:00
|
|
|
|
var response = new StatUnitFieldValuesResponse
|
2023-12-20 13:43:03 +10:00
|
|
|
|
{
|
2025-08-26 14:04:49 +10:00
|
|
|
|
AllValues = await unitFieldValueService.Get().CountAsync(),
|
|
|
|
|
|
CreatedLastDay = await unitFieldValueService.Get().CountAsync(t => t.DateCreated >= queryDate),
|
|
|
|
|
|
//UpdatedLastDay = await applicationService.Get().CountAsync(t => t.DateModified.HasValue && t.DateModified.Value >= queryDate),
|
2023-12-20 13:43:03 +10:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-26 14:04:49 +10:00
|
|
|
|
return Ok(new Response<StatUnitFieldValuesResponse>(response, true));
|
2023-12-20 13:43:03 +10:00
|
|
|
|
}
|
2024-08-30 16:40:06 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Получить статистику за период
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="timeZoneQuery"></param>
|
|
|
|
|
|
/// <param name="startPeriodDays"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-08-26 14:04:49 +10:00
|
|
|
|
[HttpGet(ApiRoutes.StatUnitFieldValues.GetForPeriod)]
|
2024-08-30 16:40:06 +10:00
|
|
|
|
public async Task<IActionResult> GetForPeriod([FromQuery] TimeZoneOffsetClient timeZoneQuery, [FromQuery] int startPeriodDays = 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
var endPeriod = calendarService.GetDateWithTimeZoneOffset(DateTimeOffset.UtcNow, timeZoneQuery.TimeZoneOffsetHours);
|
|
|
|
|
|
var startPeriod = endPeriod.AddDays(-startPeriodDays);
|
|
|
|
|
|
|
2025-08-26 14:04:49 +10:00
|
|
|
|
var query = unitFieldValueService.Get()
|
2024-09-04 09:30:57 +10:00
|
|
|
|
.Where(t =>
|
|
|
|
|
|
t.DateCreated.DateTime.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date >= startPeriod.Date
|
|
|
|
|
|
&& t.DateCreated.DateTime.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date <= endPeriod.Date
|
|
|
|
|
|
)
|
|
|
|
|
|
.GroupBy(t => t.DateCreated.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date)
|
2024-08-30 16:40:06 +10:00
|
|
|
|
.Select(t => new
|
|
|
|
|
|
{
|
|
|
|
|
|
Date = t.Key,
|
2025-08-26 14:04:49 +10:00
|
|
|
|
Count = t.Count()
|
2024-08-30 16:40:06 +10:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var result = await query.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var daysList = calendarService.GetDatesForPeriod(startPeriod, endPeriod);
|
|
|
|
|
|
|
|
|
|
|
|
var response = new List<StatApplicationPeriodResponse>();
|
|
|
|
|
|
|
|
|
|
|
|
daysList.ForEach(date =>
|
|
|
|
|
|
{
|
|
|
|
|
|
response.Add(new StatApplicationPeriodResponse
|
|
|
|
|
|
{
|
|
|
|
|
|
Date = date,
|
2025-08-26 14:04:49 +10:00
|
|
|
|
CreatedApplicationsCount = result.FirstOrDefault(t => DateOnly.FromDateTime(t.Date) == date)?.Count ?? 0
|
2024-08-30 16:40:06 +10:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
response = response.OrderBy(t => t.Date).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(new Response<List<StatApplicationPeriodResponse>>(response, true));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-20 13:43:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|