DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/ReportService.cs

68 lines
2.2 KiB
C#
Raw Normal View History

using AsbCloudApp.Services;
using AsbCloudApp.Data;
using AsbCloudDb.Model;
using System;
using System.IO;
using AsbSaubReport;
namespace AsbCloudInfrastructure.Services
{
public class ReportService : IReportService
{
private readonly IAsbCloudDbContext db;
private readonly ITelemetryService telemetryService;
public ReportService(IAsbCloudDbContext db, ITelemetryService telemetryService)
{
this.db = db;
this.telemetryService = telemetryService;
}
public int GetReportPagesCount(int wellId, DateTime begin, DateTime end, int stepSeconds, int format)
{
var generator = GetReportGenerator(wellId, begin, end, stepSeconds, format);
return generator.GetPagesCount();
}
public ReportPropertiesDto GetReportFileProperties(string reportName, string rootPath)
{
string path = Path.Combine(rootPath, reportName);
FileStream fs = new FileStream(path, FileMode.Open);
string contentType = Path.GetExtension(path);
string fileName = Path.GetFileName(path);
return new ReportPropertiesDto {
Filestream = fs,
ContentType = contentType,
FileName = fileName
};
}
public DatesRangeDto GetReportsDatesRange(int wellId)
{
var telemetry = telemetryService.GetTelemetryByWellId(wellId);
if (telemetry is null)
return null;
var result = db.GetDatesRange<Report>(telemetry.Id);
return new DatesRangeDto { From = result.From, To = result.To };
}
private IReportGenerator GetReportGenerator(int wellId,DateTime begin, DateTime end, int stepSeconds, int format)
{
var dataSource = new ReportDataSourcePgCloud((AsbCloudDbContext)db, wellId);
var generator = new PdfGenerator(dataSource);
generator.Begin = begin;
generator.End = end;
generator.Step = TimeSpan.FromSeconds(stepSeconds);
generator.WithCharts = true;
generator.WithEvents = true;
return generator;
}
}
}