หา 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
//{

View file

@ -1,5 +1,6 @@
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Retirement;
@ -31,6 +32,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
private readonly UserProfileRepository _userProfileRepository;
private readonly PermissionRepository _permission;
public RetirementOtherController(RetirementRepository repository,
@ -39,6 +41,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
MinIOService documentService,
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration,
UserProfileRepository userProfileRepository,
PermissionRepository permission)
{
_repository = repository;
@ -47,6 +50,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
_userProfileRepository = userProfileRepository;
_permission = permission;
}
@ -56,6 +60,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
@ -77,135 +82,140 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
var rootId = "";
var child1Id = "";
var child2Id = "";
var child3Id = "";
var child4Id = "";
var apiUrl = $"{_configuration["API"]}/org/permission/checkOrg/{UserId}";
using (var client = new HttpClient())
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")
{
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<OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
rootId = org.result.rootId == null ? "" : org.result.rootId;
child1Id = org.result.child1Id == null ? "" : org.result.child1Id;
child2Id = org.result.child2Id == null ? "" : org.result.child2Id;
child3Id = org.result.child3Id == null ? "" : org.result.child3Id;
child4Id = org.result.child4Id == null ? "" : org.result.child4Id;
var retirementOthers = await _context.RetirementOthers.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
// .Where(x => rootId == "" ? true : (child1Id == "" ? x.rootOldId == rootId : (child2Id == "" ? x.child1OldId == child1Id : (child3Id == "" ? x.child2OldId == child2Id : (child4Id == "" ? x.child3OldId == child3Id : x.child4OldId == child4Id)))))
.Select(p => new
{
p.Id,
p.citizenId,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootId,
p.rootShortName,
p.child1,
p.child1Id,
p.child1ShortName,
p.child2,
p.child2Id,
p.child2ShortName,
p.child3,
p.child3Id,
p.child3ShortName,
p.child4,
p.child4Id,
p.child4ShortName,
p.orgRevisionId,
p.positionId,
p.posMasterNo,
p.position,
p.PositionExecutive,
p.positionField,
p.posTypeId,
p.posTypeName,
p.posLevelId,
p.posLevelName,
node = p.root == null ? (int?)null : (p.child1 == null ? 0 : (p.child2 == null ? 1 : (p.child3 == null ? 2 : (p.child4 == null ? 3 : 4)))),
nodeName = p.root == null ? null : (p.child1 == null ? p.root : (p.child2 == null ? p.child1 : (p.child3 == null ? p.child2 : (p.child4 == null ? p.child3 : p.child4)))),
nodeId = p.rootId == null ? null : (p.child1Id == null ? p.rootId : (p.child2Id == null ? p.child1Id : (p.child3Id == null ? p.child2Id : (p.child4Id == null ? p.child3Id : p.child4Id)))),
nodeShortName = p.rootShortName == null ? null : (p.child1ShortName == null ? p.rootShortName : (p.child2ShortName == null ? p.child1ShortName : (p.child3ShortName == null ? p.child2ShortName : (p.child4ShortName == null ? p.child3ShortName : p.child4ShortName)))),
p.rootOld,
p.rootOldId,
p.rootShortNameOld,
p.child1Old,
p.child1OldId,
p.child1ShortNameOld,
p.child2Old,
p.child2OldId,
p.child2ShortNameOld,
p.child3Old,
p.child3OldId,
p.child3ShortNameOld,
p.child4Old,
p.child4OldId,
p.child4ShortNameOld,
p.PositionOld,
p.PositionExecutiveOld,
p.posMasterNoOld,
p.posTypeOldId,
p.posTypeNameOld,
p.posLevelOldId,
p.posLevelNameOld,
p.Status,
p.Amount,
p.ReportingDate,
p.CreatedAt,
p.Reason,
p.MilitaryDate,
p.EducationOld,
p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.posmasterId,
p.PositionDate,
CommandType = p.CommandType == null ? null : p.CommandType.Name,
})
.ToListAsync();
// if (keyword != "")
// {
// var data = retirementOthers.Where(x =>
// (x.prefix != null && x.prefix.Contains(keyword)) ||
// (x.firstName != null && x.firstName.Contains(keyword)) ||
// (x.lastName != null && x.lastName.Contains(keyword)) ||
// (x.rootShortNameOld != null && x.rootShortNameOld.Contains(keyword)) ||
// (x.posMasterNoOld != null && x.posMasterNoOld.ToString().Contains(keyword)) ||
// (x.posTypeNameOld != null && x.posTypeNameOld.Contains(keyword)) ||
// (x.posLevelNameOld != null && x.posLevelNameOld.Contains(keyword)) ||
// (x.OrganizationPositionOld != null && x.OrganizationPositionOld.Contains(keyword)) ||
// (x.Reason != null && x.Reason.Contains(keyword)))
// .OrderByDescending(x => x.CreatedAt)
// .Skip((page - 1) * pageSize)
// .Take(pageSize)
// .ToList();
// retirementOthers = data;
// }
if (status != null && status.Trim().ToUpper() != "ALL")
retirementOthers = retirementOthers.Where(x => x.Status.Contains(status.Trim().ToUpper())).ToList();
return Success(retirementOthers);
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 retirementOthers = await _context.RetirementOthers.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
p.citizenId,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootId,
p.rootShortName,
p.child1,
p.child1Id,
p.child1ShortName,
p.child2,
p.child2Id,
p.child2ShortName,
p.child3,
p.child3Id,
p.child3ShortName,
p.child4,
p.child4Id,
p.child4ShortName,
p.orgRevisionId,
p.positionId,
p.posMasterNo,
p.position,
p.PositionExecutive,
p.positionField,
p.posTypeId,
p.posTypeName,
p.posLevelId,
p.posLevelName,
node = p.root == null ? (int?)null : (p.child1 == null ? 0 : (p.child2 == null ? 1 : (p.child3 == null ? 2 : (p.child4 == null ? 3 : 4)))),
nodeName = p.root == null ? null : (p.child1 == null ? p.root : (p.child2 == null ? p.child1 : (p.child3 == null ? p.child2 : (p.child4 == null ? p.child3 : p.child4)))),
nodeId = p.rootId == null ? null : (p.child1Id == null ? p.rootId : (p.child2Id == null ? p.child1Id : (p.child3Id == null ? p.child2Id : (p.child4Id == null ? p.child3Id : p.child4Id)))),
nodeShortName = p.rootShortName == null ? null : (p.child1ShortName == null ? p.rootShortName : (p.child2ShortName == null ? p.child1ShortName : (p.child3ShortName == null ? p.child2ShortName : (p.child4ShortName == null ? p.child3ShortName : p.child4ShortName)))),
p.rootOld,
p.rootOldId,
p.rootShortNameOld,
p.child1Old,
p.child1OldId,
p.child1ShortNameOld,
p.child2Old,
p.child2OldId,
p.child2ShortNameOld,
p.child3Old,
p.child3OldId,
p.child3ShortNameOld,
p.child4Old,
p.child4OldId,
p.child4ShortNameOld,
p.PositionOld,
p.PositionExecutiveOld,
p.posMasterNoOld,
p.posTypeOldId,
p.posTypeNameOld,
p.posLevelOldId,
p.posLevelNameOld,
p.Status,
p.Amount,
p.ReportingDate,
p.CreatedAt,
p.Reason,
p.MilitaryDate,
p.EducationOld,
p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.posmasterId,
p.PositionDate,
CommandType = p.CommandType == null ? null : p.CommandType.Name,
p.rootDnaOldId,
p.child1DnaOldId,
p.child2DnaOldId,
p.child3DnaOldId,
p.child4DnaOldId,
})
.ToListAsync();
if (status != null && status.Trim().ToUpper() != "ALL")
retirementOthers = retirementOthers.Where(x => x.Status.Contains(status.Trim().ToUpper())).ToList();
if (role == "OWNER")
{
node = null;
}
if (role == "OWNER" || role == "CHILD")
{
retirementOthers = retirementOthers
.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")
{
retirementOthers = retirementOthers
.Where(x => x.rootDnaOldId == nodeId).ToList();
}
else if (role == "NORMAL")
{
retirementOthers = retirementOthers
.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(retirementOthers);
}
/// <summary>
@ -351,14 +361,14 @@ namespace BMA.EHR.Retirement.Service.Controllers
var apiUrl = string.Empty;
if (req.profileType.Trim().ToUpper() == "EMPLOYEE")
{
apiUrl = $"{_configuration["API"]}/org/profile-employee/profileid/position/{req.Id}";
}
else
{
apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{req.Id}";
}
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
@ -745,7 +755,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
(p.root == null ? "" : $"{p.root}"),
NewPositionType = p.posTypeName == null ? "-" : p.posTypeName,
NewPositionLevel = p.posLevelName == null ? "-" : p.posLevelName,
NewPositionNumber = p.rootShortName == null && p.posMasterNo == null ? null : $"{(p.child1ShortName == null ? p.rootShortName : (p.child2ShortName == null ? p.child1ShortName : (p.child3ShortName == null ? p.child2ShortName : (p.child4ShortName == null ? p.child3ShortName : p.child4ShortName))))}"+
NewPositionNumber = p.rootShortName == null && p.posMasterNo == null ? null : $"{(p.child1ShortName == null ? p.rootShortName : (p.child2ShortName == null ? p.child1ShortName : (p.child3ShortName == null ? p.child2ShortName : (p.child4ShortName == null ? p.child3ShortName : p.child4ShortName))))}" +
$" {p.posMasterNo?.ToString().ToThaiNumber()}",
NewSalary = r.Amount == null ? "-" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
AppointDate = p.PositionDate == null ? "-" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(),

View file

@ -1,5 +1,6 @@
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Placement;
@ -32,6 +33,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
private readonly UserProfileRepository _userProfileRepository;
private readonly PermissionRepository _permission;
public RetirementOutController(RetirementRepository repository,
@ -40,6 +42,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
MinIOService documentService,
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration,
UserProfileRepository userProfileRepository,
PermissionRepository permission)
{
_repository = repository;
@ -48,6 +51,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
_userProfileRepository = userProfileRepository;
_permission = permission;
}
@ -57,6 +61,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
@ -78,83 +83,106 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
var rootId = "";
var child1Id = "";
var child2Id = "";
var child3Id = "";
var child4Id = "";
var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position";
using (var client = new HttpClient())
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")
{
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<OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
rootId = org.result.rootId == null ? "" : org.result.rootId;
child1Id = org.result.child1Id == null ? "" : org.result.child1Id;
child2Id = org.result.child2Id == null ? "" : org.result.child2Id;
child3Id = org.result.child3Id == null ? "" : org.result.child3Id;
child4Id = org.result.child4Id == null ? "" : org.result.child4Id;
var retirementOuts = await _context.RetirementOuts.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Where(x => x.profileType.Trim().ToUpper().Contains(type.Trim().ToUpper()))
// .Where(x => rootId == "" ? true : (child1Id == "" ? x.rootOldId == rootId : (child2Id == "" ? x.child1OldId == child1Id : (child3Id == "" ? x.child2OldId == child2Id : (child4Id == "" ? x.child3OldId == child3Id : x.child4OldId == child4Id)))))
.Select(p => new
{
p.Id,
p.profileType,
p.citizenId,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.rootOld,
p.rootOldId,
p.rootShortNameOld,
p.child1Old,
p.child1OldId,
p.child1ShortNameOld,
p.child2Old,
p.child2OldId,
p.child2ShortNameOld,
p.child3Old,
p.child3OldId,
p.child3ShortNameOld,
p.child4Old,
p.child4OldId,
p.child4ShortNameOld,
p.PositionOld,
p.PositionExecutiveOld,
p.posMasterNoOld,
p.posTypeOldId,
p.posTypeNameOld,
p.posLevelOldId,
p.posLevelNameOld,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
//if (status != null && status.Trim().ToUpper() != "WAITTING")
if (status != null)
retirementOuts = retirementOuts.Where(x => x.Status.Contains(status.Trim().ToUpper())).ToList();
return Success(retirementOuts);
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 retirementOuts = await _context.RetirementOuts.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Where(x => x.profileType.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.Select(p => new
{
p.Id,
p.profileType,
p.citizenId,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.rootOld,
p.rootOldId,
p.rootShortNameOld,
p.child1Old,
p.child1OldId,
p.child1ShortNameOld,
p.child2Old,
p.child2OldId,
p.child2ShortNameOld,
p.child3Old,
p.child3OldId,
p.child3ShortNameOld,
p.child4Old,
p.child4OldId,
p.child4ShortNameOld,
p.PositionOld,
p.PositionExecutiveOld,
p.posMasterNoOld,
p.posTypeOldId,
p.posTypeNameOld,
p.posLevelOldId,
p.posLevelNameOld,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
p.rootDnaOldId,
p.child1DnaOldId,
p.child2DnaOldId,
p.child3DnaOldId,
p.child4DnaOldId,
})
.ToListAsync();
//if (status != null && status.Trim().ToUpper() != "WAITTING")
if (status != null)
retirementOuts = retirementOuts.Where(x => x.Status.Contains(status.Trim().ToUpper())).ToList();
if (role == "OWNER")
{
node = null;
}
if (role == "OWNER" || role == "CHILD")
{
retirementOuts = retirementOuts
.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")
{
retirementOuts = retirementOuts
.Where(x => x.rootDnaOldId == nodeId).ToList();
}
else if (role == "NORMAL")
{
retirementOuts = retirementOuts
.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(retirementOuts);
}
/// <summary>

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,

View file

@ -1,5 +1,6 @@
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Retirement;
@ -31,6 +32,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
private readonly UserProfileRepository _userProfileRepository;
private readonly PermissionRepository _permission;
public RetirementResignEmployeeController(RetirementEmployeeRepository repository,
@ -39,6 +41,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
MinIOService documentService,
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration,
UserProfileRepository userProfileRepository,
PermissionRepository permission)
{
_repository = repository;
@ -47,6 +50,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
_userProfileRepository = userProfileRepository;
_permission = permission;
}
@ -56,6 +60,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
/// <summary>
@ -173,6 +178,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 retirementResignEmployees = await _context.RetirementResignEmployees.AsQueryable()
.Where(x => type.Trim().ToUpper() == "APPROVE" ? (x.Status == "APPROVE" || x.Status == "REJECT") : x.Status == type.Trim().ToUpper())
.OrderByDescending(x => x.CreatedAt)
@ -205,9 +234,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")
{
retirementResignEmployees = retirementResignEmployees
.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")
{
retirementResignEmployees = retirementResignEmployees
.Where(x => x.rootDnaOldId == nodeId).ToList();
}
else if (role == "NORMAL")
{
retirementResignEmployees = retirementResignEmployees
.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(retirementResignEmployees);
}
@ -228,6 +282,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 retirementResignEmployees = await _context.RetirementResignEmployeeCancels.AsQueryable()
.Where(x => type.Trim().ToUpper() == "APPROVE" ? (x.Status == "APPROVE" || x.Status == "REJECT") : x.Status == type.Trim().ToUpper())
.OrderByDescending(x => x.CreatedAt)
@ -258,9 +336,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")
{
retirementResignEmployees = retirementResignEmployees
.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")
{
retirementResignEmployees = retirementResignEmployees
.Where(x => x.rootDnaOldId == nodeId).ToList();
}
else if (role == "NORMAL")
{
retirementResignEmployees = retirementResignEmployees
.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(retirementResignEmployees);
}
@ -1490,18 +1593,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,
@ -1929,7 +2037,31 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
var data = await _context.RetirementQuestions.AsQueryable()
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.RetirementEmployeeQuestions.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
@ -1954,11 +2086,115 @@ 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);
}
/// <summary>
/// สร้างแบบสอบถามหลังลาออก
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("questionnaire")]
public async Task<ActionResult<ResponseObject>> PostQuestion([FromBody] RetirementQuestionRequest req)
{
var retirementResign = await _context.RetirementResignEmployees.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == req.RetirementResignId);
if (retirementResign == null)
return Error(GlobalMessages.RetirementResignNotFound);
var period = new RetirementEmployeeQuestion
{
RetirementResignEmployee = retirementResign,
ReasonWork = Newtonsoft.Json.JsonConvert.SerializeObject(req.ReasonWork),
ReasonWorkOther = req.ReasonWorkOther,
TimeThink = req.TimeThink,
ExitFactor = Newtonsoft.Json.JsonConvert.SerializeObject(req.ExitFactor),
ExitFactorOther = req.ExitFactorOther,
Adjust = Newtonsoft.Json.JsonConvert.SerializeObject(req.Adjust),
AdjustOther = req.AdjustOther,
RealReason = req.RealReason,
NotExitFactor = req.NotExitFactor,
Havejob = req.Havejob,
HavejobReason = req.HavejobReason,
SuggestFriends = req.SuggestFriends,
SuggestFriendsReason = req.SuggestFriendsReason,
FutureWork = req.FutureWork,
FutureWorkReason = req.FutureWorkReason,
Suggestion = req.Suggestion,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
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-employee/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.RetirementEmployeeQuestions.AddAsync(period);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ส่งรายชื่อออกคำสั่ง C-PM-23
/// </summary>