diff --git a/Controllers/RecruitReportController.cs b/Controllers/RecruitReportController.cs index f2054ce..f03f411 100644 --- a/Controllers/RecruitReportController.cs +++ b/Controllers/RecruitReportController.cs @@ -1,4 +1,5 @@ -using BMA.EHR.Organization.Service.Extensions; +using System.Net.Http.Headers; +using BMA.EHR.Organization.Service.Extensions; using BMA.EHR.Profile.Service.Controllers; using BMA.EHR.Recruit.Service.Services; using BMA.EHR.Report.Service.Data; @@ -7,6 +8,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; using Swashbuckle.AspNetCore.Annotations; using Telerik.Reporting; using Telerik.Reporting.Processing; @@ -28,6 +30,7 @@ namespace BMA.EHR.Report.Service.Controllers private readonly IConfiguration _configuration; private readonly string space = "ㅤ"; private readonly RecruitService _recruitService; + private readonly IHttpContextAccessor _httpContextAccessor; #endregion @@ -36,14 +39,17 @@ namespace BMA.EHR.Report.Service.Controllers public RecruitReportController(ApplicationDbContext context, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, + IHttpContextAccessor httpContextAccessor, RecruitService recruitService) { this._context = context; this._hostingEnvironment = hostingEnvironment; this._configuration = configuration; this._recruitService = recruitService; + this._httpContextAccessor = httpContextAccessor; } + private string? token => _httpContextAccessor.HttpContext.Request.Headers["Authorization"]; #endregion #region " Methods " @@ -69,6 +75,23 @@ namespace BMA.EHR.Report.Service.Controllers { try { + var name = ""; + var position = ""; + var apiUrl = $"{_configuration["API"]}/org/find/head/officer"; + 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.Get, apiUrl); + var _res = await client.SendAsync(_req); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + var org = JsonConvert.DeserializeObject(_result); + name = org.result.rootId == null ? "" : org.result.rootId; + position = org.result.rootId == null ? "" : org.result.rootId; + } + } var data = await _context.Recruits.AsQueryable() .Include(x => x.RecruitImport) .Where(x => x.RecruitImport.Id == id) @@ -86,8 +109,8 @@ namespace BMA.EHR.Report.Service.Controllers FullName = $"{p.Prefix}{p.FirstName} {p.LastName}", ExamResult = sr == null ? "" : sr.ExamStatus, EndDate = p.RecruitImport.RegisterEndDate == null ? "-" : p.RecruitImport.RegisterEndDate.Value.ToThaiFullDate3(), - AuthName = "นายณัฐพงศ์ ดิษยบุตร", - AuthPosition = "หัวหน้าสำนักงาน ก.ก." + AuthName = name, + AuthPosition = position }) .FirstOrDefaultAsync();