From e2cd8cbfd23d006a1d7b94a697f314f638f01606 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Tue, 26 Mar 2024 10:16:18 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=88=D0=BD=D0=B8=D0=B9=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20Get?= =?UTF-8?q?DatesRangeAsync=20=D0=B2=20IDailyReportService=20+=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DailyReport/IDailyReportService.cs | 8 ---- .../DailyReport/DailyReportService.cs | 41 ++++--------------- .../Services/DailyReportServiceTest.cs | 7 ++-- .../Controllers/DailyReportController.cs | 3 +- 4 files changed, 13 insertions(+), 46 deletions(-) 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/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs index da55b708..488d573f 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs @@ -153,7 +153,7 @@ 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; @@ -177,9 +177,8 @@ public class DailyReportService : IDailyReportService datesRange.To = finishDate; } - if (datesRange.From.AddDays(result.Skip) <= datesRange.To) - result.Count = (int)(Math.Ceiling((datesRange.To - DateTimeOffset.UnixEpoch).TotalDays) - - Math.Floor((datesRange.From - DateTimeOffset.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); @@ -240,32 +239,6 @@ public class DailyReportService : IDailyReportService } } - public async Task GetDatesRangeAsync(int idWell, CancellationToken cancellationToken) - { - var timezone = wellService.GetTimezone(idWell); - var currentDate = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(timezone.Hours)); - - var factOperationDatesRange = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact, - cancellationToken); - - if (factOperationDatesRange is null) - return null; - - var from = (factOperationDatesRange.From.AddDays(1) <= DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(timezone.Hours)) ? - factOperationDatesRange.From : - currentDate.AddDays(-1)); - - var to = (factOperationDatesRange.To.AddDays(1) <= DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(timezone.Hours)) ? - factOperationDatesRange.To : - currentDate.AddDays(-1)); - - return new DatesRangeDto - { - From = from, - To = to - }; - } - private async Task UpdateTimeBalanceBlockAsync(DailyReportDto dailyReport, IEnumerable factWellOperations, DateTimeOffset geDateStart, DateTimeOffset leDateEnd, CancellationToken cancellationToken) { @@ -400,13 +373,13 @@ 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.ToUniversalTime().DateTime); - var to = DateOnly.FromDateTime(datesRange.To.ToUniversalTime().DateTime); + var from = DateOnly.FromDateTime(datesRange.From.DateTime); + var to = DateOnly.FromDateTime(datesRange.To.DateTime); - return dateDailyReport >= from && dateDailyReport <= to; + return dateDailyReport >= from && dateDailyReport <= to; } } \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs b/AsbCloudWebApi.Tests/Services/DailyReportServiceTest.cs index ac109d7f..b8e61aa0 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; @@ -282,7 +283,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()) @@ -523,12 +524,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/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); }