forked from ddrilling/AsbCloudServer
Фикс Drill test
This commit is contained in:
parent
01e953c10f
commit
4576a40ab0
@ -33,9 +33,9 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// Сохранить данные drill_test
|
/// Сохранить данные drill_test
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idTelemetry">ключ телеметрии</param>
|
/// <param name="idTelemetry">ключ телеметрии</param>
|
||||||
/// <param name="dto">запись drill test</param>
|
/// <param name="dtos">записи drill test</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> SaveDataAsync(int idTelemetry, DrillTestBaseDto dto, CancellationToken token);
|
Task<int> SaveDataAsync(int idTelemetry, IEnumerable<DrillTestBaseDto> dtos, CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,16 +63,20 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> SaveDataAsync(int idTelemetry, DrillTestBaseDto dto, CancellationToken token)
|
public async Task<int> SaveDataAsync(int idTelemetry, IEnumerable<DrillTestBaseDto> dtos, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entity = dto.Adapt<DrillTest>();
|
var entities = dtos.Select(dto =>
|
||||||
entity.IdTelemetry = idTelemetry;
|
{
|
||||||
db.DrillTests.Add(entity);
|
var entity = dto.Adapt<DrillTest>();
|
||||||
|
entity.IdTelemetry = idTelemetry;
|
||||||
|
return entity;
|
||||||
|
});
|
||||||
|
db.DrillTests.AddRange(entities);
|
||||||
var result = await db.SaveChangesAsync(token);
|
var result = await db.SaveChangesAsync(token);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DrillTestDto Convert(DrillTest entity)
|
private static DrillTestDto Convert(DrillTest entity)
|
||||||
{
|
{
|
||||||
var dto = entity.Adapt<DrillTestDto>();
|
var dto = entity.Adapt<DrillTestDto>();
|
||||||
dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry?.TimeZone?.Hours ?? 0);
|
dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry?.TimeZone?.Hours ?? 0);
|
||||||
|
@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -51,27 +52,27 @@ public class DrillTestController : ControllerBase
|
|||||||
/// Сохраняет в БД.
|
/// Сохраняет в БД.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="uid">уникальный идентификатор записи drill_test</param>
|
/// <param name="uid">уникальный идентификатор записи drill_test</param>
|
||||||
/// <param name="dto">запись drill test</param>
|
/// <param name="dtos">записи drill test</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpPost("api/telemetry/{uid}/[controller]")]
|
[HttpPost("api/telemetry/{uid}/[controller]")]
|
||||||
public async Task<IActionResult> PostDataAsync(
|
public async Task<IActionResult> PostDataAsync(
|
||||||
string uid,
|
string uid,
|
||||||
[FromBody] DrillTestBaseDto dto,
|
[FromBody] IEnumerable<DrillTestBaseDto> dtos,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid);
|
var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid);
|
||||||
if (telemetry is null)
|
if (telemetry is null)
|
||||||
throw new Exception($"Telemetry with RemoteUid: {uid} does not exist.");
|
throw new Exception($"Telemetry with RemoteUid: {uid} does not exist.");
|
||||||
|
|
||||||
await drillTestRepository.SaveDataAsync(telemetry.Id, dto, token);
|
await drillTestRepository.SaveDataAsync(telemetry.Id, dtos, token);
|
||||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||||
if (idWell is not null)
|
if (idWell is not null)
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var clients = telemetryHubContext.Clients.Group($"well_{idWell}");
|
var clients = telemetryHubContext.Clients.Group($"well_{idWell}");
|
||||||
await clients.ReceiveDrilltestData(dto, token);
|
await clients.ReceiveDrilltestData(dtos, token);
|
||||||
}, CancellationToken.None);
|
}, CancellationToken.None);
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
|
@ -17,10 +17,10 @@ namespace AsbCloudWebApi.SignalR.Clients
|
|||||||
/// Отправка клиенту уведомления о доставке с панели drill test данных.
|
/// Отправка клиенту уведомления о доставке с панели drill test данных.
|
||||||
/// Для подписки на метод необходимо отправить сообщение в формате $"well_{idWell}"
|
/// Для подписки на метод необходимо отправить сообщение в формате $"well_{idWell}"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dto"></param>
|
/// <param name="dtos"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task ReceiveDrilltestData(DrillTestBaseDto dto, CancellationToken token);
|
Task ReceiveDrilltestData(IEnumerable<DrillTestBaseDto> dtos, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновление записей РТК
|
/// Обновление записей РТК
|
||||||
|
Loading…
Reference in New Issue
Block a user