From 4ae22517f5ddba1702817940fae17acbc87e0cd1 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 18 Dec 2023 12:38:37 +0500 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B3=D0=B0=20=D1=81=20=D0=B2=D1=8B=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=B7=D0=BA=D0=BE=D0=B9=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B9=20=D0=BF=D0=BE=20=D1=81=D0=BA=D0=B2=D0=B0?= =?UTF-8?q?=D0=B6=D0=B8=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DetectedOperationExportService.cs | 17 ++++++++--------- .../SAUB/DetectedOperationController.cs | 8 ++++---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs index 15dab40f..a6038741 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs @@ -54,7 +54,7 @@ public class DetectedOperationExportService this.wellOperationRepository = wellOperationRepository; } - public async Task ExportAsync(int idWell, int idDomain, CancellationToken cancellationToken) + public async Task ExportAsync(int idWell, string url, CancellationToken cancellationToken) { var well = await dbContext.Wells .Include(w => w.Cluster) @@ -69,17 +69,17 @@ public class DetectedOperationExportService var operations = await DetectOperationsAsync(well.IdTelemetry.Value, DateTime.UnixEpoch, cancellationToken); - return await GenerateExcelFileStreamAsync(well, idDomain, operations, cancellationToken); + return await GenerateExcelFileStreamAsync(well, url, operations, cancellationToken); } - private async Task GenerateExcelFileStreamAsync(Well well, int idDomain, IEnumerable operationDetectorResults, + private async Task GenerateExcelFileStreamAsync(Well well, string url, IEnumerable operationDetectorResults, CancellationToken cancellationToken) { using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken); using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled); - await AddToWorkbookAsync(workbook, well, idDomain, operationDetectorResults, cancellationToken); + await AddToWorkbookAsync(workbook, well, url, operationDetectorResults, cancellationToken); MemoryStream memoryStream = new MemoryStream(); workbook.SaveAs(memoryStream, new SaveOptions { }); @@ -87,7 +87,7 @@ public class DetectedOperationExportService return memoryStream; } - private async Task AddToWorkbookAsync(XLWorkbook workbook, Well well, int idDomain, IEnumerable operationDetectorResults, + private async Task AddToWorkbookAsync(XLWorkbook workbook, Well well, string url, IEnumerable operationDetectorResults, CancellationToken cancellationToken) { const string sheetName = "Операции"; @@ -98,12 +98,12 @@ public class DetectedOperationExportService var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName) ?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}."); - await AddToSheetAsync(sheet, well, idDomain, operationDetectorResults + await AddToSheetAsync(sheet, well, url, operationDetectorResults .OrderBy(x => x.Operation.DateStart).ThenBy(x => x.Operation.DepthStart).ToArray(), cancellationToken); } - private async Task AddToSheetAsync(IXLWorksheet sheet, Well well, int idDomain, IList operationDetectorResults, + private async Task AddToSheetAsync(IXLWorksheet sheet, Well well, string url, IList operationDetectorResults, CancellationToken cancellationToken) { var wellOperationCategories = await dbContext.WellOperationCategories.ToListAsync(cancellationToken); @@ -134,8 +134,7 @@ public class DetectedOperationExportService && idReasonOfEndObject is int idReasonOfEnd) row.Cell(columnIdReasonOfEnd).Value = GetIdReasonOfEnd(idReasonOfEnd); - var link = - $"{domains[idDomain]}/well/{well.Id}/telemetry/monitoring?end={Uri.EscapeDataString(dateStart.AddSeconds(1800 * 0.9).ToString("yyyy-MM-ddTHH:mm:ss.fff"))}&range=1800"; + var link = $"{url}?end={Uri.EscapeDataString(dateStart.AddSeconds(1800 * 0.9).ToString("yyyy-MM-ddTHH:mm:ss.fff"))}&range=1800"; row.Cell(columnDateStart).Value = dateStart; row.Cell(columnDateStart).SetHyperlink(new XLHyperlink(link)); diff --git a/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs b/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs index 3c6d5b64..65231423 100644 --- a/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs @@ -122,21 +122,21 @@ namespace AsbCloudWebApi.Controllers.SAUB /// Создает excel файл с операциями по скважине /// /// id скважины - /// Идентификатор домена /// [HttpGet("export")] [Permission] [ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)] - public async Task ExportAsync(int idWell, [Range(1, 2)] int idDomain, CancellationToken token) + public async Task ExportAsync(int idWell, CancellationToken token) { var idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - - var stream = await detectedOperationExportService.ExportAsync(idWell, idDomain, token); + + var url = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/well/{idWell}/telemetry/monitoring"; + var stream = await detectedOperationExportService.ExportAsync(idWell, url, token); return File(stream, "application/octet-stream", "operations.xlsx"); } From cc45b55919b95ff09311601550e57a77edf1b844 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 18 Dec 2023 13:04:13 +0500 Subject: [PATCH 2/3] =?UTF-8?q?=D0=A0=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8?= =?UTF-8?q?=D0=BC=D0=BE=D1=81=D1=82=D0=B8=20IScheduleReportService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/DependencyInjection.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index a07bc70c..665e15d2 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -222,6 +222,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); From 37ec39f403d4d619a9013d6ef72e50abb187377d Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 18 Dec 2023 15:56:24 +0500 Subject: [PATCH 3/3] =?UTF-8?q?1.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B0=20Mic?= =?UTF-8?q?rosoft.AspNetCore.Http.Extensions=202.=20=D0=9F=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=D1=82=D0=B0=D1=82=D0=B0=D0=BC=20=D1=80=D0=B5=D0=B2?= =?UTF-8?q?=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AsbCloudInfrastructure.csproj | 1 + .../DetectedOperationExportService.cs | 35 +++++++++++-------- .../SAUB/DetectedOperationController.cs | 4 +-- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index f2edc76d..a1816762 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -56,6 +56,7 @@ + diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs index a6038741..eb119b06 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs @@ -10,6 +10,7 @@ using System.Threading; using System.Threading.Tasks; using AsbCloudInfrastructure.Services.DetectOperations.Detectors; using AsbCloudApp.Repositories; +using Microsoft.AspNetCore.Http.Extensions; namespace AsbCloudInfrastructure.Services.DetectOperations; @@ -21,12 +22,6 @@ public class DetectedOperationExportService new DetectorSlipsTime() }; - private readonly IDictionary domains = new Dictionary - { - { 1, "https://cloud.digitaldrilling.ru" }, - { 2, "https://cloud.autodrilling.ru" } - }; - private const int headerRowsCount = 1; private const string cellDepositName = "B1"; @@ -54,7 +49,15 @@ public class DetectedOperationExportService this.wellOperationRepository = wellOperationRepository; } - public async Task ExportAsync(int idWell, string url, CancellationToken cancellationToken) + /// + /// Экспорт excel файла с операциями по скважине + /// + /// ключ скважины + /// хост + /// + /// + /// + public async Task ExportAsync(int idWell, string host, CancellationToken cancellationToken) { var well = await dbContext.Wells .Include(w => w.Cluster) @@ -69,17 +72,17 @@ public class DetectedOperationExportService var operations = await DetectOperationsAsync(well.IdTelemetry.Value, DateTime.UnixEpoch, cancellationToken); - return await GenerateExcelFileStreamAsync(well, url, operations, cancellationToken); + return await GenerateExcelFileStreamAsync(well, host, operations, cancellationToken); } - private async Task GenerateExcelFileStreamAsync(Well well, string url, IEnumerable operationDetectorResults, + private async Task GenerateExcelFileStreamAsync(Well well, string host, IEnumerable operationDetectorResults, CancellationToken cancellationToken) { using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken); using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled); - await AddToWorkbookAsync(workbook, well, url, operationDetectorResults, cancellationToken); + await AddToWorkbookAsync(workbook, well, host, operationDetectorResults, cancellationToken); MemoryStream memoryStream = new MemoryStream(); workbook.SaveAs(memoryStream, new SaveOptions { }); @@ -87,7 +90,7 @@ public class DetectedOperationExportService return memoryStream; } - private async Task AddToWorkbookAsync(XLWorkbook workbook, Well well, string url, IEnumerable operationDetectorResults, + private async Task AddToWorkbookAsync(XLWorkbook workbook, Well well, string host, IEnumerable operationDetectorResults, CancellationToken cancellationToken) { const string sheetName = "Операции"; @@ -98,12 +101,12 @@ public class DetectedOperationExportService var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName) ?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}."); - await AddToSheetAsync(sheet, well, url, operationDetectorResults + await AddToSheetAsync(sheet, well, host, operationDetectorResults .OrderBy(x => x.Operation.DateStart).ThenBy(x => x.Operation.DepthStart).ToArray(), cancellationToken); } - private async Task AddToSheetAsync(IXLWorksheet sheet, Well well, string url, IList operationDetectorResults, + private async Task AddToSheetAsync(IXLWorksheet sheet, Well well, string host, IList operationDetectorResults, CancellationToken cancellationToken) { var wellOperationCategories = await dbContext.WellOperationCategories.ToListAsync(cancellationToken); @@ -134,7 +137,11 @@ public class DetectedOperationExportService && idReasonOfEndObject is int idReasonOfEnd) row.Cell(columnIdReasonOfEnd).Value = GetIdReasonOfEnd(idReasonOfEnd); - var link = $"{url}?end={Uri.EscapeDataString(dateStart.AddSeconds(1800 * 0.9).ToString("yyyy-MM-ddTHH:mm:ss.fff"))}&range=1800"; + var query = new QueryBuilder(); + query.Add("end", dateStart.AddSeconds(1800 * 0.9).ToString("yyyy-MM-ddTHH:mm:ss.fff")); + query.Add("range", "1800"); + + var link = $"{host}/well/{well.Id}/telemetry/monitoring{query}"; row.Cell(columnDateStart).Value = dateStart; row.Cell(columnDateStart).SetHyperlink(new XLHyperlink(link)); diff --git a/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs b/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs index 65231423..02f2d4cb 100644 --- a/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs @@ -135,8 +135,8 @@ namespace AsbCloudWebApi.Controllers.SAUB if (idCompany is null) return Forbid(); - var url = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/well/{idWell}/telemetry/monitoring"; - var stream = await detectedOperationExportService.ExportAsync(idWell, url, token); + var host = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}"; + var stream = await detectedOperationExportService.ExportAsync(idWell, host, token); return File(stream, "application/octet-stream", "operations.xlsx"); }