Правки по результатам ревью

This commit is contained in:
Olga Nemt 2024-03-25 16:08:59 +05:00
parent 612dd6b7ce
commit 3b7e3092f5
11 changed files with 8044 additions and 8052 deletions

View File

@ -20,5 +20,5 @@ public class ProcessMapPlanRequest
/// <summary> /// <summary>
/// Дата обновления /// Дата обновления
/// </summary> /// </summary>
public DateTimeKind? UpdateFrom { get; set; } public DateTimeOffset? UpdateFrom { get; set; }
} }

View File

@ -282,7 +282,7 @@ namespace AsbCloudDb.Migrations
.HasColumnName("date") .HasColumnName("date")
.HasComment("Дата формирования отчёта"); .HasComment("Дата формирования отчёта");
b.Property<DateTimeOffset?>("DateLastUpdate") b.Property<DateTime?>("DateLastUpdate")
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")
.HasColumnName("date_last_update") .HasColumnName("date_last_update")
.HasComment("Дата последнего обновления"); .HasComment("Дата последнего обновления");
@ -1390,7 +1390,7 @@ namespace AsbCloudDb.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTimeOffset>("DateDownload") b.Property<DateTime>("DateDownload")
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")
.HasColumnName("date_download") .HasColumnName("date_download")
.HasComment("Дата загрузки"); .HasComment("Дата загрузки");
@ -1581,17 +1581,17 @@ namespace AsbCloudDb.Migrations
.HasColumnName("message") .HasColumnName("message")
.HasComment("Сообщение уведомления"); .HasComment("Сообщение уведомления");
b.Property<DateTimeOffset?>("ReadDate") b.Property<DateTime?>("ReadDate")
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")
.HasColumnName("read_date") .HasColumnName("read_date")
.HasComment("Дата прочтения уведомления"); .HasComment("Дата прочтения уведомления");
b.Property<DateTimeOffset>("RegistrationDate") b.Property<DateTime>("RegistrationDate")
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")
.HasColumnName("registration_date") .HasColumnName("registration_date")
.HasComment("Дата регистрации уведомления"); .HasComment("Дата регистрации уведомления");
b.Property<DateTimeOffset?>("SentDate") b.Property<DateTime?>("SentDate")
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")
.HasColumnName("sent_date") .HasColumnName("sent_date")
.HasComment("Дата отправки уведомления"); .HasComment("Дата отправки уведомления");

View File

@ -36,9 +36,6 @@ namespace AsbCloudInfrastructure.Repository
var query = dbSetConfigured var query = dbSetConfigured
.Where(e => e.IdWell == request.IdWell); .Where(e => e.IdWell == request.IdWell);
double timezoneOffsetHours = query.FirstOrDefault()
?.Well.Timezone.Hours ?? 5d;
if (request.IdCategory is not null) if (request.IdCategory is not null)
query = query.Where(x => x.IdCategory == request.IdCategory); query = query.Where(x => x.IdCategory == request.IdCategory);

View File

@ -90,9 +90,11 @@ namespace AsbCloudInfrastructure.Repository
protected override ScheduleDto Convert(Schedule entity) protected override ScheduleDto Convert(Schedule entity)
{ {
var hoursOffset = wellService.GetTimezone(entity.IdWell).Hours; var hoursOffset = wellService.GetTimezone(entity.IdWell).Hours;
var timeSpan = TimeSpan.FromHours(hoursOffset);
var dto = base.Convert(entity); var dto = base.Convert(entity);
dto.DrillStart = entity.DrillStart.ToOffset(TimeSpan.FromHours(hoursOffset)); dto.DrillStart = entity.DrillStart.ToOffset(timeSpan);
dto.DrillEnd = entity.DrillEnd.ToOffset(TimeSpan.FromHours(hoursOffset)); dto.DrillEnd = entity.DrillEnd.ToOffset(timeSpan);
return dto; return dto;
} }
} }

View File

@ -94,7 +94,7 @@ namespace AsbCloudInfrastructure.Repository
{ {
var entity = dto.Adapt<TelemetryWirelineRunOut>(); var entity = dto.Adapt<TelemetryWirelineRunOut>();
entity.IdTelemetry = idTelemetry; entity.IdTelemetry = idTelemetry;
entity.DateTime = dto.DateTime.ToOffset(TimeSpan.FromHours(timezoneOffset)); entity.DateTime = dto.DateTime.ToUniversalTime();
return entity; return entity;
} }

View File

@ -37,11 +37,10 @@ namespace AsbCloudInfrastructure.Repository
if (!trajectoryRows.All(r => r.IdWell == idWell)) if (!trajectoryRows.All(r => r.IdWell == idWell))
throw new ArgumentInvalidException(nameof(trajectoryRows), "Все строки должны относиться к одной скважине"); throw new ArgumentInvalidException(nameof(trajectoryRows), "Все строки должны относиться к одной скважине");
var offsetHours = wellService.GetTimezone(idWell).Hours;
var entities = trajectoryRows var entities = trajectoryRows
.Select(e => .Select(e =>
{ {
var entity = Convert(e, offsetHours); var entity = Convert(e);
entity.Id = 0; entity.Id = 0;
return entity; return entity;
}); });
@ -52,8 +51,7 @@ namespace AsbCloudInfrastructure.Repository
public async Task<int> AddAsync(Tdto trajectoryRow, CancellationToken token) public async Task<int> AddAsync(Tdto trajectoryRow, CancellationToken token)
{ {
var offsetHours = wellService.GetTimezone(trajectoryRow.IdWell).Hours; var entity = Convert(trajectoryRow);
var entity = Convert(trajectoryRow, offsetHours);
entity.Id = 0; entity.Id = 0;
db.Set<TEntity>().Add(entity); db.Set<TEntity>().Add(entity);
return await db.SaveChangesAsync(token) return await db.SaveChangesAsync(token)
@ -98,8 +96,7 @@ namespace AsbCloudInfrastructure.Repository
public async Task<int> UpdateAsync(Tdto row, CancellationToken token) public async Task<int> UpdateAsync(Tdto row, CancellationToken token)
{ {
var offsetHours = wellService.GetTimezone(row.IdWell).Hours; var entity = Convert(row);
var entity = Convert(row, offsetHours);
db.Set<TEntity>().Update(entity); db.Set<TEntity>().Update(entity);
return await db.SaveChangesAsync(token) return await db.SaveChangesAsync(token)
.ConfigureAwait(false); .ConfigureAwait(false);
@ -112,10 +109,10 @@ namespace AsbCloudInfrastructure.Repository
return dto; return dto;
} }
private static TEntity Convert(Tdto dto, double offsetHours) private static TEntity Convert(Tdto dto)
{ {
var entity = dto.Adapt<TEntity>(); var entity = dto.Adapt<TEntity>();
entity.UpdateDate = DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(offsetHours)); entity.UpdateDate = DateTimeOffset.Now;
return entity; return entity;
} }
} }

View File

@ -98,6 +98,10 @@ public class WellOperationRepository : IWellOperationRepository
/// <inheritdoc/> /// <inheritdoc/>
public async Task<IEnumerable<SectionByOperationsDto>> GetSectionsAsync(IEnumerable<int> idsWells, CancellationToken token) public async Task<IEnumerable<SectionByOperationsDto>> GetSectionsAsync(IEnumerable<int> idsWells, CancellationToken token)
{ {
var timeSpans = idsWells
.Distinct()
.ToDictionary(idWell => idWell, idWell => TimeSpan.FromHours(wellService.GetTimezone(idWell).Hours));
var cache = await memoryCache.GetOrCreateAsync(KeyCacheSections, async (entry) => var cache = await memoryCache.GetOrCreateAsync(KeyCacheSections, async (entry) =>
{ {
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30); entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30);
@ -146,10 +150,10 @@ public class WellOperationRepository : IWellOperationRepository
Caption = item.Caption, Caption = item.Caption,
DateStart = item.First.DateStart, DateStart = item.First.DateStart.ToOffset(timeSpans[item.IdWell]),
DepthStart = item.First.DepthStart, DateEnd = item.Last.DateStart.ToOffset(timeSpans[item.IdWell]).AddHours(item.Last.DurationHours),
DateEnd = item.Last.DateStart.AddHours(item.Last.DurationHours), DepthStart = item.First.DepthStart,
DepthEnd = item.Last.DepthEnd, DepthEnd = item.Last.DepthEnd,
}) })
.ToArray() .ToArray()

View File

