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-09-27 16:48:24 +05:00
|
|
|
|
using System;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-08-11 16:54:42 +05:00
|
|
|
|
using System.Threading;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер сбора данных от буровых
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/telemetry")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class TelemetryController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
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-05-12 16:03:14 +05:00
|
|
|
|
private readonly ITelemetryTracker telemetryTracker;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
|
2021-04-23 10:21:25 +05:00
|
|
|
|
public TelemetryController(
|
2021-04-30 17:35:35 +05:00
|
|
|
|
ITelemetryService telemetryService,
|
|
|
|
|
IMessageService messageService,
|
|
|
|
|
IEventService eventService,
|
|
|
|
|
ITelemetryUserService telemetryUserService,
|
2021-05-12 16:03:14 +05:00
|
|
|
|
IHubContext<TelemetryHub> telemetryHubContext,
|
|
|
|
|
ITelemetryTracker telemetryTracker)
|
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-05-12 16:03:14 +05:00
|
|
|
|
this.telemetryTracker = telemetryTracker;
|
2021-05-12 17:25:52 +05:00
|
|
|
|
}
|
2021-07-21 15:29:19 +05:00
|
|
|
|
|
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")]
|
2021-04-30 17:35:35 +05:00
|
|
|
|
public IActionResult PostInfo(string uid, [FromBody] TelemetryInfoDto info)
|
2021-04-07 18:01:56 +05:00
|
|
|
|
{
|
|
|
|
|
telemetryService.UpdateInfo(uid, info);
|
2021-05-14 10:58:23 +05:00
|
|
|
|
telemetryTracker.SaveRequestDate(uid);
|
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>
|
2021-08-11 16:54:42 +05:00
|
|
|
|
/// <param name="token">Токен для отмены задачи</param>
|
2021-04-23 10:21:25 +05:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("{uid}/message")]
|
2021-08-11 16:54:42 +05:00
|
|
|
|
public async Task<IActionResult> PostMessagesAsync(string uid, [FromBody] IEnumerable<TelemetryMessageDto> dtos,
|
|
|
|
|
CancellationToken token = default)
|
2021-04-23 10:21:25 +05:00
|
|
|
|
{
|
2021-07-27 14:43:30 +05:00
|
|
|
|
var idWell = telemetryService.GetidWellByTelemetryUid(uid);
|
2021-08-11 17:26:02 +05:00
|
|
|
|
await messageService.InsertAsync(uid, dtos, token).ConfigureAwait(false);
|
2021-04-23 10:21:25 +05:00
|
|
|
|
|
|
|
|
|
if (dtos.Any())
|
2021-08-11 17:26:02 +05:00
|
|
|
|
await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
2021-09-17 16:24:01 +05:00
|
|
|
|
.SendAsync("ReceiveMessages", dtos), token).ConfigureAwait(false);
|
2021-04-23 10:21:25 +05:00
|
|
|
|
|
2021-05-14 10:58:23 +05:00
|
|
|
|
telemetryTracker.SaveRequestDate(uid);
|
2021-04-23 10:21:25 +05:00
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Принимает справочник событий
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">Уникальный идентификатор отправителя</param>
|
|
|
|
|
/// <param name="events">справочник событий</param>
|
2021-08-11 16:54:42 +05:00
|
|
|
|
/// <param name="token">Токен для отмены задачи</param>
|
2021-04-23 10:21:25 +05:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("{uid}/event")]
|
2021-08-11 16:54:42 +05:00
|
|
|
|
public async Task<IActionResult> PostEventsAsync(string uid, [FromBody] List<EventDto> events,
|
|
|
|
|
CancellationToken token = default)
|
2021-04-23 10:21:25 +05:00
|
|
|
|
{
|
2021-08-11 17:26:02 +05:00
|
|
|
|
await eventService.UpsertAsync(uid, events, token)
|
|
|
|
|
.ConfigureAwait(false);
|
2021-05-14 10:58:23 +05:00
|
|
|
|
telemetryTracker.SaveRequestDate(uid);
|
2021-04-23 10:21:25 +05:00
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Принимает справочник пользователей телеметрии
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">Уникальный идентификатор отправителя</param>
|
|
|
|
|
/// <param name="users">справочник пользователей телеметрии</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("{uid}/user")]
|
2021-04-30 17:35:35 +05:00
|
|
|
|
public IActionResult PostUsers(string uid, [FromBody] List<TelemetryUserDto> users)
|
2021-04-23 10:21:25 +05:00
|
|
|
|
{
|
|
|
|
|
telemetryUserService.Upsert(uid, users);
|
2021-05-14 10:58:23 +05:00
|
|
|
|
telemetryTracker.SaveRequestDate(uid);
|
2021-04-23 10:21:25 +05:00
|
|
|
|
return Ok();
|
|
|
|
|
}
|
2021-04-30 17:35:35 +05:00
|
|
|
|
|
2021-05-19 15:50:09 +05:00
|
|
|
|
///// <summary>
|
|
|
|
|
///// Загрузка архива (sqlite3).
|
|
|
|
|
///// <example>
|
|
|
|
|
///// var fileName = @"C:\temp\default.sqlite3";
|
|
|
|
|
///// var fileStream = System.IO.File.OpenRead(fileName);
|
|
|
|
|
///// var file = new FileParameter(fileStream, System.IO.Path.GetFileName(fileName));
|
|
|
|
|
///// cli.ApiTelemetryDbAsync("1", new List<FileParameter> { file }).Wait();
|
|
|
|
|
///// </example>
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="uid"></param>
|
|
|
|
|
///// <param name="files"></param>
|
|
|
|
|
///// <returns></returns>
|
2021-04-30 17:35:35 +05:00
|
|
|
|
//[HttpPost]
|
|
|
|
|
//[Route("{uid}/db")]
|
|
|
|
|
//public IActionResult PostDb(string uid, IFormFileCollection files)
|
|
|
|
|
//{
|
|
|
|
|
// foreach (var file in files)
|
|
|
|
|
// {
|
|
|
|
|
// var fileName = string.IsNullOrEmpty(file.FileName)
|
|
|
|
|
// ? System.IO.Path.GetTempFileName()
|
|
|
|
|
// : file.FileName;
|
|
|
|
|
// using (var stream = System.IO.File.Create(fileName))
|
|
|
|
|
// file.CopyTo(stream);
|
|
|
|
|
// }
|
|
|
|
|
// return Ok();
|
|
|
|
|
//}
|
2021-05-19 15:50:09 +05:00
|
|
|
|
|
2021-04-07 18:01:56 +05:00
|
|
|
|
}
|
|
|
|
|
}
|