CS2-34: В AnalyticsService добавлен метод, возвращающий все операции на скважине

This commit is contained in:
KharchenkoVV 2021-07-20 15:13:26 +05:00
parent 2586bacaf6
commit 54d917c17e
4 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,13 @@
using System;
namespace AsbCloudApp.Data
{
public class OperationDto
{
public string Name { get; set; }
public DateTime Begin { get; set; }
public DateTime End { get; set; }
public double OperationStartDepth { get; set; }
public double OperationEndDepth { get; set; }
}
}

View File

@ -7,6 +7,7 @@ namespace AsbCloudApp.Services
{
public interface IAnalyticsService
{
IEnumerable<OperationDto> GetOperations(int wellId);
IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int wellId);
IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp);

View File

@ -28,6 +28,28 @@ namespace AsbCloudInfrastructure.Services
operationDetectorService = new OperationDetectorService(operations);
}
public IEnumerable<OperationDto> GetOperations(int wellId)
{
var telemetry = telemetryService.GetTelemetryByWellId(wellId);
if (telemetry is null)
return null;
var operations = (from a in db.TelemetryAnalysis
where a.IdTelemetry == telemetry.Id
join o in db.Operations on a.IdOperation equals o.Id
select new OperationDto
{
Name = o.Name,
Begin = DateTimeOffset.FromUnixTimeSeconds(a.UnixDate).DateTime,
End = DateTimeOffset.FromUnixTimeSeconds(a.UnixDate + a.Duration).DateTime,
OperationStartDepth = a.OperationStartDepth ?? 0.0,
OperationEndDepth = a.OperationEndDepth ?? 0.0
}).ToList().OrderBy(op => op.Begin);
return operations;
}
public IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int wellId)
{
var telemetry = telemetryService.GetTelemetryByWellId(wellId);

View File

@ -22,6 +22,29 @@ namespace AsbCloudWebApi.Controllers
this.wellService = wellService;
}
/// <summary>
/// Возвращает список операций на скважине за все время
/// </summary>
/// <param name="wellId">id скважины</param>
/// <returns>Список операций на скважине за все время</returns>
[HttpGet]
[Route("{wellId}/operations")]
[ProducesResponseType(typeof(IEnumerable<OperationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperations(int wellId)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
var analytics = analyticsService.GetOperations(wellId);
if (analytics is null || !analytics.Any())
return NoContent();
return Ok(analytics);
}
/// <summary>
/// Возвращает данные по скважине "глубина-день"
/// </summary>
@ -104,7 +127,6 @@ namespace AsbCloudWebApi.Controllers
/// <param name="intervalSeconds">количество секунд в необходимом интервале времени</param>
/// <param name="workBeginSeconds">количество секунд в времени начала смены</param>
/// <returns>Коллекцию операций на скважине</returns>
[HttpGet]
[Route("{wellId}/operationsToInterval")]
[ProducesResponseType(typeof(IEnumerable<OperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]