test
This commit is contained in:
parent
ff547470b2
commit
8766eb3b1f
2 changed files with 114 additions and 97 deletions
|
|
@ -183,19 +183,26 @@ namespace BMA.EHR.Recruit.Service.Services
|
|||
// 🚀 Prepare HTTP client once
|
||||
var httpClient1 = new HttpClient();
|
||||
httpClient1.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", ""));
|
||||
Console.WriteLine("118");
|
||||
httpClient1.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
Console.WriteLine("117");
|
||||
var apiUrl1 = $"{_configuration["API"]}/api/v1/org/pos/level";
|
||||
Console.WriteLine("116");
|
||||
var response1 = await httpClient1.GetStringAsync(apiUrl1);
|
||||
Console.WriteLine("115");
|
||||
var posOptions = JsonConvert.DeserializeObject<RecruitPosRequest>(response1);
|
||||
Console.WriteLine("114");
|
||||
|
||||
var recruitImport = await _context.RecruitImports.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == examId);
|
||||
|
||||
Console.WriteLine("113");
|
||||
if (recruitImport == null)
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
||||
var _placement = await _contextMetadata.Placements.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.PlacementType.Name == "สอบแข่งขัน" && x.RefId == recruitImport.Id);
|
||||
Console.WriteLine("112");
|
||||
// if (_placement != null)
|
||||
// throw new Exception("รอบการสอบนี้ได้ทำการบรรจุไปแล้ว");
|
||||
|
||||
|
|
@ -205,6 +212,7 @@ namespace BMA.EHR.Recruit.Service.Services
|
|||
var districtsCache = await _contextOrg.district.ToListAsync();
|
||||
var subDistrictsCache = await _contextOrg.subDistrict.ToListAsync();
|
||||
var educationLevelsCache = await _contextOrg.educationLevel.ToListAsync();
|
||||
Console.WriteLine("101");
|
||||
|
||||
var placement = new Placement
|
||||
{
|
||||
|
|
@ -224,6 +232,7 @@ namespace BMA.EHR.Recruit.Service.Services
|
|||
LastUpdateFullName = FullName ?? "",
|
||||
};
|
||||
await _contextMetadata.Placements.AddAsync(placement);
|
||||
Console.WriteLine("191");
|
||||
|
||||
// 🚀 Load all related data with single queries
|
||||
var candidates = await _context.Recruits.AsQueryable()
|
||||
|
|
@ -250,6 +259,7 @@ namespace BMA.EHR.Recruit.Service.Services
|
|||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", ""));
|
||||
httpClient.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
|
||||
Console.WriteLine("181");
|
||||
// 🚀 Batch HTTP requests
|
||||
var orgTasks = candidates.Select(async candidate =>
|
||||
{
|
||||
|
|
@ -267,6 +277,7 @@ namespace BMA.EHR.Recruit.Service.Services
|
|||
return new { CitizenId = candidate.CitizenId ?? "", org = (dynamic?)null };
|
||||
}
|
||||
}).ToList();
|
||||
Console.WriteLine("171");
|
||||
|
||||
var orgResults = await Task.WhenAll(orgTasks);
|
||||
var orgDict = orgResults.ToDictionary(x => x.CitizenId ?? "", x => x.org);
|
||||
|
|
@ -275,6 +286,7 @@ namespace BMA.EHR.Recruit.Service.Services
|
|||
var placementProfiles = new List<PlacementProfile>();
|
||||
var placementEducations = new List<PlacementEducation>();
|
||||
var placementCertificates = new List<PlacementCertificate>();
|
||||
Console.WriteLine("161");
|
||||
|
||||
foreach (var candidate in candidates)
|
||||
{
|
||||
|
|
@ -433,12 +445,17 @@ namespace BMA.EHR.Recruit.Service.Services
|
|||
LastUpdateFullName = FullName ?? "",
|
||||
};
|
||||
placementCertificates.Add(placementCertificate);
|
||||
Console.WriteLine("511");
|
||||
}
|
||||
Console.WriteLine("141");
|
||||
|
||||
// 🚀 Batch insert all records
|
||||
await _contextMetadata.PlacementProfiles.AddRangeAsync(placementProfiles);
|
||||
Console.WriteLine("131");
|
||||
await _contextMetadata.PlacementEducations.AddRangeAsync(placementEducations);
|
||||
Console.WriteLine("121");
|
||||
await _contextMetadata.PlacementCertificates.AddRangeAsync(placementCertificates);
|
||||
Console.WriteLine("111");
|
||||
|
||||
// 🚀 Single SaveChanges at the end
|
||||
await _contextMetadata.SaveChangesAsync();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue