forked from ddrilling/AsbCloudServer
Убран лишний метод GetDatesRangeAsync в IDailyReportService + поправлены тесты
This commit is contained in:
parent
d6aa6c8cf5
commit
e2cd8cbfd2
@ -42,12 +42,4 @@ public interface IDailyReportService
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<PaginationContainer<DailyReportDto>> GetAsync(int idWell, FileReportRequest request, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Получить диапазон дат по которым возможно сформировать суточный отчёты
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, CancellationToken cancellationToken);
|
||||
}
|
@ -153,7 +153,7 @@ public class DailyReportService : IDailyReportService
|
||||
Items = Enumerable.Empty<DailyReportDto>()
|
||||
};
|
||||
|
||||
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<DatesRangeDto?> 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<WellOperationDto> factWellOperations,
|
||||
DateTimeOffset geDateStart, DateTimeOffset leDateEnd, CancellationToken cancellationToken)
|
||||
{
|
||||
@ -400,13 +373,13 @@ public class DailyReportService : IDailyReportService
|
||||
|
||||
private async Task<bool> 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;
|
||||
}
|
||||
}
|
@ -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<SubsystemRequest>(), Arg.Any<CancellationToken>())
|
||||
.ReturnsForAnyArgs(new[] { fakeSubsystemsStat });
|
||||
|
||||
scheduleRepositoryMock.GetAsync(Arg.Any<int>(), Arg.Any<DateTime>(), Arg.Any<CancellationToken>())
|
||||
scheduleRepositoryMock.GetAsync(Arg.Any<int>(), Arg.Any<DateTimeOffset>(), Arg.Any<CancellationToken>())
|
||||
.ReturnsForAnyArgs(new[] { fakeShedule });
|
||||
|
||||
processMapReportWellDrillingServiceMock.GetAsync(Arg.Any<int>(), fakeRequest, Arg.Any<CancellationToken>())
|
||||
@ -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<object[]> DateDailyReport()
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user