diff --git a/BMA.EHR.Application/ApplicationServicesRegistration.cs b/BMA.EHR.Application/ApplicationServicesRegistration.cs index 29d0f7b9..3f621d90 100644 --- a/BMA.EHR.Application/ApplicationServicesRegistration.cs +++ b/BMA.EHR.Application/ApplicationServicesRegistration.cs @@ -29,7 +29,7 @@ namespace BMA.EHR.Application services.AddTransient(); services.AddTransient(); services.AddTransient(); - + services.AddTransient(); services.AddTransient(); return services; diff --git a/BMA.EHR.Application/Repositories/Reports/TransferReportRepository.cs b/BMA.EHR.Application/Repositories/Reports/TransferReportRepository.cs new file mode 100644 index 00000000..b7b13e28 --- /dev/null +++ b/BMA.EHR.Application/Repositories/Reports/TransferReportRepository.cs @@ -0,0 +1,76 @@ +using System; +using System.Reflection.Metadata; +using System.Text.RegularExpressions; +using BMA.EHR.Application.Common.Interfaces; +using BMA.EHR.Application.Responses; +using BMA.EHR.Domain.Extensions; +using BMA.EHR.Domain.Models.HR; +using BMA.EHR.Domain.Models.Organizations; +using BMA.EHR.Domain.Models.Placement; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; + +namespace BMA.EHR.Application.Repositories.Reports +{ + public class TransferReportRepository + { + #region " Fields " + + private readonly IApplicationDBContext _dbContext; + private readonly IWebHostEnvironment _hostingEnvironment; + + #endregion + + #region " Constructor and Destructor " + + public TransferReportRepository(IApplicationDBContext dbContext, IWebHostEnvironment hostEnvironment) + { + _dbContext = dbContext; + _hostingEnvironment = hostEnvironment; + } + + #endregion + + #region " Methods " + + #region 2 + public async Task GetData2Transfer(Guid id) + { + var data = await _dbContext.Set().AsQueryable() + .Include(x => x.Profile) + .Where(x => x.Id == id) + .FirstOrDefaultAsync(); + + var currentdate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 16); + return new + { + CurrentDate = currentdate, + Subject = $"ข้าราชการกรุงเทพมหานครสามัญขอโอน", + Name = $"{data.Profile.Prefix?.Name}{data.Profile.FirstName} {data.Profile.LastName}", + }; + } + #endregion + + #region 3 + public async Task GetData3Transfer(Guid id) + { + var data = await _dbContext.Set().AsQueryable() + .Include(x => x.Profile) + .Where(x => x.Id == id) + .FirstOrDefaultAsync(); + var currentdate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 16); + return new + { + CurrentDate = currentdate, + Subject = $"ข้าราชการขอโอน", + Name = $"{data.Profile.Prefix?.Name}{data.Profile.FirstName} {data.Profile.LastName}", + }; + } + #endregion + + #endregion + } +} diff --git a/BMA.EHR.Report.Service/Controllers/TransferReportController.cs b/BMA.EHR.Report.Service/Controllers/TransferReportController.cs index 305ce236..48301117 100644 --- a/BMA.EHR.Report.Service/Controllers/TransferReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/TransferReportController.cs @@ -10,6 +10,7 @@ using DocumentFormat.OpenXml.Drawing; using Telerik.Reporting; using Telerik.Reporting.Processing; using System.IO; +using BMA.EHR.Application.Common.Interfaces; namespace BMA.EHR.Report.Service.Controllers { @@ -26,18 +27,18 @@ namespace BMA.EHR.Report.Service.Controllers private readonly IWebHostEnvironment _hostingEnvironment; private readonly IConfiguration _configuration; private readonly GenericReportGenerator _reportGenerator; - + private readonly TransferReportRepository _service; #endregion #region " Constuctor and Destructor " - public TransferReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator) + public TransferReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator, TransferReportRepository service) { - _hostingEnvironment = hostingEnvironment; _configuration = configuration; _reportGenerator = reportGenerator; + _service = service; } #endregion @@ -55,11 +56,11 @@ namespace BMA.EHR.Report.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("1/{exportType}/{id}")] - public IActionResult GetTransfer1ConvertReportAsync(Guid id, string exportType = "pdf") + public async Task > GetTransfer1ConvertReportAsync(Guid id, string exportType = "pdf") { try { - + var data = await _service.GetData2Transfer(id); var mimeType = ""; switch (exportType.Trim().ToLower()) { @@ -68,11 +69,27 @@ namespace BMA.EHR.Report.Service.Controllers case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } - var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-1.trdp"); - var contentData = _reportGenerator.GenerateReport(rptFile, exportType); + var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-1.trdp"); + ReportPackager reportPacker = new ReportPackager(); + Telerik.Reporting.Report? report = null; - return File(contentData, mimeType, $"transfer.{exportType.Trim().ToLower()}"); + using (var sourceStream = System.IO.File.OpenRead(rptFile)) + { + report = (Telerik.Reporting.Report)reportPacker.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 File(content, mimeType, $"หนังสือแจ้งสำนักงานการเจ้าหน้าที่.{exportType.Trim().ToLower()}"); } catch { @@ -92,11 +109,11 @@ namespace BMA.EHR.Report.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("2/{exportType}/{id}")] - public IActionResult GetTransfer2ConvertReportAsync(Guid id, string exportType = "pdf") + public async Task> GetTransfer2ConvertReportAsync(Guid id, string exportType = "pdf") { try { - + var data = await _service.GetData2Transfer(id); var mimeType = ""; switch (exportType.Trim().ToLower()) { @@ -105,11 +122,36 @@ namespace BMA.EHR.Report.Service.Controllers case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } - var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-1.trdp"); - var contentData = _reportGenerator.GenerateReport(rptFile, exportType); + var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-1.trdp"); + var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-2.trdp"); + ReportPackager reportPacker = new ReportPackager(); + Telerik.Reporting.Report? report = null; + Telerik.Reporting.Report? report2 = null; - return File(contentData, mimeType, $"transfer.{exportType.Trim().ToLower()}"); + using (var sourceStream = System.IO.File.OpenRead(rptFile)) + using (var sourceStream2 = System.IO.File.OpenRead(rptFile2)) + { + report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); + report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2); + } + report.DataSource = data; + report2.DataSource = data; + + var reportBook = new ReportBook(); + reportBook.Reports.Add(report); + reportBook.Reports.Add(report2); + + System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + InstanceReportSource instanceReportSource = new InstanceReportSource() + { + ReportDocument = reportBook, + }; + + ReportProcessor reportProcessor = new ReportProcessor(_configuration); + RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo); + var content = result.DocumentBytes; + return File(content, mimeType, $"หนังสือแจ้งสำนักงานการเจ้าหน้าที่.{exportType.Trim().ToLower()}"); } catch { @@ -122,18 +164,18 @@ namespace BMA.EHR.Report.Service.Controllers /// /// หนังสือยินยอมให้โอนและวันที่พร้อมจะให้โอนไปยัง หน่วยงานที่รับโอน /// - /// id + /// id /// pdf, docx หรือ xlsx /// - /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ - /// ไม่ได้ Login เข้าระบบ - /// เมื่อเกิดข้อผิดพลาดในการทำงาน + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("3/{exportType}/{id}")] - public IActionResult GetTransfer3ConvertReportAsync(Guid id, string exportType = "pdf") + public async Task> GetTransfer3ConvertReportAsync(Guid id, string exportType = "pdf") { try { - + var data = await _service.GetData3Transfer(id); var mimeType = ""; switch (exportType.Trim().ToLower()) { @@ -142,11 +184,36 @@ namespace BMA.EHR.Report.Service.Controllers case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } - var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-1.trdp"); - var contentData = _reportGenerator.GenerateReport(rptFile, exportType); + var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"23-หนังสือยินยอมให้โอน-1.trdp"); + var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"23-หนังสือยินยอมให้โอน-2.trdp"); + ReportPackager reportPacker = new ReportPackager(); + Telerik.Reporting.Report? report = null; + Telerik.Reporting.Report? report2 = null; - return File(contentData, mimeType, $"transfer.{exportType.Trim().ToLower()}"); + using (var sourceStream = System.IO.File.OpenRead(rptFile)) + using (var sourceStream2 = System.IO.File.OpenRead(rptFile2)) + { + report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); + report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2); + } + report.DataSource = data; + report2.DataSource = data; + + var reportBook = new ReportBook(); + reportBook.Reports.Add(report); + reportBook.Reports.Add(report2); + + System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + InstanceReportSource instanceReportSource = new InstanceReportSource() + { + ReportDocument = reportBook, + }; + + ReportProcessor reportProcessor = new ReportProcessor(_configuration); + RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo); + var content = result.DocumentBytes; + return File(content, mimeType, $"หนังสือยินยอมให้โอน.{exportType.Trim().ToLower()}"); } catch { diff --git a/BMA.EHR.Report.Service/Reports/22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-1.trdp b/BMA.EHR.Report.Service/Reports/22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-1.trdp new file mode 100644 index 00000000..6be7de0f Binary files /dev/null and b/BMA.EHR.Report.Service/Reports/22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-1.trdp differ diff --git a/BMA.EHR.Report.Service/Reports/22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-2.trdp b/BMA.EHR.Report.Service/Reports/22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-2.trdp new file mode 100644 index 00000000..c639afb7 Binary files /dev/null and b/BMA.EHR.Report.Service/Reports/22-หนังสือแจ้งสำนักงานการเจ้าหน้าที่-2.trdp differ diff --git a/BMA.EHR.Report.Service/Reports/23-หนังสือยินยอมให้โอน-1.trdp b/BMA.EHR.Report.Service/Reports/23-หนังสือยินยอมให้โอน-1.trdp new file mode 100644 index 00000000..1ec5e612 Binary files /dev/null and b/BMA.EHR.Report.Service/Reports/23-หนังสือยินยอมให้โอน-1.trdp differ diff --git a/BMA.EHR.Report.Service/Reports/23-หนังสือยินยอมให้โอน-2.trdp b/BMA.EHR.Report.Service/Reports/23-หนังสือยินยอมให้โอน-2.trdp new file mode 100644 index 00000000..8d3c5570 Binary files /dev/null and b/BMA.EHR.Report.Service/Reports/23-หนังสือยินยอมให้โอน-2.trdp differ diff --git a/BMA.EHR.Report.Service/Reports/37-คำสั่งให้ออกจากราชการ.trdp b/BMA.EHR.Report.Service/Reports/37-คำสั่งให้ออกจากราชการ.trdp index bb8c9a1c..d247dd58 100644 Binary files a/BMA.EHR.Report.Service/Reports/37-คำสั่งให้ออกจากราชการ.trdp and b/BMA.EHR.Report.Service/Reports/37-คำสั่งให้ออกจากราชการ.trdp differ