170 lines
No EOL
12 KiB
C#
170 lines
No EOL
12 KiB
C#
using BMA.EHR.Domain.Common;
|
|
using BMA.EHR.Domain.Extensions;
|
|
using BMA.EHR.Application.Repositories.Reports;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using Telerik.Reporting;
|
|
using Telerik.Reporting.Processing;
|
|
|
|
namespace BMA.EHR.Report.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/report/retire")]
|
|
[ApiVersion("2.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("API รายงานระบบเกษียณ")]
|
|
public class RetireReportController : BaseController
|
|
{
|
|
private readonly RetireReportRepository _service;
|
|
private readonly IWebHostEnvironment _hostingEnvironment;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public RetireReportController(RetireReportRepository service, IWebHostEnvironment hostingEnvironment, IConfiguration configuration)
|
|
{
|
|
_service = service;
|
|
_hostingEnvironment = hostingEnvironment;
|
|
_configuration = configuration;
|
|
}
|
|
|
|
#region 31-ประกาศเกษียณข้าราชการ & 32-ประกาศเกษียณลูกจ้างประจำ
|
|
/// <summary>
|
|
/// 31-ประกาศเกษียณข้าราชการ & 32-ประกาศเกษียณลูกจ้างประจำ
|
|
/// </summary>
|
|
/// <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>
|
|
[HttpGet("{exportType}/{Id}")]
|
|
public async Task<ActionResult<ResponseObject>> GetProfileRetirement([FromRoute] Guid Id, string exportType = "pdf")
|
|
{
|
|
var retire = await _service.GetProfileRetirementdAsync(Id);
|
|
if (retire != null)
|
|
{
|
|
var reportfile = string.Empty;
|
|
var returnfile = string.Empty;
|
|
exportType = exportType.Trim();
|
|
switch (retire.GetType().GetProperty("Type").GetValue(retire))
|
|
{
|
|
case "OFFICER":
|
|
if (string.IsNullOrEmpty(retire.GetType().GetProperty("TypeReport").GetValue(retire)))
|
|
{
|
|
reportfile = $"31-ประกาศเกษียณข้าราชการ-1.trdp";
|
|
returnfile = $"ประกาศเกษียณข้าราชการ.{exportType}";
|
|
}
|
|
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "ADD" || retire.GetType().GetProperty("TypeReport").GetValue(retire) == "EDIT")
|
|
{
|
|
reportfile = $"31-ประกาศเกษียณข้าราชการ-2.trdp";
|
|
returnfile = $"แก้ไขประกาศเกษียณข้าราชการ.{exportType}";
|
|
}
|
|
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "REMOVE")
|
|
{
|
|
reportfile = $"31-ประกาศเกษียณข้าราชการ-3.trdp";
|
|
returnfile = $"ยกเลิกประกาศเกษียณข้าราชการ.{exportType}";
|
|
}
|
|
else
|
|
{
|
|
return Error(retire.GetType().GetProperty("TypeReport").GetValue(retire));
|
|
}
|
|
break;
|
|
case "EMPLOYEE":
|
|
if (string.IsNullOrEmpty(retire.GetType().GetProperty("TypeReport").GetValue(retire)))
|
|
{
|
|
reportfile = $"32-ประกาศเกษียณลูกจ้างประจำ-1.trdp";
|
|
returnfile = $"ประกาศเกษียณลูกจ้างประจำ.{exportType}";
|
|
}
|
|
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "ADD" || retire.GetType().GetProperty("TypeReport").GetValue(retire) == "EDIT")
|
|
{
|
|
reportfile = $"32-ประกาศเกษียณลูกจ้างประจำ-2.trdp";
|
|
returnfile = $"แก้ไขประกาศเกษียณลูกจ้างประจำ.{exportType}";
|
|
}
|
|
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "REMOVE")
|
|
{
|
|
reportfile = $"32-ประกาศเกษียณลูกจ้างประจำ-3.trdp";
|
|
returnfile = $"ยกเลิกประกาศเกษียณลูกจ้างประจำ.{exportType}";
|
|
}
|
|
else
|
|
{
|
|
return Error(retire.GetType().GetProperty("TypeReport").GetValue(retire));
|
|
}
|
|
break;
|
|
default:
|
|
return Error(retire.GetType().GetProperty("Type").GetValue(retire));
|
|
}
|
|
|
|
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", reportfile);
|
|
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.ReportParameters["Type"].Value = (returnfile != "ยกเลิกประกาศเกษียณข้าราชการ.pdf" && returnfile != "ยกเลิกประกาศเกษียณข้าราชการ.docx") && (returnfile != "แก้ไขประกาศเกษียณข้าราชการ.pdf" && returnfile != "แก้ไขประกาศเกษียณข้าราชการ.docx") && (returnfile != "ยกเลิกประกาศเกษียณลูกจ้างประจำ.pdf" && returnfile != "ยกเลิกประกาศเกษียณลูกจ้างประจำ.docx") && (returnfile != "แก้ไขประกาศเกษียณลูกจ้างประจำ.pdf" && returnfile != "แก้ไขประกาศเกษียณลูกจ้างประจำ.docx") ? "1" : "0";
|
|
var _profileList = new List<dynamic>();
|
|
var _count = 0;
|
|
var tmpOc1 = string.Empty;
|
|
foreach (var profile in retire.GetType().GetProperty("profile").GetValue(retire))
|
|
{
|
|
var tmpOc2 = profile.GetType().GetProperty("oc").GetValue(profile);
|
|
if (tmpOc1 != tmpOc2)
|
|
{
|
|
_count = 1;
|
|
tmpOc1 = tmpOc2;
|
|
}
|
|
else
|
|
{
|
|
_count++;
|
|
}
|
|
string thaiOrder = profile.GetType().GetProperty("order").GetValue(profile).ToString();
|
|
thaiOrder = $"ลำดับที่ {thaiOrder.ToThaiNumber()}";
|
|
_profileList.Add(new
|
|
{
|
|
count = $"{_count.ToString().ToThaiNumber()}.",
|
|
no = $"{(_profileList.Count() + 1).ToString().ToThaiNumber()}.",
|
|
order = thaiOrder,
|
|
oc = string.IsNullOrEmpty(profile.GetType().GetProperty("oc").GetValue(profile)) ? string.Empty : profile.GetType().GetProperty("oc").GetValue(profile),
|
|
fullName = string.IsNullOrEmpty(profile.GetType().GetProperty("fullName").GetValue(profile)) ? string.Empty : profile.GetType().GetProperty("fullName").GetValue(profile),
|
|
position = string.IsNullOrEmpty(profile.GetType().GetProperty("position").GetValue(profile)) ? string.Empty : profile.GetType().GetProperty("position").GetValue(profile),
|
|
posNo = string.IsNullOrEmpty(profile.GetType().GetProperty("posNo").GetValue(profile)) ? string.Empty : profile.GetType().GetProperty("posNo").GetValue(profile),
|
|
organizationOrganization = string.IsNullOrEmpty(profile.GetType().GetProperty("organizationOrganization").GetValue(profile)) ? string.Empty : profile.GetType().GetProperty("organizationOrganization").GetValue(profile),
|
|
positionEmployeePosition = string.IsNullOrEmpty(profile.GetType().GetProperty("positionEmployeePosition").GetValue(profile)) ? string.Empty : profile.GetType().GetProperty("positionEmployeePosition").GetValue(profile),
|
|
posNoEmployee = string.IsNullOrEmpty(profile.GetType().GetProperty("posNoEmployee").GetValue(profile)) ? string.Empty : profile.GetType().GetProperty("posNoEmployee").GetValue(profile),
|
|
reason = string.IsNullOrEmpty(profile.GetType().GetProperty("reason").GetValue(profile)) ? string.Empty : profile.GetType().GetProperty("reason").GetValue(profile),
|
|
});
|
|
}
|
|
//Binding Data
|
|
if (report.ReportParameters["Type"].Value == "1")
|
|
{
|
|
report.ReportParameters["Year"].Value = string.IsNullOrEmpty(retire.GetType().GetProperty("Year").GetValue(retire)) ? string.Empty : retire.GetType().GetProperty("Year").GetValue(retire);
|
|
report.ReportParameters["Total"].Value = string.IsNullOrEmpty(retire.GetType().GetProperty("Total").GetValue(retire)) ? string.Empty : retire.GetType().GetProperty("Total").GetValue(retire);
|
|
report.ReportParameters["Detail"].Value = string.IsNullOrEmpty(retire.GetType().GetProperty("Detail").GetValue(retire)) ? string.Empty : retire.GetType().GetProperty("Detail").GetValue(retire);
|
|
report.DataSource = _profileList;
|
|
}
|
|
else
|
|
{
|
|
report.DataSource = retire;
|
|
var tblProfile = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];
|
|
tblProfile.DataSource = _profileList;
|
|
}
|
|
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, $"application/{exportType}", returnfile);
|
|
}
|
|
else
|
|
{
|
|
return NotFound();
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |