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..03a19c44 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.Min(o => o.DateStart),
+ To = factOperations.Max(o => o.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 async Task> GetFactOperationsAsync(int idWell, DateTime? startDate,
+ DateTime? finishDate, CancellationToken cancellationToken)
{
var request = new WellOperationRequest
{
@@ -211,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,
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();