Merge pull request 'Рефакторинг суточного рапорта' (#178) from feature/daily_report into dev

Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/178
This commit is contained in:
Никита Фролов 2023-12-21 10:04:31 +05:00
commit 576d4d0e57
16 changed files with 9296 additions and 91 deletions

View File

@ -64,7 +64,7 @@ public class DailyReportDto : IId,
/// <summary>
/// Дата формирования отчёта
/// </summary>
public DateTime Date { get; set; }
public DateOnly Date { get; set; }
/// <summary>
/// Дата последнего обновления

View File

@ -29,5 +29,5 @@ public interface IDailyReportRepository : ICrudRepository<DailyReportDto>
/// <param name="date"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<DailyReportDto?> GetOrDefaultAsync(int idWell, DateTime date, CancellationToken cancellationToken);
Task<DailyReportDto?> GetOrDefaultAsync(int idWell, DateOnly date, CancellationToken cancellationToken);
}

View File

@ -14,8 +14,8 @@ public interface IDailyReportExportService
/// Экспортировать
/// </summary>
/// <param name="idWell"></param>
/// <param name="dailyReportDateStart"></param>
/// <param name="dailyReportDate"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<(string FileName, Stream File)> ExportAsync(int idWell, DateTime dailyReportDateStart, CancellationToken cancellationToken);
Task<(string FileName, Stream File)> ExportAsync(int idWell, DateOnly dailyReportDate, CancellationToken cancellationToken);
}

View File

@ -21,7 +21,7 @@ public interface IDailyReportService
/// <param name="cancellationToken"></param>
/// <param name="idWell"></param>
/// <returns></returns>
Task<int> UpdateOrInsertAsync<TBlock>(int idWell, DateTime dateDailyReport, int idUser, TBlock editableBlock,
Task<int> UpdateOrInsertAsync<TBlock>(int idWell, DateOnly dateDailyReport, int idUser, TBlock editableBlock,
CancellationToken cancellationToken)
where TBlock : ItemInfoDto;
@ -32,7 +32,7 @@ public interface IDailyReportService
/// <param name="dateDailyReport"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<DailyReportDto> GetAsync(int idWell, DateTime dateDailyReport, CancellationToken cancellationToken);
Task<DailyReportDto> GetAsync(int idWell, DateOnly dateDailyReport, CancellationToken cancellationToken);
/// <summary>
/// Получить список суточных отчётов по скважине

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class UpdateDateFormat_DailyReport : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateOnly>(
name: "date",
table: "t_daily_report",
type: "date",
nullable: false,
comment: "Дата формирования отчёта",
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldComment: "Дата формирования отчёта");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "date",
table: "t_daily_report",
type: "timestamp with time zone",
nullable: false,
comment: "Дата формирования отчёта",
oldClrType: typeof(DateOnly),
oldType: "date",
oldComment: "Дата формирования отчёта");
}
}
}

View File

@ -278,8 +278,8 @@ namespace AsbCloudDb.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone")
b.Property<DateOnly>("Date")
.HasColumnType("date")
.HasColumnName("date")
.HasComment("Дата формирования отчёта");

View File

@ -20,8 +20,8 @@ public class DailyReport : IId
[Column("date_last_update", TypeName = "timestamp with time zone"), Comment("Дата последнего обновления")]
public DateTime? DateLastUpdate { get; set; }
[Column("date", TypeName = "timestamp with time zone"), Comment("Дата формирования отчёта")]
public DateTime Date { get; set; }
[Column("date", TypeName = "date"), Comment("Дата формирования отчёта")]
public DateOnly Date { get; set; }
[Column("sign_block", TypeName = "jsonb"), Comment("Подпись")]
public SignBlock? SignBlock { get; set; }

View File

