api รายงานขอโอน

This commit is contained in:
Harid Promsri (Bright) 2023-09-26 15:09:01 +07:00
parent 59f782e8cf
commit 83dba4373b
8 changed files with 166 additions and 23 deletions

View file

@ -10,6 +10,7 @@ using DocumentFormat.OpenXml.Drawing;
using Telerik.Reporting;
using Telerik.Reporting.Processing;
using System.IO;
using BMA.EHR.Application.Common.Interfaces;
namespace BMA.EHR.Report.Service.Controllers
{
@ -26,18 +27,18 @@ namespace BMA.EHR.Report.Service.Controllers
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly IConfiguration _configuration;
private readonly GenericReportGenerator _reportGenerator;
private readonly TransferReportRepository _service;
#endregion
#region " Constuctor and Destructor "
public TransferReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator)
public TransferReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator, TransferReportRepository service)
{
_hostingEnvironment = hostingEnvironment;
_configuration = configuration;
_reportGenerator = reportGenerator;
_service = service;
}
#endregion
@ -55,11 +56,11 @@ namespace BMA.EHR.Report.Service.Controllers
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("1/{exportType}/{id}")]
public IActionResult GetTransfer1ConvertReportAsync(Guid id, string exportType = "pdf")
public async Task <ActionResult<ResponseObject>> GetTransfer1ConvertReportAsync(Guid id, string exportType = "pdf")
{
try
{
var data = await _service.GetData2Transfer(id);
var mimeType = "";
switch (exportType.Trim().ToLower())
{
@ -68,11 +69,27 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-1.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-1.trdp");
ReportPackager reportPacker = new ReportPackager();
Telerik.Reporting.Report? report = null;
return File(contentData, mimeType, $"transfer.{exportType.Trim().ToLower()}");
using (var sourceStream = System.IO.File.OpenRead(rptFile))
{
report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream);
}
report.DataSource = data;
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
InstanceReportSource instanceReportSource = new InstanceReportSource()
{
ReportDocument = report,
};
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo);
var content = result.DocumentBytes;
return File(content, mimeType, $"หนังสือแจ้งสำนักงานการเจ้าหน้าที่.{exportType.Trim().ToLower()}");
}
catch
{
@ -92,11 +109,11 @@ namespace BMA.EHR.Report.Service.Controllers
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("2/{exportType}/{id}")]
public IActionResult GetTransfer2ConvertReportAsync(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetTransfer2ConvertReportAsync(Guid id, string exportType = "pdf")
{
try
{
var data = await _service.GetData2Transfer(id);
var mimeType = "";
switch (exportType.Trim().ToLower())
{
@ -105,11 +122,36 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-1.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-1.trdp");
var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-2.trdp");
ReportPackager reportPacker = new ReportPackager();
Telerik.Reporting.Report? report = null;
Telerik.Reporting.Report? report2 = null;
return File(contentData, mimeType, $"transfer.{exportType.Trim().ToLower()}");
using (var sourceStream = System.IO.File.OpenRead(rptFile))
using (var sourceStream2 = System.IO.File.OpenRead(rptFile2))
{
report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream);
report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2);
}
report.DataSource = data;
report2.DataSource = data;
var reportBook = new ReportBook();
reportBook.Reports.Add(report);
reportBook.Reports.Add(report2);
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
InstanceReportSource instanceReportSource = new InstanceReportSource()
{
ReportDocument = reportBook,
};
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo);
var content = result.DocumentBytes;
return File(content, mimeType, $"หนังสือแจ้งสำนักงานการเจ้าหน้าที่.{exportType.Trim().ToLower()}");
}
catch
{
@ -122,18 +164,18 @@ namespace BMA.EHR.Report.Service.Controllers
/// <summary>
/// หนังสือยินยอมให้โอนและวันที่พร้อมจะให้โอนไปยัง หน่วยงานที่รับโอน
/// </summary>
/// <param name="id">id </param>
/// <param name = "id" > id </param >
/// <param name="exportType">pdf, docx หรือ xlsx</param>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
/// <response code = "200" > เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code = "401" > ไม่ได้ Login เข้าระบบ</response>
/// <response code = "500" > เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("3/{exportType}/{id}")]
public IActionResult GetTransfer3ConvertReportAsync(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetTransfer3ConvertReportAsync(Guid id, string exportType = "pdf")
{
try
{
var data = await _service.GetData3Transfer(id);
var mimeType = "";
switch (exportType.Trim().ToLower())
{
@ -142,11 +184,36 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-1.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"23-หนังสือยินยอมให้โอน-1.trdp");
var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"23-หนังสือยินยอมให้โอน-2.trdp");
ReportPackager reportPacker = new ReportPackager();
Telerik.Reporting.Report? report = null;
Telerik.Reporting.Report? report2 = null;
return File(contentData, mimeType, $"transfer.{exportType.Trim().ToLower()}");
using (var sourceStream = System.IO.File.OpenRead(rptFile))
using (var sourceStream2 = System.IO.File.OpenRead(rptFile2))
{
report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream);
report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2);
}
report.DataSource = data;
report2.DataSource = data;
var reportBook = new ReportBook();
reportBook.Reports.Add(report);
reportBook.Reports.Add(report2);
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
InstanceReportSource instanceReportSource = new InstanceReportSource()
{
ReportDocument = reportBook,
};
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo);
var content = result.DocumentBytes;
return File(content, mimeType, $"หนังสือยินยอมให้โอน.{exportType.Trim().ToLower()}");
}
catch
{