2024-11-26 12:27:52 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-11-25 13:49:07 +05:00
|
|
|
|
using Persistence.Models;
|
|
|
|
|
using Persistence.Repositories;
|
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
namespace Persistence.API.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Работа с состояниями систем автобурения (АБ)
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class TechMessagesController : ControllerBase, ITechMessages
|
2024-11-25 13:49:07 +05:00
|
|
|
|
{
|
2024-11-27 13:08:06 +05:00
|
|
|
|
private readonly ITechMessagesRepository techMessagesRepository;
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
public TechMessagesController(ITechMessagesRepository techMessagesRepository)
|
|
|
|
|
{
|
|
|
|
|
this.techMessagesRepository = techMessagesRepository;
|
|
|
|
|
}
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить список технологических сообщений в виде страницы
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<PaginationContainer<TechMessageDto>>> GetPage([FromQuery] RequestDto request, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await techMessagesRepository.GetPage(request, token);
|
2024-11-26 10:23:48 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить статистику по системам
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="importantId"></param>
|
|
|
|
|
/// <param name="autoDrillingSystem"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("statistics")]
|
|
|
|
|
public async Task<ActionResult<int>> GetStatistics(int importantId, string autoDrillingSystem, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await techMessagesRepository.GetStatistics(importantId, autoDrillingSystem, token);
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить список всех систем
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("systems")]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<string>>> GetSystems(CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await techMessagesRepository.GetSystems(token);
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавить новые технологические сообщения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dtos"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<ActionResult<int>> InsertRange([FromBody] IEnumerable<TechMessageDto> dtos, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await techMessagesRepository.InsertRange(dtos, token);
|
2024-11-25 13:49:07 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
return CreatedAtAction(nameof(InsertRange), result);
|
|
|
|
|
}
|
2024-11-26 14:07:36 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить словарь категорий
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("categories")]
|
|
|
|
|
public ActionResult<Dictionary<int, string>> GetImportantCategories()
|
|
|
|
|
{
|
|
|
|
|
var result = new Dictionary<int, string>()
|
2024-11-26 14:07:36 +05:00
|
|
|
|
{
|
2024-11-27 13:08:06 +05:00
|
|
|
|
{ 0, "System" },
|
|
|
|
|
{ 1, "Авария" },
|
|
|
|
|
{ 2, "Предупреждение" },
|
|
|
|
|
{ 3, "Инфо" },
|
|
|
|
|
{ 4, "Прочее" }
|
|
|
|
|
};
|
2024-11-26 14:07:36 +05:00
|
|
|
|
|
2024-11-27 13:08:06 +05:00
|
|
|
|
return Ok(result);
|
2024-11-25 13:49:07 +05:00
|
|
|
|
}
|
|
|
|
|
}
|