forked from ddrilling/AsbCloudServer
Исправления получения диапазона дат для суточных отчётов.
This commit is contained in:
parent
2b064fe463
commit
19820b79ec
@ -31,6 +31,14 @@ public interface IAutoGeneratedDailyReportService
|
|||||||
/// <param name="reportDate"></param>
|
/// <param name="reportDate"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<(string fileName, Stream stream)> GenerateReportAsync(int idWell, DateOnly reportDate,
|
Task<(string fileName, Stream stream)> GenerateAsync(int idWell, DateOnly reportDate,
|
||||||
CancellationToken cancellationToken);
|
CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение диапазона дат
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, CancellationToken cancellationToken);
|
||||||
}
|
}
|
@ -6,7 +6,6 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.AutogeneratedDailyReport;
|
using AsbCloudApp.Data.AutogeneratedDailyReport;
|
||||||
using AsbCloudApp.Data.SAUB;
|
|
||||||
using AsbCloudApp.Data.Subsystems;
|
using AsbCloudApp.Data.Subsystems;
|
||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
@ -15,7 +14,6 @@ using AsbCloudApp.Services;
|
|||||||
using AsbCloudApp.Services.AutoGeneratedDailyReports;
|
using AsbCloudApp.Services.AutoGeneratedDailyReports;
|
||||||
using AsbCloudApp.Services.Subsystems;
|
using AsbCloudApp.Services.Subsystems;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.Services.SAUB;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
|
namespace AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
|
||||||
|
|
||||||
@ -25,7 +23,6 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
|||||||
|
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
private readonly IWellOperationRepository wellOperationRepository;
|
private readonly IWellOperationRepository wellOperationRepository;
|
||||||
private readonly TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
|
|
||||||
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
||||||
private readonly ICrudRepository<SubsystemDto> subsystemRepository;
|
private readonly ICrudRepository<SubsystemDto> subsystemRepository;
|
||||||
private readonly ILimitingParameterService limitingParameterService;
|
private readonly ILimitingParameterService limitingParameterService;
|
||||||
@ -33,7 +30,6 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
|||||||
|
|
||||||
public AutoGeneratedDailyReportService(IWellService wellService,
|
public AutoGeneratedDailyReportService(IWellService wellService,
|
||||||
IWellOperationRepository wellOperationRepository,
|
IWellOperationRepository wellOperationRepository,
|
||||||
TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache,
|
|
||||||
ISubsystemOperationTimeService subsystemOperationTimeService,
|
ISubsystemOperationTimeService subsystemOperationTimeService,
|
||||||
ICrudRepository<SubsystemDto> subsystemRepository,
|
ICrudRepository<SubsystemDto> subsystemRepository,
|
||||||
ILimitingParameterService limitingParameterService,
|
ILimitingParameterService limitingParameterService,
|
||||||
@ -41,7 +37,6 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
|||||||
{
|
{
|
||||||
this.wellOperationRepository = wellOperationRepository;
|
this.wellOperationRepository = wellOperationRepository;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
this.telemetryDataCache = telemetryDataCache;
|
|
||||||
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||||
this.subsystemRepository = subsystemRepository;
|
this.subsystemRepository = subsystemRepository;
|
||||||
this.limitingParameterService = limitingParameterService;
|
this.limitingParameterService = limitingParameterService;
|
||||||
@ -67,9 +62,9 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
|||||||
if (!well.IdTelemetry.HasValue)
|
if (!well.IdTelemetry.HasValue)
|
||||||
throw new ArgumentInvalidException("Телеметрия для скважины отсутствует", nameof(idWell));
|
throw new ArgumentInvalidException("Телеметрия для скважины отсутствует", nameof(idWell));
|
||||||
|
|
||||||
var datesRange = telemetryDataCache.GetOrDefaultDataDateRange(well.IdTelemetry.Value);
|
var datesRange = await GetDatesRangeAsync(idWell, cancellationToken);
|
||||||
|
|
||||||
if (datesRange is null)
|
if (datesRange is null)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
result.Count = (int)(Math.Ceiling((datesRange.To - DateTime.UnixEpoch).TotalDays) - Math.Floor((datesRange.From - DateTime.UnixEpoch).TotalDays));
|
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;
|
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)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var startDate = new DateTime(reportDate.Year, reportDate.Month, reportDate.Day);
|
var startDate = new DateTime(reportDate.Year, reportDate.Month, reportDate.Day);
|
||||||
@ -144,6 +139,21 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
|||||||
return (report.FileName, stream);
|
return (report.FileName, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<DatesRangeDto?> 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<WellOperationDto> factOperations)
|
private HeadBlockDto CreateHeadBlock(WellDto well, IEnumerable<WellOperationDto> factOperations)
|
||||||
{
|
{
|
||||||
var customer = well.Companies.FirstOrDefault(company => company.IdCompanyType == 1);
|
var customer = well.Companies.FirstOrDefault(company => company.IdCompanyType == 1);
|
||||||
@ -199,8 +209,8 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<IEnumerable<WellOperationDto>> GetFactOperationsAsync(int idWell, DateTime startDate,
|
private Task<IEnumerable<WellOperationDto>> GetFactOperationsAsync(int idWell, DateTime? startDate,
|
||||||
DateTime finishDate, CancellationToken cancellationToken)
|
DateTime? finishDate, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var request = new WellOperationRequest
|
var request = new WellOperationRequest
|
||||||
{
|
{
|
||||||
|
@ -49,7 +49,7 @@ public class AutoGeneratedDailyReportController : ControllerBase
|
|||||||
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var reportFile = await autoGeneratedDailyReportService.GenerateReportAsync(idWell,
|
var reportFile = await autoGeneratedDailyReportService.GenerateAsync(idWell,
|
||||||
reportDate,
|
reportDate,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
|
|
||||||
@ -78,7 +78,23 @@ public class AutoGeneratedDailyReportController : ControllerBase
|
|||||||
|
|
||||||
return Ok(reports);
|
return Ok(reports);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Диапазон дат для формирования суточных отчётов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("datesRange")]
|
||||||
|
[ProducesResponseType(typeof(DatesRangeDto), (int)HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetDatesRangeAsync(int idWell, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
return Ok(await autoGeneratedDailyReportService.GetDatesRangeAsync(idWell, cancellationToken));
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken cancellationToken)
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
Loading…
Reference in New Issue
Block a user