Правка экспорта дат операций из ГГД

This commit is contained in:
Olga Nemt 2023-12-19 09:21:09 +05:00
parent d7464a03c7
commit c924170a54

View File

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -36,17 +35,15 @@ public class WellOperationExportService : IWellOperationExportService
IdWell = idWell
}, cancellationToken);
var timezone = wellService.GetTimezone(idWell);
return MakeExcelFileStream(operations, timezone.Hours);
return MakeExcelFileStream(operations);
}
private Stream MakeExcelFileStream(IEnumerable<WellOperationDto> operations, double timezoneOffset)
private Stream MakeExcelFileStream(IEnumerable<WellOperationDto> operations)
{
using Stream ecxelTemplateStream = wellOperationImportTemplateService.GetExcelTemplateStream();
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
AddOperationsToWorkbook(workbook, operations, timezoneOffset);
AddOperationsToWorkbook(workbook, operations);
var memoryStream = new MemoryStream();
workbook.SaveAs(memoryStream, new SaveOptions { });
@ -54,14 +51,14 @@ public class WellOperationExportService : IWellOperationExportService
return memoryStream;
}
private void AddOperationsToWorkbook(XLWorkbook workbook, IEnumerable<WellOperationDto> operations, double timezoneOffset)
private void AddOperationsToWorkbook(XLWorkbook workbook, IEnumerable<WellOperationDto> operations)
{
var planOperations = operations.Where(o => o.IdType == 0);
if (planOperations.Any())
{
var sheetPlan = workbook.Worksheets.FirstOrDefault(ws => ws.Name == DefaultTemplateInfo.SheetNamePlan);
if (sheetPlan is not null)
AddOperationsToSheet(sheetPlan, planOperations, timezoneOffset);
AddOperationsToSheet(sheetPlan, planOperations);
}
var factOperations = operations.Where(o => o.IdType == 1);
@ -69,11 +66,11 @@ public class WellOperationExportService : IWellOperationExportService
{
var sheetFact = workbook.Worksheets.FirstOrDefault(ws => ws.Name == DefaultTemplateInfo.SheetNameFact);
if (sheetFact is not null)
AddOperationsToSheet(sheetFact, factOperations, timezoneOffset);
AddOperationsToSheet(sheetFact, factOperations);
}
}
private void AddOperationsToSheet(IXLWorksheet sheet, IEnumerable<WellOperationDto> operations, double timezoneOffset)
private void AddOperationsToSheet(IXLWorksheet sheet, IEnumerable<WellOperationDto> operations)
{
var operationsToArray = operations.ToArray();
@ -83,19 +80,19 @@ public class WellOperationExportService : IWellOperationExportService
for (int i = 0; i < operationsToArray.Length; i++)
{
var row = sheet.Row(1 + i + DefaultTemplateInfo.HeaderRowsCount);
AddOperationToRow(row, operationsToArray[i], sections, categories, timezoneOffset);
AddOperationToRow(row, operationsToArray[i], sections, categories);
}
}
private static void AddOperationToRow(IXLRow row, WellOperationDto operation, IEnumerable<WellSectionTypeDto> sections,
IEnumerable<WellOperationCategoryDto> categories, double timezoneOffset)
IEnumerable<WellOperationCategoryDto> categories)
{
row.Cell(DefaultTemplateInfo.ColumnSection).Value = sections.First(s => s.Id == operation.IdWellSectionType).Caption;
row.Cell(DefaultTemplateInfo.ColumnCategory).Value = categories.First(o => o.Id == operation.IdCategory).Name;
row.Cell(DefaultTemplateInfo.ColumnCategoryInfo).Value = operation.CategoryInfo;
row.Cell(DefaultTemplateInfo.ColumnDepthStart).Value = operation.DepthStart;
row.Cell(DefaultTemplateInfo.ColumnDepthEnd).Value = operation.DepthEnd;
row.Cell(DefaultTemplateInfo.ColumnDate).Value = new DateTimeOffset(operation.DateStart).ToRemoteDateTime(timezoneOffset);
row.Cell(DefaultTemplateInfo.ColumnDate).Value = operation.DateStart;
row.Cell(DefaultTemplateInfo.ColumnDuration).Value = operation.DurationHours;
row.Cell(DefaultTemplateInfo.ColumnComment).Value = operation.Comment;
}