เพิ่ม api รายงานประกาศเกษียณข้าราชการ/ move old template

This commit is contained in:
Harid Promsri (Bright) 2023-08-23 13:50:44 +07:00
parent c179b14839
commit 24bc852341
88 changed files with 39 additions and 29 deletions

View file

@ -3,8 +3,6 @@ using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Retirement; using BMA.EHR.Domain.Models.Retirement;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
//using Telerik.Reporting;
//using Telerik.Reporting.Processing;
namespace BMA.EHR.Application.Repositories.Reports namespace BMA.EHR.Application.Repositories.Reports
{ {
@ -123,27 +121,6 @@ namespace BMA.EHR.Application.Repositories.Reports
return new { retire.Id, retire.CreatedAt, Year = retire.Year.ToThaiYear().ToString().ToThaiNumber(), retire.Round, retire.Type, retire.TypeReport, Total = profile_retire.Count.ToString().ToThaiNumber(), profile = profile_retire }; return new { retire.Id, retire.CreatedAt, Year = retire.Year.ToThaiYear().ToString().ToThaiNumber(), retire.Round, retire.Type, retire.TypeReport, Total = profile_retire.Count.ToString().ToThaiNumber(), profile = profile_retire };
} }
//Report
//var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"32-ประกาศเกษียณลูกจ้างประจำ.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);
//}
//System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
//InstanceReportSource instanceReportSource = new InstanceReportSource()
//{
// ReportDocument = report,
//};
//ReportProcessor reportProcessor = new ReportProcessor(_configuration);
//RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
//var content = result.DocumentBytes;
//return File(content, "application/pdf", $"ประกาศเกษียณลูกจ้างประจำ_{null}.pdf");
} }
#endregion #endregion

View file

@ -2,6 +2,7 @@
using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Extensions;
using BMA.EHR.Application.Repositories.Reports; using BMA.EHR.Application.Repositories.Reports;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Swashbuckle.AspNetCore.Annotations; using Swashbuckle.AspNetCore.Annotations;
using Telerik.Reporting; using Telerik.Reporting;
using Telerik.Reporting.Processing; using Telerik.Reporting.Processing;
@ -12,8 +13,8 @@ namespace BMA.EHR.Report.Service.Controllers
[ApiVersion("1.0")] [ApiVersion("1.0")]
[ApiController] [ApiController]
[Produces("application/json")] [Produces("application/json")]
//[Authorize] [Authorize]
[SwaggerTag("API รายงานระบบเกษียณ")] [SwaggerTag("รายงานระบบเกษียณ")]
public class RetireReportController : BaseController public class RetireReportController : BaseController
{ {
private readonly RetireReportRepository _service; private readonly RetireReportRepository _service;
@ -33,11 +34,44 @@ namespace BMA.EHR.Report.Service.Controllers
var retire = await _service.GetProfileRetirementdAsync(Id); var retire = await _service.GetProfileRetirementdAsync(Id);
if (retire == null) if (retire == null)
{ {
return NotFound(retire); return NotFound();
} }
else else
{ {
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"32-ประกาศเกษียณลูกจ้างประจำ.trdp"); var reportfile = "";
var returnfile = "";
switch (retire.GetType().GetProperty("Type").GetValue(retire))
{
case "OFFICER":
if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "ADD")
{
reportfile = $"31-ประกาศเกษียณข้าราชการ-1.trdp";
returnfile = $"ประกาศเกษียณข้าราชการ.pdf";
}
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "EDIT")
{
reportfile = $"31-ประกาศเกษียณข้าราชการ-2.trdp";
returnfile = $"แก้ไขประกาศเกษียณข้าราชการ.pdf";
}
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "REMOVE")
{
reportfile = $"31-ประกาศเกษียณข้าราชการ-3.trdp";
returnfile = $"ยกเลิกประกาศเกษียณข้าราชการ.pdf";
}
else
{
return Error(retire.GetType().GetProperty("TypeReport").ToString());
}
break;
case "EMPLOYEE":
reportfile = $"32-ประกาศเกษียณลูกจ้างประจำ.trdp";
returnfile = $"ประกาศเกษียณลูกจ้าง";
break;
default:
return BadRequest(retire);
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", reportfile);
ReportPackager reportPacker = new ReportPackager(); ReportPackager reportPacker = new ReportPackager();
Telerik.Reporting.Report? report = null; Telerik.Reporting.Report? report = null;
using (var sourceStream = System.IO.File.OpenRead(rptFile)) using (var sourceStream = System.IO.File.OpenRead(rptFile))
@ -78,9 +112,8 @@ namespace BMA.EHR.Report.Service.Controllers
ReportProcessor reportProcessor = new ReportProcessor(_configuration); ReportProcessor reportProcessor = new ReportProcessor(_configuration);
RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
var content = result.DocumentBytes; var content = result.DocumentBytes;
return File(content, "application/pdf", $"ประกาศเกษียณลูกจ้างประจำ{null}.pdf"); return File(content, "application/pdf", returnfile);
} }
//return Success(retire);
} }