หา dna บรรจุ

This commit is contained in:
kittapath 2025-06-20 00:35:25 +07:00
parent b1ad88c37b
commit 1ef8544833
20 changed files with 1425 additions and 303 deletions

View file

@ -2,6 +2,7 @@
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Application.Repositories.Reports;
using BMA.EHR.Application.Responses;
using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Models.Retirement;
using BMA.EHR.Domain.Shared;
@ -34,6 +35,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
private readonly MinIOService _documentService;
private readonly IConfiguration _configuration;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly UserProfileRepository _userProfileRepository;
private readonly PermissionRepository _permission;
public RetirementDeceasedController(RetirementRepository repository,
@ -43,6 +45,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
MinIOService documentService,
IConfiguration configuration,
IHttpContextAccessor httpContextAccessor,
UserProfileRepository userProfileRepository,
PermissionRepository permission)
{
_repository = repository;
@ -52,6 +55,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
_userProfileRepository = userProfileRepository;
_permission = permission;
}
@ -61,6 +65,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
#endregion
@ -81,19 +86,32 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
string role = jsonData["result"];
var nodeId = string.Empty;
var profileAdmin = new GetUserOCAllDto();
profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken);
if (role == "NORMAL" || role == "CHILD")
{
nodeId = profileAdmin?.Node == 4
? profileAdmin?.Child4DnaId
: profileAdmin?.Node == 3
? profileAdmin?.Child3DnaId
: profileAdmin?.Node == 2
? profileAdmin?.Child2DnaId
: profileAdmin?.Node == 1
? profileAdmin?.Child1DnaId
: profileAdmin?.Node == 0
? profileAdmin?.RootDnaId
: "";
}
else if (role == "ROOT")
{
nodeId = profileAdmin?.RootDnaId;
}
string?[] rootId = jsonData?.result?.rootId ?? null;
string?[] child1Id = jsonData?.result?.child1Id ?? null;
string?[] child2Id = jsonData?.result?.child2Id ?? null;
string?[] child3Id = jsonData?.result?.child3Id ?? null;
string?[] child4Id = jsonData?.result?.child4Id ?? null;
var node = profileAdmin?.Node;
var retirementDeceaseds = await _context.RetirementDeceaseds.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Where(x => rootId == null ? true : rootId.Contains(x.rootId))
.Where(x => child1Id == null ? true : child1Id.Contains(x.child1Id))
.Where(x => child2Id == null ? true : child2Id.Contains(x.child2Id))
.Where(x => child3Id == null ? true : child3Id.Contains(x.child3Id))
.Where(x => child4Id == null ? true : child4Id.Contains(x.child4Id))
.Select(p => new
{
p.Id,
@ -120,8 +138,33 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.posTypeName,
p.CreatedAt,
p.IsActive,
p.rootDnaId,
p.child1DnaId,
p.child2DnaId,
p.child3DnaId,
p.child4DnaId,
})
.ToListAsync();
if (role == "OWNER")
{
node = null;
}
if (role == "OWNER" || role == "CHILD")
{
retirementDeceaseds = retirementDeceaseds
.Where(x => node == 4 ? x.child4DnaId == nodeId : (node == 3 ? x.child3DnaId == nodeId : (node == 2 ? x.child2DnaId == nodeId : (node == 1 ? x.child1DnaId == nodeId : (node == 0 ? x.rootDnaId == nodeId : (node == null ? true : true)))))).ToList();
}
else if (role == "ROOT")
{
retirementDeceaseds = retirementDeceaseds
.Where(x => x.rootDnaId == nodeId).ToList();
}
else if (role == "NORMAL")
{
retirementDeceaseds = retirementDeceaseds
.Where(x => node == 0 ? x.child1DnaId == null : (node == 1 ? x.child2DnaId == null : (node == 2 ? x.child3DnaId == null : (node == 3 ? x.child4DnaId == null : true)))).ToList();
}
return Success(retirementDeceaseds);
}
@ -482,7 +525,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdatedAt = DateTime.Now,
});
}
}
}
}
await _context.SaveChangesAsync();
@ -652,32 +695,32 @@ namespace BMA.EHR.Retirement.Service.Controllers
};
//if (retirementDeceased.profileType.Trim().ToUpper() == "OFFICER")
//{
var apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{item.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 apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{item.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);
var org = JsonConvert.DeserializeObject<Requests.OrgRequest>(_result);
if (org == null || org.result == null)
continue;
if (org == null || org.result == null)
continue;
retirementDeceasedNoti.Prefix = org.result.prefix == null ? "" : org.result.prefix;
retirementDeceasedNoti.FirstName = org.result.firstName == null ? "" : org.result.firstName;
retirementDeceasedNoti.LastName = org.result.lastName == null ? "" : org.result.lastName;
retirementDeceasedNoti.CitizenId = org.result.citizenId == null ? "" : org.result.citizenId;
retirementDeceasedNoti.PositionName = org.result.position == null ? "" : org.result.position;
retirementDeceasedNoti.OrganizationName = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
(org.result.child1 == null ? "" : org.result.child1 + "\n") +
(org.result.root == null ? "" : org.result.root);
retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti);
}
retirementDeceasedNoti.Prefix = org.result.prefix == null ? "" : org.result.prefix;
retirementDeceasedNoti.FirstName = org.result.firstName == null ? "" : org.result.firstName;
retirementDeceasedNoti.LastName = org.result.lastName == null ? "" : org.result.lastName;
retirementDeceasedNoti.CitizenId = org.result.citizenId == null ? "" : org.result.citizenId;
retirementDeceasedNoti.PositionName = org.result.position == null ? "" : org.result.position;
retirementDeceasedNoti.OrganizationName = (org.result.child4 == null ? "" : org.result.child4 + "\n") +
(org.result.child3 == null ? "" : org.result.child3 + "\n") +
(org.result.child2 == null ? "" : org.result.child2 + "\n") +
(org.result.child1 == null ? "" : org.result.child1 + "\n") +
(org.result.root == null ? "" : org.result.root);
retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti);
}
//}
//else
//{