From 67e4913c846237c47f7a707df4ce9d682e152055 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Wed, 21 Sep 2022 09:41:01 +0500 Subject: [PATCH] =?UTF-8?q?#5908066=20=D0=A1=D1=83=D1=82=D0=BE=D1=87=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D1=80=D0=B0=D0=BF=D0=BE=D1=80=D1=82.=20=D0=91?= =?UTF-8?q?=D0=BB=D0=BE=D0=BA=20=D0=9A=D0=9D=D0=91=D0=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/DailyReport/DailyReportDto.cs | 4 +++- .../Services/DailyReport/DailyReportService.cs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs index c47b8934..781a6717 100644 --- a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs +++ b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs @@ -1,5 +1,6 @@ namespace AsbCloudApp.Data.DailyReport { +#nullable enable /// /// Блоки для формирования суточного рапорта /// @@ -13,7 +14,7 @@ /// /// блок КНБК /// - public BhaDto Bha { get; set; } = new(); + public BhaDto? Bha { get; set; } = new(); /// /// блок безметражные работы @@ -35,4 +36,5 @@ /// public SignDto Sign { get; set; } = new(); } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs index 1c30ba0b..ecdd7d15 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs @@ -124,10 +124,26 @@ namespace AsbCloudInfrastructure.Services.DailyReport ClusterName = well?.Cluster ?? "", }, TimeBalance = await MakeTimeBalanceAsync(idWell, date, token), + Bha = await GetPrevBhaAsync(idWell, date, token) }; return dto; } + private async Task GetPrevBhaAsync(int idWell, DateTime date, CancellationToken token) + { + var dateOffset = date.Date; + var entity = await db.DailyReports + .OrderByDescending(x => x.StartDate) + .FirstOrDefaultAsync(r => r.IdWell == idWell && + r.StartDate.Year <= dateOffset.Year && + r.StartDate.DayOfYear <= dateOffset.DayOfYear, token); + + if (entity is null) + return null; + var dto = Convert(entity); + return dto?.Bha; + } + private async Task MakeTimeBalanceAsync(int idWell, DateTime date, CancellationToken token) { var stat = await detectedOperationService.GetOperationsStatAsync(new DetectedOperationRequest