forked from ddrilling/AsbCloudServer
1. Добавлена сборка Microsoft.AspNetCore.Http.Extensions
2. Правки по результатам ревью
This commit is contained in:
parent
cc45b55919
commit
37ec39f403
@ -56,6 +56,7 @@
|
||||
<PackageReference Include="ClosedXML" Version="0.96.0" />
|
||||
<PackageReference Include="itext7" Version="7.2.3" />
|
||||
<PackageReference Include="Mapster" Version="7.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.23.1" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.23.1" />
|
||||
|
@ -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<int, string> domains = new Dictionary<int, string>
|
||||
{
|
||||
{ 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<Stream> ExportAsync(int idWell, string url, CancellationToken cancellationToken)
|
||||
/// <summary>
|
||||
/// Экспорт excel файла с операциями по скважине
|
||||
/// </summary>
|
||||
/// <param name="idWell">ключ скважины</param>
|
||||
/// <param name="host">хост</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public async Task<Stream> 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<Stream> GenerateExcelFileStreamAsync(Well well, string url, IEnumerable<OperationDetectorResult> operationDetectorResults,
|
||||
private async Task<Stream> GenerateExcelFileStreamAsync(Well well, string host, IEnumerable<OperationDetectorResult> 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<OperationDetectorResult> operationDetectorResults,
|
||||
private async Task AddToWorkbookAsync(XLWorkbook workbook, Well well, string host, IEnumerable<OperationDetectorResult> 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<OperationDetectorResult> operationDetectorResults,
|
||||
private async Task AddToSheetAsync(IXLWorksheet sheet, Well well, string host, IList<OperationDetectorResult> 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));
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user