2024-12-02 15:14:00 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-11-26 12:27:52 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-12-16 15:38:46 +05:00
|
|
|
|
using DD.Persistence.Models;
|
|
|
|
|
using DD.Persistence.Models.Requests;
|
|
|
|
|
using DD.Persistence.Repositories;
|
2024-12-10 10:43:12 +05:00
|
|
|
|
using System.Net;
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-12-16 15:38:46 +05:00
|
|
|
|
namespace DD.Persistence.API.Controllers;
|
2024-11-27 13:08:06 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-12-12 16:11:08 +05:00
|
|
|
|
/// Работа с технологическими сообщениями систем автобурения (АБ)
|
2024-11-27 13:08:06 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[Route("api/[controller]")]
|
2024-11-28 08:55:50 +05:00
|
|
|
|
public class TechMessagesController : ControllerBase
|
2024-11-25 13:49:07 +05:00
|
|
|
|
{
|
2024-12-10 10:43:12 +05:00
|
|
|
|
private readonly ITechMessagesRepository techMessagesRepository;
|
|
|
|
|
private static readonly Dictionary<int, string> categories = new()
|
|
|
|
|
{
|
|
|
|
|
{ 0, "System" },
|
|
|
|
|
{ 1, "Авария" },
|
|
|
|
|
{ 2, "Предупреждение" },
|
|
|
|
|
{ 3, "Инфо" },
|
|
|
|
|
{ 4, "Прочее" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public TechMessagesController(ITechMessagesRepository techMessagesRepository)
|
|
|
|
|
{
|
|
|
|
|
this.techMessagesRepository = techMessagesRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить список технологических сообщений в виде страницы
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<PaginationContainer<TechMessageDto>>> GetPage([FromQuery] PaginationRequest request, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await techMessagesRepository.GetPage(request, token);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить статистику по системам
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="autoDrillingSystem"></param>
|
2024-12-02 15:14:00 +05:00
|
|
|
|
/// <param name="categoryIds"></param>
|
2024-11-27 13:08:06 +05:00
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-12-02 15:14:00 +05:00
|
|
|
|
[HttpGet("statistics")]
|
2024-12-12 11:47:52 +05:00
|
|
|
|
public async Task<ActionResult<IEnumerable<MessagesStatisticDto>>> GetStatistics([FromQuery] IEnumerable<Guid> autoDrillingSystem, [FromQuery] IEnumerable<int> categoryIds, CancellationToken token)
|
2024-11-27 13:08:06 +05:00
|
|
|
|
{
|
2024-12-02 15:14:00 +05:00
|
|
|
|
var result = await techMessagesRepository.GetStatistics(autoDrillingSystem, categoryIds, token);
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-12-10 10:43:12 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить список всех систем
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("systems")]
|
|
|
|
|
public async Task<ActionResult<Dictionary<string, int>>> GetSystems(CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await techMessagesRepository.GetSystems(token);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить диапазон дат, для которых есть данные в репозитории
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("range")]
|
2024-12-13 17:30:35 +05:00
|
|
|
|
public async Task<ActionResult<DatesRangeDto?>> GetDatesRangeAsync(CancellationToken token)
|
2024-12-10 10:43:12 +05:00
|
|
|
|
{
|
|
|
|
|
var result = await techMessagesRepository.GetDatesRangeAsync(token);
|
|
|
|
|
|
2024-12-13 15:30:11 +05:00
|
|
|
|
return result == null ? NoContent() : Ok(result);
|
2024-12-10 10:43:12 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить порцию записей, начиная с заданной даты
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dateBegin"></param>
|
|
|
|
|
/// <param name="take"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("part")]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<SetpointLogDto>>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await techMessagesRepository.GetPart(dateBegin, take, token);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-12-02 15:14:00 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавить новые технологические сообщения
|
|
|
|
|
/// </summary>
|
2024-12-12 11:47:52 +05:00
|
|
|
|
/// <param name="systemId"></param>
|
2024-11-27 13:08:06 +05:00
|
|
|
|
/// <param name="dtos"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-12-12 11:47:52 +05:00
|
|
|
|
[HttpPost("{systemId}")]
|
2024-12-02 15:14:00 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)]
|
2024-12-12 11:47:52 +05:00
|
|
|
|
public async Task<IActionResult> AddRange([FromRoute] Guid systemId, [FromBody] IEnumerable<TechMessageDto> dtos, CancellationToken token)
|
2024-11-27 13:08:06 +05:00
|
|
|
|
{
|
2024-12-02 15:14:00 +05:00
|
|
|
|
var userId = User.GetUserId<Guid>();
|
|
|
|
|
|
2024-12-12 11:47:52 +05:00
|
|
|
|
var result = await techMessagesRepository.AddRange(systemId, dtos, userId, token);
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-12-10 10:43:12 +05:00
|
|
|
|
return CreatedAtAction(nameof(AddRange), result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить словарь категорий
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("categories")]
|
|
|
|
|
public ActionResult<Dictionary<int, string>> GetImportantCategories()
|
|
|
|
|
{
|
|
|
|
|
return Ok(categories);
|
|
|
|
|
}
|
2024-12-02 15:14:00 +05:00
|
|
|
|
}
|