Linear Flow (C-PM-01, C-PM-02, C-PM-14) #224
This commit is contained in:
parent
4a8d349415
commit
9a48b0dd29
2 changed files with 194 additions and 162 deletions
|
|
@ -2395,51 +2395,67 @@ 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");
|
// {
|
||||||
placementProfile.ForEach(profile =>
|
// Console.WriteLine("[CandidateReportExcecute] External API call successful - updating placement profiles");
|
||||||
{
|
// placementProfile.ForEach(profile =>
|
||||||
profile.PlacementStatus = "DONE";
|
// {
|
||||||
if (req.refIds.Length > 0)
|
// profile.PlacementStatus = "DONE";
|
||||||
{
|
// if (req.refIds.Length > 0)
|
||||||
profile.commandId = req.refIds[0].commandId;
|
// {
|
||||||
profile.refCommandCode = req.refIds[0].commandCode;
|
// profile.commandId = req.refIds[0].commandId;
|
||||||
profile.refCommandDate = req.refIds[0].commandDateAffect;
|
// profile.refCommandCode = req.refIds[0].commandCode;
|
||||||
profile.refCommandName = req.refIds[0].commandName;
|
// profile.refCommandDate = req.refIds[0].commandDateAffect;
|
||||||
profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}";
|
// profile.refCommandName = req.refIds[0].commandName;
|
||||||
profile.templateDoc = req.refIds[0].remark;
|
// 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] Saving changes to database for {placementProfile.Count} profiles");
|
||||||
Console.WriteLine("[CandidateReportExcecute] Database save completed successfully");
|
// await _context.SaveChangesAsync();
|
||||||
}
|
// Console.WriteLine("[CandidateReportExcecute] Database save completed successfully");
|
||||||
else
|
// }
|
||||||
{
|
// else
|
||||||
Console.Error.WriteLine($"[CandidateReportExcecute] External API call failed with status: {_res.StatusCode}");
|
// {
|
||||||
Console.Error.WriteLine($"[CandidateReportExcecute] Response content: {_result}");
|
// Console.Error.WriteLine($"[CandidateReportExcecute] External API call failed with status: {_res.StatusCode}");
|
||||||
}
|
// Console.Error.WriteLine($"[CandidateReportExcecute] Response content: {_result}");
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
#endregion
|
||||||
|
|
||||||
// // update placementstatus
|
// New: Linear Flow
|
||||||
// placementProfile.ForEach(profile => profile.PlacementStatus = "DONE");
|
placementProfile.ForEach(profile =>
|
||||||
// await _context.SaveChangesAsync();
|
{
|
||||||
|
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] 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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1181,127 +1181,143 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
[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)
|
||||||
{
|
{
|
||||||
var data = await _context.PlacementReceives
|
Console.WriteLine($"[ReceiveReportExcecute] Starting execution at {DateTime.Now}");
|
||||||
.Include(x => x.Avatar)
|
try
|
||||||
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
|
||||||
.ToListAsync();
|
|
||||||
// Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ
|
|
||||||
data.ForEach(profile => profile.Status = "DONE");
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
var resultData = (from p in data
|
|
||||||
join r in req.refIds
|
|
||||||
on p.Id.ToString() equals r.refId
|
|
||||||
select new
|
|
||||||
{
|
|
||||||
bodyProfile = new
|
|
||||||
{
|
|
||||||
rank = string.IsNullOrEmpty(p.rank) ? string.Empty : p.rank,
|
|
||||||
prefix = p.prefix == null ? string.Empty : p.prefix,
|
|
||||||
firstName = p.firstName == null ? string.Empty : p.firstName,
|
|
||||||
lastName = p.lastName == null ? string.Empty : p.lastName,
|
|
||||||
citizenId = p.citizenId == null ? string.Empty : p.citizenId,
|
|
||||||
position = p.position == null ? string.Empty : p.position,
|
|
||||||
posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId,
|
|
||||||
posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId,
|
|
||||||
email = (String?)null,
|
|
||||||
phone = p.TelephoneNumber == null ? string.Empty : p.TelephoneNumber,
|
|
||||||
keycloak = string.Empty,
|
|
||||||
isProbation = false,
|
|
||||||
isLeave = false,
|
|
||||||
dateRetire = (DateTime?)null,
|
|
||||||
dateAppoint = r.commandDateAffect,
|
|
||||||
dateStart = r.commandDateAffect,
|
|
||||||
govAgeAbsent = 0,
|
|
||||||
govAgePlus = 0,
|
|
||||||
birthDate = (p.DateOfBirth == null || p.DateOfBirth == DateTime.MinValue) ? (DateTime?)null : p.DateOfBirth,
|
|
||||||
reasonSameDate = (DateTime?)null,
|
|
||||||
ethnicity = p.Race == null ? string.Empty : p.Race,
|
|
||||||
telephoneNumber = (String?)null,
|
|
||||||
nationality = p.Nationality == null ? string.Empty : p.Nationality,
|
|
||||||
gender = p.Gender == null ? string.Empty : p.Gender,
|
|
||||||
relationship = p.Relationship == null ? string.Empty : p.Relationship,
|
|
||||||
religion = p.Religion == null ? string.Empty : p.Religion,
|
|
||||||
bloodGroup = p.BloodGroup == null ? string.Empty : p.BloodGroup,
|
|
||||||
registrationAddress = (String?)null,
|
|
||||||
registrationProvinceId = (String?)null,
|
|
||||||
registrationDistrictId = (String?)null,
|
|
||||||
registrationSubDistrictId = (String?)null,
|
|
||||||
registrationZipCode = (String?)null,
|
|
||||||
currentAddress = (String?)null,
|
|
||||||
currentProvinceId = (String?)null,
|
|
||||||
currentDistrictId = (String?)null,
|
|
||||||
currentSubDistrictId = (String?)null,
|
|
||||||
currentZipCode = (String?)null,
|
|
||||||
amount = r.amount,
|
|
||||||
amountSpecial = r.amountSpecial,
|
|
||||||
objectRefId = p.Avatar != null && p.Avatar?.ObjectRefId != null ? p.Avatar?.ObjectRefId.ToString("D") : null,
|
|
||||||
},
|
|
||||||
bodySalarys = new
|
|
||||||
{
|
|
||||||
profileId = p.profileId,
|
|
||||||
amount = r.amount,
|
|
||||||
amountSpecial = r.amountSpecial,
|
|
||||||
positionSalaryAmount = r.positionSalaryAmount,
|
|
||||||
mouthSalaryAmount = r.mouthSalaryAmount,
|
|
||||||
positionExecutive = p.PositionExecutive,
|
|
||||||
positionExecutiveField = p.positionExecutiveField,
|
|
||||||
positionArea = p.positionArea,
|
|
||||||
positionType = p.posTypeName,
|
|
||||||
positionLevel = p.posLevelName,
|
|
||||||
commandId = r.commandId,
|
|
||||||
orgRoot = p.root,
|
|
||||||
orgChild1 = p.child1,
|
|
||||||
orgChild2 = p.child2,
|
|
||||||
orgChild3 = p.child3,
|
|
||||||
orgChild4 = p.child4,
|
|
||||||
commandNo = r.commandNo,
|
|
||||||
commandYear = r.commandYear,
|
|
||||||
posNo = p.posMasterNo?.ToString(),
|
|
||||||
posNoAbb = p.node == 4 ? $"{p.child4ShortName}" :
|
|
||||||
p.node == 3 ? $"{p.child3ShortName}" :
|
|
||||||
p.node == 2 ? $"{p.child2ShortName}" :
|
|
||||||
p.node == 1 ? $"{p.child1ShortName}" :
|
|
||||||
p.node == 0 ? $"{p.rootShortName}" : "",
|
|
||||||
commandDateAffect = r.commandDateAffect,
|
|
||||||
commandDateSign = r.commandDateSign,
|
|
||||||
positionName = p.position,
|
|
||||||
commandCode = r.commandCode,
|
|
||||||
commandName = r.commandName,
|
|
||||||
remark = r.remark,
|
|
||||||
},
|
|
||||||
bodyPosition = new
|
|
||||||
{
|
|
||||||
posmasterId = p.posmasterId,
|
|
||||||
positionId = p.positionId,
|
|
||||||
positionName = p.position,
|
|
||||||
positionField = p.positionField,
|
|
||||||
posTypeId = p.posTypeId,
|
|
||||||
posLevelId = p.posLevelId,
|
|
||||||
posExecutiveId = p.posExecutiveId,
|
|
||||||
positionExecutiveField = p.positionExecutiveField,
|
|
||||||
positionArea = p.positionArea,
|
|
||||||
}
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
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 ", ""));
|
var data = await _context.PlacementReceives
|
||||||
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
.Include(x => x.Avatar)
|
||||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
||||||
{
|
.ToListAsync();
|
||||||
data = resultData,
|
|
||||||
});
|
var resultData = (from p in data
|
||||||
// // var _result = await _res.Content.ReadAsStringAsync();
|
join r in req.refIds
|
||||||
// // if (_res.IsSuccessStatusCode)
|
on p.Id.ToString() equals r.refId
|
||||||
// // {
|
select new
|
||||||
// // data.ForEach(profile => profile.Status = "DONE");
|
{
|
||||||
// // await _context.SaveChangesAsync();
|
bodyProfile = new
|
||||||
// // }
|
{
|
||||||
|
rank = string.IsNullOrEmpty(p.rank) ? string.Empty : p.rank,
|
||||||
|
prefix = p.prefix == null ? string.Empty : p.prefix,
|
||||||
|
firstName = p.firstName == null ? string.Empty : p.firstName,
|
||||||
|
lastName = p.lastName == null ? string.Empty : p.lastName,
|
||||||
|
citizenId = p.citizenId == null ? string.Empty : p.citizenId,
|
||||||
|
position = p.position == null ? string.Empty : p.position,
|
||||||
|
posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId,
|
||||||
|
posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId,
|
||||||
|
email = (String?)null,
|
||||||
|
phone = p.TelephoneNumber == null ? string.Empty : p.TelephoneNumber,
|
||||||
|
keycloak = string.Empty,
|
||||||
|
isProbation = false,
|
||||||
|
isLeave = false,
|
||||||
|
dateRetire = (DateTime?)null,
|
||||||
|
dateAppoint = r.commandDateAffect,
|
||||||
|
dateStart = r.commandDateAffect,
|
||||||
|
govAgeAbsent = 0,
|
||||||
|
govAgePlus = 0,
|
||||||
|
birthDate = (p.DateOfBirth == null || p.DateOfBirth == DateTime.MinValue) ? (DateTime?)null : p.DateOfBirth,
|
||||||
|
reasonSameDate = (DateTime?)null,
|
||||||
|
ethnicity = p.Race == null ? string.Empty : p.Race,
|
||||||
|
telephoneNumber = (String?)null,
|
||||||
|
nationality = p.Nationality == null ? string.Empty : p.Nationality,
|
||||||
|
gender = p.Gender == null ? string.Empty : p.Gender,
|
||||||
|
relationship = p.Relationship == null ? string.Empty : p.Relationship,
|
||||||
|
religion = p.Religion == null ? string.Empty : p.Religion,
|
||||||
|
bloodGroup = p.BloodGroup == null ? string.Empty : p.BloodGroup,
|
||||||
|
registrationAddress = (String?)null,
|
||||||
|
registrationProvinceId = (String?)null,
|
||||||
|
registrationDistrictId = (String?)null,
|
||||||
|
registrationSubDistrictId = (String?)null,
|
||||||
|
registrationZipCode = (String?)null,
|
||||||
|
currentAddress = (String?)null,
|
||||||
|
currentProvinceId = (String?)null,
|
||||||
|
currentDistrictId = (String?)null,
|
||||||
|
currentSubDistrictId = (String?)null,
|
||||||
|
currentZipCode = (String?)null,
|
||||||
|
amount = r.amount,
|
||||||
|
amountSpecial = r.amountSpecial,
|
||||||
|
objectRefId = p.Avatar != null && p.Avatar?.ObjectRefId != null ? p.Avatar?.ObjectRefId.ToString("D") : null,
|
||||||
|
},
|
||||||
|
bodySalarys = new
|
||||||
|
{
|
||||||
|
profileId = p.profileId,
|
||||||
|
amount = r.amount,
|
||||||
|
amountSpecial = r.amountSpecial,
|
||||||
|
positionSalaryAmount = r.positionSalaryAmount,
|
||||||
|
mouthSalaryAmount = r.mouthSalaryAmount,
|
||||||
|
positionExecutive = p.PositionExecutive,
|
||||||
|
positionExecutiveField = p.positionExecutiveField,
|
||||||
|
positionArea = p.positionArea,
|
||||||
|
positionType = p.posTypeName,
|
||||||
|
positionLevel = p.posLevelName,
|
||||||
|
commandId = r.commandId,
|
||||||
|
orgRoot = p.root,
|
||||||
|
orgChild1 = p.child1,
|
||||||
|
orgChild2 = p.child2,
|
||||||
|
orgChild3 = p.child3,
|
||||||
|
orgChild4 = p.child4,
|
||||||
|
commandNo = r.commandNo,
|
||||||
|
commandYear = r.commandYear,
|
||||||
|
posNo = p.posMasterNo?.ToString(),
|
||||||
|
posNoAbb = p.node == 4 ? $"{p.child4ShortName}" :
|
||||||
|
p.node == 3 ? $"{p.child3ShortName}" :
|
||||||
|
p.node == 2 ? $"{p.child2ShortName}" :
|
||||||
|
p.node == 1 ? $"{p.child1ShortName}" :
|
||||||
|
p.node == 0 ? $"{p.rootShortName}" : "",
|
||||||
|
commandDateAffect = r.commandDateAffect,
|
||||||
|
commandDateSign = r.commandDateSign,
|
||||||
|
positionName = p.position,
|
||||||
|
commandCode = r.commandCode,
|
||||||
|
commandName = r.commandName,
|
||||||
|
remark = r.remark,
|
||||||
|
},
|
||||||
|
bodyPosition = new
|
||||||
|
{
|
||||||
|
posmasterId = p.posmasterId,
|
||||||
|
positionId = p.positionId,
|
||||||
|
positionName = p.position,
|
||||||
|
positionField = p.positionField,
|
||||||
|
posTypeId = p.posTypeId,
|
||||||
|
posLevelId = p.posLevelId,
|
||||||
|
posExecutiveId = p.posExecutiveId,
|
||||||
|
positionExecutiveField = p.positionExecutiveField,
|
||||||
|
positionArea = p.positionArea,
|
||||||
|
}
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
Console.WriteLine($"[ReceiveReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records");
|
||||||
|
#region Old: Circular Flow
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"[ReceiveReportExcecute] Error occurred: {ex.Message}");
|
||||||
|
Console.Error.WriteLine($"[ReceiveReportExcecute] Stack trace: {ex.StackTrace}");
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
return Success();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue