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

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>
public DateTimeKind? UpdateFrom { get; set; }
public DateTimeOffset? UpdateFrom { get; set; }
}

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

@ -98,6 +98,10 @@ public class WellOperationRepository : IWellOperationRepository
/// <inheritdoc/>
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) =>
{
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30);
@ -146,10 +150,10 @@ public class WellOperationRepository : IWellOperationRepository
Caption = item.Caption,
DateStart = item.First.DateStart,
DepthStart = item.First.DepthStart,
DateStart = item.First.DateStart.ToOffset(timeSpans[item.IdWell]),
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,
})
.ToArray()

View File

@ -108,15 +108,15 @@ public class DailyReportService : IDailyReportService
var offsetHours = wellService.GetTimezone(dailyReport.IdWell).Hours;
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
{
IdWell = idWell,
OperationType = WellOperation.IdOperationTypeFact,
GeDate = geDate,
LeDate = ltDate
};
LeDate = leDate
};
var factWellOperations = (await wellOperationRepository.GetAsync(factOperationRequest, cancellationToken))
.OrderBy(o => o.DateStart)
@ -131,12 +131,12 @@ public class DailyReportService : IDailyReportService
dailyReport.DepthStart = factWellOperations.FirstOrDefault()?.DepthStart;
dailyReport.DepthEnd = factWellOperations.LastOrDefault()?.DepthEnd;
await UpdateTimeBalanceBlockAsync(dailyReport, factWellOperations, cancellationToken);
await UpdateSubsystemBlockAsync(dailyReport, cancellationToken);
await UpdateTimeBalanceBlockAsync(dailyReport, factWellOperations, geDate, leDate, cancellationToken);
await UpdateSubsystemBlockAsync(dailyReport, geDate, leDate, cancellationToken);
await AddTrajectoryBlockAsync(dailyReport, cancellationToken);
await AddTrajectoryBlockAsync(dailyReport, geDate, leDate, cancellationToken);
await AddScheduleBlockAsync(dailyReport, geDate, cancellationToken);
await AddProcessMapWellDrillingBlockAsync(dailyReport, cancellationToken);
await AddProcessMapWellDrillingBlockAsync(dailyReport, geDate, leDate, cancellationToken);
AddFactWellOperationBlock(dailyReport, factWellOperations);
@ -228,11 +228,11 @@ public class DailyReportService : IDailyReportService
IdWell = idWell
};
var geDate = date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var leDate = date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var geDate = new DateTimeOffset(date, TimeOnly.MinValue, offset);
var leDate = new DateTimeOffset(date.AddDays(1), TimeOnly.MinValue, offset);
var factWellOperationPerDay = factWellOperations.Where(o => o.DateStart.Date >= geDate &&
o.DateStart.Date <= leDate);
var factWellOperationPerDay = factWellOperations.Where(o => o.DateStart >= geDate &&
o.DateStart <= leDate);
AddFactWellOperationBlock(dailyReport, factWellOperationPerDay);
@ -267,7 +267,7 @@ public class DailyReportService : IDailyReportService
}
private async Task UpdateTimeBalanceBlockAsync(DailyReportDto dailyReport, IEnumerable<WellOperationDto> factWellOperations,
CancellationToken cancellationToken)
DateTimeOffset geDateStart, DateTimeOffset leDateEnd, CancellationToken cancellationToken)
{
const int idWellOperationSlipsTime = 5011;
@ -276,10 +276,7 @@ public class DailyReportService : IDailyReportService
dailyReport.TimeBalanceBlock.SectionName = wellOperationRepository.GetSectionTypes()
.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
{
IdsCategories = new[] { idWellOperationSlipsTime },
@ -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
{
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();
@ -341,9 +337,6 @@ public class DailyReportService : IDailyReportService
IdWell = dailyReport.IdWell
}, 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
{
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();
dailyReport.ProcessMapWellDrillingBlock = (await processMapReportDrillingService.GetAsync(dailyReport.IdWell, request,
cancellationToken)).Where(p => p.DateStart >= geDate && p.DateStart <= leDate)

View File

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

View File

@ -156,7 +156,9 @@ namespace AsbCloudInfrastructure.Services.SAUB
var to = cacheItem.LastData[^1].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)

View File

@ -157,7 +157,7 @@ public class OperationsStatService : IOperationsStatService
WellType = wellType?.Caption ?? "",
IdState = 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)
};