แก้ไข api รายงานบันทึกเวียนแจ้งการถึงแก่กรรม (ขาดบางฟิลด์)

This commit is contained in:
Harid Promsri (Bright) 2023-09-13 14:29:53 +07:00
parent cfaf90cb01
commit e801653d60
3 changed files with 98 additions and 15 deletions

View file

@ -26,18 +26,19 @@ namespace BMA.EHR.Report.Service.Controllers
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly IConfiguration _configuration;
private readonly GenericReportGenerator _reportGenerator;
private readonly RetireReportRepository _repository;
#endregion
#region " Constuctor and Destructor "
public DeceasedReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator)
public DeceasedReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator, RetireReportRepository repository)
{
_hostingEnvironment = hostingEnvironment;
_configuration = configuration;
_reportGenerator = reportGenerator;
_repository = repository;
}
#endregion
@ -55,23 +56,42 @@ namespace BMA.EHR.Report.Service.Controllers
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("36/{exportType}/{id}")]
public IActionResult GetDeceasedConvertReportAsync(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetDeceasedReportAsync(Guid id, string exportType = "pdf")
{
try
{
var mimeType = "";
switch (exportType.Trim().ToLower())
var data = await _repository.GetRetirementDeceasedAsync(id);
if (data != null)
{
case "pdf": mimeType = "application/pdf"; break;
case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
var mimeType = "";
switch (exportType.Trim().ToLower())
{
case "pdf": mimeType = "application/pdf"; break;
case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp");
ReportPackager reportPacker = new ReportPackager();
Telerik.Reporting.Report? report = null;
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);
return File(result.DocumentBytes, mimeType, $"deceased.{exportType.Trim().ToLower()}");
}
else
{
return NotFound();
}
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
return File(contentData, mimeType, $"deceased.{exportType.Trim().ToLower()}");
}
catch
{