add RetirementDeceased
Some checks failed
release-dev / release-dev (push) Failing after 10s

This commit is contained in:
kittapath 2025-01-17 11:11:06 +07:00
parent 2095cd7fb4
commit 37d1ff3f40
2 changed files with 126 additions and 109 deletions

View file

@ -103,6 +103,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new
{
p.Id,
p.profileType,
p.citizenId,
p.profileId,
p.prefix,
@ -126,7 +127,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.IsActive,
})
.ToListAsync();
return Success(retirementDeceaseds);
return Success(retirementDeceaseds);
}
/// <summary>
@ -147,6 +148,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
p.Id,
p.profileId,
p.profileType,
p.prefix,
p.firstName,
p.lastName,
@ -236,6 +238,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
// Profile = profile,
Number = req.Number,
profileType = req.profileType.Trim().ToUpper(),
Date = req.Date,
Location = req.Location,
Reason = req.Reason,
@ -247,65 +250,129 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
var apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{req.ProfileId}";
using (var client = new HttpClient())
if (req.profileType.Trim().ToUpper() == "OFFICER")
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<Requests.OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
retirementDeceased.profileId = org.result.profileId;
retirementDeceased.prefix = org.result.prefix;
retirementDeceased.firstName = org.result.firstName;
retirementDeceased.lastName = org.result.lastName;
retirementDeceased.citizenId = org.result.citizenId;
retirementDeceased.root = org.result.root;
retirementDeceased.rootId = org.result.rootId;
retirementDeceased.rootShortName = org.result.rootShortName;
retirementDeceased.child1 = org.result.child1;
retirementDeceased.child1Id = org.result.child1Id;
retirementDeceased.child1ShortName = org.result.child1ShortName;
retirementDeceased.child2 = org.result.child2;
retirementDeceased.child2Id = org.result.child2Id;
retirementDeceased.child2ShortName = org.result.child2ShortName;
retirementDeceased.child3 = org.result.child3;
retirementDeceased.child3Id = org.result.child3Id;
retirementDeceased.child3ShortName = org.result.child3ShortName;
retirementDeceased.child4 = org.result.child4;
retirementDeceased.child4Id = org.result.child4Id;
retirementDeceased.child4ShortName = org.result.child4ShortName;
retirementDeceased.posMasterNo = org.result.posMasterNo;
retirementDeceased.position = org.result.position;
retirementDeceased.posTypeId = org.result.posTypeId;
retirementDeceased.posTypeName = org.result.posTypeName;
retirementDeceased.posLevelId = org.result.posLevelId;
retirementDeceased.posLevelName = org.result.posLevelName;
}
await _context.RetirementDeceaseds.AddAsync(retirementDeceased);
//await _context.SaveChangesAsync();
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/leave/{req.ProfileId}";
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
var apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{req.ProfileId}";
using (var client = new HttpClient())
{
isLeave = true,
leaveReason = "ถึงแก่กรรม",
dateLeave = req.Date,
});
var _result = await _res.Content.ReadAsStringAsync();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<Requests.OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
retirementDeceased.profileId = org.result.profileId;
retirementDeceased.prefix = org.result.prefix;
retirementDeceased.firstName = org.result.firstName;
retirementDeceased.lastName = org.result.lastName;
retirementDeceased.citizenId = org.result.citizenId;
retirementDeceased.root = org.result.root;
retirementDeceased.rootId = org.result.rootId;
retirementDeceased.rootShortName = org.result.rootShortName;
retirementDeceased.child1 = org.result.child1;
retirementDeceased.child1Id = org.result.child1Id;
retirementDeceased.child1ShortName = org.result.child1ShortName;
retirementDeceased.child2 = org.result.child2;
retirementDeceased.child2Id = org.result.child2Id;
retirementDeceased.child2ShortName = org.result.child2ShortName;
retirementDeceased.child3 = org.result.child3;
retirementDeceased.child3Id = org.result.child3Id;
retirementDeceased.child3ShortName = org.result.child3ShortName;
retirementDeceased.child4 = org.result.child4;
retirementDeceased.child4Id = org.result.child4Id;
retirementDeceased.child4ShortName = org.result.child4ShortName;
retirementDeceased.posMasterNo = org.result.posMasterNo;
retirementDeceased.position = org.result.position;
retirementDeceased.posTypeId = org.result.posTypeId;
retirementDeceased.posTypeName = org.result.posTypeName;
retirementDeceased.posLevelId = org.result.posLevelId;
retirementDeceased.posLevelName = org.result.posLevelName;
}
await _context.RetirementDeceaseds.AddAsync(retirementDeceased);
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/leave/{req.ProfileId}";
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
{
isLeave = true,
leaveReason = "ถึงแก่กรรม",
dateLeave = req.Date,
});
var _result = await _res.Content.ReadAsStringAsync();
}
}
else
{
var apiUrl = $"{_configuration["API"]}/org/profile-employee/profileid/position/{req.ProfileId}";
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.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<Requests.OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
retirementDeceased.profileId = org.result.profileId;
retirementDeceased.prefix = org.result.prefix;
retirementDeceased.firstName = org.result.firstName;
retirementDeceased.lastName = org.result.lastName;
retirementDeceased.citizenId = org.result.citizenId;
retirementDeceased.root = org.result.root;
retirementDeceased.rootId = org.result.rootId;
retirementDeceased.rootShortName = org.result.rootShortName;
retirementDeceased.child1 = org.result.child1;
retirementDeceased.child1Id = org.result.child1Id;
retirementDeceased.child1ShortName = org.result.child1ShortName;
retirementDeceased.child2 = org.result.child2;
retirementDeceased.child2Id = org.result.child2Id;
retirementDeceased.child2ShortName = org.result.child2ShortName;
retirementDeceased.child3 = org.result.child3;
retirementDeceased.child3Id = org.result.child3Id;
retirementDeceased.child3ShortName = org.result.child3ShortName;
retirementDeceased.child4 = org.result.child4;
retirementDeceased.child4Id = org.result.child4Id;
retirementDeceased.child4ShortName = org.result.child4ShortName;
retirementDeceased.posMasterNo = org.result.posMasterNo;
retirementDeceased.position = org.result.position;
retirementDeceased.posTypeId = org.result.posTypeId;
retirementDeceased.posTypeName = org.result.posTypeName;
retirementDeceased.posLevelId = org.result.posLevelId;
retirementDeceased.posLevelName = org.result.posLevelName;
}
await _context.RetirementDeceaseds.AddAsync(retirementDeceased);
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile-employee/leave/{req.ProfileId}";
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
{
isLeave = true,
leaveReason = "ถึงแก่กรรม",
dateLeave = req.Date,
});
var _result = await _res.Content.ReadAsStringAsync();
}
}
var _doc = new Domain.Models.Documents.Document();
@ -320,56 +387,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (_doc != null)
retirementDeceased.Document = _doc;
}
// await _context.ProfileSalaries.AddAsync(new ProfileSalary
// {
// Date = req.Date,
// SalaryRef = req.Number,
// CommandNo = "-",
// SalaryClass = "-",
// PosNoEmployee = "-",
// CommandTypeName = "-",
// SalaryStatus = "DEATH",
// Profile = profile,
// CreatedFullName = FullName ?? "System Administrator",
// CreatedUserId = UserId ?? "",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// });
// if (_doc != null)
// {
// await _context.ProfilePapers.AddAsync(new ProfilePaper
// {
// Detail = "ถึงแก่กรรม",
// CategoryName = "DEATH",
// Document = _doc,
// Profile = profile,
// CreatedFullName = FullName ?? "System Administrator",
// CreatedUserId = UserId ?? "",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// });
// }
// var orgPos = await _context.ProfilePositions
// .Include(x => x.Profile)
// .ThenInclude(x => x!.Prefix)
// .Include(x => x.OrganizationPosition)
// .ThenInclude(x => x!.Organization)
// .ThenInclude(x => x!.OrganizationOrganization)
// .Include(x => x.OrganizationPosition)
// .ThenInclude(x => x!.PositionMaster)
// .ThenInclude(x => x!.PositionPath)
// .Where(x => x.OrganizationPosition!.IsDirector! == true)
// .Where(x => x.OrganizationPosition!.Organization!.Id == profile.OcId)
// .FirstOrDefaultAsync();
// if (orgPos != null)
// {
// if (orgPos.Profile != null)
// {
retirementDeceased.RetirementDeceasedNotis.Add(new RetirementDeceasedNoti
{
CitizenId = retirementDeceased.citizenId == null ? "" : retirementDeceased.citizenId,
@ -389,8 +407,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
// }
// }
await _context.SaveChangesAsync();
return Success();