From a2f87591e8b779dcf37505088ab859496eaf6118 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 29 Dec 2023 11:24:46 +0500 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20?= =?UTF-8?q?=D0=B4=D0=B0=D1=82=D1=8B=20=D0=B2=20WellOperationDto=20-=20Date?= =?UTF-8?q?TimeOffset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/WellOperationDto.cs | 29 +++++++++++++++---- .../Repository/WellOperationRepository.cs | 5 ++-- .../ScheduleReportService.cs | 4 +-- .../Services/DailyReportServiceTest.cs | 4 +-- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/AsbCloudApp/Data/WellOperationDto.cs b/AsbCloudApp/Data/WellOperationDto.cs index f2a2d65f..e21471ce 100644 --- a/AsbCloudApp/Data/WellOperationDto.cs +++ b/AsbCloudApp/Data/WellOperationDto.cs @@ -1,5 +1,5 @@ -using AsbCloudApp.Validation; -using System; +using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace AsbCloudApp.Data @@ -7,7 +7,7 @@ namespace AsbCloudApp.Data /// /// Операции на скважине (заведенные пользователем) /// - public class WellOperationDto : ItemInfoDto, IId, IWellRelated + public class WellOperationDto : ItemInfoDto, IId, IWellRelated, IValidatableObject { /// public int Id { get; set; } @@ -86,8 +86,8 @@ namespace AsbCloudApp.Data /// /// Дата начала операции /// - [DateValidation(GtDate = "2010-01-01T00:00:00")] - public DateTime DateStart { get; set; } + + public DateTimeOffset DateStart { get; set; } /// /// Продолжительность, часы @@ -100,5 +100,24 @@ namespace AsbCloudApp.Data /// [StringLength(4096, ErrorMessage = "Комментарий не может быть длиннее 4096 символов")] public string? Comment { get; set; } + + /// + /// Валидация даты + /// + /// + /// + public IEnumerable Validate(ValidationContext validationContext) + { + if (!(DateStart is DateTimeOffset dateTimeOffset)) + yield return new ValidationResult( + $"{nameof(DateStart)}: дата DateStart указана не в формате DateTimeOffset", + new[] { nameof(DateStart) }); + + var gtDate = new DateTimeOffset(2010, 1, 1, 0, 0, 0, TimeSpan.Zero); + if (DateStart <= gtDate) + yield return new ValidationResult( + $"{nameof(DateStart)}: DateStart не может быть меньше {gtDate}", + new[] { nameof(DateStart) }); + } } } diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index fbc94e02..fb0a8c12 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -347,7 +347,7 @@ public class WellOperationRepository : IWellOperationRepository { var entity = dto.Adapt(); entity.Id = default; - entity.DateStart = dto.DateStart.ToUtcDateTimeOffset(timezone.Hours); + entity.DateStart = dto.DateStart.ToUniversalTime(); entity.IdWell = idWell; db.WellOperations.Add(entity); } @@ -365,7 +365,7 @@ public class WellOperationRepository : IWellOperationRepository { var timezone = wellService.GetTimezone(dto.IdWell); var entity = dto.Adapt(); - entity.DateStart = dto.DateStart.ToUtcDateTimeOffset(timezone.Hours); + entity.DateStart = dto.DateStart.ToUniversalTime(); db.WellOperations.Update(entity); var result = await db.SaveChangesAsync(token); @@ -449,7 +449,6 @@ public class WellOperationRepository : IWellOperationRepository CategoryName = o.OperationCategory.Name, WellSectionTypeName = o.WellSectionType.Caption, - DateStart = DateTime.SpecifyKind(o.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified), DepthStart = o.DepthStart, DepthEnd = o.DepthEnd, diff --git a/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs b/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs index d46bfff1..f1c44ec3 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs @@ -140,7 +140,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService .Select(t => t.Fact!) .ToList(); - DateTime lastFactDate = default; + DateTimeOffset lastFactDate = default; var lastFactI = 0; int i = 0; @@ -290,7 +290,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService static DateTime GetEndDate(WellOperationDto operation) => operation is not null - ? operation.DateStart.AddHours(operation.DurationHours) + ? operation.DateStart.Date.AddHours(operation.DurationHours) : default; var endDatePlan = planLast is not null ? GetEndDate(planLast) : default; diff --git a/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs b/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs index b75b6947..d635d53d 100644 --- a/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs +++ b/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs @@ -238,8 +238,8 @@ public class DailyReportServiceTest fakeDatesRange = new DatesRangeDto { - From = fakeFirstFactWellOperation.DateStart, - To = fakeLastFactWellOperation.DateStart + From = fakeFirstFactWellOperation.DateStart.Date, + To = fakeLastFactWellOperation.DateStart.Date }; dailyReportService = new DailyReportService(wellServiceMock, From bd2616bf36f560a27c27cb75087b6b7cca2a24c1 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 29 Dec 2023 14:21:42 +0500 Subject: [PATCH 2/3] =?UTF-8?q?=D0=90=D1=82=D1=80=D0=B8=D0=B1=D1=83=D1=82?= =?UTF-8?q?=20Required?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/WellOperationDto.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AsbCloudApp/Data/WellOperationDto.cs b/AsbCloudApp/Data/WellOperationDto.cs index e21471ce..03f55957 100644 --- a/AsbCloudApp/Data/WellOperationDto.cs +++ b/AsbCloudApp/Data/WellOperationDto.cs @@ -10,6 +10,7 @@ namespace AsbCloudApp.Data public class WellOperationDto : ItemInfoDto, IId, IWellRelated, IValidatableObject { /// + [Required] public int Id { get; set; } /// @@ -64,34 +65,39 @@ namespace AsbCloudApp.Data /// /// Глубина на начало операции, м /// + [Required] [Range(0, 50_000)] public double DepthStart { get; set; } /// /// Глубина после завершения операции, м /// + [Required] [Range(0, 50_000)] public double DepthEnd { get; set; } /// /// Кол-во дней от даты начала первой плановой (а если её нет, то фактической) операции /// + [Required] public double Day { get; set; } /// /// Кол-во часов НПВ от даты начала первой плановой (а если её нет, то фактической) операции /// + [Required] public double NptHours { get; set; } /// /// Дата начала операции /// - + [Required] public DateTimeOffset DateStart { get; set; } /// /// Продолжительность, часы /// + [Required] [Range(0, 50)] public double DurationHours { get; set; } From eafc4566d847bde1e64b94e2654ec82f9109ab66 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 29 Dec 2023 14:40:10 +0500 Subject: [PATCH 3/3] DailyReportServiceTest fix mock data --- .../UnitTests/Services/DailyReportServiceTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs b/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs index d635d53d..54bd3d2f 100644 --- a/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs +++ b/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs @@ -238,9 +238,9 @@ public class DailyReportServiceTest fakeDatesRange = new DatesRangeDto { - From = fakeFirstFactWellOperation.DateStart.Date, - To = fakeLastFactWellOperation.DateStart.Date - }; + From = fakeFirstFactWellOperation.DateStart.DateTime, + To = fakeLastFactWellOperation.DateStart.DateTime + }; dailyReportService = new DailyReportService(wellServiceMock, trajectoryFactNnbRepositoryMock,