@ -108,14 +108,14 @@ public class DailyReportService : IDailyReportService
var offsetHours = wellService.GetTimezone(dailyReport.IdWell).Hours; var offsetHours = wellService.GetTimezone(dailyReport.IdWell).Hours;
var geDate = new DateTimeOffset(dailyReport.Date, TimeOnly.MinValue, TimeSpan.FromHours(offsetHours)); var geDate = new DateTimeOffset(dailyReport.Date, TimeOnly.MinValue, TimeSpan.FromHours(offsetHours));
var ltDate = new DateTimeOffset(dailyReport.Date.AddDays(1), TimeOnly.MinValue, TimeSpan.FromHours(offsetHours)); var leDate = new DateTimeOffset(dailyReport.Date.AddDays(1), TimeOnly.MinValue, TimeSpan.FromHours(offsetHours));
var factOperationRequest = new WellOperationRequest var factOperationRequest = new WellOperationRequest
{ {
IdWell = idWell, IdWell = idWell,
OperationType = WellOperation.IdOperationTypeFact, OperationType = WellOperation.IdOperationTypeFact,
GeDate = geDate, GeDate = geDate,
LeDate = ltDate LeDate = leDate
}; };
var factWellOperations = (await wellOperationRepository.GetAsync(factOperationRequest, cancellationToken)) var factWellOperations = (await wellOperationRepository.GetAsync(factOperationRequest, cancellationToken))
@ -131,12 +131,12 @@ public class DailyReportService : IDailyReportService
dailyReport.DepthStart = factWellOperations.FirstOrDefault()?.DepthStart; dailyReport.DepthStart = factWellOperations.FirstOrDefault()?.DepthStart;
dailyReport.DepthEnd = factWellOperations.LastOrDefault()?.DepthEnd; dailyReport.DepthEnd = factWellOperations.LastOrDefault()?.DepthEnd;
await UpdateTimeBalanceBlockAsync(dailyReport, factWellOperations, cancellationToken); await UpdateTimeBalanceBlockAsync(dailyReport, factWellOperations, geDate, leDate, cancellationToken);
await UpdateSubsystemBlockAsync(dailyReport, cancellationToken); await UpdateSubsystemBlockAsync(dailyReport, geDate, leDate, cancellationToken);
await AddTrajectoryBlockAsync(dailyReport, cancellationToken); await AddTrajectoryBlockAsync(dailyReport, geDate, leDate, cancellationToken);
await AddScheduleBlockAsync(dailyReport, geDate, cancellationToken); await AddScheduleBlockAsync(dailyReport, geDate, cancellationToken);
await AddProcessMapWellDrillingBlockAsync(dailyReport, cancellationToken); await AddProcessMapWellDrillingBlockAsync(dailyReport, geDate, leDate, cancellationToken);
AddFactWellOperationBlock(dailyReport, factWellOperations); AddFactWellOperationBlock(dailyReport, factWellOperations);
@ -228,11 +228,11 @@ public class DailyReportService : IDailyReportService
IdWell = idWell IdWell = idWell
}; };
var geDate = date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified); var geDate = new DateTimeOffset(date, TimeOnly.MinValue, offset);
var leDate = date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified); var leDate = new DateTimeOffset(date.AddDays(1), TimeOnly.MinValue, offset);
var factWellOperationPerDay = factWellOperations.Where(o => o.DateStart.Date >= geDate && var factWellOperationPerDay = factWellOperations.Where(o => o.DateStart >= geDate &&
o.DateStart.Date <= leDate); o.DateStart <= leDate);
AddFactWellOperationBlock(dailyReport, factWellOperationPerDay); AddFactWellOperationBlock(dailyReport, factWellOperationPerDay);
@ -267,7 +267,7 @@ public class DailyReportService : IDailyReportService
} }
private async Task UpdateTimeBalanceBlockAsync(DailyReportDto dailyReport, IEnumerable<WellOperationDto> factWellOperations, private async Task UpdateTimeBalanceBlockAsync(DailyReportDto dailyReport, IEnumerable<WellOperationDto> factWellOperations,
CancellationToken cancellationToken) DateTimeOffset geDateStart, DateTimeOffset leDateEnd, CancellationToken cancellationToken)
{ {
const int idWellOperationSlipsTime = 5011; const int idWellOperationSlipsTime = 5011;
@ -276,9 +276,6 @@ public class DailyReportService : IDailyReportService
dailyReport.TimeBalanceBlock.SectionName = wellOperationRepository.GetSectionTypes() dailyReport.TimeBalanceBlock.SectionName = wellOperationRepository.GetSectionTypes()
.FirstOrDefault(s => s.Id == dailyReport.TimeBalanceBlock.IdSection)?.Caption; .FirstOrDefault(s => s.Id == dailyReport.TimeBalanceBlock.IdSection)?.Caption;
var geDateStart = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var leDateEnd = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
dailyReport.TimeBalanceBlock.WellOperationSlipsTimeCount = (await detectedOperationService.GetAsync( dailyReport.TimeBalanceBlock.WellOperationSlipsTimeCount = (await detectedOperationService.GetAsync(
new DetectedOperationByWellRequest new DetectedOperationByWellRequest
{ {
@ -294,11 +291,9 @@ public class DailyReportService : IDailyReportService
} }
} }
private async Task AddTrajectoryBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken) private async Task AddTrajectoryBlockAsync(DailyReportDto dailyReport,
DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken cancellationToken)
{ {
var geDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
var leDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
var trajectory = (await trajectoryFactNnbRepository.GetByRequestAsync(new TrajectoryRequest var trajectory = (await trajectoryFactNnbRepository.GetByRequestAsync(new TrajectoryRequest
{ {
IdWell = dailyReport.IdWell, IdWell = dailyReport.IdWell,
@ -328,7 +323,8 @@ public class DailyReportService : IDailyReportService
}); });
} }
private async Task UpdateSubsystemBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken) private async Task UpdateSubsystemBlockAsync(DailyReportDto dailyReport,
DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken cancellationToken)
{ {
dailyReport.SubsystemBlock ??= new SubsystemBlockDto(); dailyReport.SubsystemBlock ??= new SubsystemBlockDto();
@ -341,9 +337,6 @@ public class DailyReportService : IDailyReportService
IdWell = dailyReport.IdWell IdWell = dailyReport.IdWell
}, cancellationToken); }, cancellationToken);
var geDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var leDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var subsystemsStatPerDay = await subsystemService.GetStatAsync(new SubsystemRequest var subsystemsStatPerDay = await subsystemService.GetStatAsync(new SubsystemRequest
{ {
IdWell = dailyReport.IdWell, IdWell = dailyReport.IdWell,
@ -366,12 +359,9 @@ public class DailyReportService : IDailyReportService
} }
} }
private async Task AddProcessMapWellDrillingBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken) private async Task AddProcessMapWellDrillingBlockAsync(DailyReportDto dailyReport,
DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken cancellationToken)
{ {
var offsetHours = wellService.GetTimezone(dailyReport.IdWell).Hours;
var geDate = new DateTimeOffset(dailyReport.Date, TimeOnly.MinValue, TimeSpan.FromHours(offsetHours));
var leDate = new DateTimeOffset(dailyReport.Date.AddDays(1), TimeOnly.MinValue, TimeSpan.FromHours(offsetHours));
var request = new DataSaubStatRequest(); var request = new DataSaubStatRequest();
dailyReport.ProcessMapWellDrillingBlock = (await processMapReportDrillingService.GetAsync(dailyReport.IdWell, request, dailyReport.ProcessMapWellDrillingBlock = (await processMapReportDrillingService.GetAsync(dailyReport.IdWell, request,
cancellationToken)).Where(p => p.DateStart >= geDate && p.DateStart <= leDate) cancellationToken)).Where(p => p.DateStart >= geDate && p.DateStart <= leDate)

View File

@ -102,7 +102,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
if (dateBegin == default) if (dateBegin == default)
{ {
var dateRange = telemetryDataCache.GetOrDefaultDataDateRange(telemetry.Id); var dateRange = telemetryDataCache.GetOrDefaultDataDateRange(telemetry.Id);
dateBeginUtc = (dateRange?.To.ToOffset(timezone.Offset) ?? DateTimeOffset.UtcNow) dateBeginUtc = (dateRange?.To ?? DateTimeOffset.UtcNow)
.AddSeconds(-intervalSec); .AddSeconds(-intervalSec);
} }
else else

View File

@ -156,7 +156,9 @@ namespace AsbCloudInfrastructure.Services.SAUB
var to = cacheItem.LastData[^1].DateTime; var to = cacheItem.LastData[^1].DateTime;
from = from ?? cacheItem.LastData[0].DateTime; from = from ?? cacheItem.LastData[0].DateTime;
return new DatesRangeDto { From = from.Value, To = to }; return new DatesRangeDto {
From = from.Value.ToUtcDateTimeOffset(cacheItem.TimezoneHours),
To = to.ToUtcDateTimeOffset(cacheItem.TimezoneHours) };
} }
public DatesRangeDto? GetOrDefaultCachedDateRange(int idTelemetry) public DatesRangeDto? GetOrDefaultCachedDateRange(int idTelemetry)

View File

@ -157,7 +157,7 @@ public class OperationsStatService : IOperationsStatService
WellType = wellType?.Caption ?? "", WellType = wellType?.Caption ?? "",
IdState = well.IdState, IdState = well.IdState,
State = wellService.GetStateText(well.IdState), State = wellService.GetStateText(well.IdState),
LastTelemetryDate = wellService.GetLastTelemetryDate(well.Id).ToOffset(timezone.Offset), LastTelemetryDate = wellService.GetLastTelemetryDate(well.Id),
Companies = await wellService.GetCompaniesAsync(well.Id, token) Companies = await wellService.GetCompaniesAsync(well.Id, token)
}; };