forked from ddrilling/AsbCloudServer
CS2-34: Добавлена пагинация в метод, возвращающий список событий на скважине
This commit is contained in:
parent
beab5a39a1
commit
e447473a71
@ -4,10 +4,11 @@ namespace AsbCloudApp.Data
|
|||||||
{
|
{
|
||||||
public class OperationDto
|
public class OperationDto
|
||||||
{
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public DateTime Begin { get; set; }
|
public DateTime BeginDate { get; set; }
|
||||||
public DateTime End { get; set; }
|
public DateTime EndDate { get; set; }
|
||||||
public double OperationStartDepth { get; set; }
|
public double StartWellDepth { get; set; }
|
||||||
public double OperationEndDepth { get; set; }
|
public double EndWellDepth { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
public class OperationDurationDto
|
public class OperationDurationDto
|
||||||
{
|
{
|
||||||
public string ProcessName { get; set; }
|
public string OperationName { get; set; }
|
||||||
public double Duration { get; set; }
|
public double Duration { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,9 @@ namespace AsbCloudApp.Services
|
|||||||
{
|
{
|
||||||
public interface IAnalyticsService
|
public interface IAnalyticsService
|
||||||
{
|
{
|
||||||
IEnumerable<OperationDto> GetOperations(int wellId);
|
PaginationContainer<OperationDto> GetOperationsByWell(int wellId,
|
||||||
|
IEnumerable<int> categoryids = default, DateTime begin = default,
|
||||||
|
DateTime end = default, int skip = 0, int take = 32);
|
||||||
IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int wellId);
|
IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int wellId);
|
||||||
IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int wellId,
|
IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int wellId,
|
||||||
int intervalHoursTimestamp, int workBeginTimestamp);
|
int intervalHoursTimestamp, int workBeginTimestamp);
|
||||||
|
@ -17,7 +17,7 @@ namespace AsbCloudDb.Model
|
|||||||
public int IdTelemetry { get; set; }
|
public int IdTelemetry { get; set; }
|
||||||
|
|
||||||
[Column("id_operation")]
|
[Column("id_operation")]
|
||||||
public int? IdOperation { get; set; }
|
public int IdOperation { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ using AsbCloudInfrastructure.Services.Cache;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
@ -28,28 +29,6 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
operationDetectorService = new OperationDetectorService(operations);
|
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)
|
public IEnumerable<WellDepthToDayDto> GetWellDepthToDay(int wellId)
|
||||||
{
|
{
|
||||||
var telemetry = telemetryService.GetTelemetryByWellId(wellId);
|
var telemetry = telemetryService.GetTelemetryByWellId(wellId);
|
||||||
@ -104,6 +83,70 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return wellDepthToIntervalData;
|
return wellDepthToIntervalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PaginationContainer<OperationDto> GetOperationsByWell(int wellId,
|
||||||
|
IEnumerable<int> categoryIds = default, DateTime begin = default,
|
||||||
|
DateTime end = default, int skip = 0, int take = 32)
|
||||||
|
{
|
||||||
|
var telemetry = telemetryService.GetTelemetryByWellId(wellId);
|
||||||
|
|
||||||
|
if (telemetry is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var operations = from a in db.TelemetryAnalysis.Include(t => t.Operation)
|
||||||
|
where a.IdTelemetry == telemetry.Id
|
||||||
|
select a;
|
||||||
|
|
||||||
|
if ((categoryIds != default) && (categoryIds.Any()))
|
||||||
|
operations = operations.Where(o => categoryIds.Contains(o.IdOperation));
|
||||||
|
|
||||||
|
var result = new PaginationContainer<OperationDto>
|
||||||
|
{
|
||||||
|
Skip = skip,
|
||||||
|
Take = take
|
||||||
|
};
|
||||||
|
|
||||||
|
operations = operations.OrderBy(o => o.UnixDate);
|
||||||
|
|
||||||
|
if (begin != default)
|
||||||
|
{
|
||||||
|
var unixBegin = (begin - new DateTime(1970, 1, 1)).TotalSeconds;
|
||||||
|
operations = operations.Where(o => o.UnixDate >= unixBegin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end != default)
|
||||||
|
{
|
||||||
|
var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds;
|
||||||
|
operations = operations.Where(m => (m.UnixDate + m.Duration) <= unixEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Count = operations.Count();
|
||||||
|
|
||||||
|
if (skip > 0)
|
||||||
|
operations = operations.Skip(skip);
|
||||||
|
|
||||||
|
var operationsList = operations.Take(take).ToList();
|
||||||
|
|
||||||
|
if (operationsList.Count == 0)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
foreach(var operation in operations)
|
||||||
|
{
|
||||||
|
var operationDto = new OperationDto
|
||||||
|
{
|
||||||
|
Id = operation.Id,
|
||||||
|
Name = operation.Operation.Name,
|
||||||
|
BeginDate = DateTimeOffset.FromUnixTimeSeconds(operation.UnixDate).DateTime,
|
||||||
|
EndDate = DateTimeOffset.FromUnixTimeSeconds(operation.UnixDate + operation.Duration).DateTime,
|
||||||
|
StartWellDepth = operation.OperationStartDepth ?? 0.0,
|
||||||
|
EndWellDepth = operation.OperationEndDepth ?? 0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
result.Items.Add(operationDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<OperationDurationDto> GetOperationsSummary(int wellId,
|
public IEnumerable<OperationDurationDto> GetOperationsSummary(int wellId,
|
||||||
DateTime begin = default, DateTime end = default)
|
DateTime begin = default, DateTime end = default)
|
||||||
{
|
{
|
||||||
@ -117,13 +160,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
var operations = (from a in db.TelemetryAnalysis
|
var operations = (from a in db.TelemetryAnalysis
|
||||||
where a.IdTelemetry == telemetry.Id &&
|
where a.IdTelemetry == telemetry.Id &&
|
||||||
a.UnixDate > unixBegin && a.UnixDate < unixEnd &&
|
a.UnixDate > unixBegin && a.UnixDate < unixEnd
|
||||||
a.IdOperation != null
|
|
||||||
join o in db.Operations on a.IdOperation equals o.Id
|
join o in db.Operations on a.IdOperation equals o.Id
|
||||||
group a by new { a.IdOperation, o.Name } into g
|
group a by new { a.IdOperation, o.Name } into g
|
||||||
select new OperationDurationDto
|
select new OperationDurationDto
|
||||||
{
|
{
|
||||||
ProcessName = g.Key.Name,
|
OperationName = g.Key.Name,
|
||||||
Duration = g.Where(g => g.Duration > 0)
|
Duration = g.Where(g => g.Duration > 0)
|
||||||
.Sum(a => a.Duration)
|
.Sum(a => a.Duration)
|
||||||
}).ToList();
|
}).ToList();
|
||||||
@ -144,8 +186,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id);
|
var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId(telemetry.Id);
|
||||||
|
|
||||||
var operations = (from a in db.TelemetryAnalysis
|
var operations = (from a in db.TelemetryAnalysis
|
||||||
where a.IdTelemetry == telemetry.Id &&
|
where a.IdTelemetry == telemetry.Id
|
||||||
a.IdOperation != null
|
|
||||||
join o in db.Operations on a.IdOperation equals o.Id
|
join o in db.Operations on a.IdOperation equals o.Id
|
||||||
group a by new
|
group a by new
|
||||||
{
|
{
|
||||||
|
@ -26,20 +26,26 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// Возвращает список операций на скважине за все время
|
/// Возвращает список операций на скважине за все время
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="wellId">id скважины</param>
|
/// <param name="wellId">id скважины</param>
|
||||||
|
/// <param name="categoryIds">список категорий</param>
|
||||||
|
/// <param name="begin">дата начала</param>
|
||||||
|
/// <param name="end">окончание</param>
|
||||||
|
/// <param name="skip">для пагинации кол-во записей пропустить</param>
|
||||||
|
/// <param name="take">для пагинации кол-во записей </param>
|
||||||
/// <returns>Список операций на скважине за все время</returns>
|
/// <returns>Список операций на скважине за все время</returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{wellId}/operations")]
|
[Route("{wellId}/operationsByWell")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<OperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginationContainer<OperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public IActionResult GetOperations(int wellId)
|
public IActionResult GetOperationsByWell(int wellId, int skip = 0, int take = 32,
|
||||||
|
[FromQuery] IEnumerable<int> categoryIds = default, DateTime begin = default, DateTime end = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId))
|
if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var analytics = analyticsService.GetOperations(wellId);
|
var analytics = analyticsService.GetOperationsByWell(wellId, categoryIds, begin, end, skip, take);
|
||||||
|
|
||||||
if (analytics is null || !analytics.Any())
|
if (analytics is null || analytics.Count == 0)
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
return Ok(analytics);
|
return Ok(analytics);
|
||||||
|
Loading…
Reference in New Issue
Block a user