diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs index 9ebcf854..7f47b570 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs @@ -3,10 +3,6 @@ using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Application.Repositories.Reports; using BMA.EHR.Application.Responses; using BMA.EHR.Domain.Common; -using BMA.EHR.Domain.Extensions; -using BMA.EHR.Domain.Models.HR; -using BMA.EHR.Domain.Models.MetaData; -using BMA.EHR.Domain.Models.Notifications; using BMA.EHR.Domain.Models.Retirement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -18,10 +14,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Swashbuckle.AspNetCore.Annotations; using System.Net.Http.Headers; -using System.Reflection.Metadata; using System.Security.Claims; -using System.Security.Cryptography; -using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace BMA.EHR.Retirement.Service.Controllers { @@ -747,5 +740,63 @@ namespace BMA.EHR.Retirement.Service.Controllers return Success(); } + /// + /// 36-บันทึกเวียนแจ้งการถึงแก่กรรม + /// + /// Id รายการบันทึกเวียนแจ้งการถึงแก่กรรม + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("36/{exportType}/{id}")] + public async Task> GetDeceasedReportAsync(Guid id, string exportType = "pdf") + { + try + { + var head = await _repositoryRetireReport.GetHeadRetirementDeceasedAsync(id); + var detail = await _repositoryRetireReport.GetRetirementDeceasedAsync(id); + if (detail != null && head != null) + { + var mergeData = new + { + Oc = head.GetType().GetProperty("Oc").GetValue(head), + Number = head.GetType().GetProperty("Number").GetValue(head), + Date = head.GetType().GetProperty("Date").GetValue(head), + Subject = head.GetType().GetProperty("Subject").GetValue(head), + Send = head.GetType().GetProperty("Send").GetValue(head), + FullName = detail.GetType().GetProperty("FullName").GetValue(detail), + Position = detail.GetType().GetProperty("Position").GetValue(detail), + Reason = detail.GetType().GetProperty("Reason").GetValue(detail), + DeceasedDate = detail.GetType().GetProperty("Date").GetValue(detail), + CurrentDate = detail.GetType().GetProperty("CurrentDate").GetValue(detail), + DeceasedNumber = detail.GetType().GetProperty("Number").GetValue(detail), + Location = detail.GetType().GetProperty("Location").GetValue(detail), + }; + 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 data = new + { + template = "deceased", + reportName = "docx-report", + data = mergeData + }; + return Success(data); + } + else + { + return NotFound(); + } + } + catch + { + throw; + } + } } }