โหลดใบรับรอง

This commit is contained in:
kittapath-Jool 2025-09-15 00:11:36 +07:00
parent 9284a89cb4
commit e44a255b53
4 changed files with 81 additions and 16 deletions

View file

@ -75,23 +75,34 @@ namespace BMA.EHR.Report.Service.Controllers
{
try
{
var name = "";
var position = "";
var apiUrl = $"{_configuration["API"]}/org/find/head/officer";
using (var client = new HttpClient())
var _data = await _context.Recruits.AsQueryable()
.Include(x => x.RecruitImport)
.Where(x => x.RecruitImport.Id == id)
.Where(x => x.ExamId == examId)
.FirstOrDefaultAsync();
if (_data == null)
return Error("ไม่พบข้อมูลในระบบ");
if (_data.AuthName == null || _data.AuthName == "")
{
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 apiUrl = $"{_configuration["API"]}/org/find/head/officer";
using (var client = new HttpClient())
{
var org = JsonConvert.DeserializeObject<dynamic>(_result);
name = org.result.rootId == null ? "" : org.result.rootId;
position = org.result.rootId == null ? "" : org.result.rootId;
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<dynamic>(_result);
_data.AuthName = org.result.name == null ? "" : org.result.name;
_data.AuthPosition = org.result.position == null ? "" : org.result.position;
await _context.SaveChangesAsync();
}
}
}
var data = await _context.Recruits.AsQueryable()
.Include(x => x.RecruitImport)
.Where(x => x.RecruitImport.Id == id)
@ -109,8 +120,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 = name,
AuthPosition = position
AuthName = p.AuthName,
AuthPosition = p.AuthPosition
})
.FirstOrDefaultAsync();
if (data == null)