Merge pull request 'fix/wellOperation-date-time-offset' (#191) from fix/wellOperation-date-time-offset into dev

Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/191
This commit is contained in:
Никита Фролов 2023-12-29 14:40:45 +05:00
commit f07924160e
4 changed files with 37 additions and 13 deletions

View File

@ -1,5 +1,5 @@
using AsbCloudApp.Validation;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Data
@ -7,9 +7,10 @@ namespace AsbCloudApp.Data
/// <summary>
/// Операции на скважине (заведенные пользователем)
/// </summary>
public class WellOperationDto : ItemInfoDto, IId, IWellRelated
public class WellOperationDto : ItemInfoDto, IId, IWellRelated, IValidatableObject
{
/// <inheritdoc/>
[Required]
public int Id { get; set; }
/// <inheritdoc/>
@ -64,34 +65,39 @@ namespace AsbCloudApp.Data
/// <summary>
/// Глубина на начало операции, м
/// </summary>
[Required]
[Range(0, 50_000)]
public double DepthStart { get; set; }
/// <summary>
/// Глубина после завершения операции, м
/// </summary>
[Required]
[Range(0, 50_000)]
public double DepthEnd { get; set; }
/// <summary>
/// Кол-во дней от даты начала первой плановой (а если её нет, то фактической) операции
/// </summary>
[Required]
public double Day { get; set; }
/// <summary>
/// Кол-во часов НПВ от даты начала первой плановой (а если её нет, то фактической) операции
/// </summary>
[Required]
public double NptHours { get; set; }
/// <summary>
/// Дата начала операции
/// </summary>
[DateValidation(GtDate = "2010-01-01T00:00:00")]
public DateTime DateStart { get; set; }
[Required]
public DateTimeOffset DateStart { get; set; }
/// <summary>
/// Продолжительность, часы
/// </summary>
[Required]
[Range(0, 50)]
public double DurationHours { get; set; }
@ -100,5 +106,24 @@ namespace AsbCloudApp.Data
/// </summary>
[StringLength(4096, ErrorMessage = "Комментарий не может быть длиннее 4096 символов")]
public string? Comment { get; set; }
/// <summary>
/// Валидация даты
/// </summary>
/// <param name="validationContext"></param>
/// <returns></returns>
public IEnumerable<ValidationResult> 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) });
}
}
}

View File

@ -347,7 +347,7 @@ public class WellOperationRepository : IWellOperationRepository
{
var entity = dto.Adapt<WellOperation>();
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<WellOperation>();
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,

View File

@ -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;

View File

@ -238,9 +238,9 @@ public class DailyReportServiceTest
fakeDatesRange = new DatesRangeDto
{
From = fakeFirstFactWellOperation.DateStart,
To = fakeLastFactWellOperation.DateStart
};
From = fakeFirstFactWellOperation.DateStart.DateTime,
To = fakeLastFactWellOperation.DateStart.DateTime
};
dailyReportService = new DailyReportService(wellServiceMock,
trajectoryFactNnbRepositoryMock,