From 81b2ad210bedb782fa72528c641e8d90e6a83457 Mon Sep 17 00:00:00 2001 From: "Harid Promsri (Bright)" Date: Tue, 22 Aug 2023 17:24:21 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=87?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A8=E0=B9=80=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93?= =?UTF-8?q?=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=88=E0=B8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApplicationServicesRegistration.cs | 2 + .../Reports/RetireReportRepository.cs | 138 ++++++++++++++---- BMA.EHR.Domain/Extensions/IntegerExtension.cs | 22 +++ .../Controllers/RetireReportController.cs | 78 +++++++++- .../Reports/32-ประกาศเกษียณลูกจ้างประจำ.trdp | Bin 29173 -> 29263 bytes 5 files changed, 211 insertions(+), 29 deletions(-) diff --git a/BMA.EHR.Application/ApplicationServicesRegistration.cs b/BMA.EHR.Application/ApplicationServicesRegistration.cs index 502acb37..911d01eb 100644 --- a/BMA.EHR.Application/ApplicationServicesRegistration.cs +++ b/BMA.EHR.Application/ApplicationServicesRegistration.cs @@ -1,6 +1,7 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.Commands; using BMA.EHR.Application.Repositories.MessageQueue; +using BMA.EHR.Application.Repositories.Reports; using Microsoft.Extensions.DependencyInjection; namespace BMA.EHR.Application @@ -23,6 +24,7 @@ namespace BMA.EHR.Application services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); return services; } diff --git a/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs b/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs index 672d378b..53f7141e 100644 --- a/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs @@ -1,13 +1,10 @@ using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Retirement; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//using Telerik.Reporting; +//using Telerik.Reporting.Processing; namespace BMA.EHR.Application.Repositories.Reports { @@ -16,46 +13,137 @@ namespace BMA.EHR.Application.Repositories.Reports #region " Fields " private readonly IApplicationDBContext _dbContext; + private readonly IWebHostEnvironment _hostingEnvironment; #endregion #region " Constructor and Destructor " - public RetireReportRepository(IApplicationDBContext dbContext) + public RetireReportRepository(IApplicationDBContext dbContext, IWebHostEnvironment hostEnvironment) { _dbContext = dbContext; + _hostingEnvironment = hostEnvironment; + } #endregion #region " Methods " - public async Task> GetListRetirePeriodAsync() + //public async Task> GetListRetirePeriodAsync(Guid Id) + //{ + // try + // { + // // 1. query + // //var data = await _dbContext.Set() + // // .Include(x => x.RetirementProfiles) + // // .ThenInclude(x => x.Profile) + // // .ToListAsync(); + + // // 2. data not found throw exception + + // // 3. Load Report File + + // //return data; + // } + // catch + // { + // throw; + // } + //} + + public async Task GetProfileRetirementdAsync(Guid retireId) { - try + var retire = await _dbContext.Set() + .Include(x => x.RetirementProfiles) + .FirstOrDefaultAsync(x => x.Id == retireId); + if (retire == null) { - // 1. query - var data = await _dbContext.Set() - .Include(x => x.RetirementPeriodHistorys) - .Include(x => x.RetirementProfiles) - .ThenInclude(x => x.Profile) - .ToListAsync(); + var retireHistorys = await _dbContext.Set().AsQueryable() + .FirstOrDefaultAsync(x => x.Id == retireId); + if (retireHistorys == null) + return null; - // 2. data not found throw exception - - - // 3. Load Report File - - - - return data; + var profile_retireHistory = await _dbContext.Set() + .Where(x => x.RetirementPeriod == retire) + .OrderBy(x => x.Order) + .Select(x => new + { + order = x.Order, + id = x.Id, + reason = x.Reason, + remove = x.Remove, + profileId = x.Profile.Id, + citizenId = x.Profile.CitizenId, + prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, + fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", + organizationOrganization = x.Profile.OrganizationOrganization, + oc = x.Profile.Oc, + position = x.Profile.Position == null ? null : x.Profile.Position.Name, + positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, + positionExecutive = x.Profile.PositionExecutive, + posNo = x.Profile.PosNo == null ? null : x.Profile.PosNo.Name, + positionEmployeePosition = x.Profile.PositionEmployeePosition, + positionEmployeeLevel = x.Profile.PositionEmployeeLevel, + positionEmployeeGroup = x.Profile.PositionEmployeeGroup, + posNoEmployee = x.Profile.PosNoEmployee, + }) + .ToListAsync(); + return new { retireHistorys.Id, retireHistorys.CreatedAt, Year = retireHistorys.Year.ToThaiYear().ToString().ToThaiNumber(), retireHistorys.Round, retireHistorys.Type, retireHistorys.TypeReport, Total = retireHistorys.Total.ToString().ToThaiNumber(), profile = profile_retireHistory }; } - catch + else { - throw; + var profile_retire = await _dbContext.Set() + .Where(x => x.RetirementPeriod == retire) + .OrderBy(x => x.Order) + .Select(x => new + { + order = x.Order, + id = x.Id, + reason = x.Reason, + remove = x.Remove, + profileId = x.Profile.Id, + citizenId = x.Profile.CitizenId, + prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, + fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", + organizationOrganization = x.Profile.OrganizationOrganization, + oc = x.Profile.Oc, + position = x.Profile.Position == null ? null : x.Profile.Position.Name, + positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, + positionExecutive = x.Profile.PositionExecutive, + posNo = x.Profile.PosNo == null ? null : x.Profile.PosNo.Name, + positionEmployeePosition = x.Profile.PositionEmployeePosition, + positionEmployeeLevel = x.Profile.PositionEmployeeLevel, + positionEmployeeGroup = x.Profile.PositionEmployeeGroup, + posNoEmployee = x.Profile.PosNoEmployee, + }) + .ToListAsync(); + + return new { retire.Id, retire.CreatedAt, Year = retire.Year.ToThaiYear().ToString().ToThaiNumber(), retire.Round, retire.Type, retire.TypeReport, Total = profile_retire.Count.ToString().ToThaiNumber(), profile = profile_retire }; } + + //Report + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"32-ประกาศเกษียณลูกจ้างประจำ.trdp"); + //ReportPackager reportPacker = new ReportPackager(); + //Telerik.Reporting.Report? report = null; + + //using (var sourceStream = System.IO.File.OpenRead(rptFile)) + //{ + // report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); + //} + + //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + //InstanceReportSource instanceReportSource = new InstanceReportSource() + //{ + // ReportDocument = report, + //}; + + //ReportProcessor reportProcessor = new ReportProcessor(_configuration); + //RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + //var content = result.DocumentBytes; + //return File(content, "application/pdf", $"ประกาศเกษียณลูกจ้างประจำ_{null}.pdf"); } #endregion diff --git a/BMA.EHR.Domain/Extensions/IntegerExtension.cs b/BMA.EHR.Domain/Extensions/IntegerExtension.cs index fc1a1857..730132fc 100644 --- a/BMA.EHR.Domain/Extensions/IntegerExtension.cs +++ b/BMA.EHR.Domain/Extensions/IntegerExtension.cs @@ -1,3 +1,5 @@ +using System.Text; + namespace BMA.EHR.Domain.Extensions { public static class IntegerExtension @@ -40,5 +42,25 @@ namespace BMA.EHR.Domain.Extensions { return number.ToString("#,##0"); } + + public static string ToThaiNumber(this string value) + { + string arabicNumbers = "0123456789"; + string thaiNumbers = "๐๑๒๓๔๕๖๗๘๙"; + StringBuilder ThaiYear = new StringBuilder(); + foreach (char digit in value) + { + int index = arabicNumbers.IndexOf(digit); + if (index >= 0) + { + ThaiYear.Append(thaiNumbers[index]); + } + else + { + ThaiYear.Append(digit); + } + } + return ThaiYear.ToString(); + } } } \ No newline at end of file diff --git a/BMA.EHR.Report.Service/Controllers/RetireReportController.cs b/BMA.EHR.Report.Service/Controllers/RetireReportController.cs index 918cbfce..27b829c7 100644 --- a/BMA.EHR.Report.Service/Controllers/RetireReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/RetireReportController.cs @@ -1,18 +1,88 @@ using BMA.EHR.Domain.Common; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; +using BMA.EHR.Domain.Extensions; +using BMA.EHR.Application.Repositories.Reports; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; +using Telerik.Reporting; +using Telerik.Reporting.Processing; namespace BMA.EHR.Report.Service.Controllers { [Route("api/v{version:apiVersion}/report/retire")] - [ApiVersion("2.0")] + [ApiVersion("1.0")] [ApiController] [Produces("application/json")] - [Authorize] + //[Authorize] [SwaggerTag("API รายงานระบบเกษียณ")] public class RetireReportController : BaseController { + private readonly RetireReportRepository _service; + private readonly IWebHostEnvironment _hostingEnvironment; + private readonly IConfiguration _configuration; + + public RetireReportController(RetireReportRepository service, IWebHostEnvironment hostingEnvironment, IConfiguration configuration) + { + _service = service; + _hostingEnvironment = hostingEnvironment; + _configuration = configuration; + } + + [HttpGet("{Id}")] + public async Task> GetProfileRetirement([FromRoute] Guid Id) + { + var retire = await _service.GetProfileRetirementdAsync(Id); + if (retire == null) + { + return NotFound(retire); + } + else + { + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"32-ประกาศเกษียณลูกจ้างประจำ.trdp"); + ReportPackager reportPacker = new ReportPackager(); + Telerik.Reporting.Report? report = null; + using (var sourceStream = System.IO.File.OpenRead(rptFile)) + { + report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); + } + //Add Parameter + report.ReportParameters["Year"].Value = retire.GetType().GetProperty("Year").GetValue(retire); + report.ReportParameters["Total"].Value = retire.GetType().GetProperty("Total").GetValue(retire); + + var _profileList = new List(); + + foreach (var profile in retire.GetType().GetProperty("profile").GetValue(retire)) + { + string thaiOrder = profile.GetType().GetProperty("order").GetValue(profile).ToString()+"."; + thaiOrder = thaiOrder.ToThaiNumber(); + _profileList.Add(new + { + order = thaiOrder, + fullName = profile.GetType().GetProperty("fullName").GetValue(profile).ToString(), + position = profile.GetType().GetProperty("position").GetValue(profile).ToString(), + posNo = profile.GetType().GetProperty("posNo").GetValue(profile).ToString(), + organizationOrganization = profile.GetType().GetProperty("organizationOrganization").GetValue(profile).ToString(), + }); + } + + //Binding to Table + var tblProfile = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; + tblProfile.DataSource = _profileList; + + + System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + InstanceReportSource instanceReportSource = new InstanceReportSource() + { + ReportDocument = report, + }; + + ReportProcessor reportProcessor = new ReportProcessor(_configuration); + RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + var content = result.DocumentBytes; + return File(content, "application/pdf", $"ประกาศเกษียณลูกจ้างประจำ{null}.pdf"); + } + //return Success(retire); + } + + } } diff --git a/BMA.EHR.Report.Service/Reports/32-ประกาศเกษียณลูกจ้างประจำ.trdp b/BMA.EHR.Report.Service/Reports/32-ประกาศเกษียณลูกจ้างประจำ.trdp index a0cc5f8ed8c8268f74d3651b662549f349dab8fd..bbb55bcf8c11d25efb2d68c24102735187cd1c3a 100644 GIT binary patch delta 2081 zcmV++2;TSg;{ng)0S!<~0|XQR000O8wS*S24U=dNwS*Q|zw5Spr3U~27a^0bXfS`x zT3c`1HWYpzu>U}4K(V42;x8dRIHg~^g9$xG6w^#UZ_)`woQ z)X7jR$%=L>0<=ZD$^S+_W#pkK(UN>gnx+jLhawLT&-u=UhhoZSS6T-8iP(;AnH43A zGYTSR&8q8WqoQ=&r7ud#*)yMhQeJ-`ZOeAiw|d=eQo3TTrJy;jMJkH#{powJeeaI% z{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