Linear Flow (C-PM-01, C-PM-02, C-PM-14) #224

This commit is contained in:
harid 2026-06-18 15:46:22 +07:00
parent 4a8d349415
commit 9a48b0dd29
2 changed files with 194 additions and 162 deletions

View file

@ -2395,22 +2395,49 @@ namespace BMA.EHR.Placement.Service.Controllers
Console.WriteLine($"[CandidateReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records"); Console.WriteLine($"[CandidateReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records");
Console.WriteLine($"[CandidateReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile"); #region Old: Circular Flow
var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; // Console.WriteLine($"[CandidateReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile");
using (var client = new HttpClient()) // 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"]); // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
var _res = await client.PostAsJsonAsync(apiUrl, new // var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
{ // var _res = await client.PostAsJsonAsync(apiUrl, new
data = resultData // {
}); // data = resultData
var _result = await _res.Content.ReadAsStringAsync(); // });
Console.WriteLine($"[CandidateReportExcecute] External API response status: {_res.StatusCode}"); // var _result = await _res.Content.ReadAsStringAsync();
if (_res.IsSuccessStatusCode) // Console.WriteLine($"[CandidateReportExcecute] External API response status: {_res.StatusCode}");
{ // if (_res.IsSuccessStatusCode)
Console.WriteLine("[CandidateReportExcecute] External API call successful - updating placement profiles"); // {
// Console.WriteLine("[CandidateReportExcecute] 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($"[CandidateReportExcecute] Saving changes to database for {placementProfile.Count} profiles");
// await _context.SaveChangesAsync();
// Console.WriteLine("[CandidateReportExcecute] Database save completed successfully");
// }
// else
// {
// Console.Error.WriteLine($"[CandidateReportExcecute] External API call failed with status: {_res.StatusCode}");
// Console.Error.WriteLine($"[CandidateReportExcecute] Response content: {_result}");
// }
// }
#endregion
// New: Linear Flow
placementProfile.ForEach(profile => placementProfile.ForEach(profile =>
{ {
profile.PlacementStatus = "DONE"; profile.PlacementStatus = "DONE";
@ -2426,20 +2453,9 @@ namespace BMA.EHR.Placement.Service.Controllers
}); });
Console.WriteLine($"[CandidateReportExcecute] Saving changes to database for {placementProfile.Count} profiles"); Console.WriteLine($"[CandidateReportExcecute] Saving changes to database for {placementProfile.Count} profiles");
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
Console.WriteLine("[CandidateReportExcecute] Database save completed successfully");
}
else
{
Console.Error.WriteLine($"[CandidateReportExcecute] External API call failed with status: {_res.StatusCode}");
Console.Error.WriteLine($"[CandidateReportExcecute] Response content: {_result}");
}
}
// // update placementstatus
// placementProfile.ForEach(profile => profile.PlacementStatus = "DONE");
// await _context.SaveChangesAsync();
Console.WriteLine($"[CandidateReportExcecute] Process completed successfully at {DateTime.Now}"); Console.WriteLine($"[CandidateReportExcecute] Process completed successfully at {DateTime.Now}");
return Success(); // Return resultData for Node to process directly (Linear Flow)
return Success(resultData);
} }
catch (Exception ex) catch (Exception ex)
{ {

View file

@ -1180,14 +1180,14 @@ namespace BMA.EHR.Placement.Service.Controllers
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response> /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("command/report/excecute")] [HttpPost("command/report/excecute")]
public async Task<ActionResult<ResponseObject>> PostReportExecute([FromBody] ReportExecuteRequest req) public async Task<ActionResult<ResponseObject>> PostReportExecute([FromBody] ReportExecuteRequest req)
{
Console.WriteLine($"[ReceiveReportExcecute] Starting execution at {DateTime.Now}");
try
{ {
var data = await _context.PlacementReceives var data = await _context.PlacementReceives
.Include(x => x.Avatar) .Include(x => x.Avatar)
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
.ToListAsync(); .ToListAsync();
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
data.ForEach(profile => profile.Status = "DONE");
await _context.SaveChangesAsync();
var resultData = (from p in data var resultData = (from p in data
join r in req.refIds join r in req.refIds
@ -1284,24 +1284,40 @@ namespace BMA.EHR.Placement.Service.Controllers
} }
}).ToList(); }).ToList();
var baseAPIOrg = _configuration["API"]; Console.WriteLine($"[ReceiveReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records");
var apiUrlOrg = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; #region Old: Circular Flow
using (var client = new HttpClient()) // var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{_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 _res = await client.PostAsJsonAsync(apiUrlOrg, new
// {
// data = resultData,
// });
// // // var _result = await _res.Content.ReadAsStringAsync();
// // // if (_res.IsSuccessStatusCode)
// // // {
// // // data.ForEach(profile => profile.Status = "DONE");
// // // await _context.SaveChangesAsync();
// // // }
// }
#endregion
// New: Linear Flow
data.ForEach(profile => profile.Status = "DONE");
Console.WriteLine($"[ReceiveReportExcecute] Saving changes to database for {data.Count} profiles");
await _context.SaveChangesAsync();
Console.WriteLine($"[ReceiveReportExcecute] Process completed successfully at {DateTime.Now}");
return Success(resultData);
}
catch (Exception ex)
{ {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); Console.Error.WriteLine($"[ReceiveReportExcecute] Error occurred: {ex.Message}");
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); Console.Error.WriteLine($"[ReceiveReportExcecute] Stack trace: {ex.StackTrace}");
var _res = await client.PostAsJsonAsync(apiUrlOrg, new throw;
{ }
data = resultData,
});
// // var _result = await _res.Content.ReadAsStringAsync();
// // if (_res.IsSuccessStatusCode)
// // {
// // data.ForEach(profile => profile.Status = "DONE");
// // await _context.SaveChangesAsync();
// // }
}
return Success();
} }
} }
} }