forked from ddrilling/AsbCloudServer
66 lines
2.3 KiB
C#
66 lines
2.3 KiB
C#
using AsbCloudApp.Data;
|
||
using AsbCloudApp.Services;
|
||
using AsbCloudWebApi.SignalR;
|
||
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.AspNetCore.SignalR;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace AsbCloudWebApi.Controllers
|
||
{
|
||
/// <summary>
|
||
/// Контроллер сбора данных от буровых
|
||
/// </summary>
|
||
[Route("api/telemetry")]
|
||
[ApiController]
|
||
public class TelemetryController : ControllerBase
|
||
{
|
||
private readonly ITelemetryService telemetryService;
|
||
private readonly IHubContext<TelemetryHub> telemetryHubContext;
|
||
|
||
public TelemetryController(ITelemetryService telemetryService, IHubContext<TelemetryHub> telemetryHubContext)
|
||
{
|
||
this.telemetryService = telemetryService;
|
||
this.telemetryHubContext = telemetryHubContext;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Принимает общую информацию по скважине
|
||
/// </summary>
|
||
/// <param name="uid">Уникальный идентификатор отправителя</param>
|
||
/// <param name="info">нформация об отправителе</param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[Route("{uid}/info")]
|
||
public IActionResult Info(string uid, [FromBody] TelemetryInfoDto info)
|
||
{
|
||
telemetryService.UpdateInfo(uid, info);
|
||
return Ok();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Принимает данные от разных систем по скважине
|
||
/// </summary>
|
||
/// <param name="uid">Уникальный идентификатор отправителя</param>
|
||
/// <param name="data">Данные</param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[Route("{uid}/data")]
|
||
public IActionResult Data(string uid, [FromBody] TelemetryDataDto data)
|
||
{
|
||
telemetryService.UpdateData(uid, data);
|
||
|
||
var wellId = telemetryService.GetWellIdByUid(uid);
|
||
|
||
if (wellId != null && data.DataSaub?.Count > 0)
|
||
Task.Run(() => telemetryHubContext.Clients.Group($"well_{wellId}").SendAsync(nameof(ITelemetryHubClient.ReceiveDataSaub), data.DataSaub) );
|
||
|
||
return Ok();
|
||
}
|
||
|
||
}
|
||
}
|