fix bug ส่งหนังสือเวียน (issue #1280, #1282)
Some checks failed
release-dev / release-dev (push) Failing after 11s

This commit is contained in:
Bright 2025-03-25 18:05:25 +07:00
parent a7bf381d0a
commit 54e634d006

View file

@ -553,6 +553,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (retirementDeceased == null) if (retirementDeceased == null)
return Error(GlobalMessages.RetirementDeceasedNotFound, 404); return Error(GlobalMessages.RetirementDeceasedNotFound, 404);
bool checkDup = req.Persons.Any(x => retirementDeceased.RetirementDeceasedNotis.Any(y => y.profileId == x.ProfileId));
if (checkDup)
return Error("ไม่สามารถเพิ่มรายชื่อส่งหนังสือเวียนซ้ำได้", 404);
foreach (var item in req.Persons) foreach (var item in req.Persons)
{ {
// var profile = await _context.Profiles.AsQueryable() // var profile = await _context.Profiles.AsQueryable()
@ -574,8 +578,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "", LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now, LastUpdatedAt = DateTime.Now,
}; };
if (retirementDeceased.profileType.Trim().ToUpper() == "OFFICER") //if (retirementDeceased.profileType.Trim().ToUpper() == "OFFICER")
{ //{
var apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{item.ProfileId}"; var apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{item.ProfileId}";
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {
@ -602,36 +606,36 @@ namespace BMA.EHR.Retirement.Service.Controllers
(org.result.root == null ? "" : org.result.root); (org.result.root == null ? "" : org.result.root);
retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti); retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti);
} }
} //}
else //else
{ //{
var apiUrl = $"{_configuration["API"]}/org/profile-employee/profileid/position/{item.ProfileId}"; // var apiUrl = $"{_configuration["API"]}/org/profile-employee/profileid/position/{item.ProfileId}";
using (var client = new HttpClient()) // using (var client = new HttpClient())
{ // {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); // client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); // var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req); // var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync(); // var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<Requests.OrgRequest>(_result); // var org = JsonConvert.DeserializeObject<Requests.OrgRequest>(_result);
if (org == null || org.result == null) // if (org == null || org.result == null)
continue; // continue;
retirementDeceasedNoti.Prefix = org.result.prefix == null ? "" : org.result.prefix; // retirementDeceasedNoti.Prefix = org.result.prefix == null ? "" : org.result.prefix;
retirementDeceasedNoti.FirstName = org.result.firstName == null ? "" : org.result.firstName; // retirementDeceasedNoti.FirstName = org.result.firstName == null ? "" : org.result.firstName;
retirementDeceasedNoti.LastName = org.result.lastName == null ? "" : org.result.lastName; // retirementDeceasedNoti.LastName = org.result.lastName == null ? "" : org.result.lastName;
retirementDeceasedNoti.CitizenId = org.result.citizenId == null ? "" : org.result.citizenId; // retirementDeceasedNoti.CitizenId = org.result.citizenId == null ? "" : org.result.citizenId;
retirementDeceasedNoti.PositionName = org.result.position == null ? "" : org.result.position; // retirementDeceasedNoti.PositionName = org.result.position == null ? "" : org.result.position;
retirementDeceasedNoti.OrganizationName = (org.result.child4 == null ? "" : org.result.child4 + "\n") + // retirementDeceasedNoti.OrganizationName = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
(org.result.child3 == null ? "" : org.result.child3 + "\n") + // (org.result.child3 == null ? "" : org.result.child3 + "\n") +
(org.result.child2 == null ? "" : org.result.child2 + "\n") + // (org.result.child2 == null ? "" : org.result.child2 + "\n") +
(org.result.child1 == null ? "" : org.result.child1 + "\n") + // (org.result.child1 == null ? "" : org.result.child1 + "\n") +
(org.result.root == null ? "" : org.result.root); // (org.result.root == null ? "" : org.result.root);
retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti); // retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti);
} // }
} //}
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
} }