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

@ -1,5 +1,6 @@
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Discipline.Service.Requests;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
@ -32,6 +33,7 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly NotificationRepository _repositoryNoti;
private readonly IConfiguration _configuration;
private readonly UserProfileRepository _userProfileRepository;
private readonly PermissionRepository _permission;
public DisciplineComplaint_AppealController(DisciplineDbContext context,
@ -40,6 +42,7 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
MinIODisciplineService documentService,
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration,
UserProfileRepository userProfileRepository,
PermissionRepository permission)
{
// _repository = repository;
@ -49,6 +52,7 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
_userProfileRepository = userProfileRepository;
_permission = permission;
}
@ -58,6 +62,8 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.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"];
private static string StatusDisciplineComplaintAppeal(string value)
{
switch (value)
@ -361,6 +367,36 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.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/{id}";
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);
disciplineComplaint_Appeal.root = org.result.root;
disciplineComplaint_Appeal.rootId = org.result.rootId;
disciplineComplaint_Appeal.rootDnaId = org.result.rootDnaId;
disciplineComplaint_Appeal.child1 = org.result.child1;
disciplineComplaint_Appeal.child1Id = org.result.child1Id;
disciplineComplaint_Appeal.child1DnaId = org.result.child1DnaId;
disciplineComplaint_Appeal.child2 = org.result.child2;
disciplineComplaint_Appeal.child2Id = org.result.child2Id;
disciplineComplaint_Appeal.child2DnaId = org.result.child2DnaId;
disciplineComplaint_Appeal.child3 = org.result.child3;
disciplineComplaint_Appeal.child3Id = org.result.child3Id;
disciplineComplaint_Appeal.child3DnaId = org.result.child3DnaId;
disciplineComplaint_Appeal.child4 = org.result.child4;
disciplineComplaint_Appeal.child4Id = org.result.child4Id;
disciplineComplaint_Appeal.child4DnaId = org.result.child4DnaId;
}
var disciplineComplaint_Appeal_History = new DisciplineComplaint_Appeal_History
{
DisciplineComplaint_Appeal = disciplineComplaint_Appeal,
@ -469,6 +505,37 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.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/{req.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);
disciplineComplaint_Appeal.root = org.result.root;
disciplineComplaint_Appeal.rootId = org.result.rootId;
disciplineComplaint_Appeal.rootDnaId = org.result.rootDnaId;
disciplineComplaint_Appeal.child1 = org.result.child1;
disciplineComplaint_Appeal.child1Id = org.result.child1Id;
disciplineComplaint_Appeal.child1DnaId = org.result.child1DnaId;
disciplineComplaint_Appeal.child2 = org.result.child2;
disciplineComplaint_Appeal.child2Id = org.result.child2Id;
disciplineComplaint_Appeal.child2DnaId = org.result.child2DnaId;
disciplineComplaint_Appeal.child3 = org.result.child3;
disciplineComplaint_Appeal.child3Id = org.result.child3Id;
disciplineComplaint_Appeal.child3DnaId = org.result.child3DnaId;
disciplineComplaint_Appeal.child4 = org.result.child4;
disciplineComplaint_Appeal.child4Id = org.result.child4Id;
disciplineComplaint_Appeal.child4DnaId = org.result.child4DnaId;
}
var disciplineComplaint_Appeal_History = new DisciplineComplaint_Appeal_History
{
DisciplineComplaint_Appeal = disciplineComplaint_Appeal,
@ -653,6 +720,30 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.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_search = (from x in _context.DisciplineComplaint_Appeals
where (x.Title == null ? false : x.Title.Contains(keyword)) ||
(x.Description == null ? false : x.Description.Contains(keyword)) ||
@ -667,6 +758,26 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
data_search = data_search.Where(x => x.Type == type).ToList();
if (year != 0)
data_search = data_search.Where(x => x.Year == year).ToList();
if (role == "OWNER")
{
node = null;
}
if (role == "OWNER" || role == "CHILD")
{
data_search = data_search
.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_search = data_search
.Where(x => x.rootDnaId == nodeId).ToList();
}
else if (role == "NORMAL")
{
data_search = data_search
.Where(x => node == 0 ? x.child1DnaId == null : (node == 1 ? x.child2DnaId == null : (node == 2 ? x.child3DnaId == null : (node == 3 ? x.child4DnaId == null : true)))).ToList();
}
var data = data_search
.Select(x => new
{

View file

@ -0,0 +1,55 @@
namespace BMA.EHR.Discipline.Service.Requests
{
public class OrgRequest
{
public OrgRequestData result { get; set; } = new();
}
public class OrgRequestData
{
public string? profileId { get; set; }
public string? prefix { get; set; }
public string? firstName { get; set; }
public string? lastName { get; set; }
public string? citizenId { get; set; }
public string? root { get; set; }
public string? rootId { get; set; }
public string? rootDnaId { get; set; }
public string? rootShortName { get; set; }
public string? child1 { get; set; }
public string? child1Id { get; set; }
public string? child1DnaId { get; set; }
public string? child1ShortName { get; set; }
public string? child2 { get; set; }
public string? child2Id { get; set; }
public string? child2DnaId { get; set; }
public string? child2ShortName { get; set; }
public string? child3 { get; set; }
public string? child3Id { get; set; }
public string? child3DnaId { get; set; }
public string? child3ShortName { get; set; }
public string? child4 { get; set; }
public string? child4Id { get; set; }
public string? child4DnaId { get; set; }
public string? child4ShortName { get; set; }
public string? node { get; set; }
public string? nodeId { get; set; }
public string? nodeShortName { get; set; }
public int? posMasterNo { get; set; }
public string? position { get; set; }
public string? posTypeId { get; set; }
public string? posTypeName { get; set; }
public int? posTypeRank { get; set; }
public string? posLevelId { get; set; }
public string? posTypeShortName { get; set; }
public string? posLevelName { get; set; }
public int? posLevelRank { get; set; }
public string? posExecutiveId { get; set; }
public string? posExecutiveName { get; set; }
public string? positionExecutiveField { get; set; }
public string? positionArea { get; set; }
public string? posNo { get; set; }
public DateTime? leaveDate { get; set; }
public string? education { get; set; }
public double? salary { get; set; }
}
}