forked from ddrilling/AsbCloudServer
#7987467 report
This commit is contained in:
parent
54d68cc52d
commit
e9bd1e4789
20
AsbCloudApp/Services/IProcessMapReportService.cs
Normal file
20
AsbCloudApp/Services/IProcessMapReportService.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Сервис формирования РТК.
|
||||
/// </summary>
|
||||
public interface IProcessMapReportService
|
||||
{
|
||||
/// <summary>
|
||||
/// Сформировать.
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<Stream> MakeReportAsync(int idWell, CancellationToken token = default);
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
<None Remove="CommonLibs\logo_720x404.png" />
|
||||
<None Remove="CommonLibs\Readme.md" />
|
||||
<None Remove="Services\DailyReport\DailyReportTemplate.xlsx" />
|
||||
<None Remove="Services\ProcessMap\ProcessMapReportTemplate.xlsx" />
|
||||
<None Remove="Services\WellOperationService\ScheduleReportTemplate.xlsx" />
|
||||
<None Remove="Services\WellOperationService\WellOperationImportTemplate.xlsx" />
|
||||
<None Remove="Services\DailyReport\DailyReportBlocks\" />
|
||||
@ -28,6 +29,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Services\DailyReport\DailyReportTemplate.xlsx" />
|
||||
<EmbeddedResource Include="Services\ProcessMap\ProcessMapReportTemplate.xlsx" />
|
||||
<EmbeddedResource Include="Services\WellOperationService\ScheduleReportTemplate.xlsx" />
|
||||
<EmbeddedResource Include="Services\WellOperationService\WellOperationImportTemplate.xlsx" />
|
||||
</ItemGroup>
|
||||
|
@ -12,6 +12,7 @@ using AsbCloudInfrastructure.Services;
|
||||
using AsbCloudInfrastructure.Services.DailyReport;
|
||||
using AsbCloudInfrastructure.Services.DetectOperations;
|
||||
using AsbCloudInfrastructure.Services.DrillingProgram;
|
||||
using AsbCloudInfrastructure.Services.ProcessMap;
|
||||
using AsbCloudInfrastructure.Services.SAUB;
|
||||
using AsbCloudInfrastructure.Services.Subsystems;
|
||||
using AsbCloudInfrastructure.Services.WellOperationService;
|
||||
@ -134,6 +135,7 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<IWellFinalDocumentsService, WellFinalDocumentsService>();
|
||||
services.AddTransient<IFileCategoryService, FileCategoryService>();
|
||||
services.AddTransient<ILimitingParameterService, LimitingParameterService>();
|
||||
services.AddTransient<IProcessMapReportService, ProcessMapReportService>();
|
||||
|
||||
// admin crud services:
|
||||
services.AddTransient<ICrudRepository<TelemetryDto>, CrudCacheRepositoryBase<TelemetryDto, Telemetry>>(s =>
|
||||
|
@ -0,0 +1,55 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -20,12 +20,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
public class ProcessMapController : CrudWellRelatedController<ProcessMapDto, IProcessMapRepository>
|
||||
{
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly IProcessMapReportService processMapReportService;
|
||||
|
||||
public ProcessMapController(IWellService wellService, IProcessMapRepository service,
|
||||
public ProcessMapController(IWellService wellService, IProcessMapRepository repository, IProcessMapReportService processMapReportService,
|
||||
ITelemetryService telemetryService)
|
||||
: base(wellService, service)
|
||||
: base(wellService, repository)
|
||||
{
|
||||
this.telemetryService = telemetryService;
|
||||
this.processMapReportService = processMapReportService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -77,14 +79,28 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// Выгрузка расширенной РТК
|
||||
/// </summary>
|
||||
/// <param name="wellId"></param>
|
||||
/// /// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
[HttpGet]
|
||||
[Route("getReportFile/{wellId}")]
|
||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
||||
public Task<IActionResult> GetReportFileAsync(int wellId)
|
||||
public async Task<IActionResult> GetReportFileAsync(int wellId, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var stream = await processMapReportService.MakeReportAsync(wellId, token);
|
||||
if (stream != null)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(wellId, token);
|
||||
if (well is null)
|
||||
return NoContent();
|
||||
else
|
||||
{
|
||||
var fileName = $"РТК по скважине {well.Caption} куст {well.Cluster}.xlsx";
|
||||
return File(stream, "application/octet-stream", fileName);
|
||||
}
|
||||
}
|
||||
else
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user