Фикс формирования DTO

This commit is contained in:
Степанов Дмитрий 2024-08-28 11:13:09 +05:00
parent b6cbc63267
commit 053b210401
2 changed files with 27 additions and 32 deletions

View File

@ -12,21 +12,6 @@ public class VersionDto
/// </summary>
public int IdWell { get; set; }
/// <summary>
/// дата начала бурения (заполнения данных на панели)
/// </summary>
public DateTime DrillingStartDate { get; set; }
/// <summary>
/// идентификатор временной зоны
/// </summary>
public string? TimeZoneId { get; set; }
/// <summary>
/// смещение в часах относительно UTC
/// </summary>
public double TimeZoneOffsetTotalHours { get; set; }
/// <summary>
/// название скважины
/// </summary>
@ -66,9 +51,4 @@ public class VersionDto
/// версия ПО ПЛК Памп мастер
/// </summary>
public string? PumpPlcVersion { get; set; }
/// <summary>
/// комментарий
/// </summary>
public string? Comment { get; set; }
}

View File

@ -80,19 +80,23 @@ public class TelemetryService : ITelemetryService
public async Task<IEnumerable<VersionDto>> GetVersionsAsync(VersionRequest request, CancellationToken token)
{
var wells = db.Set<Well>()
var query = db.Set<Well>()
.Include(x => x.RelationCompaniesWells)
.ThenInclude(x => x.Company)
.Include(x => x.Cluster)
.ThenInclude(c => c.Deposit)
.Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany));
if (request.IdWellState.HasValue)
wells = wells.Where(x => x.IdState == request.IdWellState);
query = query.Where(x => x.IdState == request.IdWellState);
if (request.IdsWell?.Any() == true)
wells = wells.Where(x => request.IdsWell.Contains(x.Id));
query = query.Where(x => request.IdsWell.Contains(x.Id));
var idTelemetries = await wells.Where(x => x.IdTelemetry.HasValue)
.Select(x => x.IdTelemetry!.Value)
.ToArrayAsync(token);
var wells = await query.Where(x => x.IdTelemetry.HasValue)
.ToDictionaryAsync(x => x.Id, x => x, token);
var idTelemetries = wells.Select(x => x.Value.IdTelemetry!.Value);
var telemetries = GetTelemetryCache()
.Where(x => idTelemetries.Contains(x.Id))
@ -100,9 +104,19 @@ public class TelemetryService : ITelemetryService
var dtos = telemetries.Select(x =>
{
var dto = x.Info.Adapt<VersionDto>();
dto.IdWell = x.Well!.Id;
dto.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(dto.TimeZoneOffsetTotalHours);
var well = wells[x.Well!.Id];
var dto = new VersionDto
{
IdWell = well.Id,
Well = well.Caption,
Cluster = well.Cluster.Caption,
Deposit = well.Cluster.Deposit.Caption,
Customer = well.RelationCompaniesWells.Select(r => r.Company).FirstOrDefault(c => c.IdCompanyType == 1)?.Caption,
HmiVersion = x.Info.HmiVersion,
SaubPlcVersion = x.Info.SaubPlcVersion,
SpinPlcVersion = x.Info.SpinPlcVersion,
};
return dto;
});
@ -110,6 +124,7 @@ public class TelemetryService : ITelemetryService
return dtos;
}
[Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")]
public SimpleTimezoneDto GetTimezone(int idTelemetry)
{