2021-04-07 18:01:56 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
2021-04-09 17:59:07 +05:00
|
|
|
|
using AsbCloudWebApi.SignalR;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-04-08 17:54:02 +05:00
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер сбора данных от буровых
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/telemetry")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class TelemetryController : ControllerBase
|
|
|
|
|
{
|
2021-04-23 10:21:25 +05:00
|
|
|
|
private readonly IDataService DataService;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
private readonly ITelemetryService telemetryService;
|
2021-04-23 10:21:25 +05:00
|
|
|
|
private readonly IMessageService messageService;
|
|
|
|
|
private readonly IEventService eventService;
|
|
|
|
|
private readonly ITelemetryUserService telemetryUserService;
|
2021-04-08 17:54:02 +05:00
|
|
|
|
private readonly IHubContext<TelemetryHub> telemetryHubContext;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
|
2021-04-23 10:21:25 +05:00
|
|
|
|
public TelemetryController(
|
|
|
|
|
ITelemetryService telemetryService,
|
|
|
|
|
IDataService DataService,
|
|
|
|
|
IMessageService messageService,
|
|
|
|
|
IEventService eventService,
|
|
|
|
|
ITelemetryUserService telemetryUserService,
|
|
|
|
|
IHubContext<TelemetryHub> telemetryHubContext)
|
2021-04-07 18:01:56 +05:00
|
|
|
|
{
|
2021-04-23 10:21:25 +05:00
|
|
|
|
this.DataService = DataService;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
this.telemetryService = telemetryService;
|
2021-04-23 10:21:25 +05:00
|
|
|
|
this.messageService = messageService;
|
|
|
|
|
this.eventService = eventService;
|
|
|
|
|
this.telemetryUserService = telemetryUserService;
|
2021-04-08 17:54:02 +05:00
|
|
|
|
this.telemetryHubContext = telemetryHubContext;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Принимает общую информацию по скважине
|
|
|
|
|
/// </summary>
|
2021-04-08 17:54:02 +05:00
|
|
|
|
/// <param name="uid">Уникальный идентификатор отправителя</param>
|
|
|
|
|
/// <param name="info">нформация об отправителе</param>
|
2021-04-07 18:01:56 +05:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("{uid}/info")]
|
|
|
|
|
public IActionResult Info(string uid, [FromBody] TelemetryInfoDto info)
|
|
|
|
|
{
|
|
|
|
|
telemetryService.UpdateInfo(uid, info);
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Принимает данные от разных систем по скважине
|
|
|
|
|
/// </summary>
|
2021-04-08 17:54:02 +05:00
|
|
|
|
/// <param name="uid">Уникальный идентификатор отправителя</param>
|
2021-04-23 10:21:25 +05:00
|
|
|
|
/// <param name="dtos">Данные</param>
|
2021-04-07 18:01:56 +05:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("{uid}/data")]
|
2021-04-23 10:21:25 +05:00
|
|
|
|
public IActionResult Data(string uid, [FromBody] IEnumerable<DataSaubBaseDto> dtos)
|
2021-04-07 18:01:56 +05:00
|
|
|
|
{
|
2021-04-23 10:21:25 +05:00
|
|
|
|
var wellId = telemetryService.GetWellIdByTelemetryUid(uid);
|
|
|
|
|
DataService.UpdateData(uid, dtos);
|
2021-04-09 17:59:07 +05:00
|
|
|
|
|
2021-04-23 10:21:25 +05:00
|
|
|
|
if (wellId != null && dtos.Any())
|
|
|
|
|
Task.Run(() => telemetryHubContext.Clients.Group($"well_{wellId}").SendAsync(nameof(ITelemetryHubClient.ReceiveDataSaub), dtos));
|
2021-04-09 17:59:07 +05:00
|
|
|
|
|
2021-04-07 18:01:56 +05:00
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-23 10:21:25 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Принимает список новых сообщений от телеметрии
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">Уникальный идентификатор отправителя</param>
|
|
|
|
|
/// <param name="dtos">сообщения</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("{uid}/message")]
|
|
|
|
|
public IActionResult Message(string uid, [FromBody] IEnumerable<TelemetryMessageDto> dtos)
|
|
|
|
|
{
|
|
|
|
|
var wellId = telemetryService.GetWellIdByTelemetryUid(uid);
|
|
|
|
|
messageService.Insert(uid, dtos);
|
|
|
|
|
|
|
|
|
|
if (dtos.Any())
|
|
|
|
|
Task.Run(() => telemetryHubContext.Clients.Group($"well_{wellId}").SendAsync(nameof(ITelemetryHubClient.ReceiveMessages), dtos));
|
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Принимает справочник событий
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">Уникальный идентификатор отправителя</param>
|
|
|
|
|
/// <param name="events">справочник событий</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("{uid}/event")]
|
|
|
|
|
public IActionResult Events(string uid, [FromBody] List<EventDto> events)
|
|
|
|
|
{
|
|
|
|
|
eventService.Upsert(uid, events);
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Принимает справочник пользователей телеметрии
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">Уникальный идентификатор отправителя</param>
|
|
|
|
|
/// <param name="users">справочник пользователей телеметрии</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("{uid}/user")]
|
|
|
|
|
public IActionResult Users(string uid, [FromBody] List<TelemetryUserDto> users)
|
|
|
|
|
{
|
|
|
|
|
telemetryUserService.Upsert(uid, users);
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
2021-04-07 18:01:56 +05:00
|
|
|
|
}
|
|
|
|
|
}
|