diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index c607d523..02400268 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -55,6 +55,7 @@ + diff --git a/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs b/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs index 84506a21..64208a8e 100644 --- a/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs +++ b/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs @@ -193,7 +193,8 @@ public abstract class ChangeLogRepositoryAbstract : ICh dates = dates.Select(date => date.ToOffset(offset)); var datesOnly = dates .Select(d => new DateOnly(d.Year, d.Month, d.Day)) - .Distinct(); + .Distinct() + .OrderBy(d => d); return datesOnly; } @@ -214,7 +215,11 @@ public abstract class ChangeLogRepositoryAbstract : ICh query = createdQuery.Union(editedQuery); } - var entities = await query.ToListAsync(token); + var entities = await query + .OrderBy(e => e.Creation) + .ThenBy(e => e.Obsolete) + .ThenBy(e => e.Id) + .ToListAsync(token); var dtos = entities.Select(e => Convert(e, offset)); return dtos; @@ -223,7 +228,11 @@ public abstract class ChangeLogRepositoryAbstract : ICh public async Task> Get(TRequest request, CancellationToken token) { var query = BuildQuery(request); - var entities = await query.ToArrayAsync(token); + var entities = await query + .OrderBy(e => e.Creation) + .ThenBy(e => e.Obsolete) + .ThenBy(e => e.Id) + .ToArrayAsync(token); TimeSpan offset = GetTimezoneOffset(request); var dtos = entities.Select(e => Convert(e, offset)); diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 208e94ac..ea9a6975 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -383,12 +383,12 @@ public class WellOperationRepository : IWellOperationRepository new[] { nameof(wellOperationDtos) }); } - if (previousDateEnd > currentDateStart) - { - yield return new ValidationResult( - "Предыдущая операция не завершена", - new[] { nameof(wellOperationDtos) }); - } + //if (previousDateEnd > currentDateStart) + //{ + // yield return new ValidationResult( + // "Предыдущая операция не завершена", + // new[] { nameof(wellOperationDtos) }); + //} previous = current; } diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs index 99983dd5..7a94d595 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataCache.cs @@ -299,7 +299,7 @@ namespace AsbCloudInfrastructure.Services.SAUB if (request.LeDate.HasValue) { var leDate = request.LeDate.Value.ToRemoteDateTime(cacheItem.TimezoneHours); - data = data.Where(d => d.DateTime >= request.LeDate); + data = data.Where(d => d.DateTime <= request.LeDate); } if (request.Divider > 1) diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/SlipsStatControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/SlipsStatControllerTest.cs index a31c5f19..908d5b95 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/SlipsStatControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/SlipsStatControllerTest.cs @@ -2,6 +2,7 @@ using AsbCloudApp.Data; using AsbCloudApp.Requests; using AsbCloudDb.Model; using AsbCloudWebApi.IntegrationTests.Clients; +using Microsoft.EntityFrameworkCore; using Xunit; namespace AsbCloudWebApi.IntegrationTests.Controllers; @@ -10,7 +11,7 @@ public class SlipsStatControllerTest : BaseIntegrationTest { private static readonly Schedule schedule = new() { - Id = 1, + Id = 0, IdDriller = Data.Defaults.Drillers[0].Id, IdWell = Data.Defaults.Wells[0].Id, ShiftStart = new TimeOnly(8, 0, 0), @@ -21,7 +22,7 @@ public class SlipsStatControllerTest : BaseIntegrationTest private static readonly DetectedOperation detectedOperation = new() { - Id = 1, + Id = 0, IdTelemetry = Data.Defaults.Telemetries[0].Id, IdCategory = WellOperationCategory.IdSlipsTime, DateStart = new DateTimeOffset(new DateTime(2024, 1, 23, 15, 0, 0, 0, DateTimeKind.Utc)), @@ -34,7 +35,7 @@ public class SlipsStatControllerTest : BaseIntegrationTest private static readonly WellOperation factWellOperation = new() { - Id = 1, + Id = 0, IdWell = Data.Defaults.Wells[0].Id, IdWellSectionType = 1, IdCategory = WellOperationCategory.IdRotor, @@ -51,9 +52,18 @@ public class SlipsStatControllerTest : BaseIntegrationTest public SlipsStatControllerTest(WebAppFactoryFixture factory) : base(factory) { - dbContext.Schedule.Add(schedule); - dbContext.DetectedOperations.Add(detectedOperation); - dbContext.WellOperations.Add(factWellOperation); + var schedules = dbContext.Set(); + var detectedOperations = dbContext.Set(); + var wellOperations = dbContext.Set(); + + schedules.RemoveRange(schedules); + detectedOperations.RemoveRange(detectedOperations); + wellOperations.RemoveRange(wellOperations); + dbContext.SaveChanges(); + + schedules.Add(schedule); + detectedOperations.Add(detectedOperation); + wellOperations.Add(factWellOperation); dbContext.SaveChanges(); client = factory.GetAuthorizedHttpClient(); diff --git a/AsbCloudWebApi/Extentions.cs b/AsbCloudWebApi/Extentions.cs index d6ce96a4..5e46eef6 100644 --- a/AsbCloudWebApi/Extentions.cs +++ b/AsbCloudWebApi/Extentions.cs @@ -76,8 +76,10 @@ namespace Microsoft.AspNetCore.Mvc public static BadRequestObjectResult ValidationBadRequest(this ControllerBase controller, IEnumerable validationResults) { var errors = validationResults - .SelectMany(e => e.MemberNames.Select(name=> new { name, e.ErrorMessage })) - .ToDictionary(e => e.name, e => new[] { e.ErrorMessage ?? string.Empty }); + .SelectMany(e => e.MemberNames.Select(name => new { name, e.ErrorMessage })) + .GroupBy(e => e.name) + .ToDictionary(e => e.Key, e => e.Select(el => el.ErrorMessage ?? string.Empty).ToArray()); + var problem = new ValidationProblemDetails(errors); return controller.BadRequest(problem); }