forked from ddrilling/AsbCloudServer
55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using ClosedXML.Excel;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Services.ProcessMap
|
|
{
|
|
public class ProcessMapReportService : IProcessMapReportService
|
|
{
|
|
private readonly IAsbCloudDbContext context;
|
|
private readonly IProcessMapRepository processMapRepository;
|
|
|
|
public ProcessMapReportService(IAsbCloudDbContext context, IProcessMapRepository processMapRepository)
|
|
{
|
|
this.context = context;
|
|
this.processMapRepository = processMapRepository;
|
|
}
|
|
|
|
public async Task<Stream> MakeReportAsync(int idWell, CancellationToken token)
|
|
{
|
|
var dtos = (await processMapRepository.GetByIdWellAsync(idWell, token))
|
|
.GroupBy(x => x.IdWellSectionType);
|
|
var stream = GetExcelTemplateStream();
|
|
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
|
|
|
|
FillProcessMapToWorkbook(workbook, dtos);
|
|
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
workbook.SaveAs(memoryStream, new SaveOptions { });
|
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
|
return memoryStream;
|
|
}
|
|
|
|
private static void FillProcessMapToWorkbook(XLWorkbook workbook, IEnumerable<IGrouping<int, ProcessMapDto>> dto)
|
|
{
|
|
var sheet = workbook.Worksheets.FirstOrDefault();
|
|
if (sheet is null)
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
private Stream GetExcelTemplateStream()
|
|
{
|
|
var stream = System.Reflection.Assembly.GetExecutingAssembly()
|
|
.GetManifestResourceStream("AsbCloudInfrastructure.Services.ProcessMap.ProcessMapReportTemplate.xlsx");
|
|
return stream;
|
|
}
|
|
}
|
|
} |