diff --git a/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs index d0112a7c..013b70a9 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs @@ -1,4 +1,6 @@ -using BMA.EHR.Application.Common.Interfaces; +using Amazon.Runtime.Internal.Transform; +using Amazon.S3.Model.Internal.MarshallTransformations; +using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Application.Responses.Reports; using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Commands.Core; @@ -460,6 +462,76 @@ namespace BMA.EHR.Application.Repositories.Commands } } + public async Task> GetCommandType11Async(Guid id) + { + try + { + var raw_data = await _dbContext.Set() + .Include(c => c.Command) + .Where(c => c.Command.Id == id) + .Select(r => new CommandType11Response + { + CommandNo = r.Command.CommandNo, + CommandYear = r.Command.CommandYear, + CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3(), + IssuerOrganizationName = r.Command.IssuerOrganizationName, + AuthorizedUserFullName = r.Command.AuthorizedUserFullName, + AuthorizedPosition = r.Command.AuthorizedPosition, + CitizenId = r.CitizenId, + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + PlacementCommandIssuer = r.Command.PlacementCommandIssuer, + PlacementCommandNo = r.Command.PlacementCommandNo, + PlacementCommandDate = r.Command.PlacementCommandDate == null ? "" : r.Command.PlacementCommandDate.Value.ToThaiFullDate3() + }) + .ToListAsync(); + if (raw_data == null) + { + throw new Exception(GlobalMessages.CommandNotFound); + } + + return raw_data; + } + catch + { + throw; + } + } + + public async Task> GetCommandType12Async(Guid id) + { + try + { + var raw_data = await _dbContext.Set() + .Include(c => c.Command) + .Where(c => c.Command.Id == id) + .Select(r => new CommandType11Response + { + CommandNo = r.Command.CommandNo, + CommandYear = r.Command.CommandYear, + CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3(), + IssuerOrganizationName = r.Command.IssuerOrganizationName, + AuthorizedUserFullName = r.Command.AuthorizedUserFullName, + AuthorizedPosition = r.Command.AuthorizedPosition, + CitizenId = r.CitizenId, + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + PlacementCommandIssuer = r.Command.PlacementCommandIssuer, + PlacementCommandNo = r.Command.PlacementCommandNo, + PlacementCommandDate = r.Command.PlacementCommandDate == null ? "" : r.Command.PlacementCommandDate.Value.ToThaiFullDate3() + }) + .ToListAsync(); + if (raw_data == null) + { + throw new Exception(GlobalMessages.CommandNotFound); + } + + return raw_data; + } + catch + { + throw; + } + } + public async Task> GetCommandType15AttachmentAsync(Guid id) { try diff --git a/BMA.EHR.Application/Responses/Reports/CommandType11Response.cs b/BMA.EHR.Application/Responses/Reports/CommandType11Response.cs new file mode 100644 index 00000000..7e45cdac --- /dev/null +++ b/BMA.EHR.Application/Responses/Reports/CommandType11Response.cs @@ -0,0 +1,27 @@ +namespace BMA.EHR.Application.Responses.Reports +{ + public class CommandType11Response + { + public string CommandNo { get; set; } = string.Empty; + + public string CommandYear { get; set; } = string.Empty; + + public string IssuerOrganizationName { get; set; } = string.Empty; + + public string CommandAffectDate { get; set; } = string.Empty; + + public string AuthorizedUserFullName { get; set; } = string.Empty; + + public string AuthorizedPosition { get; set; } = string.Empty; + + public string CitizenId { get; set; } = string.Empty; + + public string FullName { get; set; } = string.Empty; + + public string PlacementCommandIssuer { get; set; } = string.Empty; + + public string PlacementCommandNo { get; set; } = string.Empty; + + public string PlacementCommandDate { get; set; } = string.Empty; + } +} diff --git a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs index 9224b3fe..961c766f 100644 --- a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs @@ -70,7 +70,7 @@ namespace BMA.EHR.Report.Service.Controllers CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(), IssuerOrganizationName = raw_data.IssuerOrganizationName, ConclusionRegisterNo = raw_data.ConclusionRegisterNo, - ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "": raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(), + ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(), ConclusionResultNo = raw_data.ConclusionResultNo, ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(), PositionList = "", @@ -92,7 +92,7 @@ namespace BMA.EHR.Report.Service.Controllers report.DataSource = command; System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - if(exportType == "docx") + if (exportType == "docx") deviceInfo["OutputFormat"] = "DOCX"; InstanceReportSource instanceReportSource = new InstanceReportSource() @@ -1196,6 +1196,100 @@ namespace BMA.EHR.Report.Service.Controllers #endregion + #region " C-PM-11 " + + private async Task GenerateCommandReportType11_Cover(Guid commandId, string exportType) + { + try + { + var command = await _repository.GetByIdAsync(commandId); + if (command == null) + { + throw new Exception(GlobalMessages.CommandNotFound); + } + + var data = await _commandReportRepository.GetCommandType11Async(commandId); + + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"11-คำสั่งให้ข้าราชการที่ผ่านการประเมิน รับราชการต่อไป.trdp"); + + ReportPackager reportPackager = new ReportPackager(); + Telerik.Reporting.Report? report = null; + using (var sourceStream = System.IO.File.OpenRead(rptFile)) + { + report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + } + + report.DataSource = data; + + 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 content; + } + catch + { + throw; + } + } + + #endregion + + #region " C-PM-12 " + + private async Task GenerateCommandReportType12_Cover(Guid commandId, string exportType) + { + try + { + var command = await _repository.GetByIdAsync(commandId); + if (command == null) + { + throw new Exception(GlobalMessages.CommandNotFound); + } + + var data = await _commandReportRepository.GetCommandType11Async(commandId); + + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"12-คำสั่งให้ข้าราชการที่ไม่ผ่านการประเมิน ออกจากราชการ.trdp"); + + ReportPackager reportPackager = new ReportPackager(); + Telerik.Reporting.Report? report = null; + using (var sourceStream = System.IO.File.OpenRead(rptFile)) + { + report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + } + + report.DataSource = data; + + 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 content; + } + catch + { + throw; + } + } + + #endregion + #region " C-PM-15 " private async Task GenerateCommandReportType15_Cover(Guid commandId, string exportType) @@ -1522,7 +1616,7 @@ namespace BMA.EHR.Report.Service.Controllers using (var sourceStream = System.IO.File.OpenRead(rptFile)) { report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); - } + } report.DataSource = data; @@ -2451,7 +2545,7 @@ namespace BMA.EHR.Report.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public IActionResult GetCommandType11CoverReport(Guid id, string exportType = "pdf") + public async Task> GetCommandType11CoverReportAsync(Guid id, string exportType = "pdf") { try { @@ -2463,10 +2557,12 @@ namespace BMA.EHR.Report.Service.Controllers case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"11-คำสั่งให้ข้าราชการที่ผ่านการประเมิน รับราชการต่อไป.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 GenerateCommandReportType11_Cover(id, exportType); + return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); } catch { @@ -2492,7 +2588,7 @@ namespace BMA.EHR.Report.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public IActionResult GetCommandType12CoverReport(Guid id, string exportType = "pdf") + public async Task> GetCommandType12CoverReportAsync(Guid id, string exportType = "pdf") { try { @@ -2504,10 +2600,12 @@ namespace BMA.EHR.Report.Service.Controllers case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"12-คำสั่งให้ข้าราชการที่ไม่ผ่านการประเมิน ออกจากราชการ.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 GenerateCommandReportType12_Cover(id, exportType); + return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); } catch { @@ -3009,6 +3107,47 @@ namespace BMA.EHR.Report.Service.Controllers #endregion + #region " C-PM-21 คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ " + + /// + /// คำสั่ง C-PM-21 คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("c-pm-21/cover/{exportType}/{id}")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public IActionResult GetCommandType21CoverReport(Guid id, string exportType = "pdf") + { + try + { + 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 rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"20-คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ-2.trdp"); + var contentData = _reportGenerator.GenerateReport(rptFile, exportType); + + return File(contentData, mimeType, $"command.{exportType.Trim().ToLower()}"); + } + catch + { + throw; + } + } + + #endregion + #endregion } } diff --git a/BMA.EHR.Report.Service/Reports/11-คำสั่งให้ข้าราชการที่ผ่านการประเมิน รับราชการต่อไป.trdp b/BMA.EHR.Report.Service/Reports/11-คำสั่งให้ข้าราชการที่ผ่านการประเมิน รับราชการต่อไป.trdp index 079b8903..fe6c4eea 100644 Binary files a/BMA.EHR.Report.Service/Reports/11-คำสั่งให้ข้าราชการที่ผ่านการประเมิน รับราชการต่อไป.trdp and b/BMA.EHR.Report.Service/Reports/11-คำสั่งให้ข้าราชการที่ผ่านการประเมิน รับราชการต่อไป.trdp differ diff --git a/BMA.EHR.Report.Service/Reports/12-คำสั่งให้ข้าราชการที่ไม่ผ่านการประเมิน ออกจากราชการ.trdp b/BMA.EHR.Report.Service/Reports/12-คำสั่งให้ข้าราชการที่ไม่ผ่านการประเมิน ออกจากราชการ.trdp index f99af7d9..c8b43e35 100644 Binary files a/BMA.EHR.Report.Service/Reports/12-คำสั่งให้ข้าราชการที่ไม่ผ่านการประเมิน ออกจากราชการ.trdp and b/BMA.EHR.Report.Service/Reports/12-คำสั่งให้ข้าราชการที่ไม่ผ่านการประเมิน ออกจากราชการ.trdp differ