From 160ff2abcf4fc4a6f63b067637ef09c5ca41ab86 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 24 Aug 2023 12:31:16 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD?= =?UTF-8?q?=E0=B8=A1=E0=B8=90=E0=B8=B2=E0=B8=99=E0=B8=82=E0=B9=89=E0=B8=AD?= =?UTF-8?q?=E0=B8=A1=E0=B8=B9=E0=B8=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CommandReportController.cs | 126 +++--------------- 1 file changed, 21 insertions(+), 105 deletions(-) diff --git a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs index 04116742..c6a6309f 100644 --- a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs @@ -49,6 +49,8 @@ namespace BMA.EHR.Report.Service.Controllers #region " Private " + #region " C-PM-01 " + private async Task GenerateCommandReportType01_Cover(Guid commandId, string exportType) { try @@ -158,6 +160,8 @@ namespace BMA.EHR.Report.Service.Controllers #endregion + #endregion + #region " C-PM-01 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้ " /// @@ -174,7 +178,7 @@ namespace BMA.EHR.Report.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public IActionResult GetCommandType01CoverReport(Guid id, string exportType = "pdf") + public async Task> GetCommandType01CoverReportAsync(Guid id, string exportType = "pdf") { try { @@ -186,10 +190,16 @@ namespace BMA.EHR.Report.Service.Controllers case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp"); - var contentData = _reportGenerator.GenerateReport(rptFile, exportType); + var cmd = await _repository.GetByIdAsync(id); + if (cmd == null) + throw new Exception(GlobalMessages.CommandNotFound); - return File(contentData, mimeType, $"command.{exportType.Trim().ToLower()}"); + var contentData = await GenerateCommandReportType01_Cover(id, exportType); + return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); + + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp"); + //var contentData = _reportGenerator.GenerateReport(rptFile, exportType); + //return File(contentData, mimeType, $"command.{exportType.Trim().ToLower()}"); } catch { @@ -211,10 +221,14 @@ namespace BMA.EHR.Report.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public IActionResult GetCommandType01AttachmentReport(Guid id, string exportType = "pdf") + public async Task> GetCommandType01AttachmentReportAsync(Guid id, string exportType = "pdf") { try { + var cmd = await _repository.GetByIdAsync(id); + if (cmd == null) + throw new Exception(GlobalMessages.CommandNotFound); + var mimeType = ""; switch (exportType.Trim().ToLower()) { @@ -223,10 +237,8 @@ namespace BMA.EHR.Report.Service.Controllers case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-2.trdp"); - var contentData = _reportGenerator.GenerateReport(rptFile, exportType); - - return File(contentData, mimeType, $"command-attachment.{exportType.Trim().ToLower()}"); + var contentData = await GenerateCommandReportType01_Attachment(id, exportType); + return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); } catch { @@ -1465,102 +1477,6 @@ namespace BMA.EHR.Report.Service.Controllers #endregion - /// - /// รายงานหน้าคำสั่ง - /// - /// Record Id ของคำสั่ง - /// pdf, docx หรือ xlsx - /// - /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ - /// ไม่ได้ Login เข้าระบบ - /// เมื่อเกิดข้อผิดพลาดในการทำงาน - [HttpGet("cover/{exportType}/{id}")] - [AllowAnonymous] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status401Unauthorized)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task> GetCommandCoverReportAsync(Guid id, string exportType = "pdf") - { - try - { - var cmd = await _repository.GetByIdAsync(id); - if (cmd == null) - throw new Exception(GlobalMessages.CommandNotFound); - - 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; - } - - switch (cmd.CommandType.CommandCode.Trim().ToUpper()) - { - case "C-PM-01": - case "C-PM-02": - case "C-PM-03": - { - var contentData = await GenerateCommandReportType01_Cover(id, exportType); - return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); - } - default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); - } - } - catch - { - throw; - } - } - - /// - /// รายงานเอกสารแนบท้าย - /// - /// Record Id ของคำสั่ง - /// pdf, docx หรือ xlsx - /// - /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ - /// ไม่ได้ Login เข้าระบบ - /// เมื่อเกิดข้อผิดพลาดในการทำงาน - [HttpGet("attachment/{exportType}/{id}")] - [AllowAnonymous] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status401Unauthorized)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task> GetCommandAttachmentReportAsync(Guid id, string exportType = "pdf") - { - try - { - var cmd = await _repository.GetByIdAsync(id); - if (cmd == null) - throw new Exception(GlobalMessages.CommandNotFound); - - 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; - } - - switch (cmd.CommandType.CommandCode.Trim().ToUpper()) - { - case "C-PM-01": - case "C-PM-02": - case "C-PM-03": - { - var contentData = await GenerateCommandReportType01_Attachment(id, exportType); - return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); - } - default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); - } - } - catch - { - throw; - } - } - #endregion } }