แยกประเภทขรก

This commit is contained in:
Kittapath 2024-07-03 00:43:01 +07:00
parent 811fa781b4
commit b02f8bc2e6
7 changed files with 80 additions and 19 deletions

View file

@ -15,6 +15,8 @@ using OfficeOpenXml;
using BMA.EHR.Domain.Models.Placement;
using OfficeOpenXml.Style;
using System.Text;
using Newtonsoft.Json;
using System.Net.Http.Headers;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
@ -27,6 +29,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly MinIOService _minioService;
private readonly MailService _mailService;
private readonly IConfiguration _configuration;
#endregion
@ -36,13 +39,15 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
MetadataDbContext contextMetadata,
IHttpContextAccessor httpContextAccessor,
MinIOService minioService,
MailService mailService)
MailService mailService,
IConfiguration configuration)
{
_context = context;
_contextMetadata = contextMetadata;
_httpContextAccessor = httpContextAccessor;
_minioService = minioService;
_mailService = mailService;
_configuration = configuration;
}
#endregion
@ -52,6 +57,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
#endregion
@ -2097,6 +2103,28 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
await _contextMetadata.Placements.AddAsync(placement);
foreach (var candidate in periodExam.Candidate.Where(x => x.Status == "done" && x.Pass == "ได้"))
{
var IsOfficer = false;
dynamic org = null;
var apiUrl = $"{_configuration["API"]}org/profile/citizenid/position/{candidate.CitizenId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
org = JsonConvert.DeserializeObject<dynamic>(_result);
if (org == null || org.result == null)
{
IsOfficer = false;
}
else
{
IsOfficer = true;
}
}
var profile = await _contextMetadata.Profiles
.Include(x => x.Salaries)
.FirstOrDefaultAsync(p => p.CitizenId == candidate.CitizenId);
@ -2187,6 +2215,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
LastUpdatedAt = DateTime.Now,
LastUpdateUserId = UserId ?? "",
LastUpdateFullName = FullName ?? "",
IsOfficer = IsOfficer,
profileId = org == null || org.result == null ? null : org.result.profileId,
};
await _contextMetadata.PlacementProfiles.AddAsync(placementProfile);
@ -2254,6 +2284,27 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.ToListAsync();
foreach (var candidate in candidates)
{
var IsOfficer = false;
dynamic org = null;
var apiUrl = $"{_configuration["API"]}org/profile/citizenid/position/{candidate.CitizenId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
org = JsonConvert.DeserializeObject<dynamic>(_result);
if (org == null || org.result == null)
{
IsOfficer = false;
}
else
{
IsOfficer = true;
}
}
var Address = candidate.Addresses.FirstOrDefault() == null ? null : $"{candidate.Addresses.FirstOrDefault().Address}";
var Moo = candidate.Addresses.FirstOrDefault() == null ? null : $" หมู่ {candidate.Addresses.FirstOrDefault().Moo}";
var Soi = candidate.Addresses.FirstOrDefault() == null ? null : $" ซอย {candidate.Addresses.FirstOrDefault().Soi}";
@ -2359,6 +2410,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
LastUpdatedAt = DateTime.Now,
LastUpdateUserId = UserId ?? "",
LastUpdateFullName = FullName ?? "",
IsOfficer = IsOfficer,
profileId = org == null || org.result == null ? null : org.result.profileId,
};
await _contextMetadata.PlacementProfiles.AddAsync(placementProfile);