@ -33,25 +33,14 @@ public class DailyReportRepository : CrudRepositoryBase<DailyReportDto, DailyRep
var query = GetQuery().Where(d => d.IdWell == idWell);
if (request.GeDate.HasValue)
{
var geDate = request.GeDate.Value.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
query = query.Where(d => d.Date >= geDate);
}
query = query.Where(d => d.Date >= request.GeDate.Value);
if (request.LeDate.HasValue)
{
var leDate = request.LeDate.Value.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
query = query.Where(d => d.Date <= leDate);
}
query = query.Where(d => d.Date <= request.LeDate.Value);
if (request.SortFields?.Any() == true)
{
query = query.SortBy(request.SortFields);
}
else
{
query = query.OrderBy(d => d.Date);
}
query = request.SortFields?.Any() == true ?
query.SortBy(request.SortFields) :
query.OrderBy(d => d.Date);
var entities = await query
.Skip(skip)
@ -64,7 +53,7 @@ public class DailyReportRepository : CrudRepositoryBase<DailyReportDto, DailyRep
return dtos;
}
public async Task<DailyReportDto?> GetOrDefaultAsync(int idWell, DateTime date, CancellationToken cancellationToken)
public async Task<DailyReportDto?> GetOrDefaultAsync(int idWell, DateOnly date, CancellationToken cancellationToken)
{
var entity = await GetQuery()
.AsNoTracking()

View File

@ -9,20 +9,26 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Services;
namespace AsbCloudInfrastructure.Repository
{
public class TrajectoryNnbRepository : ITrajectoryNnbRepository
{
private readonly IAsbCloudDbContext db;
public TrajectoryNnbRepository(IAsbCloudDbContext db)
private readonly IWellService wellService;
public TrajectoryNnbRepository(IAsbCloudDbContext db,
IWellService wellService)
{
this.db = db;
this.wellService = wellService;
}
private IQueryable<Record7> BuildQuery(TrajectoryRequest request)
{
var well = db.Wells.SingleOrDefault(w => w.Id == request.IdWell);
var timezone = wellService.GetTimezone(request.IdWell);
if (well is null)
throw new ArgumentInvalidException($"Скважина с Id: {request.IdWell} не найдена", nameof(request.IdWell));
@ -31,10 +37,16 @@ namespace AsbCloudInfrastructure.Repository
.Where(x => x.IdTelemetry == well.IdTelemetry);
if (request.GeDate.HasValue)
query = query.Where(r => r.DateTime >= request.GeDate.Value);
{
var geDate = request.GeDate.Value.ToUtcDateTimeOffset(timezone.Hours);
query = query.Where(r => r.DateTime >= geDate);
}
if (request.LeDate.HasValue)
query = query.Where(r => r.DateTime <= request.LeDate.Value);
{
var leDate = request.LeDate.Value.ToUtcDateTimeOffset(timezone.Hours);
query = query.Where(r => r.DateTime <= leDate);
}
return query.OrderBy(e => e.Deptsvym);
}

View File

@ -186,15 +186,20 @@ public class WellOperationRepository : IWellOperationRepository
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken)
{
var timezone = wellService.GetTimezone(idWell);
var query = db.WellOperations.Where(o => o.IdWell == idWell && o.IdType == idType);
if (!await query.AnyAsync(cancellationToken))
return null;
var minDate = await query.MinAsync(o => o.DateStart, cancellationToken);
var maxDate = await query.MaxAsync(o => o.DateStart, cancellationToken);
return new DatesRangeDto
{
From = (await query.MinAsync(o => o.DateStart, cancellationToken)).Date,
To = (await query.MaxAsync(o => o.DateStart, cancellationToken)).Date
From = minDate.ToRemoteDateTime(timezone.Hours),
To = maxDate.ToRemoteDateTime(timezone.Hours)
};
}

View File

@ -89,9 +89,9 @@ public class DailyReportExportService : IDailyReportExportService
this.dailyReportService = dailyReportService;
}
public async Task<(string FileName, Stream File)> ExportAsync(int idWell, DateTime dailyReportDateStart, CancellationToken cancellationToken)
public async Task<(string FileName, Stream File)> ExportAsync(int idWell, DateOnly dailyReportDate, CancellationToken cancellationToken)
{
var dailyReport = await dailyReportService.GetAsync(idWell, dailyReportDateStart, cancellationToken);
var dailyReport = await dailyReportService.GetAsync(idWell, dailyReportDate, cancellationToken);
var stream = await GenerateFileAsync(dailyReport, cancellationToken);
@ -236,12 +236,16 @@ public class DailyReportExportService : IDailyReportExportService
private static void AddFactWellOperationBlockToSheet(IXLWorksheet sheet, WellOperationBlockDto factWellOperationBlock)
{
var rowCurrent = rowStartFactWellOperationBlock;
sheet.Cell(cellSectionDrillingHours).Value = factWellOperationBlock.SectionDrillingHours;
foreach (var factOperation in factWellOperationBlock.WellOperations.OrderBy(w => w.CategoryName))
{
sheet.Cell(rowStartFactWellOperationBlock, columnWellOperationCategory).Value = factOperation.CategoryName;
sheet.Cell(rowStartFactWellOperationBlock, columnWellOperationDurationHours).Value = factOperation.DurationHours;
sheet.Cell(rowCurrent, columnWellOperationCategory).Value = factOperation.CategoryName;
sheet.Cell(rowCurrent, columnWellOperationDurationHours).Value = factOperation.DurationHours;
rowCurrent++;
}
}

View File

@ -51,7 +51,7 @@ public class DailyReportService : IDailyReportService
this.detectedOperationService = detectedOperationService;
}
public async Task<int> UpdateOrInsertAsync<TBlock>(int idWell, DateTime dateDailyReport, int idUser, TBlock editableBlock,
public async Task<int> UpdateOrInsertAsync<TBlock>(int idWell, DateOnly dateDailyReport, int idUser, TBlock editableBlock,
CancellationToken cancellationToken)
where TBlock : ItemInfoDto
{
@ -91,7 +91,7 @@ public class DailyReportService : IDailyReportService
return await dailyReportRepository.UpdateAsync(dailyReport, cancellationToken);
}
public async Task<DailyReportDto> GetAsync(int idWell, DateTime dateDailyReport, CancellationToken cancellationToken)
public async Task<DailyReportDto> GetAsync(int idWell, DateOnly dateDailyReport, CancellationToken cancellationToken)
{
var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken)
?? throw new ArgumentNullException(nameof(idWell), $"Скважина с Id: {idWell} не найдена");
@ -102,16 +102,19 @@ public class DailyReportService : IDailyReportService
var dailyReport = await dailyReportRepository.GetOrDefaultAsync(idWell, dateDailyReport, cancellationToken) ?? new DailyReportDto
{
Date = dateDailyReport.Date,
Date = dateDailyReport,
IdWell = well.Id
};
var geDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var ltDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var factOperationRequest = new WellOperationRequest
{
IdWell = idWell,
OperationType = WellOperation.IdOperationTypeFact,
GeDate = dateDailyReport,
LtDate = dateDailyReport.AddHours(24)
GeDate = geDate,
LtDate = ltDate
};
var factWellOperations = (await wellOperationRepository.GetAsync(factOperationRequest, cancellationToken))
@ -197,7 +200,7 @@ public class DailyReportService : IDailyReportService
{
for (var day = result.Skip; day - result.Skip < result.Take && datesRange.To.AddDays(-day) >= datesRange.From; day++)
{
var dateDailyReport = datesRange.To.AddDays(-day).Date;
var dateDailyReport = DateOnly.FromDateTime(datesRange.To.AddDays(-day));
AddDailyReport(dateDailyReport);
}
@ -206,7 +209,7 @@ public class DailyReportService : IDailyReportService
{
for (var day = result.Skip; day - result.Skip < result.Take && datesRange.From.AddDays(day) <= datesRange.To; day++)
{
var dateDailyReport = datesRange.From.AddDays(day).Date;
var dateDailyReport = DateOnly.FromDateTime(datesRange.From.AddDays(day));
AddDailyReport(dateDailyReport);
}
@ -216,7 +219,7 @@ public class DailyReportService : IDailyReportService
return result;
void AddDailyReport(DateTime date)
void AddDailyReport(DateOnly date)
{
var dailyReport = existingDailyReports.FirstOrDefault(d => d.IdWell == idWell && d.Date == date)
?? new DailyReportDto
@ -225,7 +228,11 @@ public class DailyReportService : IDailyReportService
IdWell = idWell
};
var factWellOperationPerDay = factWellOperations.Where(o => o.DateStart.Date >= date && o.DateStart.Date <= date.AddDays(1));
var geDate = date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var leDate = date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var factWellOperationPerDay = factWellOperations.Where(o => o.DateStart.Date >= geDate &&
o.DateStart.Date <= leDate);
AddFactWellOperationBlock(dailyReport, factWellOperationPerDay);
@ -235,16 +242,29 @@ public class DailyReportService : IDailyReportService
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, CancellationToken cancellationToken)
{
var timezone = wellService.GetTimezone(idWell);
var currentDate = DateTimeOffset.UtcNow.ToRemoteDateTime(timezone.Hours);
var factOperationDatesRange = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact,
cancellationToken);
if (factOperationDatesRange is null)
return null;
var from = (factOperationDatesRange.From.AddDays(1) <= DateTime.UtcNow ?
factOperationDatesRange.From :
currentDate.AddDays(-1))
.Date;
var to = (factOperationDatesRange.To.AddDays(1) <= DateTime.UtcNow ?
factOperationDatesRange.To :
currentDate.AddDays(-1))
.Date;
return new DatesRangeDto
{
From = factOperationDatesRange.From.AddDays(1) <= DateTime.UtcNow ? factOperationDatesRange.From : DateTime.UtcNow.Date.AddDays(-1),
To = factOperationDatesRange.To.AddDays(1) <= DateTime.UtcNow ? factOperationDatesRange.To : DateTime.UtcNow.Date.AddDays(-1)
From = from,
To = to
};
}
@ -258,13 +278,16 @@ public class DailyReportService : IDailyReportService
dailyReport.TimeBalanceBlock.SectionName = wellOperationRepository.GetSectionTypes()
.FirstOrDefault(s => s.Id == dailyReport.TimeBalanceBlock.IdSection)?.Caption;
var geDateStart = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var leDateEnd = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
dailyReport.TimeBalanceBlock.WellOperationSlipsTimeCount = (await detectedOperationService.GetAsync(
new DetectedOperationRequest
{
IdsCategories = new[] { idWellOperationSlipsTime },
IdWell = dailyReport.IdWell,
GeDateStart = dailyReport.Date,
LeDateEnd = dailyReport.Date.AddHours(24)
GeDateStart = geDateStart,
LeDateEnd = leDateEnd
}, cancellationToken))?.Stats.Sum(s => s.Count);
dailyReport.TimeBalanceBlock.WellDepth.Fact = factWellOperations
@ -275,11 +298,14 @@ public class DailyReportService : IDailyReportService
private async Task AddTrajectoryBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
{
var geDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
var leDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
var trajectory = (await trajectoryFactNnbRepository.GetByRequestAsync(new TrajectoryRequest
{
IdWell = dailyReport.IdWell,
GeDate = dailyReport.Date,
LeDate = dailyReport.Date.AddHours(24)
GeDate = geDate,
LeDate = leDate
}, cancellationToken)).MaxBy(t => t.WellboreDepth);
dailyReport.TrajectoryBlock = new TrajectoryBlockDto
@ -291,8 +317,11 @@ public class DailyReportService : IDailyReportService
};
}
private async Task AddScheduleBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken) =>
dailyReport.ScheduleBlock = (await scheduleRepository.GetAsync(dailyReport.IdWell, dailyReport.Date, cancellationToken))
private async Task AddScheduleBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
{
var workDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
dailyReport.ScheduleBlock = (await scheduleRepository.GetAsync(dailyReport.IdWell, workDate, cancellationToken))
.Select(s => new ScheduleRecordDto
{
ShiftStart = s.ShiftStart,
@ -301,6 +330,7 @@ public class DailyReportService : IDailyReportService
Surname = s.Driller?.Surname,
Patronymic = s.Driller?.Patronymic
});
}
private async Task UpdateSubsystemBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
{
@ -315,11 +345,14 @@ public class DailyReportService : IDailyReportService
IdWell = dailyReport.IdWell
}, cancellationToken);
var geDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var leDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var subsystemsStatPerDay = await subsystemService.GetStatAsync(new SubsystemRequest
{
IdWell = dailyReport.IdWell,
GeDate = dailyReport.Date,
LeDate = dailyReport.Date.AddHours(24)
GeDate = geDate,
LeDate = leDate
}, cancellationToken);
var subsystems = subsystemsStatPerWell
@ -339,9 +372,11 @@ public class DailyReportService : IDailyReportService
private async Task AddProcessMapWellDrillingBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
{
var geDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var leDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
dailyReport.ProcessMapWellDrillingBlock = (await processMapReportWellDrillingService.GetAsync(dailyReport.IdWell,
cancellationToken)).Where(p => p.DateStart >= dailyReport.Date &&
p.DateStart <= dailyReport.Date.AddHours(24))
cancellationToken)).Where(p => p.DateStart >= geDate && p.DateStart <= leDate)
.GroupBy(p => p.DrillingMode)
.Select(g => new ProcessMapWellDrillingRecordDto
{
@ -362,7 +397,7 @@ public class DailyReportService : IDailyReportService
dailyReport.FactWellOperationBlock = new WellOperationBlockDto
{
WellOperations = factWellOperations.GroupBy(o => o.IdParentCategory)
WellOperations = factWellOperations.GroupBy(o => o.IdCategory)
.Select(g => new WellOperationRecordDto
{
CategoryName = g.First().CategoryName,
@ -375,10 +410,16 @@ public class DailyReportService : IDailyReportService
};
}
private async Task<bool> IsDateDailyReportInRangeAsync(int idWell, DateTime dateDailyReport, CancellationToken cancellationToken)
private async Task<bool> IsDateDailyReportInRangeAsync(int idWell, DateOnly dateDailyReport, CancellationToken cancellationToken)
{
var datesRange = await GetDatesRangeAsync(idWell, cancellationToken);
return dateDailyReport >= datesRange?.From && dateDailyReport <= datesRange.To;
if (datesRange is null)
return false;
var from = DateOnly.FromDateTime(datesRange.From);
var to = DateOnly.FromDateTime(datesRange.To);
return from >= dateDailyReport && dateDailyReport <= to;
}
}

View File

@ -28,9 +28,7 @@ public class DailyReportServiceTest
private const int idDailyReport = 1;
private const int idUser = 3;
private const int idWell = 2;
private readonly DateTime dateDailyReport = new DateOnly(2023, 10, 26).ToDateTime(TimeOnly.MinValue);
private readonly SubsystemBlockDto fakeSubsystemBlock = new()
{
IdUser = idUser,
@ -219,7 +217,7 @@ public class DailyReportServiceTest
{
Id = idDailyReport,
IdWell = idWell,
Date = dateDailyReport,
Date = new(2023, 10, 26),
DateLastUpdate = null
};
@ -251,7 +249,7 @@ public class DailyReportServiceTest
dailyReportRepositoryMock.InsertAsync(Arg.Any<DailyReportDto>(), Arg.Any<CancellationToken>())
.ReturnsForAnyArgs(idDailyReport);
dailyReportRepositoryMock.GetOrDefaultAsync(Arg.Any<int>(), Arg.Any<DateTime>(), Arg.Any<CancellationToken>())
dailyReportRepositoryMock.GetOrDefaultAsync(Arg.Any<int>(), Arg.Any<DateOnly>(), Arg.Any<CancellationToken>())
.ReturnsForAnyArgs(fakeDailyReport);
dailyReportRepositoryMock.UpdateAsync(Arg.Any<DailyReportDto>(), Arg.Any<CancellationToken>())
@ -278,10 +276,10 @@ public class DailyReportServiceTest
subsystemServiceMock.GetStatAsync(Arg.Any<SubsystemRequest>(), Arg.Any<CancellationToken>())
.ReturnsForAnyArgs(new[] { fakeSubsystemsStat });
scheduleRepositoryMock.GetAsync(idWell, dateDailyReport, Arg.Any<CancellationToken>())
scheduleRepositoryMock.GetAsync(Arg.Any<int>(), Arg.Any<DateTime>(), Arg.Any<CancellationToken>())
.ReturnsForAnyArgs(new[] { fakeShedule });
processMapReportWellDrillingServiceMock.GetAsync(idWell, Arg.Any<CancellationToken>())
processMapReportWellDrillingServiceMock.GetAsync(Arg.Any<int>(), Arg.Any<CancellationToken>())
.ReturnsForAnyArgs(new[] { fakeProcessMapReportWellDrilling });
}
@ -289,7 +287,7 @@ public class DailyReportServiceTest
public async Task UpdateOrInsertAsync_ShouldReturn_UpdatedSubsystemBlock()
{
//act
var result = await dailyReportService.UpdateOrInsertAsync(idWell, dateDailyReport, idUser, fakeSubsystemBlock, CancellationToken.None);
var result = await dailyReportService.UpdateOrInsertAsync(idWell, fakeDailyReport.Date, idUser, fakeSubsystemBlock, CancellationToken.None);
//assert
Assert.NotNull(fakeSubsystemBlock.LastUpdateDate);
@ -300,14 +298,13 @@ public class DailyReportServiceTest
}
[Theory]
[InlineData("2090.01.01")]
[InlineData("2000.01.01")]
public async Task UpdateOrInsertAsync_ShouldReturn_UnableToUpdateDailyReport(DateTime dateDaileReport)
[MemberData(nameof(DateDailyReport))]
public async Task UpdateOrInsertAsync_ShouldReturn_UnableToUpdateDailyReport(DateOnly dateDailyReport)
{
//act
var result = await Assert.ThrowsAsync<ArgumentInvalidException>(() => dailyReportService.UpdateOrInsertAsync(
idWell,
dateDaileReport,
dateDailyReport,
idUser,
fakeSignBlock,
CancellationToken.None));
@ -320,7 +317,7 @@ public class DailyReportServiceTest
public async Task UpdateOrInsertAsync_ShouldReturn_UpdatedSignBlock()
{
//act
var result = await dailyReportService.UpdateOrInsertAsync(idWell, dateDailyReport, idUser, fakeSignBlock, CancellationToken.None);
var result = await dailyReportService.UpdateOrInsertAsync(idWell, fakeDailyReport.Date, idUser, fakeSignBlock, CancellationToken.None);
//assert
Assert.NotNull(fakeSignBlock.LastUpdateDate);
@ -334,7 +331,7 @@ public class DailyReportServiceTest
public async Task UpdateOrInsertAsync_ShouldReturn_UpdatedTimeBalanceBlock()
{
//act
var result = await dailyReportService.UpdateOrInsertAsync(idWell, dateDailyReport, idUser, fakeTimeBalanceBlock,
var result = await dailyReportService.UpdateOrInsertAsync(idWell, fakeDailyReport.Date, idUser, fakeTimeBalanceBlock,
CancellationToken.None);
//assert
@ -346,13 +343,12 @@ public class DailyReportServiceTest
}
[Theory]
[InlineData("2090.01.01")]
[InlineData("2000.01.01")]
public async Task GetAsync_ShouldReturn_UnableToGetDailyReport(DateTime dateDaileReport)
[MemberData(nameof(DateDailyReport))]
public async Task GetAsync_ShouldReturn_UnableToGetDailyReport(DateOnly dateDailyReport)
{
//act
var result = await Assert.ThrowsAsync<ArgumentInvalidException>(() => dailyReportService.GetAsync(idWell,
dateDaileReport,
dateDailyReport,
CancellationToken.None));
//assert
@ -363,7 +359,7 @@ public class DailyReportServiceTest
public async Task GetAsync_ShouldReturn_AddedWellInfo()
{
//act
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
//assert
Assert.Equal(result.IdWell, fakeWell.Id);
@ -381,7 +377,7 @@ public class DailyReportServiceTest
public async Task GetAsync_ShouldReturn_AddedTrajectoryBlock()
{
//act
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
//assert
Assert.Equal(fakeLastFactTrajectory.WellboreDepth, result.TrajectoryBlock.WellboreDepth);
@ -394,7 +390,7 @@ public class DailyReportServiceTest
public async Task GetAsync_ShouldReturn_AddedFactWellOperationBlock()
{
//act
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
//assert
Assert.Equal(16, result.FactWellOperationBlock.SectionDrillingHours);
@ -410,7 +406,7 @@ public class DailyReportServiceTest
public async Task GetAsync_ShouldReturn_AddedScheduleBlock()
{
//act
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
//assert
Assert.Single(result.ScheduleBlock);
@ -431,7 +427,7 @@ public class DailyReportServiceTest
fakeDailyReport.TimeBalanceBlock = fakeTimeBalanceBlock;
//act
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
//assert
Assert.NotNull(result.TimeBalanceBlock);
@ -446,7 +442,7 @@ public class DailyReportServiceTest
public async Task GetAsync_ShouldReturn_AddedProcessMapWellDrillingBlock()
{
//act
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
//assert
Assert.Single(result.ProcessMapWellDrillingBlock);
@ -467,7 +463,7 @@ public class DailyReportServiceTest
fakeDailyReport.SubsystemBlock = fakeSubsystemBlock;
//act
var result = await dailyReportService.GetAsync(idDailyReport, dateDailyReport, CancellationToken.None);
var result = await dailyReportService.GetAsync(idDailyReport, fakeDailyReport.Date, CancellationToken.None);
//assert
Assert.NotNull(result.SubsystemBlock);
@ -526,6 +522,15 @@ public class DailyReportServiceTest
Assert.True(result.To < DateTime.UtcNow.Date);
}
public static IEnumerable<object[]> DateDailyReport()
{
yield return new object[]
{
new DateOnly(2090, 01, 01),
new DateOnly(2000, 01, 01)
};
}
public static IEnumerable<object[]> FactWellOperationDatesRange()
{
yield return new object[]

View File

@ -175,8 +175,7 @@ public class DailyReportController : ControllerBase
{
await AssertUserAccessToWell(idWell, cancellationToken);
var dailyReport = await dailyReportExportService.ExportAsync(idWell,
dateDailyReport.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc), cancellationToken);
var dailyReport = await dailyReportExportService.ExportAsync(idWell, dateDailyReport, cancellationToken);
return File(dailyReport.File, "application/octet-stream", dailyReport.FileName);
}
@ -187,8 +186,7 @@ public class DailyReportController : ControllerBase
{
await AssertUserAccessToWell(idWell, cancellationToken);
var id = await dailyReportService.UpdateOrInsertAsync(idWell, dateDailyReport.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc), IdUser,
block, cancellationToken);
var id = await dailyReportService.UpdateOrInsertAsync(idWell, dateDailyReport, IdUser, block, cancellationToken);
return Ok(id);
}