Linear Flow (ทดสอบเฉพาะคำสั่ง C-PM-01) #224
All checks were successful
Build & Deploy Placement Service / build (push) Successful in 2m57s

This commit is contained in:
harid 2026-06-18 11:47:11 +07:00
parent 7d2be029b6
commit 4a8d349415

View file

@ -1989,49 +1989,66 @@ namespace BMA.EHR.Placement.Service.Controllers
}).ToList();
Console.WriteLine($"[RecruitReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records");
Console.WriteLine($"[RecruitReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile");
var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile";
using (var client = new HttpClient())
#region Old: Circular Flow
// Console.WriteLine($"[RecruitReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile");
// var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile";
// 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.Post, apiUrl);
// var _res = await client.PostAsJsonAsync(apiUrl, new
// {
// data = resultData
// });
// var _result = await _res.Content.ReadAsStringAsync();
// Console.WriteLine($"[RecruitReportExcecute] External API response status: {_res.StatusCode}");
// if (_res.IsSuccessStatusCode)
// {
// Console.WriteLine("[RecruitReportExcecute] External API call successful - updating placement profiles");
// placementProfile.ForEach(profile =>
// {
// profile.PlacementStatus = "DONE";
// if (req.refIds.Length > 0)
// {
// profile.commandId = req.refIds[0].commandId;
// profile.refCommandCode = req.refIds[0].commandCode;
// profile.refCommandDate = req.refIds[0].commandDateAffect;
// profile.refCommandName = req.refIds[0].commandName;
// profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}";
// profile.templateDoc = req.refIds[0].remark;
// }
// });
// Console.WriteLine($"[RecruitReportExcecute] Saving changes to database for {placementProfile.Count} profiles");
// await _context.SaveChangesAsync();
// Console.WriteLine("[RecruitReportExcecute] Database save completed successfully");
// }
// else
// {
// Console.Error.WriteLine($"[RecruitReportExcecute] External API call failed with status: {_res.StatusCode}");
// Console.Error.WriteLine($"[RecruitReportExcecute] Response content: {_result}");
// }
// }
#endregion
// New: Linear Flow
placementProfile.ForEach(profile =>
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
profile.PlacementStatus = "DONE";
if (req.refIds.Length > 0)
{
data = resultData
});
var _result = await _res.Content.ReadAsStringAsync();
Console.WriteLine($"[RecruitReportExcecute] External API response status: {_res.StatusCode}");
if (_res.IsSuccessStatusCode)
{
Console.WriteLine("[RecruitReportExcecute] External API call successful - updating placement profiles");
placementProfile.ForEach(profile =>
{
profile.PlacementStatus = "DONE";
if (req.refIds.Length > 0)
{
profile.commandId = req.refIds[0].commandId;
profile.refCommandCode = req.refIds[0].commandCode;
profile.refCommandDate = req.refIds[0].commandDateAffect;
profile.refCommandName = req.refIds[0].commandName;
profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}";
profile.templateDoc = req.refIds[0].remark;
}
});
Console.WriteLine($"[RecruitReportExcecute] Saving changes to database for {placementProfile.Count} profiles");
await _context.SaveChangesAsync();
Console.WriteLine("[RecruitReportExcecute] Database save completed successfully");
profile.commandId = req.refIds[0].commandId;
profile.refCommandCode = req.refIds[0].commandCode;
profile.refCommandDate = req.refIds[0].commandDateAffect;
profile.refCommandName = req.refIds[0].commandName;
profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}";
profile.templateDoc = req.refIds[0].remark;
}
else
{
Console.Error.WriteLine($"[RecruitReportExcecute] External API call failed with status: {_res.StatusCode}");
Console.Error.WriteLine($"[RecruitReportExcecute] Response content: {_result}");
}
}
});
Console.WriteLine($"[RecruitReportExcecute] Saving changes to database for {placementProfile.Count} profiles");
await _context.SaveChangesAsync();
Console.WriteLine($"[RecruitReportExcecute] Process completed successfully at {DateTime.Now}");
return Success();
return Success(resultData);
}
catch (Exception ex)
{