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