Фикс версий прошивок

This commit is contained in:
Степанов Дмитрий 2024-08-26 11:08:32 +05:00
parent f27bdb65b1
commit da52a8d9b6
5 changed files with 47 additions and 21 deletions

View File

@ -67,3 +67,19 @@ public class TelemetryInfoDto
/// </summary>
public string? Comment { get; set; }
}
/// <summary>
/// Информация о телеметрии скважины
/// </summary>
public class WellTelemetryInfoDto
{
/// <summary>
/// Идентификатор скважины
/// </summary>
public int IdWell { get; set; }
/// <summary>
/// Информация о телеметрии
/// </summary>
public TelemetryInfoDto Info { get; set; } = null!;
}

View File

@ -11,10 +11,10 @@ public class TelemetryInfoRequest
public int IdCompany { get; set; }
/// <summary>
/// Определяет состояние скважины
/// Необязательный параметр. Определяет состояние скважины
/// 0 - неизвестно,
/// 1 - в работе,
/// 2 - завершена
/// </summary>
public int IdWellState { get; set; }
public int? IdWellState { get; set; }
}

View File

@ -69,7 +69,7 @@ public interface ITelemetryService
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token);
Task<IEnumerable<WellTelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token);
/// <summary>
/// Слить данные телеметрии в одну

View File

@ -78,15 +78,18 @@ public class TelemetryService : ITelemetryService
DropTelemetryCache();
}
public async Task<IEnumerable<TelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token)
public async Task<IEnumerable<WellTelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token)
{
var idTelemetries = await db.Set<Well>()
var wells = db.Set<Well>()
.Include(x => x.RelationCompaniesWells)
.Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany) &&
x.IdState == request.IdWellState)
.Where(x => x.IdTelemetry.HasValue)
.Select(x => x.IdTelemetry!.Value)
.ToArrayAsync(token);
.Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany));
if (request.IdWellState.HasValue)
wells = wells.Where(x => x.IdState == request.IdWellState);
var idTelemetries = await wells.Where(x => x.IdTelemetry.HasValue)
.Select(x => x.IdTelemetry!.Value)
.ToArrayAsync(token);
var key = $"TelemetryInfo_{string.Join("", idTelemetries)}";
@ -94,19 +97,25 @@ public class TelemetryService : ITelemetryService
{
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10);
var query = db.Set<Telemetry>()
var telemetries = await db.Set<Telemetry>()
.Include(x => x.Well)
.Where(x => idTelemetries.Contains(x.Id))
.OrderBy(x => x.Info.DrillingStartDate);
var entities = await query
.OrderBy(x => x.Info.DrillingStartDate)
.AsNoTracking()
.ToArrayAsync(token);
var dtos = entities.Select(x =>
var dtos = telemetries.Select(x =>
{
var dto = x.Info.Adapt<TelemetryInfoDto>();
dto.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(dto.TimeZoneOffsetTotalHours);
return dto;
var info = x.Info.Adapt<TelemetryInfoDto>();
info.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(info.TimeZoneOffsetTotalHours);
var dto = new WellTelemetryInfoDto
{
IdWell = x.Well!.Id,
Info = info
};
return dto;
});
return dtos;

View File

@ -28,7 +28,8 @@ public class TelemetryInfoController : ControllerBase
/// <summary>
/// Получить список версий прошивок
/// </summary>
/// <param name="idWellState">Определяет состояние скважины
/// <param name="idWellState">Необязательный параметр. Определяет состояние скважины
/// null - возвращаются все записи
/// 0 - неизвестно,
/// 1 - в работе,
/// 2 - завершена</param>
@ -36,8 +37,8 @@ public class TelemetryInfoController : ControllerBase
/// <returns></returns>
[HttpGet]
[Permission]
[ProducesResponseType(typeof(IEnumerable<TelemetryInfoDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetAsync([FromQuery] int idWellState, CancellationToken token)
[ProducesResponseType(typeof(IEnumerable<WellTelemetryInfoDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetAsync([FromQuery] int? idWellState, CancellationToken token)
{
var idCompany = User.GetCompanyId();