forked from ddrilling/AsbCloudServer
CS2-119: Added .FixDatesRangeByTimeZoneAsync() to fix dates ranges to well timezone everywhere
This commit is contained in:
parent
4bed0623f1
commit
e62ac96bd7
@ -13,7 +13,7 @@ namespace AsbCloudApp.Services
|
||||
DateTime end = default, string searchString = default,
|
||||
int skip = 0, int take = 32, bool isUtc = true,
|
||||
CancellationToken token = default);
|
||||
Task<DatesRangeDto> GetMessagesDatesRangeAsync(int idWell,
|
||||
Task<DatesRangeDto> GetMessagesDatesRangeAsync(int idWell, bool isUtc,
|
||||
CancellationToken token = default);
|
||||
Task InsertAsync(string uid, IEnumerable<TelemetryMessageDto> dtos,
|
||||
CancellationToken token);
|
||||
|
@ -14,12 +14,11 @@ namespace AsbCloudApp.Services
|
||||
Action<object, int> handleReportProgress);
|
||||
int GetReportPagesCount(int idWell, DateTime begin, DateTime end,
|
||||
int stepSeconds, int format);
|
||||
|
||||
Task<List<ReportPropertiesDto>> GetSuitableReportsAsync(int idWell,
|
||||
DateTime begin, DateTime end, int stepSeconds, int format,
|
||||
CancellationToken token);
|
||||
Task<DatesRangeDto> GetReportsDatesRangeAsync(int idWell,
|
||||
CancellationToken token);
|
||||
Task<DatesRangeDto> GetReportsDatesRangeAsync(int idWell, bool isUtc,
|
||||
CancellationToken token = default);
|
||||
Task<List<ReportPropertiesDto>> GetAllReportsByWellAsync(int idWell, CancellationToken token);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace AsbCloudApp.Services
|
||||
int intervalHoursTimestamp, int workBeginTimestamp,
|
||||
CancellationToken token = default);
|
||||
Task AnalyzeAndSaveTelemetriesAsync(CancellationToken token = default);
|
||||
Task<DatesRangeDto> GetOperationsDateRangeAsync(int idWell,
|
||||
Task<DatesRangeDto> GetOperationsDateRangeAsync(int idWell, bool isUtc,
|
||||
CancellationToken token = default);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ namespace AsbCloudApp.Services
|
||||
Task UpdateInfoAsync(string uid, TelemetryInfoDto info, CancellationToken token);
|
||||
Task<DateTime> FixDateToTimeZoneAsync(int idTelemetry, DateTime date,
|
||||
CancellationToken token);
|
||||
Task<DatesRangeDto> FixDatesRangeByTimeZoneAsync(int telemetryId, DatesRangeDto result,
|
||||
CancellationToken token);
|
||||
Task<TimeZoneInfo> GetTimeZoneInfoAsync(int idWell, CancellationToken token);
|
||||
Task UpdateTimeZoneAsync(string uid, TelemetryTimeZoneDto telemetryTimeZoneInfo, CancellationToken token);
|
||||
int? GetIdTelemetryByIdWell(int idWell);
|
||||
|
@ -294,7 +294,7 @@ namespace AsbCloudInfrastructure.Services.Analysis
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<DatesRangeDto> GetOperationsDateRangeAsync(int idWell,
|
||||
public async Task<DatesRangeDto> GetOperationsDateRangeAsync(int idWell, bool isUtc,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||
@ -315,13 +315,21 @@ namespace AsbCloudInfrastructure.Services.Analysis
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return new DatesRangeDto
|
||||
var result = new DatesRangeDto
|
||||
{
|
||||
From = DateTimeOffset.FromUnixTimeSeconds(datesRange.From).DateTime,
|
||||
To = datesRange.To == default
|
||||
? DateTime.MaxValue
|
||||
: DateTimeOffset.FromUnixTimeSeconds(datesRange.To).DateTime
|
||||
};
|
||||
|
||||
if (isUtc)
|
||||
return result;
|
||||
|
||||
result = await telemetryService.FixDatesRangeByTimeZoneAsync((int)telemetryId, result, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<DateTime> GetLastAnalysisDateAsync(int idTelemetry, CancellationToken token = default)
|
||||
|
@ -142,7 +142,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<DatesRangeDto> GetMessagesDatesRangeAsync(int idWell,
|
||||
public async Task<DatesRangeDto> GetMessagesDatesRangeAsync(int idWell, bool isUtc,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||
@ -152,7 +152,15 @@ namespace AsbCloudInfrastructure.Services
|
||||
var (From, To) = await db.GetDatesRangeAsync<TelemetryMessage>((int)telemetryId, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return new DatesRangeDto { From = From, To = To };
|
||||
var result = new DatesRangeDto { From = From, To = To };
|
||||
|
||||
if (isUtc)
|
||||
return result;
|
||||
|
||||
result = await telemetryService.FixDatesRangeByTimeZoneAsync((int)telemetryId, result, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task InsertAsync(string uid, IEnumerable<TelemetryMessageDto> dtos,
|
||||
|
@ -97,7 +97,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
return generator.GetPagesCount();
|
||||
}
|
||||
|
||||
public async Task<DatesRangeDto> GetReportsDatesRangeAsync(int idWell,
|
||||
public async Task<DatesRangeDto> GetReportsDatesRangeAsync(int idWell, bool isUtc,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||
@ -121,11 +121,19 @@ namespace AsbCloudInfrastructure.Services
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return new DatesRangeDto
|
||||
var result = new DatesRangeDto
|
||||
{
|
||||
From = datesRange.From,
|
||||
To = datesRange.To.Year == 1 ? DateTime.MaxValue : datesRange.To
|
||||
};
|
||||
|
||||
if (isUtc)
|
||||
return result;
|
||||
|
||||
result = await telemetryService.FixDatesRangeByTimeZoneAsync((int)telemetryId, result, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<List<ReportPropertiesDto>> GetSuitableReportsAsync(int idWell, DateTime begin, DateTime end, int stepSeconds, int format, CancellationToken token) =>
|
||||
|
@ -164,18 +164,9 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
if (isUtc)
|
||||
return result;
|
||||
|
||||
var telemetry = await cacheTelemetry.FirstOrDefaultAsync(t => t.Id == telemetryId,
|
||||
token).ConfigureAwait(false);
|
||||
|
||||
if (telemetry?.TelemetryTimeZone is null)
|
||||
return result;
|
||||
|
||||
result = new DatesRangeDto()
|
||||
{
|
||||
From = From.AddHours(telemetry.TelemetryTimeZone.Hours),
|
||||
To = To.AddHours(telemetry.TelemetryTimeZone.Hours)
|
||||
};
|
||||
result = await telemetryService.FixDatesRangeByTimeZoneAsync((int)telemetryId, result, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return result;
|
||||
|
||||
|
@ -141,6 +141,22 @@ namespace AsbCloudInfrastructure.Services
|
||||
return date.AddHours(offsetHours * -1);
|
||||
}
|
||||
|
||||
public async Task<DatesRangeDto> FixDatesRangeByTimeZoneAsync(int telemetryId, DatesRangeDto result,
|
||||
CancellationToken token)
|
||||
{
|
||||
var telemetry = await cacheTelemetry.FirstOrDefaultAsync(t => t.Id == telemetryId,
|
||||
token).ConfigureAwait(false);
|
||||
|
||||
if (telemetry?.TelemetryTimeZone is null)
|
||||
return result;
|
||||
|
||||
return new DatesRangeDto()
|
||||
{
|
||||
From = result.From.AddHours(telemetry.TelemetryTimeZone.Hours),
|
||||
To = result.To.AddHours(telemetry.TelemetryTimeZone.Hours)
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<TimeZoneInfo> GetTimeZoneInfoAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var coordinates = await GetWellCoordinatesAsync(idWell, token);
|
||||
|
@ -64,11 +64,12 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="token">Токен для отмены задачи</param>
|
||||
/// <param name="isUtc">Смена дат с UTC формата на часовой пояс скважины</param>
|
||||
/// <returns>список сообщений по скважине</returns>
|
||||
[HttpGet]
|
||||
[Route("datesRange")]
|
||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetMessagesDateRangeAsync(int idWell,
|
||||
public async Task<IActionResult> GetMessagesDateRangeAsync(int idWell, bool isUtc = true,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
@ -82,8 +83,8 @@ namespace AsbCloudWebApi.Controllers
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
||||
DatesRangeDto wellMessagesDatesRange = await messageService.GetMessagesDatesRangeAsync(idWell,
|
||||
token);
|
||||
var wellMessagesDatesRange = await messageService.GetMessagesDatesRangeAsync(idWell,
|
||||
isUtc, token);
|
||||
|
||||
return Ok(wellMessagesDatesRange);
|
||||
}
|
||||
|
@ -167,11 +167,12 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="token">Токен для отмены задачи</param>
|
||||
/// <param name="isUtc">Смена дат с UTC формата на часовой пояс скважины</param>
|
||||
/// <returns>Даты самого старого и самого свежего отчетов в БД</returns>
|
||||
[HttpGet]
|
||||
[Route("datesRange")]
|
||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetReportsDateRangeAsync(int idWell,
|
||||
public async Task<IActionResult> GetReportsDateRangeAsync(int idWell, bool isUtc = true,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
@ -183,7 +184,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
DatesRangeDto wellReportsDatesRange = await reportService.GetReportsDatesRangeAsync(idWell,
|
||||
var wellReportsDatesRange = await reportService.GetReportsDatesRangeAsync(idWell, isUtc,
|
||||
token).ConfigureAwait(false);
|
||||
|
||||
return Ok(wellReportsDatesRange);
|
||||
|
@ -176,11 +176,12 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="token">Токен для отмены задачи</param>
|
||||
/// <param name="isUtc">Смена дат с UTC формата на часовой пояс скважины</param>
|
||||
/// <returns>Даты самой первой и самой последней операций на скважине</returns>
|
||||
[HttpGet]
|
||||
[Route("datesRange")]
|
||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetOperationsDateRangeAsync(int idWell,
|
||||
public async Task<IActionResult> GetOperationsDateRangeAsync(int idWell, bool isUtc = true,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
@ -192,8 +193,8 @@ namespace AsbCloudWebApi.Controllers
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
DatesRangeDto wellOperationsDatesRange = await analyticsService.GetOperationsDateRangeAsync(idWell,
|
||||
token).ConfigureAwait(false);
|
||||
var wellOperationsDatesRange = await analyticsService.GetOperationsDateRangeAsync(idWell,
|
||||
isUtc, token).ConfigureAwait(false);
|
||||
|
||||
return Ok(wellOperationsDatesRange);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// Возвращает диапазон дат сохраненных данных.
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="isUtc">Даты в формате UTC или часового пояса скважины</param>
|
||||
/// <param name="isUtc">Смена дат с UTC формата на часовой пояс скважины</param>
|
||||
/// <param name="token">Токен завершения задачи</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
|
Loading…
Reference in New Issue
Block a user