forked from ddrilling/AsbCloudServer
Правка бага с выгрузкой операций по скважине
This commit is contained in:
parent
d7464a03c7
commit
4ae22517f5
@ -54,7 +54,7 @@ public class DetectedOperationExportService
|
|||||||
this.wellOperationRepository = wellOperationRepository;
|
this.wellOperationRepository = wellOperationRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Stream> ExportAsync(int idWell, int idDomain, CancellationToken cancellationToken)
|
public async Task<Stream> ExportAsync(int idWell, string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var well = await dbContext.Wells
|
var well = await dbContext.Wells
|
||||||
.Include(w => w.Cluster)
|
.Include(w => w.Cluster)
|
||||||
@ -69,17 +69,17 @@ public class DetectedOperationExportService
|
|||||||
|
|
||||||
var operations = await DetectOperationsAsync(well.IdTelemetry.Value, DateTime.UnixEpoch, cancellationToken);
|
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<Stream> GenerateExcelFileStreamAsync(Well well, int idDomain, IEnumerable<OperationDetectorResult> operationDetectorResults,
|
private async Task<Stream> GenerateExcelFileStreamAsync(Well well, string url, IEnumerable<OperationDetectorResult> operationDetectorResults,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken);
|
using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken);
|
||||||
|
|
||||||
using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled);
|
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();
|
MemoryStream memoryStream = new MemoryStream();
|
||||||
workbook.SaveAs(memoryStream, new SaveOptions { });
|
workbook.SaveAs(memoryStream, new SaveOptions { });
|
||||||
@ -87,7 +87,7 @@ public class DetectedOperationExportService
|
|||||||
return memoryStream;
|
return memoryStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AddToWorkbookAsync(XLWorkbook workbook, Well well, int idDomain, IEnumerable<OperationDetectorResult> operationDetectorResults,
|
private async Task AddToWorkbookAsync(XLWorkbook workbook, Well well, string url, IEnumerable<OperationDetectorResult> operationDetectorResults,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
const string sheetName = "Операции";
|
const string sheetName = "Операции";
|
||||||
@ -98,12 +98,12 @@ public class DetectedOperationExportService
|
|||||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName)
|
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName)
|
||||||
?? throw new FileFormatException($"Книга excel не содержит листа {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(),
|
.OrderBy(x => x.Operation.DateStart).ThenBy(x => x.Operation.DepthStart).ToArray(),
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AddToSheetAsync(IXLWorksheet sheet, Well well, int idDomain, IList<OperationDetectorResult> operationDetectorResults,
|
private async Task AddToSheetAsync(IXLWorksheet sheet, Well well, string url, IList<OperationDetectorResult> operationDetectorResults,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var wellOperationCategories = await dbContext.WellOperationCategories.ToListAsync(cancellationToken);
|
var wellOperationCategories = await dbContext.WellOperationCategories.ToListAsync(cancellationToken);
|
||||||
@ -134,8 +134,7 @@ public class DetectedOperationExportService
|
|||||||
&& idReasonOfEndObject is int idReasonOfEnd)
|
&& idReasonOfEndObject is int idReasonOfEnd)
|
||||||
row.Cell(columnIdReasonOfEnd).Value = GetIdReasonOfEnd(idReasonOfEnd);
|
row.Cell(columnIdReasonOfEnd).Value = GetIdReasonOfEnd(idReasonOfEnd);
|
||||||
|
|
||||||
var link =
|
var link = $"{url}?end={Uri.EscapeDataString(dateStart.AddSeconds(1800 * 0.9).ToString("yyyy-MM-ddTHH:mm:ss.fff"))}&range=1800";
|
||||||
$"{domains[idDomain]}/well/{well.Id}/telemetry/monitoring?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).Value = dateStart;
|
||||||
row.Cell(columnDateStart).SetHyperlink(new XLHyperlink(link));
|
row.Cell(columnDateStart).SetHyperlink(new XLHyperlink(link));
|
||||||
|
@ -122,21 +122,21 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
/// Создает excel файл с операциями по скважине
|
/// Создает excel файл с операциями по скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="idDomain">Идентификатор домена</param>
|
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
[HttpGet("export")]
|
[HttpGet("export")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public async Task<IActionResult> ExportAsync(int idWell, [Range(1, 2)] int idDomain, CancellationToken token)
|
public async Task<IActionResult> ExportAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var idCompany = User.GetCompanyId();
|
var idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if (idCompany is null)
|
||||||
return Forbid();
|
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");
|
return File(stream, "application/octet-stream", "operations.xlsx");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user