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

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> /// </summary>
public string? Comment { get; set; } 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; } public int IdCompany { get; set; }
/// <summary> /// <summary>
/// Определяет состояние скважины /// Необязательный параметр. Определяет состояние скважины
/// 0 - неизвестно, /// 0 - неизвестно,
/// 1 - в работе, /// 1 - в работе,
/// 2 - завершена /// 2 - завершена
/// </summary> /// </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="request"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<TelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token); Task<IEnumerable<WellTelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token);
/// <summary> /// <summary>
/// Слить данные телеметрии в одну /// Слить данные телеметрии в одну

View File

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

View File

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