diff --git a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs index d8d9d4c8..c31dd73c 100644 --- a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs +++ b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs @@ -74,7 +74,7 @@ public class DailyReportDto : IId, /// /// Дата последнего обновления /// - public DateTime? DateLastUpdate { get; set; } + public DateTimeOffset? DateLastUpdate { get; set; } /// /// Блок фактической траектории diff --git a/AsbCloudApp/Data/DrillTestReport/DrillTestReportDataDto.cs b/AsbCloudApp/Data/DrillTestReport/DrillTestReportDataDto.cs index ee63bf9b..b45783e6 100644 --- a/AsbCloudApp/Data/DrillTestReport/DrillTestReportDataDto.cs +++ b/AsbCloudApp/Data/DrillTestReport/DrillTestReportDataDto.cs @@ -21,6 +21,6 @@ namespace AsbCloudApp.Data.DrillTestReport /// /// Дата отчета /// - public DateTime Date { get; set; } = DateTime.Now; + public DateTimeOffset Date { get; set; } = DateTimeOffset.Now; } } diff --git a/AsbCloudApp/Data/DrillTestReport/DrillTestReportInfoDto.cs b/AsbCloudApp/Data/DrillTestReport/DrillTestReportInfoDto.cs index 39d37a11..a178e6fe 100644 --- a/AsbCloudApp/Data/DrillTestReport/DrillTestReportInfoDto.cs +++ b/AsbCloudApp/Data/DrillTestReport/DrillTestReportInfoDto.cs @@ -24,6 +24,6 @@ namespace AsbCloudApp.Data.DrillTestReport /// Дата и время /// [Required] - public DateTime DateTime { get; set; } + public DateTimeOffset DateTime { get; set; } } } diff --git a/AsbCloudApp/Data/FileInfoDto.cs b/AsbCloudApp/Data/FileInfoDto.cs index 8e006661..ab44b317 100644 --- a/AsbCloudApp/Data/FileInfoDto.cs +++ b/AsbCloudApp/Data/FileInfoDto.cs @@ -43,7 +43,7 @@ namespace AsbCloudApp.Data /// дата загрузки /// [Required] - public DateTime UploadDate { get; set; } + public DateTimeOffset UploadDate { get; set; } /// /// размер в байтах diff --git a/AsbCloudApp/Data/FileMarkDto.cs b/AsbCloudApp/Data/FileMarkDto.cs index 7329821b..305fad5c 100644 --- a/AsbCloudApp/Data/FileMarkDto.cs +++ b/AsbCloudApp/Data/FileMarkDto.cs @@ -33,7 +33,7 @@ namespace AsbCloudApp.Data /// . /// [Required] - public DateTime DateCreated { get; set; } + public DateTimeOffset DateCreated { get; set; } /// /// diff --git a/AsbCloudApp/Data/LimitingParameterDataDto.cs b/AsbCloudApp/Data/LimitingParameterDataDto.cs index 1bf982dc..c5692729 100644 --- a/AsbCloudApp/Data/LimitingParameterDataDto.cs +++ b/AsbCloudApp/Data/LimitingParameterDataDto.cs @@ -20,12 +20,12 @@ namespace AsbCloudApp.Data /// /// Дата начала ограничения /// - public DateTime DateStart { get; set; } + public DateTimeOffset DateStart { get; set; } /// /// Дата окончания ограничения /// - public DateTime DateEnd { get; set; } + public DateTimeOffset DateEnd { get; set; } /// /// Глубина начала ограничения diff --git a/AsbCloudApp/Data/Manuals/ManualDto.cs b/AsbCloudApp/Data/Manuals/ManualDto.cs index bb89dfbe..c5aa92c4 100644 --- a/AsbCloudApp/Data/Manuals/ManualDto.cs +++ b/AsbCloudApp/Data/Manuals/ManualDto.cs @@ -18,7 +18,7 @@ public class ManualDto : IId /// /// Дата загрузки /// - public DateTime DateDownload { get; set; } + public DateTimeOffset DateDownload { get; set; } /// /// Id автора diff --git a/AsbCloudApp/Data/MeasureDto.cs b/AsbCloudApp/Data/MeasureDto.cs index 9f823a91..4eddd78f 100644 --- a/AsbCloudApp/Data/MeasureDto.cs +++ b/AsbCloudApp/Data/MeasureDto.cs @@ -36,7 +36,7 @@ namespace AsbCloudApp.Data /// отметка времени замера /// [Required] - public DateTime Timestamp { get; set; } + public DateTimeOffset Timestamp { get; set; } /// /// данные замера diff --git a/AsbCloudApp/Data/MessageDto.cs b/AsbCloudApp/Data/MessageDto.cs index 071967d9..7234db7a 100644 --- a/AsbCloudApp/Data/MessageDto.cs +++ b/AsbCloudApp/Data/MessageDto.cs @@ -16,7 +16,7 @@ namespace AsbCloudApp.Data /// дата появления события /// [Required] - public DateTime DateTime { get; set; } + public DateTimeOffset DateTime { get; set; } /// /// категория события diff --git a/AsbCloudApp/Data/NotificationDto.cs b/AsbCloudApp/Data/NotificationDto.cs index ee42f8d7..0fd8b673 100644 --- a/AsbCloudApp/Data/NotificationDto.cs +++ b/AsbCloudApp/Data/NotificationDto.cs @@ -42,17 +42,17 @@ public class NotificationDto : IId /// Дата регистрации уведомления /// [Required] - public DateTime RegistrationDate { get; set; } + public DateTimeOffset RegistrationDate { get; set; } /// /// Дата отправки уведомления /// - public DateTime? SentDate { get; set; } + public DateTimeOffset? SentDate { get; set; } /// /// Дата прочтения уведомления /// - public DateTime? ReadDate { get; set; } + public DateTimeOffset? ReadDate { get; set; } /// /// Состояние уведомления @@ -82,12 +82,12 @@ public class NotificationDto : IId ReadDate = null; break; case 1: - SentDate = DateTime.UtcNow; + SentDate = DateTimeOffset.UtcNow; ReadDate = null; break; case 2: - SentDate = DateTime.UtcNow; - ReadDate = DateTime.UtcNow; + SentDate = DateTimeOffset.UtcNow; + ReadDate = DateTimeOffset.UtcNow; break; } } diff --git a/AsbCloudApp/Data/ProcessMaps/Report/ProcessMapReportDataSaubStatDto.cs b/AsbCloudApp/Data/ProcessMaps/Report/ProcessMapReportDataSaubStatDto.cs index 6255726f..4bf221de 100644 --- a/AsbCloudApp/Data/ProcessMaps/Report/ProcessMapReportDataSaubStatDto.cs +++ b/AsbCloudApp/Data/ProcessMaps/Report/ProcessMapReportDataSaubStatDto.cs @@ -44,7 +44,7 @@ public class ProcessMapReportDataSaubStatDto /// на начало интервала /// /// - public DateTime DateStart { get; set; } + public DateTimeOffset DateStart { get; set; } /// /// Режим бурения (Ротор/слайд/ручной) diff --git a/AsbCloudApp/Data/ProcessMaps/Report/ProcessMapReportWellDrillingDto.cs b/AsbCloudApp/Data/ProcessMaps/Report/ProcessMapReportWellDrillingDto.cs index 16a9749c..cee53050 100644 --- a/AsbCloudApp/Data/ProcessMaps/Report/ProcessMapReportWellDrillingDto.cs +++ b/AsbCloudApp/Data/ProcessMaps/Report/ProcessMapReportWellDrillingDto.cs @@ -44,7 +44,7 @@ public class ProcessMapReportWellDrillingDto /// на начало интервала /// /// - public DateTime DateStart { get; set; } + public DateTimeOffset DateStart { get; set; } /// /// Время мех бурения, ч diff --git a/AsbCloudApp/Data/ReportPropertiesDto.cs b/AsbCloudApp/Data/ReportPropertiesDto.cs index 82caa77e..f802a7e0 100644 --- a/AsbCloudApp/Data/ReportPropertiesDto.cs +++ b/AsbCloudApp/Data/ReportPropertiesDto.cs @@ -29,17 +29,17 @@ namespace AsbCloudApp.Data /// /// Дата формирования /// - public DateTime Date { get; set; } + public DateTimeOffset Date { get; set; } /// /// Дата начала рапорта /// - public DateTime Begin { get; set; } + public DateTimeOffset Begin { get; set; } /// /// Дата окончания рапорта /// - public DateTime End { get; set; } + public DateTimeOffset End { get; set; } /// /// шаг между точками диаграммы diff --git a/AsbCloudApp/Data/SAUB/SetpointsRequestDto.cs b/AsbCloudApp/Data/SAUB/SetpointsRequestDto.cs index ed81c0ef..192805a6 100644 --- a/AsbCloudApp/Data/SAUB/SetpointsRequestDto.cs +++ b/AsbCloudApp/Data/SAUB/SetpointsRequestDto.cs @@ -33,7 +33,7 @@ namespace AsbCloudApp.Data.SAUB /// /// отметка времени создания запроса /// - public DateTime UploadDate { get; set; } = DateTime.Now; + public DateTimeOffset UploadDate { get; set; } = DateTimeOffset.Now; /// /// время в секундах актуальности этого запроса diff --git a/AsbCloudApp/Data/SAUB/TelemetryMessageDto.cs b/AsbCloudApp/Data/SAUB/TelemetryMessageDto.cs index 6c246f16..ee86fc46 100644 --- a/AsbCloudApp/Data/SAUB/TelemetryMessageDto.cs +++ b/AsbCloudApp/Data/SAUB/TelemetryMessageDto.cs @@ -15,7 +15,7 @@ namespace AsbCloudApp.Data.SAUB /// /// отметка времени /// - public DateTime Date { get; set; } + public DateTimeOffset Date { get; set; } /// /// глубина забоя diff --git a/AsbCloudApp/Data/SAUB/TelemetryWirelineRunOutDto.cs b/AsbCloudApp/Data/SAUB/TelemetryWirelineRunOutDto.cs index 69ac6929..213b67ec 100644 --- a/AsbCloudApp/Data/SAUB/TelemetryWirelineRunOutDto.cs +++ b/AsbCloudApp/Data/SAUB/TelemetryWirelineRunOutDto.cs @@ -10,7 +10,7 @@ namespace AsbCloudApp.Data.SAUB /// /// отметка времени /// - public DateTime DateTime { get; set; } + public DateTimeOffset DateTime { get; set; } /// /// Наработка талевого каната с момента перетяжки каната, т*км diff --git a/AsbCloudApp/Data/ScheduleDto.cs b/AsbCloudApp/Data/ScheduleDto.cs index 84cbe515..a8c8d652 100644 --- a/AsbCloudApp/Data/ScheduleDto.cs +++ b/AsbCloudApp/Data/ScheduleDto.cs @@ -39,13 +39,13 @@ namespace AsbCloudApp.Data /// Начало бурения /// [Required] - public DateTime DrillStart { get; set; } + public DateTimeOffset DrillStart { get; set; } /// /// Конец бурения /// [Required] - public DateTime DrillEnd { get; set; } + public DateTimeOffset DrillEnd { get; set; } /// /// Бурильщик diff --git a/AsbCloudApp/Data/StatOperationsDto.cs b/AsbCloudApp/Data/StatOperationsDto.cs index 7d082648..ec59eae0 100644 --- a/AsbCloudApp/Data/StatOperationsDto.cs +++ b/AsbCloudApp/Data/StatOperationsDto.cs @@ -11,12 +11,12 @@ namespace AsbCloudApp.Data /// /// Дата и время начала /// - public DateTime? Start { get; set; } + public DateTimeOffset? Start { get; set; } /// /// Дата и время окончания /// - public DateTime? End { get; set; } + public DateTimeOffset? End { get; set; } /// /// Глубина, м diff --git a/AsbCloudApp/Data/StatWellDto.cs b/AsbCloudApp/Data/StatWellDto.cs index ece9756c..9cf27fe4 100644 --- a/AsbCloudApp/Data/StatWellDto.cs +++ b/AsbCloudApp/Data/StatWellDto.cs @@ -42,7 +42,7 @@ namespace AsbCloudApp.Data /// дата прихода последней телеметрии /// [Required] - public DateTime LastTelemetryDate { get; set; } + public DateTimeOffset LastTelemetryDate { get; set; } /// /// Статистика по секциям diff --git a/AsbCloudApp/Data/Trajectory/TrajectoryGeoDto.cs b/AsbCloudApp/Data/Trajectory/TrajectoryGeoDto.cs index 237c20b2..11b88141 100644 --- a/AsbCloudApp/Data/Trajectory/TrajectoryGeoDto.cs +++ b/AsbCloudApp/Data/Trajectory/TrajectoryGeoDto.cs @@ -46,7 +46,7 @@ namespace AsbCloudApp.Data.Trajectory /// /// Дата загрузки /// - public DateTime UpdateDate { get; set; } + public DateTimeOffset UpdateDate { get; set; } /// /// ИД пользователя diff --git a/AsbCloudApp/Data/WellDto.cs b/AsbCloudApp/Data/WellDto.cs index 30f524c2..368e58c9 100644 --- a/AsbCloudApp/Data/WellDto.cs +++ b/AsbCloudApp/Data/WellDto.cs @@ -67,12 +67,12 @@ namespace AsbCloudApp.Data /// /// Дата/время первой операции /// - public DateTime? StartDate { get; set; } + public DateTimeOffset? StartDate { get; set; } /// /// Дата/время кода приходили данные последний раз /// - public DateTime LastTelemetryDate { get; set; } + public DateTimeOffset LastTelemetryDate { get; set; } /// /// ID телеметрии diff --git a/AsbCloudApp/Data/WellMapInfoDto.cs b/AsbCloudApp/Data/WellMapInfoDto.cs index a677a1e3..55098f4b 100644 --- a/AsbCloudApp/Data/WellMapInfoDto.cs +++ b/AsbCloudApp/Data/WellMapInfoDto.cs @@ -82,14 +82,14 @@ namespace AsbCloudApp.Data /// Дата начала первой фактической операции /// Используется как дата начала бурения /// - public DateTime? FirstFactOperationDateStart { get; set; } + public DateTimeOffset? FirstFactOperationDateStart { get; set; } /// /// Дата окончания последней прогнозируемой операции /// Если скважина завершена, то дата окончания последней фактической операции /// Используется как прогноз окончания бурения /// - public DateTime? LastPredictOperationDateEnd { get; set; } + public DateTimeOffset? LastPredictOperationDateEnd { get; set; } /// /// Рейсовая скорость проходки, последнего рейса diff --git a/AsbCloudApp/Data/WellOperationPlanDto.cs b/AsbCloudApp/Data/WellOperationPlanDto.cs new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/AsbCloudApp/Data/WellOperationPlanDto.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs index ffc69970..5f14a373 100644 --- a/AsbCloudApp/Repositories/IWellOperationRepository.cs +++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs @@ -1,6 +1,4 @@ using AsbCloudApp.Data; -using AsbCloudApp.Requests; -using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -53,7 +51,7 @@ namespace AsbCloudApp.Repositories Task InsertRangeAsync(IEnumerable dtos, bool deleteBeforeInsert, CancellationToken token); /// - /// Обновить несколько существующую операций + /// Обновить существующую операцию /// /// /// diff --git a/AsbCloudApp/Requests/FileRequest.cs b/AsbCloudApp/Requests/FileRequest.cs index 7ea84c7e..403c0655 100644 --- a/AsbCloudApp/Requests/FileRequest.cs +++ b/AsbCloudApp/Requests/FileRequest.cs @@ -33,12 +33,12 @@ namespace AsbCloudApp.Requests /// /// Дата начала периода /// - public DateTime? Begin { get; set; } + public DateTimeOffset? Begin { get; set; } /// /// Дата окончания периода /// - public DateTime? End { get; set; } + public DateTimeOffset? End { get; set; } /// /// Признак удаления diff --git a/AsbCloudApp/Requests/LimitingParameterRequest.cs b/AsbCloudApp/Requests/LimitingParameterRequest.cs index 31fb02f0..4e1b5d98 100644 --- a/AsbCloudApp/Requests/LimitingParameterRequest.cs +++ b/AsbCloudApp/Requests/LimitingParameterRequest.cs @@ -17,12 +17,12 @@ namespace AsbCloudApp.Requests /// /// Больше или равно дате /// - public DateTime? GtDate { get; set; } + public DateTimeOffset? GtDate { get; set; } /// /// Меньше или равно дате /// - public DateTime? LtDate { get; set; } + public DateTimeOffset? LtDate { get; set; } /// /// Больше или равно глубины забоя diff --git a/AsbCloudApp/Requests/MessageRequest.cs b/AsbCloudApp/Requests/MessageRequest.cs index 1bfba1a2..a474c7b9 100644 --- a/AsbCloudApp/Requests/MessageRequest.cs +++ b/AsbCloudApp/Requests/MessageRequest.cs @@ -17,12 +17,12 @@ namespace AsbCloudApp.Requests /// /// начальная дата /// - public DateTime? Begin { get; set; } + public DateTimeOffset? Begin { get; set; } /// /// конечная дата /// - public DateTime? End { get; set; } + public DateTimeOffset? End { get; set; } /// /// строка поиска diff --git a/AsbCloudApp/Requests/NotificationDeleteRequest.cs b/AsbCloudApp/Requests/NotificationDeleteRequest.cs index ec2026f3..56921d70 100644 --- a/AsbCloudApp/Requests/NotificationDeleteRequest.cs +++ b/AsbCloudApp/Requests/NotificationDeleteRequest.cs @@ -15,10 +15,10 @@ public class NotificationDeleteRequest /// /// Меньше или равно дате отправки /// - public DateTime? LtSentDate { get; set; } + public DateTimeOffset? LtSentDate { get; set; } /// /// Меньше или равно дате прочтения /// - public DateTime? LtReadDate { get; set; } + public DateTimeOffset? LtReadDate { get; set; } } \ No newline at end of file diff --git a/AsbCloudApp/Requests/ProcessMapPlanRequest.cs b/AsbCloudApp/Requests/ProcessMapPlanRequest.cs index b614b8c3..b3247ce2 100644 --- a/AsbCloudApp/Requests/ProcessMapPlanRequest.cs +++ b/AsbCloudApp/Requests/ProcessMapPlanRequest.cs @@ -20,5 +20,5 @@ public class ProcessMapPlanRequest /// /// Дата обновления /// - public DateTime? UpdateFrom { get; set; } + public DateTimeOffset? UpdateFrom { get; set; } } \ No newline at end of file diff --git a/AsbCloudApp/Requests/ReportParametersRequest.cs b/AsbCloudApp/Requests/ReportParametersRequest.cs index 57b83e4d..74bc358a 100644 --- a/AsbCloudApp/Requests/ReportParametersRequest.cs +++ b/AsbCloudApp/Requests/ReportParametersRequest.cs @@ -24,12 +24,12 @@ public class ReportParametersRequest: IValidatableObject /// /// Дата начала интервала /// - public DateTime Begin { get; set; } = default; + public DateTimeOffset Begin { get; set; } = default; /// /// Дата окончания интервала /// - public DateTime End { get; set; } = default; + public DateTimeOffset End { get; set; } = default; /// public IEnumerable Validate(ValidationContext validationContext) @@ -37,7 +37,7 @@ public class ReportParametersRequest: IValidatableObject if (End < Begin) yield return new("End mast be less then begin"); - if (Begin < new DateTime(2000, 1, 1)) + if (Begin < new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero)) yield return new("Begin mast be > 2000-1-1"); } } \ No newline at end of file diff --git a/AsbCloudApp/Requests/SubsystemRequest.cs b/AsbCloudApp/Requests/SubsystemRequest.cs index 23a7e70a..08b980ab 100644 --- a/AsbCloudApp/Requests/SubsystemRequest.cs +++ b/AsbCloudApp/Requests/SubsystemRequest.cs @@ -9,7 +9,7 @@ namespace AsbCloudApp.Requests /// public class SubsystemRequest: RequestBase, IValidatableObject { - private static readonly DateTime validationMinDate = new DateTime(2020,01,01,0,0,0,DateTimeKind.Utc); + private static readonly DateTimeOffset validationMinDate = new DateTimeOffset(2020,01,01,0,0,0, TimeSpan.Zero); /// /// идентификатор скважины diff --git a/AsbCloudApp/Requests/TrajectoryRequest.cs b/AsbCloudApp/Requests/TrajectoryRequest.cs index 954879bc..35eca8c3 100644 --- a/AsbCloudApp/Requests/TrajectoryRequest.cs +++ b/AsbCloudApp/Requests/TrajectoryRequest.cs @@ -15,10 +15,10 @@ public class TrajectoryRequest : RequestBase /// /// Больше или равно дате /// - public DateTime? GeDate { get; set; } + public DateTimeOffset? GeDate { get; set; } /// /// Меньше или равно дате /// - public DateTime? LeDate { get; set; } + public DateTimeOffset? LeDate { get; set; } } \ No newline at end of file diff --git a/AsbCloudApp/Services/DailyReport/IDailyReportService.cs b/AsbCloudApp/Services/DailyReport/IDailyReportService.cs index f0318025..b39375a6 100644 --- a/AsbCloudApp/Services/DailyReport/IDailyReportService.cs +++ b/AsbCloudApp/Services/DailyReport/IDailyReportService.cs @@ -42,12 +42,4 @@ public interface IDailyReportService /// /// Task> GetAsync(int idWell, FileReportRequest request, CancellationToken cancellationToken); - - /// - /// Получить диапазон дат по которым возможно сформировать суточный отчёты - /// - /// - /// - /// - Task GetDatesRangeAsync(int idWell, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/AsbCloudApp/Services/IReportService.cs b/AsbCloudApp/Services/IReportService.cs index 5f992a20..4b259240 100644 --- a/AsbCloudApp/Services/IReportService.cs +++ b/AsbCloudApp/Services/IReportService.cs @@ -46,7 +46,7 @@ namespace AsbCloudApp.Services /// /// /// - int GetReportPagesCount(int idWell, DateTime begin, DateTime end, + int GetReportPagesCount(int idWell, DateTimeOffset begin, DateTimeOffset end, int stepSeconds, int format); /// diff --git a/AsbCloudApp/Services/IScheduleService.cs b/AsbCloudApp/Services/IScheduleService.cs index 5a28b4c2..81c0d385 100644 --- a/AsbCloudApp/Services/IScheduleService.cs +++ b/AsbCloudApp/Services/IScheduleService.cs @@ -19,7 +19,7 @@ namespace AsbCloudApp.Services /// /// /// - Task> GetAsync(int idWell, DateTime workTime, CancellationToken token); + Task> GetAsync(int idWell, DateTimeOffset workTime, CancellationToken token); /// /// получить бурильщика по idWell и времени @@ -28,7 +28,7 @@ namespace AsbCloudApp.Services /// /// /// - Task GetOrDefaultDrillerAsync(int idWell, DateTime workTime, CancellationToken token); + Task GetOrDefaultDrillerAsync(int idWell, DateTimeOffset workTime, CancellationToken token); /// /// Получить расписание смен diff --git a/AsbCloudApp/Services/IWellService.cs b/AsbCloudApp/Services/IWellService.cs index edea98ae..4279f587 100644 --- a/AsbCloudApp/Services/IWellService.cs +++ b/AsbCloudApp/Services/IWellService.cs @@ -72,7 +72,7 @@ namespace AsbCloudApp.Services /// /// /// - DateTime GetLastTelemetryDate(int idWell); + DateTimeOffset GetLastTelemetryDate(int idWell); //TODO: выяснить и удалить отсюда /// diff --git a/AsbCloudApp/Services/Notifications/NotificationService.cs b/AsbCloudApp/Services/Notifications/NotificationService.cs index d703ffb4..97b8bfb5 100644 --- a/AsbCloudApp/Services/Notifications/NotificationService.cs +++ b/AsbCloudApp/Services/Notifications/NotificationService.cs @@ -49,7 +49,7 @@ public class NotificationService var notification = new NotificationDto { IdUser = request.IdUser, - RegistrationDate = DateTime.UtcNow, + RegistrationDate = DateTimeOffset.UtcNow, IdNotificationCategory = notificationCategory.Id, Title = request.Title, Message = request.Message, @@ -71,7 +71,7 @@ public class NotificationService Console.WriteLine(ex.Message); } - notification.SentDate = DateTime.UtcNow; + notification.SentDate = DateTimeOffset.UtcNow; await notificationRepository.UpdateAsync(notification, cancellationToken); } @@ -92,7 +92,7 @@ public class NotificationService if(isRead && !notification.SentDate.HasValue) throw new ArgumentInvalidException(nameof(isRead), "Уведомление не может быть прочитано"); - notification.ReadDate = isRead ? DateTime.UtcNow : null; + notification.ReadDate = isRead ? DateTimeOffset.UtcNow : null; await notificationRepository.UpdateAsync(notification, cancellationToken); @@ -119,7 +119,7 @@ public class NotificationService var tasks = notifications.Select(notification => { - notification.SentDate = DateTime.UtcNow; + notification.SentDate = DateTimeOffset.UtcNow; return notificationRepository.UpdateAsync(notification, cancellationToken); }); diff --git a/AsbCloudDb/Model/DailyReports/DailyReport.cs b/AsbCloudDb/Model/DailyReports/DailyReport.cs index c521ca54..8bc99470 100644 --- a/AsbCloudDb/Model/DailyReports/DailyReport.cs +++ b/AsbCloudDb/Model/DailyReports/DailyReport.cs @@ -18,7 +18,7 @@ public class DailyReport : IId public int IdWell { get; set; } [Column("date_last_update", TypeName = "timestamp with time zone"), Comment("Дата последнего обновления")] - public DateTime? DateLastUpdate { get; set; } + public DateTimeOffset? DateLastUpdate { get; set; } [Column("date", TypeName = "date"), Comment("Дата формирования отчёта")] public DateOnly Date { get; set; } diff --git a/AsbCloudDb/Model/Manuals/Manual.cs b/AsbCloudDb/Model/Manuals/Manual.cs index 35b091b5..8ab64735 100644 --- a/AsbCloudDb/Model/Manuals/Manual.cs +++ b/AsbCloudDb/Model/Manuals/Manual.cs @@ -15,8 +15,8 @@ public class Manual : IId [Column("name"), Comment("Название")] public string Name { get; set; } = null!; - [Column("date_download"), Comment("Дата загрузки")] - public DateTime DateDownload { get; set; } + [Column("date_download", TypeName = "timestamp with time zone"), Comment("Дата загрузки")] + public DateTimeOffset DateDownload { get; set; } [Column("id_directory"), Comment("Id директории")] public int IdDirectory { get; set; } diff --git a/AsbCloudDb/Model/Notification.cs b/AsbCloudDb/Model/Notification.cs index 09f718b1..bed84a2b 100644 --- a/AsbCloudDb/Model/Notification.cs +++ b/AsbCloudDb/Model/Notification.cs @@ -25,13 +25,13 @@ public class Notification : IId public string Message { get; set; } = null!; [Column("registration_date"), Comment("Дата регистрации уведомления")] - public DateTime RegistrationDate { get; set; } + public DateTimeOffset RegistrationDate { get; set; } [Column("sent_date"), Comment("Дата отправки уведомления")] - public DateTime? SentDate { get; set; } + public DateTimeOffset? SentDate { get; set; } [Column("read_date"), Comment("Дата прочтения уведомления")] - public DateTime? ReadDate { get; set; } + public DateTimeOffset? ReadDate { get; set; } [Column("id_transport_type"), Comment("Id типа доставки уведомления")] public int IdTransportType { get; set; } diff --git a/AsbCloudInfrastructure/Background/WorkToSendEmail.cs b/AsbCloudInfrastructure/Background/WorkToSendEmail.cs index 57605438..ef8048e9 100644 --- a/AsbCloudInfrastructure/Background/WorkToSendEmail.cs +++ b/AsbCloudInfrastructure/Background/WorkToSendEmail.cs @@ -27,7 +27,7 @@ namespace AsbCloudInfrastructure.Background await notificationService.SendAsync(notification, token); - notification.SentDate = DateTime.UtcNow; + notification.SentDate = DateTimeOffset.UtcNow; await notificationRepository.UpdateAsync(notification, token); } diff --git a/AsbCloudInfrastructure/Repository/DailyReportRepository.cs b/AsbCloudInfrastructure/Repository/DailyReportRepository.cs index b82b0ce1..f7f582fa 100644 --- a/AsbCloudInfrastructure/Repository/DailyReportRepository.cs +++ b/AsbCloudInfrastructure/Repository/DailyReportRepository.cs @@ -1,80 +1,85 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; using AsbCloudApp.Data.DailyReport; using AsbCloudApp.Data.DailyReport.Blocks.Sign; using AsbCloudApp.Data.DailyReport.Blocks.Subsystems; using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; +using AsbCloudApp.Services; using AsbCloudDb; using AsbCloudDb.Model; using AsbCloudDb.Model.DailyReports; using Mapster; using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; namespace AsbCloudInfrastructure.Repository; public class DailyReportRepository : CrudRepositoryBase, - IDailyReportRepository + IDailyReportRepository { - public DailyReportRepository(IAsbCloudDbContext dbContext) - : base(dbContext) - { - } + private IWellService wellService; - public async Task> GetAsync(int idWell, FileReportRequest request, CancellationToken cancellationToken) - { - var skip = request.Skip ?? 0; - var take = request.Take ?? 10; + public DailyReportRepository(IAsbCloudDbContext dbContext, IWellService wellService) + : base(dbContext) + { + this.wellService = wellService; + } - var query = GetQuery().Where(d => d.IdWell == idWell); + public async Task> GetAsync(int idWell, FileReportRequest request, CancellationToken cancellationToken) + { + var skip = request.Skip ?? 0; + var take = request.Take ?? 10; - if (request.GeDate.HasValue) - query = query.Where(d => d.Date >= request.GeDate.Value); - - if (request.LeDate.HasValue) - query = query.Where(d => d.Date <= request.LeDate.Value); + var query = GetQuery().Where(d => d.IdWell == idWell); - query = request.SortFields?.Any() == true ? - query.SortBy(request.SortFields) : - query.OrderBy(d => d.Date); + if (request.GeDate.HasValue) + query = query.Where(d => d.Date >= request.GeDate.Value); - var entities = await query - .Skip(skip) - .Take(take) - .AsNoTracking() - .ToArrayAsync(cancellationToken); + if (request.LeDate.HasValue) + query = query.Where(d => d.Date <= request.LeDate.Value); - var dtos = entities.Select(Convert); + query = request.SortFields?.Any() == true ? + query.SortBy(request.SortFields) : + query.OrderBy(d => d.Date); - return dtos; - } + var entities = await query + .Skip(skip) + .Take(take) + .AsNoTracking() + .ToArrayAsync(cancellationToken); - public async Task GetOrDefaultAsync(int idWell, DateOnly date, CancellationToken cancellationToken) - { - var entity = await GetQuery() - .AsNoTracking() - .SingleOrDefaultAsync(d => d.IdWell == idWell && d.Date == date, cancellationToken); + var timezoneOffset = wellService.GetTimezone(idWell).Offset; + var dtos = entities.Select(entity => Convert(entity, timezoneOffset)); - return entity is null ? null : Convert(entity); - } + return dtos; + } - protected override DailyReportDto Convert(DailyReport src) - { - var dto = new DailyReportDto - { - Id = src.Id, - IdWell = src.IdWell, - DateLastUpdate = src.DateLastUpdate, - Date = src.Date, - SignBlock = src.SignBlock?.Adapt(), - TimeBalanceBlock = src.TimeBalanceBlock?.Adapt(), - SubsystemBlock = src.SubsystemBlock?.Adapt() - }; - - return dto; - } + public async Task GetOrDefaultAsync(int idWell, DateOnly date, CancellationToken cancellationToken) + { + var entity = await GetQuery() + .AsNoTracking() + .SingleOrDefaultAsync(d => d.IdWell == idWell && d.Date == date, cancellationToken); + + return entity is null ? null : Convert(entity); + } + + protected DailyReportDto Convert(DailyReport src, TimeSpan timezoneOffset) + { + var dto = new DailyReportDto + { + Id = src.Id, + IdWell = src.IdWell, + DateLastUpdate = src.DateLastUpdate?.ToOffset(timezoneOffset), + Date = src.Date, + SignBlock = src.SignBlock?.Adapt(), + TimeBalanceBlock = src.TimeBalanceBlock?.Adapt(), + SubsystemBlock = src.SubsystemBlock?.Adapt() + }; + + return dto; + } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Repository/DepositRepository.cs b/AsbCloudInfrastructure/Repository/DepositRepository.cs index 7f19f1d7..804d130e 100644 --- a/AsbCloudInfrastructure/Repository/DepositRepository.cs +++ b/AsbCloudInfrastructure/Repository/DepositRepository.cs @@ -4,6 +4,7 @@ using AsbCloudApp.Services; using AsbCloudDb.Model; using Mapster; using Microsoft.EntityFrameworkCore; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -111,7 +112,8 @@ namespace AsbCloudInfrastructure.Repository { var dto = well.Adapt(); dto.WellType = well.WellType.Caption; - dto.LastTelemetryDate = wellService.GetLastTelemetryDate(well.Id); + dto.LastTelemetryDate = wellService.GetLastTelemetryDate(well.Id) + .ToOffset(TimeSpan.FromHours(well.Timezone.Hours)); dto.Cluster = gCluster.Key.Caption; dto.Deposit = gDeposit.Key.Caption; return dto; diff --git a/AsbCloudInfrastructure/Repository/FileRepository.cs b/AsbCloudInfrastructure/Repository/FileRepository.cs index cafc5649..3e97da03 100644 --- a/AsbCloudInfrastructure/Repository/FileRepository.cs +++ b/AsbCloudInfrastructure/Repository/FileRepository.cs @@ -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); @@ -53,13 +50,13 @@ namespace AsbCloudInfrastructure.Repository if (request.Begin is not null) { - var beginUtc = request.Begin.Value.ToUtcDateTimeOffset(timezoneOffsetHours); + var beginUtc = request.Begin.Value.ToUniversalTime(); query = query.Where(e => e.UploadDate >= beginUtc); } if (request.End is not null) { - var endUtc = request.End.Value.ToUtcDateTimeOffset(timezoneOffsetHours); + var endUtc = request.End.Value.ToUniversalTime(); query = query.Where(e => e.UploadDate <= endUtc); } @@ -184,7 +181,7 @@ namespace AsbCloudInfrastructure.Repository var newFileMark = fileMarkDto.Adapt(); newFileMark.Id = default; - newFileMark.DateCreated = DateTime.UtcNow; + newFileMark.DateCreated = DateTimeOffset.UtcNow; newFileMark.IdUser = idUser; newFileMark.User = null!; @@ -244,7 +241,7 @@ namespace AsbCloudInfrastructure.Repository IdAuthor = newItem.IdAuthor, IdCategory = newItem.IdCategory, Name = newItem.Name, - UploadDate = DateTime.UtcNow, + UploadDate = DateTimeOffset.UtcNow, IsDeleted = false, Size = newItem.Size, }; @@ -278,11 +275,11 @@ namespace AsbCloudInfrastructure.Repository private static FileInfoDto Convert(FileInfo entity, double timezoneOffset) { var dto = entity.Adapt(); - dto.UploadDate = entity.UploadDate.ToRemoteDateTime(timezoneOffset); + dto.UploadDate = entity.UploadDate.ToOffset(TimeSpan.FromHours(timezoneOffset)); dto.FileMarks = entity.FileMarks.Select(m => { var mark = m.Adapt(); - mark.DateCreated = m.DateCreated.ToRemoteDateTime(timezoneOffset); + mark.DateCreated = m.DateCreated.ToOffset(TimeSpan.FromHours(timezoneOffset)); return mark; }); return dto; diff --git a/AsbCloudInfrastructure/Repository/LimitingParameterRepository.cs b/AsbCloudInfrastructure/Repository/LimitingParameterRepository.cs index 8f3c42c1..67fc5960 100644 --- a/AsbCloudInfrastructure/Repository/LimitingParameterRepository.cs +++ b/AsbCloudInfrastructure/Repository/LimitingParameterRepository.cs @@ -39,8 +39,8 @@ namespace AsbCloudInfrastructure.Repository IdWell = request.IdWell, IdTelemetry = x.IdTelemetry, IdFeedRegulator = x.IdFeedRegulator, - DateStart = DateTime.SpecifyKind(x.DateStart.UtcDateTime + timezoneSpan, DateTimeKind.Unspecified), - DateEnd = DateTime.SpecifyKind(x.DateEnd.UtcDateTime + timezoneSpan, DateTimeKind.Unspecified), + DateStart = x.DateStart.ToOffset(timezoneSpan), + DateEnd = x.DateEnd.ToOffset(timezoneSpan), DepthStart = x.DepthStart, DepthEnd = x.DepthEnd }); @@ -56,13 +56,13 @@ namespace AsbCloudInfrastructure.Repository if (request.GtDate.HasValue) { - var gtDate = request.GtDate.Value.ToUtcDateTimeOffset(timezoneHours); + var gtDate = request.GtDate.Value.ToUniversalTime(); query = query.Where(x => x.DateEnd >= gtDate); } if (request.LtDate.HasValue) { - var ltDate = request.LtDate.Value.ToUtcDateTimeOffset(timezoneHours); + var ltDate = request.LtDate.Value.ToUniversalTime(); query = query.Where(x => x.DateStart <= ltDate); } diff --git a/AsbCloudInfrastructure/Repository/NotificationRepository.cs b/AsbCloudInfrastructure/Repository/NotificationRepository.cs index 6f1e4a98..7e184f02 100644 --- a/AsbCloudInfrastructure/Repository/NotificationRepository.cs +++ b/AsbCloudInfrastructure/Repository/NotificationRepository.cs @@ -110,10 +110,10 @@ public class NotificationRepository : CrudRepositoryBase n.IdNotificationCategory == request.IdCategory.Value); if (request.LtSentDate.HasValue) - query = query.Where(n => n.SentDate <= request.LtSentDate.Value); + query = query.Where(n => n.SentDate <= request.LtSentDate.Value.ToUniversalTime()); if (request.LtReadDate.HasValue) - query = query.Where(n => n.ReadDate <= request.LtReadDate.Value); + query = query.Where(n => n.ReadDate <= request.LtReadDate.Value.ToUniversalTime()); dbContext.Notifications.RemoveRange(query); diff --git a/AsbCloudInfrastructure/Repository/ScheduleRepository.cs b/AsbCloudInfrastructure/Repository/ScheduleRepository.cs index e7c2aa1f..413bb661 100644 --- a/AsbCloudInfrastructure/Repository/ScheduleRepository.cs +++ b/AsbCloudInfrastructure/Repository/ScheduleRepository.cs @@ -24,7 +24,7 @@ namespace AsbCloudInfrastructure.Repository this.wellService = wellService; } - public async Task> GetAsync(int idWell, DateTime workTime, CancellationToken token) + public async Task> GetAsync(int idWell, DateTimeOffset workTime, CancellationToken token) { var entities = await BuildQuery(idWell, workTime) .AsNoTracking() @@ -33,7 +33,7 @@ namespace AsbCloudInfrastructure.Repository return entities.Select(Convert); } - public async Task GetOrDefaultDrillerAsync(int idWell, DateTime workTime, CancellationToken token) + public async Task GetOrDefaultDrillerAsync(int idWell, DateTimeOffset workTime, CancellationToken token) { var entities = await BuildQuery(idWell, workTime) .AsNoTracking() @@ -43,8 +43,7 @@ namespace AsbCloudInfrastructure.Repository return null; var hoursOffset = wellService.GetTimezone(idWell).Hours; - var remoteDate = workTime.ToUtcDateTimeOffset(hoursOffset).ToRemoteDateTime(hoursOffset); - var time = new TimeOnly(remoteDate.Hour, remoteDate.Minute, remoteDate.Second); + var time = new TimeOnly(workTime.Hour, workTime.Minute, workTime.Second); var entity = entities.FirstOrDefault(s => s.ShiftStart > s.ShiftEnd ^ @@ -69,11 +68,11 @@ namespace AsbCloudInfrastructure.Repository } - private IQueryable BuildQuery(int idWell, DateTime workTime) + private IQueryable BuildQuery(int idWell, DateTimeOffset workTime) { var hoursOffset = wellService.GetTimezone(idWell).Hours; - var workTimeDateTime = workTime.ToUtcDateTimeOffset(hoursOffset); + var workTimeDateTime = workTime.ToUniversalTime(); return GetQuery().Where(s => s.IdWell == idWell && s.DrillStart <= workTimeDateTime @@ -82,19 +81,20 @@ namespace AsbCloudInfrastructure.Repository protected override Schedule Convert(ScheduleDto dto) { - var hoursOffset = wellService.GetTimezone(dto.IdWell).Hours; var entity = base.Convert(dto); - entity.DrillStart = dto.DrillStart.ToUtcDateTimeOffset(hoursOffset); - entity.DrillEnd = dto.DrillEnd.ToUtcDateTimeOffset(hoursOffset); + entity.DrillStart = dto.DrillStart.ToUniversalTime(); + entity.DrillEnd = dto.DrillEnd.ToUniversalTime(); return entity; } 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.ToRemoteDateTime(hoursOffset); - dto.DrillEnd = entity.DrillEnd.ToRemoteDateTime(hoursOffset); + dto.DrillStart = entity.DrillStart.ToOffset(timeSpan); + dto.DrillEnd = entity.DrillEnd.ToOffset(timeSpan); return dto; } } diff --git a/AsbCloudInfrastructure/Repository/SetpointsRequestRepository.cs b/AsbCloudInfrastructure/Repository/SetpointsRequestRepository.cs index 838ae15b..2c1f7905 100644 --- a/AsbCloudInfrastructure/Repository/SetpointsRequestRepository.cs +++ b/AsbCloudInfrastructure/Repository/SetpointsRequestRepository.cs @@ -50,15 +50,14 @@ namespace AsbCloudInfrastructure.Repository { var result = base.Convert(src); var timezoneOffsetHours = wellService.GetTimezone(src.IdWell).Hours; - result.UploadDate = src.UploadDate.ToRemoteDateTime(timezoneOffsetHours); + result.UploadDate = src.UploadDate.ToOffset(TimeSpan.FromHours(timezoneOffsetHours)); return result; } protected override SetpointsRequest Convert(SetpointsRequestDto src) { var result = base.Convert(src); - var timezoneOffsetHours = wellService.GetTimezone(src.IdWell).Hours; - result.UploadDate = src.UploadDate.ToUtcDateTimeOffset(timezoneOffsetHours); + result.UploadDate = src.UploadDate.ToUniversalTime(); return result; } } diff --git a/AsbCloudInfrastructure/Repository/TelemetryWirelineRunOutRepository.cs b/AsbCloudInfrastructure/Repository/TelemetryWirelineRunOutRepository.cs index 81427cf6..af2b6438 100644 --- a/AsbCloudInfrastructure/Repository/TelemetryWirelineRunOutRepository.cs +++ b/AsbCloudInfrastructure/Repository/TelemetryWirelineRunOutRepository.cs @@ -5,6 +5,7 @@ using AsbCloudApp.Services; using AsbCloudDb.Model; using Mapster; using Microsoft.EntityFrameworkCore; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -93,14 +94,14 @@ namespace AsbCloudInfrastructure.Repository { var entity = dto.Adapt(); entity.IdTelemetry = idTelemetry; - entity.DateTime = dto.DateTime.ToUtcDateTimeOffset(timezoneOffset); + entity.DateTime = dto.DateTime.ToUniversalTime(); return entity; } private static TelemetryWirelineRunOutDto Convert(TelemetryWirelineRunOut entity, WellDto well, double timezoneOffset) { var dto = entity.Adapt(); - dto.DateTime = entity.DateTime.ToRemoteDateTime(timezoneOffset); + dto.DateTime = entity.DateTime.ToOffset(TimeSpan.FromHours(timezoneOffset)); dto.WellInfo = well; return dto; } diff --git a/AsbCloudInfrastructure/Repository/TrajectoryEditableRepository.cs b/AsbCloudInfrastructure/Repository/TrajectoryEditableRepository.cs index 4c8ab283..6ac07c52 100644 --- a/AsbCloudInfrastructure/Repository/TrajectoryEditableRepository.cs +++ b/AsbCloudInfrastructure/Repository/TrajectoryEditableRepository.cs @@ -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 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().Add(entity); return await db.SaveChangesAsync(token) @@ -98,8 +96,7 @@ namespace AsbCloudInfrastructure.Repository public async Task UpdateAsync(Tdto row, CancellationToken token) { - var offsetHours = wellService.GetTimezone(row.IdWell).Hours; - var entity = Convert(row, offsetHours); + var entity = Convert(row); db.Set().Update(entity); return await db.SaveChangesAsync(token) .ConfigureAwait(false); @@ -108,14 +105,14 @@ namespace AsbCloudInfrastructure.Repository private static Tdto Convert(TEntity entity, double offsetHours) { var dto = entity.Adapt(); - dto.UpdateDate = entity.UpdateDate.ToRemoteDateTime(offsetHours); + dto.UpdateDate = entity.UpdateDate.ToOffset(TimeSpan.FromHours(offsetHours)); return dto; } - private static TEntity Convert(Tdto dto, double offsetHours) + private static TEntity Convert(Tdto dto) { var entity = dto.Adapt(); - entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(offsetHours); + entity.UpdateDate = DateTimeOffset.Now; return entity; } } diff --git a/AsbCloudInfrastructure/Repository/TrajectoryNnbRepository.cs b/AsbCloudInfrastructure/Repository/TrajectoryNnbRepository.cs index a55e465f..69c2cccc 100644 --- a/AsbCloudInfrastructure/Repository/TrajectoryNnbRepository.cs +++ b/AsbCloudInfrastructure/Repository/TrajectoryNnbRepository.cs @@ -38,13 +38,13 @@ namespace AsbCloudInfrastructure.Repository if (request.GeDate.HasValue) { - var geDate = request.GeDate.Value.ToUtcDateTimeOffset(timezone.Hours); + var geDate = request.GeDate.Value.ToUniversalTime(); query = query.Where(r => r.DateTime >= geDate); } if (request.LeDate.HasValue) { - var leDate = request.LeDate.Value.ToUtcDateTimeOffset(timezone.Hours); + var leDate = request.LeDate.Value.ToUniversalTime(); query = query.Where(r => r.DateTime <= leDate); } diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs index 3e9607f4..21fba541 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs @@ -84,7 +84,7 @@ public class DailyReportService : IDailyReportService editableBlock.IdUser = idUser; editableBlock.LastUpdateDate = DateTime.UtcNow; - dailyReport.DateLastUpdate = DateTime.UtcNow; + dailyReport.DateLastUpdate = DateTimeOffset.UtcNow; if (dailyReport.Id == 0) return await dailyReportRepository.InsertAsync(dailyReport, cancellationToken); @@ -107,9 +107,10 @@ public class DailyReportService : IDailyReportService IdWell = well.Id }; - var geDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified); - var leDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified); - + 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 factOperationRequest = new WellOperationRequest(new []{ idWell }) { OperationType = WellOperation.IdOperationTypeFact, @@ -130,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 AddScheduleBlockAsync(dailyReport, cancellationToken); - await AddProcessMapWellDrillingBlockAsync(dailyReport, cancellationToken); + await AddTrajectoryBlockAsync(dailyReport, geDate, leDate, cancellationToken); + await AddScheduleBlockAsync(dailyReport, geDate, cancellationToken); + await AddProcessMapWellDrillingBlockAsync(dailyReport, geDate, leDate, cancellationToken); AddFactWellOperationBlock(dailyReport, factWellOperations); @@ -152,34 +153,32 @@ public class DailyReportService : IDailyReportService Items = Enumerable.Empty() }; - var datesRange = await GetDatesRangeAsync(idWell, cancellationToken); + var datesRange = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact, cancellationToken); if (datesRange is null) return result; var dailyReports = new List(); - - if (request.GeDate.HasValue) - { - var startDate = new DateTime(request.GeDate.Value.Year, request.GeDate.Value.Month, - request.GeDate.Value.Day); + TimeSpan offset = wellService.GetTimezone(idWell).Offset; - if (startDate.Date >= datesRange.From.Date) + if (request.GeDate.HasValue) + { + var startDate = new DateTimeOffset(request.GeDate.Value, TimeOnly.MinValue, offset); + + if (startDate >= datesRange.From) datesRange.From = startDate; } if (request.LeDate.HasValue) { - var finishDate = new DateTime(request.LeDate.Value.Year, request.LeDate.Value.Month, - request.LeDate.Value.Day); + var finishDate = new DateTimeOffset(request.LeDate.Value, TimeOnly.MinValue, offset); - if (finishDate.Date <= datesRange.To.Date) + if (finishDate <= datesRange.To) datesRange.To = finishDate; } - if (datesRange.From.AddDays(result.Skip) <= datesRange.To) - result.Count = (int)(Math.Ceiling((datesRange.To - DateTime.UnixEpoch).TotalDays) - - Math.Floor((datesRange.From - DateTime.UnixEpoch).TotalDays)) + 1; + result.Count = (int)(Math.Ceiling((datesRange.To - DateTimeOffset.UnixEpoch).TotalDays) + - Math.Floor((datesRange.From - DateTimeOffset.UnixEpoch).TotalDays)); var existingDailyReports = await dailyReportRepository.GetAsync(idWell, request, cancellationToken); @@ -227,11 +226,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); @@ -239,36 +238,8 @@ public class DailyReportService : IDailyReportService } } - public async Task GetDatesRangeAsync(int idWell, CancellationToken cancellationToken) - { - var timezone = wellService.GetTimezone(idWell); - var currentDate = DateTimeOffset.UtcNow.ToRemoteDateTime(timezone.Hours); - - var factOperationDatesRange = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact, - cancellationToken); - - if (factOperationDatesRange is null) - return null; - - var from = (factOperationDatesRange.From.AddDays(1) <= DateTime.UtcNow ? - factOperationDatesRange.From : - currentDate.AddDays(-1)) - .Date; - - var to = (factOperationDatesRange.To.AddDays(1) <= DateTime.UtcNow ? - factOperationDatesRange.To : - currentDate.AddDays(-1)) - .Date; - - return new DatesRangeDto - { - From = from, - To = to - }; - } - private async Task UpdateTimeBalanceBlockAsync(DailyReportDto dailyReport, IEnumerable factWellOperations, - CancellationToken cancellationToken) + DateTimeOffset geDateStart, DateTimeOffset leDateEnd, CancellationToken cancellationToken) { const int idWellOperationSlipsTime = 5011; @@ -277,10 +248,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 }, @@ -295,11 +263,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, @@ -316,11 +282,9 @@ public class DailyReportService : IDailyReportService }; } - private async Task AddScheduleBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken) + private async Task AddScheduleBlockAsync(DailyReportDto dailyReport, DateTimeOffset workDate, CancellationToken cancellationToken) { - var workDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified); - - dailyReport.ScheduleBlock = (await scheduleRepository.GetAsync(dailyReport.IdWell, workDate, cancellationToken)) + dailyReport.ScheduleBlock = (await scheduleRepository.GetAsync(dailyReport.IdWell, workDate, cancellationToken)) .Select(s => new ScheduleRecordDto { ShiftStart = s.ShiftStart, @@ -331,7 +295,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(); @@ -343,9 +308,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 { @@ -369,11 +331,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 geDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified); - var leDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified); - var request = new DataSaubStatRequest(); dailyReport.ProcessMapWellDrillingBlock = (await processMapReportDrillingService.GetAsync(dailyReport.IdWell, request, cancellationToken)).Where(p => p.DateStart >= geDate && p.DateStart <= leDate) @@ -412,11 +372,10 @@ public class DailyReportService : IDailyReportService private async Task IsDateDailyReportInRangeAsync(int idWell, DateOnly dateDailyReport, CancellationToken cancellationToken) { - var datesRange = await GetDatesRangeAsync(idWell, cancellationToken); + var datesRange = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact, cancellationToken); if (datesRange is null) return false; - var from = DateOnly.FromDateTime(datesRange.From.DateTime); var to = DateOnly.FromDateTime(datesRange.To.DateTime); diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs index 31f2c821..a4c3c8b0 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs @@ -265,8 +265,8 @@ public class DetectedOperationService : IDetectedOperationService dto.OperationValue = operationValues.FirstOrDefault(v => v.IdOperationCategory == dto.IdCategory && v.DepthStart <= dto.DepthStart && v.DepthEnd > dto.DepthStart); - - var dateStart = dto.DateStart; + + var dateStart = dto.DateStart.ToUniversalTime(); var timeStart = new TimeDto(dateStart); var driller = schedules.FirstOrDefault(s => s.DrillStart <= dateStart && diff --git a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs index 983d1f7c..ff29ed0f 100644 --- a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs +++ b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs @@ -49,7 +49,7 @@ namespace AsbCloudInfrastructure.Services.DrillTestReport well.Deposit ?? "-", well.Cluster ?? "-", well.Caption ?? "-"), - Date = DateTime.Now, + Date = DateTimeOffset.Now, }; var fileName = string.Format("Drill_test_{0}.xlsx", dto.TimeStampStart.ToString("dd.mm.yyyy_HH_MM_ss")); @@ -78,15 +78,15 @@ namespace AsbCloudInfrastructure.Services.DrillTestReport var dtos = await drillTestRepository.GetAllAsync(telemetry.Id, request, cancellationToken); foreach (var dto in dtos) { - var remoteDateTime = dto.TimeStampStart.ToRemoteDateTime(timezone.Hours); + var remoteDateTime = dto.TimeStampStart.ToOffset(TimeSpan.FromHours(timezone.Hours)); reports.Add(new DrillTestReportInfoDto { - FileName = string.Format("Drill_test_{0}", dto.TimeStampStart.DateTime), + FileName = string.Format("Drill_test_{0}", remoteDateTime), DrillDepth = (dto.Params .Where(p => p.DepthDrillStep.HasValue) .Sum(x => x.DepthDrillStep) ?? 0) + dto.DepthStart, - DateTime = dto.TimeStampStart.DateTime, + DateTime = remoteDateTime, Id = dto.Id, }); } diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs index 3e8349ad..18e6acf2 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs @@ -480,7 +480,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram IdWell = fileEntity.IdWell, Name = fileEntity.Name, Size = fileEntity.Size, - UploadDate = fileEntity.UploadDate.ToRemoteDateTime(timezoneOffset), + UploadDate = fileEntity.UploadDate.ToOffset(TimeSpan.FromHours(timezoneOffset)), }; var marks = fileEntity.FileMarks?.Where(m => !m.IsDeleted); @@ -489,7 +489,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram part.File.FileMarks = marks.Select(m => { var mark = m.Adapt(); - mark.DateCreated = m.DateCreated.ToRemoteDateTime(timezoneOffset); + mark.DateCreated = m.DateCreated.ToOffset(TimeSpan.FromHours(timezoneOffset)); return mark; }); var hasReject = marks.Any(m => m.IdMarkType == idMarkTypeReject); diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/TitleListSheet.cs b/AsbCloudInfrastructure/Services/DrillingProgram/TitleListSheet.cs index 3d6482a7..7c9355d8 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/TitleListSheet.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgram/TitleListSheet.cs @@ -11,7 +11,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram { private const string directionDirectorPositionName = "Руководитель направления по ТСБ"; - private readonly DateTime totalDate; + private readonly DateTimeOffset totalDate; private readonly FileMarkDto? acceptDirectionDirector; private readonly List acceptsOthers; private readonly WellDto well; @@ -157,7 +157,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left); } - private static string FormatDate(DateTime dateTime) + private static string FormatDate(DateTimeOffset dateTime) => $"{dateTime.Day:00}.{dateTime.Month:00}.{dateTime.Year:00}"; } diff --git a/AsbCloudInfrastructure/Services/LimitingParameterService.cs b/AsbCloudInfrastructure/Services/LimitingParameterService.cs index c4323597..5dee9f53 100644 --- a/AsbCloudInfrastructure/Services/LimitingParameterService.cs +++ b/AsbCloudInfrastructure/Services/LimitingParameterService.cs @@ -106,7 +106,7 @@ namespace AsbCloudInfrastructure.Services return (float)result; } - private DateTime GetDate(double depth, LimitingParameterDataDto dto) + private DateTimeOffset GetDate(double depth, LimitingParameterDataDto dto) { var a = depth - dto.DepthStart; var b = dto.DepthEnd - dto.DepthStart; diff --git a/AsbCloudInfrastructure/Services/ManualCatalogService.cs b/AsbCloudInfrastructure/Services/ManualCatalogService.cs index c8713ab1..8c779bc7 100644 --- a/AsbCloudInfrastructure/Services/ManualCatalogService.cs +++ b/AsbCloudInfrastructure/Services/ManualCatalogService.cs @@ -57,7 +57,7 @@ public class ManualCatalogService : IManualCatalogService var manual = new ManualDto { Name = name, - DateDownload = DateTime.UtcNow, + DateDownload = DateTimeOffset.UtcNow, IdDirectory = idDirectory, IdCategory = IdFileCategory, IdAuthor = idAuthor diff --git a/AsbCloudInfrastructure/Services/MeasureService.cs b/AsbCloudInfrastructure/Services/MeasureService.cs index 58c5c295..7a349450 100644 --- a/AsbCloudInfrastructure/Services/MeasureService.cs +++ b/AsbCloudInfrastructure/Services/MeasureService.cs @@ -87,8 +87,7 @@ namespace AsbCloudInfrastructure.Services throw new ArgumentInvalidException(nameof(dto), "wrong idCategory"); if (!dto.Data.Any()) throw new ArgumentInvalidException(nameof(dto), "data.data is not optional"); - var timezone = wellService.GetTimezone(idWell); - var entity = Convert(dto, timezone.Hours); + var entity = Convert(dto); entity.IdWell = idWell; db.Measures.Add(entity); return db.SaveChangesAsync(token); @@ -110,7 +109,7 @@ namespace AsbCloudInfrastructure.Services var timezone = wellService.GetTimezone(idWell); entity.IdWell = idWell; - entity.Timestamp = dto.Timestamp.ToUtcDateTimeOffset(timezone.Hours); + entity.Timestamp = dto.Timestamp.ToOffset(TimeSpan.FromHours(timezone.Hours)); entity.Data = dto.Data.Adapt(); return await db.SaveChangesAsync(token).ConfigureAwait(false); @@ -142,13 +141,13 @@ namespace AsbCloudInfrastructure.Services { var dto = entity.Adapt(); dto.CategoryName = entity.Category?.Name ?? String.Empty; - dto.Timestamp = entity.Timestamp.ToRemoteDateTime(hours); + dto.Timestamp = entity.Timestamp.ToOffset(TimeSpan.FromHours(hours)); return dto; } - private Measure Convert(MeasureDto dto, double hours) + private Measure Convert(MeasureDto dto) { var entity = dto.Adapt(); - entity.Timestamp = dto.Timestamp.ToUtcDateTimeOffset(hours); + entity.Timestamp = dto.Timestamp.ToUniversalTime(); return entity; } } diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs index 9f527b4c..c15c00aa 100644 --- a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs @@ -174,7 +174,7 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService var result = new ProcessMapReportDataSaubStatDto() { IdWellSectionType = wellSectionType.Id, - DateStart = firstElemInInterval.DateStart.DateTime, + DateStart = firstElemInInterval.DateStart, WellSectionTypeName = wellSectionType.Caption, DepthStart = firstElemInInterval.DepthStart, DepthEnd = lastElemInInterval.DepthEnd, diff --git a/AsbCloudInfrastructure/Services/ReportService.cs b/AsbCloudInfrastructure/Services/ReportService.cs index fd7d86a3..4d321525 100644 --- a/AsbCloudInfrastructure/Services/ReportService.cs +++ b/AsbCloudInfrastructure/Services/ReportService.cs @@ -64,11 +64,11 @@ public class ReportService : IReportService return work.Id; } - public int GetReportPagesCount(int idWell, DateTime begin, DateTime end, int stepSeconds, int format) + public int GetReportPagesCount(int idWell, DateTimeOffset begin, DateTimeOffset end, int stepSeconds, int format) { var timezoneOffset = wellService.GetTimezone(idWell).Hours; - var beginRemote = begin.ToTimeZoneOffsetHours(timezoneOffset); - var endRemote = end.ToTimeZoneOffsetHours(timezoneOffset); + var beginRemote = begin.DateTime.ToTimeZoneOffsetHours(timezoneOffset); + var endRemote = end.DateTime.ToTimeZoneOffsetHours(timezoneOffset); var generator = GetReportGenerator(idWell, beginRemote, endRemote, stepSeconds, format, db); var pagesCount = generator.GetPagesCount(); @@ -87,6 +87,7 @@ public class ReportService : IReportService public async Task> GetAllReportsByWellAsync(int idWell, CancellationToken token) { var timezoneOffset = wellService.GetTimezone(idWell).Hours; + var timeSpan = TimeSpan.FromHours(timezoneOffset); var propertiesQuery = db.ReportProperties.Include(r => r.File) .Where(p => p.IdWell == idWell) .OrderBy(o => o.File.UploadDate) @@ -106,12 +107,12 @@ public class ReportService : IReportService IdWell = p.File.IdWell, Name = p.File.Name, Size = p.File.Size, - UploadDate = p.File.UploadDate.ToRemoteDateTime(timezoneOffset), + UploadDate = p.File.UploadDate.ToOffset(timeSpan), }, IdWell = p.IdWell, - Date = p.File.UploadDate.ToRemoteDateTime(timezoneOffset), - Begin = p.Begin.ToRemoteDateTime(timezoneOffset), - End = p.End.ToRemoteDateTime(timezoneOffset), + Date = p.File.UploadDate.ToOffset(timeSpan), + Begin = p.Begin.ToOffset(timeSpan), + End = p.End.ToOffset(timeSpan), Step = p.Step, Format = p.Format == 0 ? ".pdf" : ".las" }); @@ -127,10 +128,10 @@ public class ReportService : IReportService CancellationToken token) { var timezoneOffset = wellService.GetTimezone(idWell).Hours; - var beginRemote = request.Begin.ToTimeZoneOffsetHours(timezoneOffset); - var endRemote = request.End.ToTimeZoneOffsetHours(timezoneOffset); - var beginUtc = request.Begin.ToUtcDateTimeOffset(timezoneOffset); - var endUtc = request.End.ToUtcDateTimeOffset(timezoneOffset); + var beginRemote = request.Begin.DateTime; + var endRemote = request.End.DateTime; + var beginUtc = request.Begin.ToUniversalTime(); + var endUtc = request.End.ToUniversalTime(); var tempDir = Path.Combine(Path.GetTempPath(), "report"); diff --git a/AsbCloudInfrastructure/Services/SAUB/MessageService.cs b/AsbCloudInfrastructure/Services/SAUB/MessageService.cs index 350829e1..d728536a 100644 --- a/AsbCloudInfrastructure/Services/SAUB/MessageService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/MessageService.cs @@ -72,13 +72,13 @@ namespace AsbCloudInfrastructure.Services.SAUB if (request.Begin is not null) { - var beginUtc = request.Begin.Value.ToUtcDateTimeOffset(timezone.Hours); + var beginUtc = request.Begin.Value.ToUniversalTime(); query = query.Where(m => m.DateTime >= beginUtc); } if (request.End is not null) { - var endUtc = request.End.Value.ToUtcDateTimeOffset(timezone.Hours); + var endUtc = request.End.Value.ToUniversalTime(); query = query.Where(m => m.DateTime <= endUtc); } @@ -111,7 +111,7 @@ namespace AsbCloudInfrastructure.Services.SAUB WellDepth = message.WellDepth }; - messageDto.DateTime = message.DateTime.ToRemoteDateTime(timezone.Hours); + messageDto.DateTime = message.DateTime.ToOffset(TimeSpan.FromHours(timezone.Hours)); if (message.IdTelemetryUser is not null) { @@ -150,7 +150,7 @@ namespace AsbCloudInfrastructure.Services.SAUB var entity = dto.Adapt(); entity.Id = 0; entity.IdTelemetry = telemetry.Id; - entity.DateTime = dto.Date.ToUtcDateTimeOffset(timezone.Hours); + entity.DateTime = dto.Date.ToOffset(TimeSpan.FromHours(timezone.Hours)); db.TelemetryMessages.Add(entity); } diff --git a/AsbCloudInfrastructure/Services/SAUB/SetpointsService.cs b/AsbCloudInfrastructure/Services/SAUB/SetpointsService.cs index b0f5c824..657a99c6 100644 --- a/AsbCloudInfrastructure/Services/SAUB/SetpointsService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/SetpointsService.cs @@ -72,7 +72,6 @@ namespace AsbCloudInfrastructure.Services.SAUB foreach (var item in filtered) { item.IdState = 2; - item.UploadDate = DateTime.SpecifyKind(item.UploadDate, DateTimeKind.Utc); } await setpointsRepository.UpdateRangeAsync(filtered, token); diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs index a491b483..53ed062b 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs @@ -102,7 +102,7 @@ namespace AsbCloudInfrastructure.Services.SAUB if (dateBegin == default) { var dateRange = telemetryDataCache.GetOrDefaultDataDateRange(telemetry.Id); - dateBeginUtc = (dateRange?.To.UtcDateTime ?? DateTime.UtcNow) + dateBeginUtc = (dateRange?.To ?? DateTimeOffset.UtcNow) .AddSeconds(-intervalSec); } else diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs index 74643429..a75c7bf3 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs @@ -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) diff --git a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs index e5d46b27..638232f3 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs @@ -146,6 +146,8 @@ public class OperationsStatService : IOperationsStatService private async Task CalcWellStatAsync(Well well, CancellationToken token) { + var timezone = wellService.GetTimezone(well.Id); + var wellType = (await memoryCache .GetOrCreateBasicAsync(db.Set(), token)) .FirstOrDefault(t => t.Id == well.IdWellType); @@ -170,9 +172,8 @@ public class OperationsStatService : IOperationsStatService if (!wellOperations.Any()) return statWellDto; - var timezoneOffsetH = wellService.GetTimezone(well.Id).Hours; - statWellDto.Sections = CalcSectionsStats(wellOperations, timezoneOffsetH); - statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezoneOffsetH); + statWellDto.Sections = CalcSectionsStats(wellOperations, timezone.Hours); + statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezone.Hours); statWellDto.TvdLagDays = CalcTvdLagDays(wellOperations); statWellDto.TvdDrillingDays = CalcDrillingDays(wellOperations); @@ -288,8 +289,8 @@ public class OperationsStatService : IOperationsStatService var section = new StatOperationsDto { - Start = operations.FirstOrDefault()?.DateStart.ToRemoteDateTime(timezoneOffsetHours), - End = operations.Max(o => o.DateStart.ToRemoteDateTime(timezoneOffsetHours).AddHours(o.DurationHours)), + Start = operations.FirstOrDefault()?.DateStart.ToOffset(TimeSpan.FromHours(timezoneOffsetHours)), + End = operations.Max(o => o.DateStart.ToOffset(TimeSpan.FromHours(timezoneOffsetHours)).AddHours(o.DurationHours)), WellDepthStart = operations.Min(o => o.DepthStart), WellDepthEnd = operations.Max(o => o.DepthStart), Rop = CalcROP(operations), diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index cfccf153..6ed241a0 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -63,12 +63,12 @@ namespace AsbCloudInfrastructure.Services private void DropCacheRelationCompanyWell() => memoryCache.DropBasic(); - public DateTime GetLastTelemetryDate(int idWell) + public DateTimeOffset GetLastTelemetryDate(int idWell) { var well = GetOrDefault(idWell); if (well?.IdTelemetry is null) - return DateTime.MinValue; + return DateTimeOffset.MinValue; var datesRange = telemetryService.GetDatesRange(well.IdTelemetry.Value); return datesRange.To.DateTime; @@ -279,7 +279,7 @@ namespace AsbCloudInfrastructure.Services dto.Cluster = entity.Cluster.Caption; dto.Deposit = entity.Cluster.Deposit.Caption; if (entity.IdTelemetry is not null) - dto.LastTelemetryDate = telemetryService.GetDatesRange(entity.IdTelemetry.Value).To.DateTime; + dto.LastTelemetryDate = telemetryService.GetDatesRange(entity.IdTelemetry.Value).To.ToOffset(dto.Timezone.Offset); dto.Companies = entity.RelationCompaniesWells .Select(r => Convert(r.Company)) .ToList(); @@ -297,47 +297,10 @@ namespace AsbCloudInfrastructure.Services public SimpleTimezoneDto GetTimezone(int idWell) { - var well = GetOrDefault(idWell) + var cache = GetCache(); + var cacheItem = cache.FirstOrDefault(d => d.Id == idWell) ?? throw new ArgumentInvalidException(nameof(idWell), $"idWell: {idWell} does not exist."); - return GetTimezone(well); - } - - private SimpleTimezoneDto GetTimezone(WellDto wellDto) - { - if (wellDto.Timezone is not null) - return wellDto.Timezone; - - if (wellDto.Telemetry is not null) - { - var timezone = telemetryService.GetTimezone(wellDto.Telemetry.Id); - if (timezone is not null) - return timezone; - } - - var well = GetQuery().FirstOrDefault(w => w.Id == wellDto.Id); - - if (well is not null) - { - var point = GetCoordinates(well); - if (point is not null) - { - if (point.Timezone is not null) - { - return point.Timezone.Adapt(); - } - - if (point.Latitude is not null & point.Longitude is not null) - { - var timezone = timezoneService.GetOrDefaultByCoordinates(point.Latitude!.Value, point.Longitude!.Value); - if (timezone is not null) - { - return timezone; - } - } - } - } - - throw new Exception($"Can't find timezone for well {wellDto.Caption} id: {wellDto.Id}"); + return cacheItem.Timezone.Adapt(); } private bool IsTelemetryAssignedToDifferentWell(WellDto wellDto) @@ -350,7 +313,7 @@ namespace AsbCloudInfrastructure.Services if (existingWellWithAssignedTelemetry is null) return false; - + return existingWellWithAssignedTelemetry.Id != wellDto.Id; } diff --git a/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs b/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs index d7af2c1c..38f1959e 100644 --- a/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs +++ b/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs @@ -12,6 +12,7 @@ using AsbCloudApp.Repositories; using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudApp.Services.ProcessMaps.WellDrilling; +using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.DailyReport; using NSubstitute; using System; @@ -114,7 +115,7 @@ public class DailyReportServiceTest private readonly ProcessMapReportDataSaubStatDto fakeProcessMapReportWellDrilling = new() { DrillingMode = "Ротор", - DateStart = new DateTime(2023, 10, 26), + DateStart = new DateTimeOffset(2023, 10, 26, 0, 0, 0, TimeSpan.Zero), DeltaDepth = 500, Rop = new PlanFactDto { @@ -179,8 +180,8 @@ public class DailyReportServiceTest IdWell = idWell, ShiftStart = new TimeDto(1), ShiftEnd = new TimeDto(5), - DrillStart = new DateTime(2023, 01, 26), - DrillEnd = new DateTime(2023, 12, 26), + DrillStart = new DateTimeOffset(2023, 01, 26, 0, 0, 0, TimeSpan.Zero), + DrillEnd = new DateTimeOffset(2023, 12, 26, 0, 0, 0, TimeSpan.Zero), Driller = new() { Name = "Иван", @@ -283,7 +284,7 @@ public class DailyReportServiceTest subsystemServiceMock.GetStatAsync(Arg.Any(), Arg.Any()) .ReturnsForAnyArgs(new[] { fakeSubsystemsStat }); - scheduleRepositoryMock.GetAsync(Arg.Any(), Arg.Any(), Arg.Any()) + scheduleRepositoryMock.GetAsync(Arg.Any(), Arg.Any(), Arg.Any()) .ReturnsForAnyArgs(new[] { fakeShedule }); processMapReportWellDrillingServiceMock.GetAsync(Arg.Any(), fakeRequest, Arg.Any()) @@ -524,12 +525,12 @@ public class DailyReportServiceTest .Returns(datesRange); //act - var result = await dailyReportService.GetDatesRangeAsync(idWell, CancellationToken.None); + var result = await wellOperationRepositoryMock.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact, CancellationToken.None); //assert Assert.NotNull(result); Assert.True(result.From <= result.To); - Assert.True(result.To < DateTime.UtcNow.Date); + Assert.True(result.To < DateTimeOffset.UtcNow); } public static IEnumerable DateDailyReport() diff --git a/AsbCloudWebApi.Tests/Services/FileServiceTest.cs b/AsbCloudWebApi.Tests/Services/FileServiceTest.cs index 311e483f..b1200160 100644 --- a/AsbCloudWebApi.Tests/Services/FileServiceTest.cs +++ b/AsbCloudWebApi.Tests/Services/FileServiceTest.cs @@ -39,7 +39,7 @@ public class FileServiceTest IdCategory = idCategory, Name = fileName, Size = 0, - UploadDate = DateTime.Now + UploadDate = DateTimeOffset.Now }; private static FileMarkDto fileMark = new() diff --git a/AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs b/AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs index 724f1e7b..5b6bcb1d 100644 --- a/AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs +++ b/AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs @@ -26,7 +26,7 @@ namespace AsbCloudWebApi.Tests.Services.Notification IdUser = 1, IdTransportType = 1, IdState = 0, - RegistrationDate = DateTime.Now, + RegistrationDate = DateTimeOffset.Now, IdNotificationCategory = 10000, }; private readonly UserExtendedDto user = new UserExtendedDto() diff --git a/AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryExportTest.cs b/AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryExportTest.cs index 34d2077c..bffab69f 100644 --- a/AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryExportTest.cs +++ b/AsbCloudWebApi.Tests/Services/Trajectory/TrajectoryExportTest.cs @@ -34,7 +34,7 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory IdUser = 1, IdWell = 4, Radius = 3, - UpdateDate = DateTime.Now, + UpdateDate = DateTimeOffset.Now, VerticalDepth = 100, WellboreDepth = 100, ZenithAngle = 10 @@ -47,7 +47,7 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory IdUser = 1, IdWell = 4, Radius = 3, - UpdateDate = DateTime.Now, + UpdateDate = DateTimeOffset.Now, VerticalDepth = 100, WellboreDepth = 100, ZenithAngle = 10 @@ -62,7 +62,7 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory Comment = "комментарий", IdUser = 1, IdWell = 4, - UpdateDate = DateTime.Now, + UpdateDate = DateTimeOffset.Now, VerticalDepth = 100, WellboreDepth = 100, ZenithAngle = 10 @@ -74,7 +74,7 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory Comment = "комментарий", IdUser = 1, IdWell = 4, - UpdateDate = DateTime.Now, + UpdateDate = DateTimeOffset.Now, VerticalDepth = 100, WellboreDepth = 100, ZenithAngle = 10 diff --git a/AsbCloudWebApi.Tests/Services/WellboreServiceTest.cs b/AsbCloudWebApi.Tests/Services/WellboreServiceTest.cs index 7f647158..f256c384 100644 --- a/AsbCloudWebApi.Tests/Services/WellboreServiceTest.cs +++ b/AsbCloudWebApi.Tests/Services/WellboreServiceTest.cs @@ -21,7 +21,7 @@ public class WellboreServiceTest Id = 1, IdState = 1, IdTelemetry = 1, - LastTelemetryDate = DateTime.Now, + LastTelemetryDate = DateTimeOffset.Now, Caption = "well 1" }; @@ -30,7 +30,7 @@ public class WellboreServiceTest Id = 2, IdState = 1, IdTelemetry = 100, - LastTelemetryDate = DateTime.Now, + LastTelemetryDate = DateTimeOffset.Now, Caption = "well 2" }; diff --git a/AsbCloudWebApi/Controllers/DailyReportController.cs b/AsbCloudWebApi/Controllers/DailyReportController.cs index e36868f1..682dc74d 100644 --- a/AsbCloudWebApi/Controllers/DailyReportController.cs +++ b/AsbCloudWebApi/Controllers/DailyReportController.cs @@ -13,6 +13,7 @@ using AsbCloudApp.Repositories; using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudApp.Services.DailyReport; +using AsbCloudDb.Model; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -156,7 +157,7 @@ public class DailyReportController : ControllerBase { await AssertUserAccessToWell(idWell, cancellationToken); - var datesRanges = await dailyReportService.GetDatesRangeAsync(idWell, cancellationToken); + var datesRanges = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact, cancellationToken); return Ok(datesRanges); } diff --git a/AsbCloudWebApi/Controllers/ScheduleController.cs b/AsbCloudWebApi/Controllers/ScheduleController.cs index a8c73d30..cc56a296 100644 --- a/AsbCloudWebApi/Controllers/ScheduleController.cs +++ b/AsbCloudWebApi/Controllers/ScheduleController.cs @@ -33,7 +33,7 @@ namespace AsbCloudWebApi.Controllers /// /// бурильщик [HttpGet("driller")] - public async Task> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token) + public async Task> GetDrillerAsync(int idWell, DateTimeOffset workTime, CancellationToken token) { if (!await UserHasAccesToWellAsync(idWell, token)) return Forbid(); diff --git a/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs b/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs index 6799e71d..05c93a29 100644 --- a/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs +++ b/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs @@ -35,7 +35,7 @@ public class NotificationPublisher { foreach (var notification in groupedNotifications) { - notification.SentDate = DateTime.UtcNow; + notification.SentDate = DateTimeOffset.UtcNow; } var notifications = groupedNotifications.Select(n => n);