From 1d3f8973e0cea3453c2b5e698ea24b56225fc6b9 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 3 Apr 2025 11:51:50 +0700 Subject: [PATCH] no message --- .../RetirementDeceasedController.cs | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs index 27ce95c8..31add2a5 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs @@ -15,6 +15,7 @@ using Newtonsoft.Json.Linq; using Swashbuckle.AspNetCore.Annotations; using System.Net.Http.Headers; using System.Security.Claims; +using System.Text; namespace BMA.EHR.Retirement.Service.Controllers { @@ -882,5 +883,86 @@ namespace BMA.EHR.Retirement.Service.Controllers throw; } } + + /// + /// รายงานบันทึกเวียนแจ้งการถึงแก่กรรม + /// + /// Id รายการบันทึกเวียนแจ้งการถึงแก่กรรม + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("report/36/{id}")] + public async Task> GetDeceasedNotiReportAsync(Guid id) + { + try + { + var head = await _repositoryRetireReport.GetHeadRetirementDeceasedAsync(id); + var detail = await _repositoryRetireReport.GetRetirementDeceasedAsync(id); + + if (detail == null || head == null) + { + return Error("รายการบันทึกเวียนแจ้งการถึงแก่กรรม", 404); + } + + 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 reqPayload = new + { + template = "deceased", + reportName = "docx-report", + data = mergeData + }; + + + //using (var client = new HttpClient()) + //{ + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + // var _req = new HttpRequestMessage(HttpMethod.Post, _apiUrl); + // var _res = await client.PostAsJsonAsync(_apiUrl, new + // { + // isLeave = true, + // leaveReason = "ถึงแก่กรรม", + // dateLeave = req.Date, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + //} + + + var apiUrl = "https://report-server.frappet.synology.me/api/v1/report-template/docx"; + using (var client = new HttpClient()) + { + //client.DefaultRequestHeaders.Add("accept", "application/pdf"); + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/pdf")); + var _res = await client.PostAsJsonAsync(apiUrl, reqPayload); + + if (_res.IsSuccessStatusCode) + { + var fileBytes = await _res.Content.ReadAsByteArrayAsync(); + return File(fileBytes, "application/pdf", "report"); + } + return NotFound(); + } + } + catch + { + throw; + } + } } }