หา 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.Repositories.Reports;
using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Retirement;
@ -34,6 +35,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
private readonly PermissionRepository _permission;
private readonly UserProfileRepository _userProfileRepository;
private readonly RetireReportRepository _service;
public RetirementResignController(RetirementRepository repository,
@ -43,6 +45,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration,
PermissionRepository permission,
UserProfileRepository userProfileRepository,
RetireReportRepository service)
{
_repository = repository;
@ -52,6 +55,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
_permission = permission;
_userProfileRepository = userProfileRepository;
_service = service;
}
@ -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
// private List<string> GetOcNameFullPath(Guid id, bool showRoot = false)
@ -234,6 +239,30 @@ 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;
}
var node = profileAdmin?.Node;
var retirementResigns = await _context.RetirementResigns.AsQueryable()
.Where(x => type.Trim().ToUpper() == "APPROVE" ? (x.Status == "APPROVE" || x.Status == "REJECT") : x.Status == type.Trim().ToUpper())
.OrderByDescending(x => x.CreatedAt)
@ -266,9 +295,34 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.CreatedAt,
p.ApproveStep,
p.Group,
p.rootDnaOldId,
p.child1DnaOldId,
p.child2DnaOldId,
p.child3DnaOldId,
p.child4DnaOldId,
})
.ToListAsync();
if (role == "OWNER")
{
node = null;
}
if (role == "OWNER" || role == "CHILD")
{
retirementResigns = retirementResigns
.Where(x => node == 4 ? x.child4DnaOldId == nodeId : (node == 3 ? x.child3DnaOldId == nodeId : (node == 2 ? x.child2DnaOldId == nodeId : (node == 1 ? x.child1DnaOldId == nodeId : (node == 0 ? x.rootDnaOldId == nodeId : (node == null ? true : true)))))).ToList();
}
else if (role == "ROOT")
{
retirementResigns = retirementResigns
.Where(x => x.rootDnaOldId == nodeId).ToList();
}
else if (role == "NORMAL")
{
retirementResigns = retirementResigns
.Where(x => node == 0 ? x.child1DnaOldId == null : (node == 1 ? x.child2DnaOldId == null : (node == 2 ? x.child3DnaOldId == null : (node == 3 ? x.child4DnaOldId == null : true)))).ToList();
}
return Success(retirementResigns);
}
@ -289,6 +343,30 @@ 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;
}
var node = profileAdmin?.Node;
var retirementResigns = await _context.RetirementResignCancels.AsQueryable()
.Where(x => type.Trim().ToUpper() == "APPROVE" ? (x.Status == "APPROVE" || x.Status == "REJECT") : x.Status == type.Trim().ToUpper())
.OrderByDescending(x => x.CreatedAt)
@ -320,9 +398,34 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.CreatedAt,
p.ApproveStep,
p.Group,
p.rootDnaOldId,
p.child1DnaOldId,
p.child2DnaOldId,
p.child3DnaOldId,
p.child4DnaOldId,
})
.ToListAsync();
if (role == "OWNER")
{
node = null;
}
if (role == "OWNER" || role == "CHILD")
{
retirementResigns = retirementResigns
.Where(x => node == 4 ? x.child4DnaOldId == nodeId : (node == 3 ? x.child3DnaOldId == nodeId : (node == 2 ? x.child2DnaOldId == nodeId : (node == 1 ? x.child1DnaOldId == nodeId : (node == 0 ? x.rootDnaOldId == nodeId : (node == null ? true : true)))))).ToList();
}
else if (role == "ROOT")
{
retirementResigns = retirementResigns
.Where(x => x.rootDnaOldId == nodeId).ToList();
}
else if (role == "NORMAL")
{
retirementResigns = retirementResigns
.Where(x => node == 0 ? x.child1DnaOldId == null : (node == 1 ? x.child2DnaOldId == null : (node == 2 ? x.child3DnaOldId == null : (node == 3 ? x.child4DnaOldId == null : true)))).ToList();
}
return Success(retirementResigns);
}
@ -1572,18 +1675,23 @@ namespace BMA.EHR.Retirement.Service.Controllers
citizenId = updated.citizenId,
rootOld = updated.rootOld,
rootOldId = updated.rootOldId,
rootDnaOldId = updated.rootDnaOldId,
rootShortNameOld = updated.rootShortNameOld,
child1Old = updated.child1Old,
child1OldId = updated.child1OldId,
child1DnaOldId = updated.child1DnaOldId,
child1ShortNameOld = updated.child1ShortNameOld,
child2Old = updated.child2Old,
child2OldId = updated.child2OldId,
child2DnaOldId = updated.child2DnaOldId,
child2ShortNameOld = updated.child2ShortNameOld,
child3Old = updated.child3Old,
child3OldId = updated.child3OldId,
child3DnaOldId = updated.child3DnaOldId,
child3ShortNameOld = updated.child3ShortNameOld,
child4Old = updated.child4Old,
child4OldId = updated.child4OldId,
child4DnaOldId = updated.child4DnaOldId,
child4ShortNameOld = updated.child4ShortNameOld,
posMasterNoOld = updated.posMasterNoOld,
posTypeOldId = updated.posTypeOldId,
@ -2001,6 +2109,30 @@ 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;
}
var node = profileAdmin?.Node;
var data = await _context.RetirementQuestions.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
@ -2026,8 +2158,33 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdatedAt = p.LastUpdatedAt,
CreatedAt = p.CreatedAt,
AppointDate = p.AppointDate,
p.rootDnaId,
p.child1DnaId,
p.child2DnaId,
p.child3DnaId,
p.child4DnaId,
})
.ToListAsync();
if (role == "OWNER")
{
node = null;
}
if (role == "OWNER" || role == "CHILD")
{
data = data
.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")
{
data = data
.Where(x => x.rootDnaId == nodeId).ToList();
}
else if (role == "NORMAL")
{
data = data
.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(data);
}
@ -2150,6 +2307,37 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{retirementResign.profileId}";
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
period.root = org.result.root;
period.rootId = org.result.rootId;
period.rootDnaId = org.result.rootDnaId;
period.child1 = org.result.child1;
period.child1Id = org.result.child1Id;
period.child1DnaId = org.result.child1DnaId;
period.child2 = org.result.child2;
period.child2Id = org.result.child2Id;
period.child2DnaId = org.result.child2DnaId;
period.child3 = org.result.child3;
period.child3Id = org.result.child3Id;
period.child3DnaId = org.result.child3DnaId;
period.child4 = org.result.child4;
period.child4Id = org.result.child4Id;
period.child4DnaId = org.result.child4DnaId;
}
await _context.RetirementQuestions.AddAsync(period);
await _context.SaveChangesAsync();
@ -2637,7 +2825,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
positionLevel = p.PositionLevelOld,
isLeave = p.IsCancel == true ? false : true,
//leaveReason = "ออกจากราชการ",
leaveReason = p.ReasonResign == "อื่น ๆ"
leaveReason = p.ReasonResign == "อื่น ๆ"
? string.IsNullOrWhiteSpace(p.Remark) ? p.ReasonResign : $"{p.ReasonResign}({p.Remark})"
: p.ReasonResign,
dateLeave = r.commandDateAffect,