From 19820b79ec8896b4ae5f6ddf0b7b7b06859b5d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Mon, 14 Aug 2023 11:54:30 +0500 Subject: [PATCH 1/2] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=B8=D0=B0=D0=BF=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B4=D0=B0=D1=82=20=D0=B4=D0=BB=D1=8F=20=D1=81?= =?UTF-8?q?=D1=83=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D1=85=20=D0=BE=D1=82=D1=87?= =?UTF-8?q?=D1=91=D1=82=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IAutoGeneratedDailyReportService.cs | 10 +++++- .../AutoGeneratedDailyReportService.cs | 32 ++++++++++++------- .../AutoGeneratedDailyReportController.cs | 20 ++++++++++-- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportService.cs b/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportService.cs index 16cdaed6..13bdb1ea 100644 --- a/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportService.cs +++ b/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportService.cs @@ -31,6 +31,14 @@ public interface IAutoGeneratedDailyReportService /// /// /// - Task<(string fileName, Stream stream)> GenerateReportAsync(int idWell, DateOnly reportDate, + Task<(string fileName, Stream stream)> GenerateAsync(int idWell, DateOnly reportDate, CancellationToken cancellationToken); + + /// + /// Получение диапазона дат + /// + /// + /// + /// + Task GetDatesRangeAsync(int idWell, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs index 514b0b66..edf3641b 100644 --- a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs +++ b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs @@ -6,7 +6,6 @@ using System.Threading; using System.Threading.Tasks; using AsbCloudApp.Data; using AsbCloudApp.Data.AutogeneratedDailyReport; -using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.Subsystems; using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; @@ -15,7 +14,6 @@ using AsbCloudApp.Services; using AsbCloudApp.Services.AutoGeneratedDailyReports; using AsbCloudApp.Services.Subsystems; using AsbCloudDb.Model; -using AsbCloudInfrastructure.Services.SAUB; namespace AsbCloudInfrastructure.Services.AutoGeneratedDailyReports; @@ -25,7 +23,6 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService private readonly IWellService wellService; private readonly IWellOperationRepository wellOperationRepository; - private readonly TelemetryDataCache telemetryDataCache; private readonly ISubsystemOperationTimeService subsystemOperationTimeService; private readonly ICrudRepository subsystemRepository; private readonly ILimitingParameterService limitingParameterService; @@ -33,7 +30,6 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService public AutoGeneratedDailyReportService(IWellService wellService, IWellOperationRepository wellOperationRepository, - TelemetryDataCache telemetryDataCache, ISubsystemOperationTimeService subsystemOperationTimeService, ICrudRepository subsystemRepository, ILimitingParameterService limitingParameterService, @@ -41,7 +37,6 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService { this.wellOperationRepository = wellOperationRepository; this.wellService = wellService; - this.telemetryDataCache = telemetryDataCache; this.subsystemOperationTimeService = subsystemOperationTimeService; this.subsystemRepository = subsystemRepository; this.limitingParameterService = limitingParameterService; @@ -67,9 +62,9 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService if (!well.IdTelemetry.HasValue) throw new ArgumentInvalidException("Телеметрия для скважины отсутствует", nameof(idWell)); - var datesRange = telemetryDataCache.GetOrDefaultDataDateRange(well.IdTelemetry.Value); - - if (datesRange is null) + var datesRange = await GetDatesRangeAsync(idWell, cancellationToken); + + if (datesRange is null) return result; result.Count = (int)(Math.Ceiling((datesRange.To - DateTime.UnixEpoch).TotalDays) - Math.Floor((datesRange.From - DateTime.UnixEpoch).TotalDays)); @@ -109,7 +104,7 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService return result; } - public async Task<(string fileName, Stream stream)> GenerateReportAsync(int idWell, DateOnly reportDate, + public async Task<(string fileName, Stream stream)> GenerateAsync(int idWell, DateOnly reportDate, CancellationToken cancellationToken) { var startDate = new DateTime(reportDate.Year, reportDate.Month, reportDate.Day); @@ -144,6 +139,21 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService return (report.FileName, stream); } + public async Task GetDatesRangeAsync(int idWell, CancellationToken cancellationToken) + { + var factOperations = await GetFactOperationsAsync(idWell, null, null, + cancellationToken); + + if (!factOperations.Any()) + return null; + + return new DatesRangeDto + { + From = factOperations.First().DateStart, + To = factOperations.Last().DateStart + }; + } + private HeadBlockDto CreateHeadBlock(WellDto well, IEnumerable factOperations) { var customer = well.Companies.FirstOrDefault(company => company.IdCompanyType == 1); @@ -199,8 +209,8 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService }); } - private Task> GetFactOperationsAsync(int idWell, DateTime startDate, - DateTime finishDate, CancellationToken cancellationToken) + private Task> GetFactOperationsAsync(int idWell, DateTime? startDate, + DateTime? finishDate, CancellationToken cancellationToken) { var request = new WellOperationRequest { diff --git a/AsbCloudWebApi/Controllers/AutoGeneratedDailyReportController.cs b/AsbCloudWebApi/Controllers/AutoGeneratedDailyReportController.cs index f38a3ea8..de26e843 100644 --- a/AsbCloudWebApi/Controllers/AutoGeneratedDailyReportController.cs +++ b/AsbCloudWebApi/Controllers/AutoGeneratedDailyReportController.cs @@ -49,7 +49,7 @@ public class AutoGeneratedDailyReportController : ControllerBase if (!await CanUserAccessToWellAsync(idWell, cancellationToken)) return Forbid(); - var reportFile = await autoGeneratedDailyReportService.GenerateReportAsync(idWell, + var reportFile = await autoGeneratedDailyReportService.GenerateAsync(idWell, reportDate, cancellationToken); @@ -78,7 +78,23 @@ public class AutoGeneratedDailyReportController : ControllerBase return Ok(reports); } - + + /// + /// Диапазон дат для формирования суточных отчётов + /// + /// + /// + /// + [HttpGet("datesRange")] + [ProducesResponseType(typeof(DatesRangeDto), (int)HttpStatusCode.OK)] + public async Task GetDatesRangeAsync(int idWell, CancellationToken cancellationToken) + { + if (!await CanUserAccessToWellAsync(idWell, cancellationToken)) + return Forbid(); + + return Ok(await autoGeneratedDailyReportService.GetDatesRangeAsync(idWell, cancellationToken)); + } + private async Task CanUserAccessToWellAsync(int idWell, CancellationToken cancellationToken) { int? idCompany = User.GetCompanyId(); From 36ec92f055ca5b1d286f58c225e9fe34db21fc03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Tue, 15 Aug 2023 13:39:04 +0500 Subject: [PATCH 2/2] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutoGeneratedDailyReportService.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs index edf3641b..03a19c44 100644 --- a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs +++ b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs @@ -149,8 +149,8 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService return new DatesRangeDto { - From = factOperations.First().DateStart, - To = factOperations.Last().DateStart + From = factOperations.Min(o => o.DateStart), + To = factOperations.Max(o => o.DateStart) }; } @@ -209,7 +209,7 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService }); } - private Task> GetFactOperationsAsync(int idWell, DateTime? startDate, + private async Task> GetFactOperationsAsync(int idWell, DateTime? startDate, DateTime? finishDate, CancellationToken cancellationToken) { var request = new WellOperationRequest @@ -221,7 +221,8 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService SortFields = new[] { "DateStart asc" }, }; - return wellOperationRepository.GetAsync(request, cancellationToken); + return (await wellOperationRepository.GetAsync(request, cancellationToken)) + .OrderBy(w => w.DateStart); } private Task?> GetSubsystemStatsAsync(int idWell, DateTime startDate,