forked from ddrilling/AsbCloudServer
Рефакторинг суточного рапорта
This commit is contained in:
parent
8bc7e8b9c5
commit
202665dce2
@ -64,7 +64,7 @@ public class DailyReportDto : IId,
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дата формирования отчёта
|
/// Дата формирования отчёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime Date { get; set; }
|
public DateOnly Date { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дата последнего обновления
|
/// Дата последнего обновления
|
||||||
|
@ -29,5 +29,5 @@ public interface IDailyReportRepository : ICrudRepository<DailyReportDto>
|
|||||||
/// <param name="date"></param>
|
/// <param name="date"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<DailyReportDto?> GetOrDefaultAsync(int idWell, DateTime date, CancellationToken cancellationToken);
|
Task<DailyReportDto?> GetOrDefaultAsync(int idWell, DateOnly date, CancellationToken cancellationToken);
|
||||||
}
|
}
|
@ -14,8 +14,8 @@ public interface IDailyReportExportService
|
|||||||
/// Экспортировать
|
/// Экспортировать
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="dailyReportDateStart"></param>
|
/// <param name="dailyReportDate"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <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);
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ public interface IDailyReportService
|
|||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <returns></returns>
|
/// <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)
|
CancellationToken cancellationToken)
|
||||||
where TBlock : ItemInfoDto;
|
where TBlock : ItemInfoDto;
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ public interface IDailyReportService
|
|||||||
/// <param name="dateDailyReport"></param>
|
/// <param name="dateDailyReport"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<DailyReportDto> GetAsync(int idWell, DateTime dateDailyReport, CancellationToken cancellationToken);
|
Task<DailyReportDto> GetAsync(int idWell, DateOnly dateDailyReport, CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить список суточных отчётов по скважине
|
/// Получить список суточных отчётов по скважине
|
||||||
|
@ -33,25 +33,14 @@ public class DailyReportRepository : CrudRepositoryBase<DailyReportDto, DailyRep
|
|||||||
var query = GetQuery().Where(d => d.IdWell == idWell);
|
var query = GetQuery().Where(d => d.IdWell == idWell);
|
||||||
|
|
||||||
if (request.GeDate.HasValue)
|
if (request.GeDate.HasValue)
|
||||||
{
|
query = query.Where(d => d.Date >= request.GeDate.Value);
|
||||||
var geDate = request.GeDate.Value.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
|
|
||||||
query = query.Where(d => d.Date >= geDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.LeDate.HasValue)
|
if (request.LeDate.HasValue)
|
||||||
{
|
query = query.Where(d => d.Date <= request.LeDate.Value);
|
||||||
var leDate = request.LeDate.Value.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
|
|
||||||
query = query.Where(d => d.Date <= leDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.SortFields?.Any() == true)
|
query = request.SortFields?.Any() == true ?
|
||||||
{
|
query.SortBy(request.SortFields) :
|
||||||
query = query.SortBy(request.SortFields);
|
query.OrderBy(d => d.Date);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
query = query.OrderBy(d => d.Date);
|
|
||||||
}
|
|
||||||
|
|
||||||
var entities = await query
|
var entities = await query
|
||||||
.Skip(skip)
|
.Skip(skip)
|
||||||
@ -64,7 +53,7 @@ public class DailyReportRepository : CrudRepositoryBase<DailyReportDto, DailyRep
|
|||||||
return dtos;
|
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()
|
var entity = await GetQuery()
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
|
@ -89,9 +89,9 @@ public class DailyReportExportService : IDailyReportExportService
|
|||||||
this.dailyReportService = dailyReportService;
|
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);
|
var stream = await GenerateFileAsync(dailyReport, cancellationToken);
|
||||||
|
|
||||||
@ -236,12 +236,16 @@ public class DailyReportExportService : IDailyReportExportService
|
|||||||
|
|
||||||
private static void AddFactWellOperationBlockToSheet(IXLWorksheet sheet, WellOperationBlockDto factWellOperationBlock)
|
private static void AddFactWellOperationBlockToSheet(IXLWorksheet sheet, WellOperationBlockDto factWellOperationBlock)
|
||||||
{
|
{
|
||||||
|
var rowCurrent = rowStartFactWellOperationBlock;
|
||||||
|
|
||||||
sheet.Cell(cellSectionDrillingHours).Value = factWellOperationBlock.SectionDrillingHours;
|
sheet.Cell(cellSectionDrillingHours).Value = factWellOperationBlock.SectionDrillingHours;
|
||||||
|
|
||||||
foreach (var factOperation in factWellOperationBlock.WellOperations.OrderBy(w => w.CategoryName))
|
foreach (var factOperation in factWellOperationBlock.WellOperations.OrderBy(w => w.CategoryName))
|
||||||
{
|
{
|
||||||
sheet.Cell(rowStartFactWellOperationBlock, columnWellOperationCategory).Value = factOperation.CategoryName;
|
sheet.Cell(rowCurrent, columnWellOperationCategory).Value = factOperation.CategoryName;
|
||||||
sheet.Cell(rowStartFactWellOperationBlock, columnWellOperationDurationHours).Value = factOperation.DurationHours;
|
sheet.Cell(rowCurrent, columnWellOperationDurationHours).Value = factOperation.DurationHours;
|
||||||
|
|
||||||
|
rowCurrent++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class DailyReportService : IDailyReportService
|
|||||||
this.detectedOperationService = detectedOperationService;
|
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)
|
CancellationToken cancellationToken)
|
||||||
where TBlock : ItemInfoDto
|
where TBlock : ItemInfoDto
|
||||||
{
|
{
|
||||||
@ -91,7 +91,7 @@ public class DailyReportService : IDailyReportService
|
|||||||
return await dailyReportRepository.UpdateAsync(dailyReport, cancellationToken);
|
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)
|
var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken)
|
||||||
?? throw new ArgumentNullException(nameof(idWell), $"Скважина с Id: {idWell} не найдена");
|
?? 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
|
var dailyReport = await dailyReportRepository.GetOrDefaultAsync(idWell, dateDailyReport, cancellationToken) ?? new DailyReportDto
|
||||||
{
|
{
|
||||||
Date = dateDailyReport.Date,
|
Date = dateDailyReport,
|
||||||
IdWell = well.Id
|
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
|
var factOperationRequest = new WellOperationRequest
|
||||||
{
|
{
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
OperationType = WellOperation.IdOperationTypeFact,
|
OperationType = WellOperation.IdOperationTypeFact,
|
||||||
GeDate = dateDailyReport,
|
GeDate = geDate,
|
||||||
LtDate = dateDailyReport.AddHours(24)
|
LtDate = ltDate
|
||||||
};
|
};
|
||||||
|
|
||||||
var factWellOperations = (await wellOperationRepository.GetAsync(factOperationRequest, cancellationToken))
|
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++)
|
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);
|
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++)
|
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);
|
AddDailyReport(dateDailyReport);
|
||||||
}
|
}
|
||||||
@ -216,7 +219,7 @@ public class DailyReportService : IDailyReportService
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
void AddDailyReport(DateTime date)
|
void AddDailyReport(DateOnly date)
|
||||||
{
|
{
|
||||||
var dailyReport = existingDailyReports.FirstOrDefault(d => d.IdWell == idWell && d.Date == date)
|
var dailyReport = existingDailyReports.FirstOrDefault(d => d.IdWell == idWell && d.Date == date)
|
||||||
?? new DailyReportDto
|
?? new DailyReportDto
|
||||||
@ -225,7 +228,11 @@ public class DailyReportService : IDailyReportService
|
|||||||
IdWell = idWell
|
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);
|
AddFactWellOperationBlock(dailyReport, factWellOperationPerDay);
|
||||||
|
|
||||||
@ -235,16 +242,29 @@ public class DailyReportService : IDailyReportService
|
|||||||
|
|
||||||
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, CancellationToken cancellationToken)
|
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,
|
var factOperationDatesRange = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
|
|
||||||
if (factOperationDatesRange is null)
|
if (factOperationDatesRange is null)
|
||||||
return 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
|
return new DatesRangeDto
|
||||||
{
|
{
|
||||||
From = factOperationDatesRange.From.AddDays(1) <= DateTime.UtcNow ? factOperationDatesRange.From : DateTime.UtcNow.Date.AddDays(-1),
|
From = from,
|
||||||
To = factOperationDatesRange.To.AddDays(1) <= DateTime.UtcNow ? factOperationDatesRange.To : DateTime.UtcNow.Date.AddDays(-1)
|
To = to
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,13 +278,16 @@ public class DailyReportService : IDailyReportService
|
|||||||
dailyReport.TimeBalanceBlock.SectionName = wellOperationRepository.GetSectionTypes()
|
dailyReport.TimeBalanceBlock.SectionName = wellOperationRepository.GetSectionTypes()
|
||||||
.FirstOrDefault(s => s.Id == dailyReport.TimeBalanceBlock.IdSection)?.Caption;
|
.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(
|
dailyReport.TimeBalanceBlock.WellOperationSlipsTimeCount = (await detectedOperationService.GetAsync(
|
||||||
new DetectedOperationRequest
|
new DetectedOperationRequest
|
||||||
{
|
{
|
||||||
IdsCategories = new[] { idWellOperationSlipsTime },
|
IdsCategories = new[] { idWellOperationSlipsTime },
|
||||||
IdWell = dailyReport.IdWell,
|
IdWell = dailyReport.IdWell,
|
||||||
GeDateStart = dailyReport.Date,
|
GeDateStart = geDateStart,
|
||||||
LeDateEnd = dailyReport.Date.AddHours(24)
|
LeDateEnd = leDateEnd
|
||||||
}, cancellationToken))?.Stats.Sum(s => s.Count);
|
}, cancellationToken))?.Stats.Sum(s => s.Count);
|
||||||
|
|
||||||
dailyReport.TimeBalanceBlock.WellDepth.Fact = factWellOperations
|
dailyReport.TimeBalanceBlock.WellDepth.Fact = factWellOperations
|
||||||
@ -275,11 +298,14 @@ public class DailyReportService : IDailyReportService
|
|||||||
|
|
||||||
private async Task AddTrajectoryBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
|
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
|
var trajectory = (await trajectoryFactNnbRepository.GetByRequestAsync(new TrajectoryRequest
|
||||||
{
|
{
|
||||||
IdWell = dailyReport.IdWell,
|
IdWell = dailyReport.IdWell,
|
||||||
GeDate = dailyReport.Date,
|
GeDate = geDate,
|
||||||
LeDate = dailyReport.Date.AddHours(24)
|
LeDate = leDate
|
||||||
}, cancellationToken)).MaxBy(t => t.WellboreDepth);
|
}, cancellationToken)).MaxBy(t => t.WellboreDepth);
|
||||||
|
|
||||||
dailyReport.TrajectoryBlock = new TrajectoryBlockDto
|
dailyReport.TrajectoryBlock = new TrajectoryBlockDto
|
||||||
@ -291,8 +317,11 @@ public class DailyReportService : IDailyReportService
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AddScheduleBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken) =>
|
private async Task AddScheduleBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
|
||||||
dailyReport.ScheduleBlock = (await scheduleRepository.GetAsync(dailyReport.IdWell, dailyReport.Date, cancellationToken))
|
{
|
||||||
|
var workDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
|
||||||
|
|
||||||
|
dailyReport.ScheduleBlock = (await scheduleRepository.GetAsync(dailyReport.IdWell, workDate, cancellationToken))
|
||||||
.Select(s => new ScheduleRecordDto
|
.Select(s => new ScheduleRecordDto
|
||||||
{
|
{
|
||||||
ShiftStart = s.ShiftStart,
|
ShiftStart = s.ShiftStart,
|
||||||
@ -301,6 +330,7 @@ public class DailyReportService : IDailyReportService
|
|||||||
Surname = s.Driller?.Surname,
|
Surname = s.Driller?.Surname,
|
||||||
Patronymic = s.Driller?.Patronymic
|
Patronymic = s.Driller?.Patronymic
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private async Task UpdateSubsystemBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
|
private async Task UpdateSubsystemBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
@ -315,11 +345,14 @@ public class DailyReportService : IDailyReportService
|
|||||||
IdWell = dailyReport.IdWell
|
IdWell = dailyReport.IdWell
|
||||||
}, cancellationToken);
|
}, 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
|
var subsystemsStatPerDay = await subsystemService.GetStatAsync(new SubsystemRequest
|
||||||
{
|
{
|
||||||
IdWell = dailyReport.IdWell,
|
IdWell = dailyReport.IdWell,
|
||||||
GeDate = dailyReport.Date,
|
GeDate = geDate,
|
||||||
LeDate = dailyReport.Date.AddHours(24)
|
LeDate = leDate
|
||||||
}, cancellationToken);
|
}, cancellationToken);
|
||||||
|
|
||||||
var subsystems = subsystemsStatPerWell
|
var subsystems = subsystemsStatPerWell
|
||||||
@ -339,9 +372,11 @@ public class DailyReportService : IDailyReportService
|
|||||||
|
|
||||||
private async Task AddProcessMapWellDrillingBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
|
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,
|
dailyReport.ProcessMapWellDrillingBlock = (await processMapReportWellDrillingService.GetAsync(dailyReport.IdWell,
|
||||||
cancellationToken)).Where(p => p.DateStart >= dailyReport.Date &&
|
cancellationToken)).Where(p => p.DateStart >= geDate && p.DateStart <= leDate)
|
||||||
p.DateStart <= dailyReport.Date.AddHours(24))
|
|
||||||
.GroupBy(p => p.DrillingMode)
|
.GroupBy(p => p.DrillingMode)
|
||||||
.Select(g => new ProcessMapWellDrillingRecordDto
|
.Select(g => new ProcessMapWellDrillingRecordDto
|
||||||
{
|
{
|
||||||
@ -362,7 +397,7 @@ public class DailyReportService : IDailyReportService
|
|||||||
|
|
||||||
dailyReport.FactWellOperationBlock = new WellOperationBlockDto
|
dailyReport.FactWellOperationBlock = new WellOperationBlockDto
|
||||||
{
|
{
|
||||||
WellOperations = factWellOperations.GroupBy(o => o.IdParentCategory)
|
WellOperations = factWellOperations.GroupBy(o => o.IdCategory)
|
||||||
.Select(g => new WellOperationRecordDto
|
.Select(g => new WellOperationRecordDto
|
||||||
{
|
{
|
||||||
CategoryName = g.First().CategoryName,
|
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);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,8 +29,6 @@ public class DailyReportServiceTest
|
|||||||
private const int idUser = 3;
|
private const int idUser = 3;
|
||||||
private const int idWell = 2;
|
private const int idWell = 2;
|
||||||
|
|
||||||
private readonly DateTime dateDailyReport = new DateOnly(2023, 10, 26).ToDateTime(TimeOnly.MinValue);
|
|
||||||
|
|
||||||
private readonly SubsystemBlockDto fakeSubsystemBlock = new()
|
private readonly SubsystemBlockDto fakeSubsystemBlock = new()
|
||||||
{
|
{
|
||||||
IdUser = idUser,
|
IdUser = idUser,
|
||||||
@ -219,7 +217,7 @@ public class DailyReportServiceTest
|
|||||||
{
|
{
|
||||||
Id = idDailyReport,
|
Id = idDailyReport,
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
Date = dateDailyReport,
|
Date = new(2023, 10, 26),
|
||||||
DateLastUpdate = null
|
DateLastUpdate = null
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -251,7 +249,7 @@ public class DailyReportServiceTest
|
|||||||
dailyReportRepositoryMock.InsertAsync(Arg.Any<DailyReportDto>(), Arg.Any<CancellationToken>())
|
dailyReportRepositoryMock.InsertAsync(Arg.Any<DailyReportDto>(), Arg.Any<CancellationToken>())
|
||||||
.ReturnsForAnyArgs(idDailyReport);
|
.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);
|
.ReturnsForAnyArgs(fakeDailyReport);
|
||||||
|
|
||||||
dailyReportRepositoryMock.UpdateAsync(Arg.Any<DailyReportDto>(), Arg.Any<CancellationToken>())
|
dailyReportRepositoryMock.UpdateAsync(Arg.Any<DailyReportDto>(), Arg.Any<CancellationToken>())
|
||||||
@ -278,10 +276,10 @@ public class DailyReportServiceTest
|
|||||||
subsystemServiceMock.GetStatAsync(Arg.Any<SubsystemRequest>(), Arg.Any<CancellationToken>())
|
subsystemServiceMock.GetStatAsync(Arg.Any<SubsystemRequest>(), Arg.Any<CancellationToken>())
|
||||||
.ReturnsForAnyArgs(new[] { fakeSubsystemsStat });
|
.ReturnsForAnyArgs(new[] { fakeSubsystemsStat });
|
||||||
|
|
||||||
scheduleRepositoryMock.GetAsync(idWell, dateDailyReport, Arg.Any<CancellationToken>())
|
scheduleRepositoryMock.GetAsync(Arg.Any<int>(), Arg.Any<DateTime>(), Arg.Any<CancellationToken>())
|
||||||
.ReturnsForAnyArgs(new[] { fakeShedule });
|
.ReturnsForAnyArgs(new[] { fakeShedule });
|
||||||
|
|
||||||
processMapReportWellDrillingServiceMock.GetAsync(idWell, Arg.Any<CancellationToken>())
|
processMapReportWellDrillingServiceMock.GetAsync(Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||||
.ReturnsForAnyArgs(new[] { fakeProcessMapReportWellDrilling });
|
.ReturnsForAnyArgs(new[] { fakeProcessMapReportWellDrilling });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +287,7 @@ public class DailyReportServiceTest
|
|||||||
public async Task UpdateOrInsertAsync_ShouldReturn_UpdatedSubsystemBlock()
|
public async Task UpdateOrInsertAsync_ShouldReturn_UpdatedSubsystemBlock()
|
||||||
{
|
{
|
||||||
//act
|
//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
|
||||||
Assert.NotNull(fakeSubsystemBlock.LastUpdateDate);
|
Assert.NotNull(fakeSubsystemBlock.LastUpdateDate);
|
||||||
@ -300,14 +298,13 @@ public class DailyReportServiceTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("2090.01.01")]
|
[MemberData(nameof(DateDailyReport))]
|
||||||
[InlineData("2000.01.01")]
|
public async Task UpdateOrInsertAsync_ShouldReturn_UnableToUpdateDailyReport(DateOnly dateDailyReport)
|
||||||
public async Task UpdateOrInsertAsync_ShouldReturn_UnableToUpdateDailyReport(DateTime dateDaileReport)
|
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var result = await Assert.ThrowsAsync<ArgumentInvalidException>(() => dailyReportService.UpdateOrInsertAsync(
|
var result = await Assert.ThrowsAsync<ArgumentInvalidException>(() => dailyReportService.UpdateOrInsertAsync(
|
||||||
idWell,
|
idWell,
|
||||||
dateDaileReport,
|
dateDailyReport,
|
||||||
idUser,
|
idUser,
|
||||||
fakeSignBlock,
|
fakeSignBlock,
|
||||||
CancellationToken.None));
|
CancellationToken.None));
|
||||||
@ -320,7 +317,7 @@ public class DailyReportServiceTest
|
|||||||
public async Task UpdateOrInsertAsync_ShouldReturn_UpdatedSignBlock()
|
public async Task UpdateOrInsertAsync_ShouldReturn_UpdatedSignBlock()
|
||||||
{
|
{
|
||||||
//act
|
//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
|
||||||
Assert.NotNull(fakeSignBlock.LastUpdateDate);
|
Assert.NotNull(fakeSignBlock.LastUpdateDate);
|
||||||
@ -334,7 +331,7 @@ public class DailyReportServiceTest
|
|||||||
public async Task UpdateOrInsertAsync_ShouldReturn_UpdatedTimeBalanceBlock()
|
public async Task UpdateOrInsertAsync_ShouldReturn_UpdatedTimeBalanceBlock()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var result = await dailyReportService.UpdateOrInsertAsync(idWell, dateDailyReport, idUser, fakeTimeBalanceBlock,
|
var result = await dailyReportService.UpdateOrInsertAsync(idWell, fakeDailyReport.Date, idUser, fakeTimeBalanceBlock,
|
||||||
CancellationToken.None);
|
CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
@ -346,13 +343,12 @@ public class DailyReportServiceTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("2090.01.01")]
|
[MemberData(nameof(DateDailyReport))]
|
||||||
[InlineData("2000.01.01")]
|
public async Task GetAsync_ShouldReturn_UnableToGetDailyReport(DateOnly dateDailyReport)
|
||||||
public async Task GetAsync_ShouldReturn_UnableToGetDailyReport(DateTime dateDaileReport)
|
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var result = await Assert.ThrowsAsync<ArgumentInvalidException>(() => dailyReportService.GetAsync(idWell,
|
var result = await Assert.ThrowsAsync<ArgumentInvalidException>(() => dailyReportService.GetAsync(idWell,
|
||||||
dateDaileReport,
|
dateDailyReport,
|
||||||
CancellationToken.None));
|
CancellationToken.None));
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
@ -363,7 +359,7 @@ public class DailyReportServiceTest
|
|||||||
public async Task GetAsync_ShouldReturn_AddedWellInfo()
|
public async Task GetAsync_ShouldReturn_AddedWellInfo()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
|
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(result.IdWell, fakeWell.Id);
|
Assert.Equal(result.IdWell, fakeWell.Id);
|
||||||
@ -381,7 +377,7 @@ public class DailyReportServiceTest
|
|||||||
public async Task GetAsync_ShouldReturn_AddedTrajectoryBlock()
|
public async Task GetAsync_ShouldReturn_AddedTrajectoryBlock()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
|
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(fakeLastFactTrajectory.WellboreDepth, result.TrajectoryBlock.WellboreDepth);
|
Assert.Equal(fakeLastFactTrajectory.WellboreDepth, result.TrajectoryBlock.WellboreDepth);
|
||||||
@ -394,7 +390,7 @@ public class DailyReportServiceTest
|
|||||||
public async Task GetAsync_ShouldReturn_AddedFactWellOperationBlock()
|
public async Task GetAsync_ShouldReturn_AddedFactWellOperationBlock()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
|
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(16, result.FactWellOperationBlock.SectionDrillingHours);
|
Assert.Equal(16, result.FactWellOperationBlock.SectionDrillingHours);
|
||||||
@ -410,7 +406,7 @@ public class DailyReportServiceTest
|
|||||||
public async Task GetAsync_ShouldReturn_AddedScheduleBlock()
|
public async Task GetAsync_ShouldReturn_AddedScheduleBlock()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
|
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Single(result.ScheduleBlock);
|
Assert.Single(result.ScheduleBlock);
|
||||||
@ -431,7 +427,7 @@ public class DailyReportServiceTest
|
|||||||
fakeDailyReport.TimeBalanceBlock = fakeTimeBalanceBlock;
|
fakeDailyReport.TimeBalanceBlock = fakeTimeBalanceBlock;
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
|
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.NotNull(result.TimeBalanceBlock);
|
Assert.NotNull(result.TimeBalanceBlock);
|
||||||
@ -446,7 +442,7 @@ public class DailyReportServiceTest
|
|||||||
public async Task GetAsync_ShouldReturn_AddedProcessMapWellDrillingBlock()
|
public async Task GetAsync_ShouldReturn_AddedProcessMapWellDrillingBlock()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var result = await dailyReportService.GetAsync(idWell, dateDailyReport, CancellationToken.None);
|
var result = await dailyReportService.GetAsync(idWell, fakeDailyReport.Date, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Single(result.ProcessMapWellDrillingBlock);
|
Assert.Single(result.ProcessMapWellDrillingBlock);
|
||||||
@ -467,7 +463,7 @@ public class DailyReportServiceTest
|
|||||||
fakeDailyReport.SubsystemBlock = fakeSubsystemBlock;
|
fakeDailyReport.SubsystemBlock = fakeSubsystemBlock;
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var result = await dailyReportService.GetAsync(idDailyReport, dateDailyReport, CancellationToken.None);
|
var result = await dailyReportService.GetAsync(idDailyReport, fakeDailyReport.Date, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.NotNull(result.SubsystemBlock);
|
Assert.NotNull(result.SubsystemBlock);
|
||||||
@ -526,6 +522,15 @@ public class DailyReportServiceTest
|
|||||||
Assert.True(result.To < DateTime.UtcNow.Date);
|
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()
|
public static IEnumerable<object[]> FactWellOperationDatesRange()
|
||||||
{
|
{
|
||||||
yield return new object[]
|
yield return new object[]
|
||||||
|
@ -175,8 +175,7 @@ public class DailyReportController : ControllerBase
|
|||||||
{
|
{
|
||||||
await AssertUserAccessToWell(idWell, cancellationToken);
|
await AssertUserAccessToWell(idWell, cancellationToken);
|
||||||
|
|
||||||
var dailyReport = await dailyReportExportService.ExportAsync(idWell,
|
var dailyReport = await dailyReportExportService.ExportAsync(idWell, dateDailyReport, cancellationToken);
|
||||||
dateDailyReport.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc), cancellationToken);
|
|
||||||
|
|
||||||
return File(dailyReport.File, "application/octet-stream", dailyReport.FileName);
|
return File(dailyReport.File, "application/octet-stream", dailyReport.FileName);
|
||||||
}
|
}
|
||||||
@ -187,8 +186,7 @@ public class DailyReportController : ControllerBase
|
|||||||
{
|
{
|
||||||
await AssertUserAccessToWell(idWell, cancellationToken);
|
await AssertUserAccessToWell(idWell, cancellationToken);
|
||||||
|
|
||||||
var id = await dailyReportService.UpdateOrInsertAsync(idWell, dateDailyReport.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc), IdUser,
|
var id = await dailyReportService.UpdateOrInsertAsync(idWell, dateDailyReport, IdUser, block, cancellationToken);
|
||||||
block, cancellationToken);
|
|
||||||
|
|
||||||
return Ok(id);
|
return Ok(id);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user