2024-07-04 11:02:45 +05:00
|
|
|
|
using AsbCloudApp.Data.DrillTestReport;
|
2023-10-20 11:24:04 +05:00
|
|
|
|
using ClosedXML.Excel;
|
2023-10-20 16:55:08 +05:00
|
|
|
|
using System;
|
2023-10-20 11:24:04 +05:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-02-07 11:33:00 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2023-10-20 11:24:04 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Services.DrillTestReport;
|
|
|
|
|
|
|
|
|
|
public class DrillTestReportMakerService : IReportMakerService<DrillTestReportDataDto>
|
2023-10-20 11:24:04 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
private readonly string templateName = "DrillTestReportTemplate.xlsx";
|
|
|
|
|
private readonly string sheetName = "Лист1";
|
|
|
|
|
private readonly int startRowNumber = 8;
|
2023-10-20 11:24:04 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
public Stream MakeReport(DrillTestReportDataDto report)
|
|
|
|
|
{
|
|
|
|
|
using var excelTemplateStream = Assembly.GetExecutingAssembly().GetTemplateCopyStream(templateName);
|
2023-10-20 11:24:04 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
using var workbook = new XLWorkbook(excelTemplateStream);
|
2023-10-20 11:24:04 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
AddToWorkbook(workbook, report);
|
2023-10-20 11:24:04 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
|
|
|
workbook.SaveAs(memoryStream, new SaveOptions { });
|
|
|
|
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
2023-10-20 11:24:04 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
return memoryStream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddToWorkbook(XLWorkbook workbook, DrillTestReportDataDto report)
|
|
|
|
|
{
|
|
|
|
|
var drillTests = report.Data.Params;
|
2024-02-07 11:33:00 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (!drillTests.Any())
|
|
|
|
|
return;
|
2023-10-20 11:24:04 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var sheet = workbook.GetWorksheet(sheetName);
|
2023-10-20 11:24:04 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
sheet.Cell(4, 2).SetCellValue(report.Caption);
|
|
|
|
|
sheet.Cell(5, 2).SetCellValue(report.Date);
|
|
|
|
|
|
|
|
|
|
var stepWithMaxDepthSpeed = drillTests.MaxBy(p => p.DepthSpeed)!.Step;
|
|
|
|
|
var startDepth = report.Data.DepthStart;
|
|
|
|
|
var startDate = report.Data.TimeStampStart;
|
2023-10-20 11:24:04 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var rowNumber = startRowNumber;
|
|
|
|
|
|
|
|
|
|
foreach (var drillTestEntity in drillTests)
|
|
|
|
|
{
|
|
|
|
|
var endDepth = startDepth + (drillTestEntity.DepthDrillStep ?? 0);
|
|
|
|
|
var endDateTime = startDate.AddSeconds(drillTestEntity.TimeDrillStep ?? 0);
|
2024-02-07 11:33:00 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
sheet.Cell(rowNumber, 2).SetCellValue(startDepth);
|
|
|
|
|
sheet.Cell(rowNumber, 3).SetCellValue(endDepth);
|
|
|
|
|
sheet.Cell(rowNumber, 4).SetCellValue(drillTestEntity.DepthDrillStep);
|
|
|
|
|
sheet.Cell(rowNumber, 5).SetCellValue(drillTestEntity.Workload);
|
|
|
|
|
sheet.Cell(rowNumber, 6).SetCellValue(drillTestEntity.Speed);
|
|
|
|
|
sheet.Cell(rowNumber, 7).SetCellValue(startDate.DateTime);
|
|
|
|
|
sheet.Cell(rowNumber, 8).SetCellValue(endDateTime.DateTime);
|
|
|
|
|
sheet.Cell(rowNumber, 9).SetCellValue(Math.Round((drillTestEntity.TimeDrillStep ?? 0) / (60 * 60), 2));
|
|
|
|
|
sheet.Cell(rowNumber, 10).SetCellValue(drillTestEntity.DepthSpeed);
|
2023-10-20 11:24:04 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (drillTestEntity.Step == stepWithMaxDepthSpeed)
|
|
|
|
|
{
|
|
|
|
|
var currentCells = sheet.Row(rowNumber).Cells(1, 10);
|
|
|
|
|
currentCells.Style.Fill.BackgroundColor = XLColor.Yellow;
|
2023-10-20 11:24:04 +05:00
|
|
|
|
}
|
2024-08-19 10:01:07 +05:00
|
|
|
|
|
|
|
|
|
startDepth = endDepth;
|
|
|
|
|
startDate = endDateTime;
|
|
|
|
|
rowNumber++;
|
2023-10-20 11:24:04 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|