DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportService.cs

90 lines
3.4 KiB
C#
Raw Normal View History

2022-12-27 14:30:52 +05:00
using AsbCloudApp.Data.ProcessMap;
2022-12-14 08:41:19 +05:00
using AsbCloudApp.Services;
using AsbCloudDb.Model;
2022-12-27 14:30:52 +05:00
using AsbCloudInfrastructure.Services.DailyReport;
2022-12-14 08:41:19 +05:00
using ClosedXML.Excel;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.ProcessMap
{
2022-12-27 14:30:52 +05:00
#nullable enable
2022-12-14 08:41:19 +05:00
public class ProcessMapReportService : IProcessMapReportService
{
private readonly IAsbCloudDbContext context;
private readonly IProcessMapRepository processMapRepository;
2022-12-27 14:30:52 +05:00
private readonly IProcessMapService processMapService;
2022-12-14 08:41:19 +05:00
2022-12-27 14:30:52 +05:00
public ProcessMapReportService(IAsbCloudDbContext context, IProcessMapRepository processMapRepository, IProcessMapService processMapService)
2022-12-14 08:41:19 +05:00
{
this.context = context;
this.processMapRepository = processMapRepository;
2022-12-27 14:30:52 +05:00
this.processMapService = processMapService;
2022-12-14 08:41:19 +05:00
}
public async Task<Stream> MakeReportAsync(int idWell, CancellationToken token)
{
var stream = GetExcelTemplateStream();
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
2022-12-27 14:30:52 +05:00
var data = processMapService.GetProcessMapAsync(idWell, token);
//var dtos = await processMapRepository.GetByIdWellAsync(idWell, token).ConfigureAwait(false);
//if (dtos is not null)
//{
// var processMapReportDto = await processMapService.GetProcessMapAsync(dtos, token).ConfigureAwait(false);
// FillProcessMapToWorkbook(workbook, processMapReportDto);
//}
FillProcessMapToWorkbook(workbook, new List<ProcessMapReportDto>());
2022-12-14 08:41:19 +05:00
MemoryStream memoryStream = new MemoryStream();
workbook.SaveAs(memoryStream, new SaveOptions { });
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
2022-12-27 14:30:52 +05:00
private static void FillProcessMapToWorkbook(XLWorkbook workbook, IEnumerable<ProcessMapReportDto> dto)
2022-12-14 08:41:19 +05:00
{
2022-12-27 14:30:52 +05:00
var rowsCount = 4;
var columnCount = 2;
var countMerge = 27;
2022-12-14 08:41:19 +05:00
var sheet = workbook.Worksheets.FirstOrDefault();
if (sheet is null)
return;
2022-12-27 14:30:52 +05:00
sheet.Row(rowsCount).Cell(columnCount).Value = "saddadasdasdasds";
sheet.Range(rowsCount, columnCount, rowsCount, countMerge).Row(1).Merge();
SetBorder(sheet.Row(rowsCount).Cell(columnCount).Style);
rowsCount++;
sheet.Row(rowsCount).Cell(columnCount).Value = 2;
sheet.Row(rowsCount).Cell(columnCount).Value = 3;
columnCount++;
sheet.Row(rowsCount).Cell(columnCount).Value = 4;
2022-12-14 08:41:19 +05:00
}
private Stream GetExcelTemplateStream()
{
var stream = System.Reflection.Assembly.GetExecutingAssembly()
.GetManifestResourceStream("AsbCloudInfrastructure.Services.ProcessMap.ProcessMapReportTemplate.xlsx");
2022-12-27 14:30:52 +05:00
return stream!;
}
private static IXLStyle SetBorder(IXLStyle style)
{
style.Border.RightBorder = XLBorderStyleValues.Medium;
style.Border.LeftBorder = XLBorderStyleValues.Medium;
style.Border.TopBorder = XLBorderStyleValues.Medium;
style.Border.BottomBorder = XLBorderStyleValues.Medium;
style.Border.InsideBorder = XLBorderStyleValues.Medium;
return style;
2022-12-14 08:41:19 +05:00
}
}
2022-12-27 14:30:52 +05:00
#nullable disable
2022-12-14 08:41:19 +05:00
}