From 7bafbf5001d462edc59b7f215ef71ae446a1f38d Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 17 Apr 2026 15:35:29 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=A3?= =?UTF-8?q?=E0=B8=B1=E0=B8=81=E0=B8=A9=E0=B8=B2=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=20#2431?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/PermissionRepository.cs | 34 +++ .../Leaves/GetPermissionWithActingDto.cs | 32 +++ BMA.EHR.Leave/Controllers/LeaveController.cs | 87 +++++- .../Controllers/LeaveRequestController.cs | 268 ++++++++++++++++-- 4 files changed, 398 insertions(+), 23 deletions(-) create mode 100644 BMA.EHR.Application/Responses/Leaves/GetPermissionWithActingDto.cs diff --git a/BMA.EHR.Application/Repositories/PermissionRepository.cs b/BMA.EHR.Application/Repositories/PermissionRepository.cs index 84191f91..a63207ec 100644 --- a/BMA.EHR.Application/Repositories/PermissionRepository.cs +++ b/BMA.EHR.Application/Repositories/PermissionRepository.cs @@ -10,6 +10,7 @@ using System.Net.Http.Headers; using Microsoft.Extensions.Configuration; using System.Security.Claims; using System.Net.Http.Json; +using BMA.EHR.Application.Responses.Leaves; namespace BMA.EHR.Application.Repositories { @@ -76,6 +77,39 @@ namespace BMA.EHR.Application.Repositories } } + public async Task GetPermissionWithActingAPIAsync(string action, string system) + { + try + { + var apiPath = $"{_configuration["API"]}/org/permission/dotnet-acting/{action}/{system}"; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = + new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + var req = await client.GetAsync(apiPath); + if (!req.IsSuccessStatusCode) + { + throw new Exception("Error calling permission API"); + } + var apiResult = await req.Content.ReadAsStringAsync(); + //return res; + + if (apiResult != null) + { + var raw = JsonConvert.DeserializeObject(apiResult); + return raw; + } + return null; + } + } + catch + { + throw; + } + } + public async Task GetPermissionOrgAPIAsync(string action, string system, string profileId) { try diff --git a/BMA.EHR.Application/Responses/Leaves/GetPermissionWithActingDto.cs b/BMA.EHR.Application/Responses/Leaves/GetPermissionWithActingDto.cs new file mode 100644 index 00000000..0050f7d1 --- /dev/null +++ b/BMA.EHR.Application/Responses/Leaves/GetPermissionWithActingDto.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace BMA.EHR.Application.Responses.Leaves +{ + public class GetPermissionWithActingDto + { + public string privilege {get; set;} = string.Empty; + public bool isAct {get; set;} = false; + public List posMasterActs {get; set;} = new(); + } + + public class ActingPermission + { + public string posNo {get; set;} = string.Empty; + public string privilege {get; set;} = string.Empty; + public Guid? rootDnaId {get; set;} + public Guid? child1DnaId {get; set;} + public Guid? child2DnaId {get; set;} + public Guid? child3DnaId {get; set;} + public Guid? child4DnaId {get; set;} + } + + public class GetPermissionWithActingResultDto + { + public int status {get; set;} = 0; + public string message {get; set;} = string.Empty; + public GetPermissionWithActingDto result {get; set;} = new(); + } +} \ No newline at end of file diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index 60841b8d..8ff74510 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -3,8 +3,10 @@ using BMA.EHR.Application.Repositories.Commands; using BMA.EHR.Application.Repositories.Leaves.LeaveRequests; using BMA.EHR.Application.Repositories.Leaves.TimeAttendants; using BMA.EHR.Application.Repositories.MessageQueue; +using BMA.EHR.Application.Responses.Leaves; using BMA.EHR.Application.Responses.Profiles; using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Leave.TimeAttendants; using BMA.EHR.Domain.Models.Notifications; using BMA.EHR.Domain.Shared; @@ -3162,13 +3164,14 @@ namespace BMA.EHR.Leave.Service.Controllers [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetAdditionalCheckRequestAsync([Required] int year, [Required] int month, [Required] int page = 1, [Required] int pageSize = 10, string keyword = "", string? sortBy = "", bool? descending = false) { - var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_CHECKIN_SPECIAL"); - var jsonData = JsonConvert.DeserializeObject(getPermission); - if (jsonData["status"]?.ToString() != "200") + var jsonData = await _permission.GetPermissionWithActingAPIAsync("LIST", "SYS_CHECKIN_SPECIAL"); + //var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData!.status != 200) { - return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + return Error(jsonData.message, StatusCodes.Status403Forbidden); } - string role = jsonData["result"]?.ToString(); + //string role = jsonData["result"]?.ToString(); + string role = jsonData.result.privilege; var nodeId = string.Empty; var profileAdmin = new GetUserOCAllDto(); profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken); @@ -3206,6 +3209,80 @@ namespace BMA.EHR.Leave.Service.Controllers //var rawData = await _additionalCheckRequestRepository.GetAdditionalCheckRequests(year, month); var rawData = await _additionalCheckRequestRepository.GetAdditionalCheckRequestsByAdminRole(year, month, role, nodeId, profileAdmin?.Node, keyword); + // ถ้ามีการรักษาการ + if (jsonData.result.isAct) + { + var posActs = jsonData.result.posMasterActs; + foreach(var act in posActs) + { + var actRole = act.privilege; + string actNodeId = string.Empty; + int? actNode; + + if (role == "NORMAL" || role == "CHILD") + { + actNodeId = act.child4DnaId != null ? + act.child4DnaId.Value.ToString("D") : + act.child3DnaId != null ? + act.child3DnaId.Value.ToString("D") : + act.child2DnaId != null ? + act.child2DnaId.Value.ToString("D") : + act.child1DnaId != null ? + act.child1DnaId.Value.ToString("D") : + act.rootDnaId != null ? + act.rootDnaId.Value.ToString("D") : + ""; + actNode = act.child4DnaId != null ? + 4 : + act.child3DnaId != null ? + 3 : + act.child2DnaId != null ? + 2 : + act.child1DnaId != null ? + 1 : + act.rootDnaId != null ? + 0 : + null; + } + else if (role == "BROTHER") + { + actNodeId = act.child3DnaId != null ? + act.child3DnaId.Value.ToString("D") : + act.child2DnaId != null ? + act.child2DnaId.Value.ToString("D") : + act.child1DnaId != null ? + act.rootDnaId!.Value.ToString("D") : + act.rootDnaId != null ? + act.rootDnaId.Value.ToString("D") : + ""; + actNode = act.child4DnaId != null ? + 4 : + act.child3DnaId != null ? + 4 : + act.child2DnaId != null ? + 3 : + act.child1DnaId != null ? + 2 : + act.rootDnaId != null ? + 0 : + null; + } + else if (role == "ROOT" /*|| role == "PARENT"*/) + { + actNodeId = act.rootDnaId!.Value.ToString("D"); + actNode = 0; + } + + var rawDataAct = await _additionalCheckRequestRepository.GetAdditionalCheckRequestsByAdminRole(year, month, actRole, actNodeId, profileAdmin?.Node, keyword); + if (rawDataAct != null) + { + if (rawData != null) + rawData = rawData.Union(rawDataAct).ToList(); + else + rawData = rawDataAct; + } + } + } var total = rawData.Count; var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync(); diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index c2954ca4..5720bccc 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -1352,14 +1352,14 @@ namespace BMA.EHR.Leave.Service.Controllers public async Task> GetLeaveRequestCalendarAdminAsync( [FromBody] GetLeaveRequestCalendarDto req) { - var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_LEAVE_LIST"); - var jsonData = JsonConvert.DeserializeObject(getPermission); - if (jsonData["status"]?.ToString() != "200") + var jsonData = await _permission.GetPermissionWithActingAPIAsync("LIST", "SYS_LEAVE_LIST"); + //var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData!.status != 200) { - return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + return Error(jsonData.message, StatusCodes.Status403Forbidden); } - - string role = jsonData["result"]?.ToString(); + //string role = jsonData["result"]?.ToString(); + string role = jsonData.result.privilege; var nodeId = string.Empty; var profileAdmin = new GetUserOCAllDto(); profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken); @@ -1395,6 +1395,85 @@ namespace BMA.EHR.Leave.Service.Controllers } var data = await _leaveRequestRepository.GetLeaveRequestByYearForAdminAsync(req.Year, role, nodeId, profileAdmin.Node); + + // ถ้ามีการรักษาการ + if (jsonData.result.isAct) + { + var posActs = jsonData.result.posMasterActs; + foreach(var act in posActs) + { + var actRole = act.privilege; + string actNodeId = string.Empty; + int? actNode = null; + + if (role == "NORMAL" || role == "CHILD") + { + actNodeId = act.child4DnaId != null ? + act.child4DnaId.Value.ToString("D") : + act.child3DnaId != null ? + act.child3DnaId.Value.ToString("D") : + act.child2DnaId != null ? + act.child2DnaId.Value.ToString("D") : + act.child1DnaId != null ? + act.child1DnaId.Value.ToString("D") : + act.rootDnaId != null ? + act.rootDnaId.Value.ToString("D") : + ""; + actNode = act.child4DnaId != null ? + 4 : + act.child3DnaId != null ? + 3 : + act.child2DnaId != null ? + 2 : + act.child1DnaId != null ? + 1 : + act.rootDnaId != null ? + 0 : + null; + } + else if (role == "BROTHER") + { + actNodeId = act.child3DnaId != null ? + act.child3DnaId.Value.ToString("D") : + act.child2DnaId != null ? + act.child2DnaId.Value.ToString("D") : + act.child1DnaId != null ? + act.rootDnaId!.Value.ToString("D") : + act.rootDnaId != null ? + act.rootDnaId.Value.ToString("D") : + ""; + actNode = act.child4DnaId != null ? + 4 : + act.child3DnaId != null ? + 4 : + act.child2DnaId != null ? + 3 : + act.child1DnaId != null ? + 2 : + act.rootDnaId != null ? + 0 : + null; + } + else if (role == "ROOT" /*|| role == "PARENT"*/) + { + actNodeId = act.rootDnaId!.Value.ToString("D"); + actNode = 0; + } + + var rawDataAct = await _leaveRequestRepository.GetLeaveRequestByYearForAdminAsync(req.Year, actRole, actNodeId, actNode); + if (rawDataAct != null) + { + if (data != null) + data = data.Union(rawDataAct).ToList(); + else + data = rawDataAct; + } + } + } + + + + var resultData = (from d in data //join p in profileList on d.KeycloakUserId equals p.Keycloak select new GetLeaveRequestCalendarResultDto @@ -1750,14 +1829,14 @@ namespace BMA.EHR.Leave.Service.Controllers public async Task> GetLeaveRequestForAdminAsync( [FromBody] GetLeaveRequestForAdminDto req) { - var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_LEAVE_LIST"); - var jsonData = JsonConvert.DeserializeObject(getPermission); - if (jsonData["status"]?.ToString() != "200") + var jsonData = await _permission.GetPermissionWithActingAPIAsync("LIST", "SYS_LEAVE_LIST"); + //var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData!.status != 200) { - return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + return Error(jsonData.message, StatusCodes.Status403Forbidden); } - - string role = jsonData["result"]?.ToString(); + //string role = jsonData["result"]?.ToString(); + string role = jsonData.result.privilege; var nodeId = string.Empty; var profileAdmin = new GetUserOCAllDto(); profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken); @@ -1794,6 +1873,83 @@ namespace BMA.EHR.Leave.Service.Controllers var rawData = await _leaveRequestRepository.GetListLeaveRequestForAdminAsync(req.Year, req.Type, req.Status, req.StartDate, req.EndDate, role, nodeId, profileAdmin?.Node); + + // ถ้ามีการรักษาการ + if (jsonData.result.isAct) + { + var posActs = jsonData.result.posMasterActs; + foreach(var act in posActs) + { + var actRole = act.privilege; + string actNodeId = string.Empty; + int? actNode = null; + + if (role == "NORMAL" || role == "CHILD") + { + actNodeId = act.child4DnaId != null ? + act.child4DnaId.Value.ToString("D") : + act.child3DnaId != null ? + act.child3DnaId.Value.ToString("D") : + act.child2DnaId != null ? + act.child2DnaId.Value.ToString("D") : + act.child1DnaId != null ? + act.child1DnaId.Value.ToString("D") : + act.rootDnaId != null ? + act.rootDnaId.Value.ToString("D") : + ""; + actNode = act.child4DnaId != null ? + 4 : + act.child3DnaId != null ? + 3 : + act.child2DnaId != null ? + 2 : + act.child1DnaId != null ? + 1 : + act.rootDnaId != null ? + 0 : + null; + } + else if (role == "BROTHER") + { + actNodeId = act.child3DnaId != null ? + act.child3DnaId.Value.ToString("D") : + act.child2DnaId != null ? + act.child2DnaId.Value.ToString("D") : + act.child1DnaId != null ? + act.rootDnaId!.Value.ToString("D") : + act.rootDnaId != null ? + act.rootDnaId.Value.ToString("D") : + ""; + actNode = act.child4DnaId != null ? + 4 : + act.child3DnaId != null ? + 4 : + act.child2DnaId != null ? + 3 : + act.child1DnaId != null ? + 2 : + act.rootDnaId != null ? + 0 : + null; + } + else if (role == "ROOT" /*|| role == "PARENT"*/) + { + actNodeId = act.rootDnaId!.Value.ToString("D"); + actNode = 0; + } + + var rawDataAct = await _leaveRequestRepository.GetListLeaveRequestForAdminAsync(req.Year, req.Type, req.Status, req.StartDate, req.EndDate, actRole, actNodeId, actNode); + if (rawDataAct != null) + { + if (rawData != null) + rawData = rawData.Union(rawDataAct).ToList(); + else + rawData = rawDataAct; + } + } + } + + var result = new List(); foreach (var item in rawData) @@ -1976,14 +2132,14 @@ namespace BMA.EHR.Leave.Service.Controllers public async Task> GetCancelLeaveRequestForAdminAsync( [FromBody] GetLeaveRequestForAdminDto req) { - var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_LEAVE_LIST"); - var jsonData = JsonConvert.DeserializeObject(getPermission); - if (jsonData["status"]?.ToString() != "200") + var jsonData = await _permission.GetPermissionWithActingAPIAsync("LIST", "SYS_LEAVE_LIST"); + //var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData!.status != 200) { - return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + return Error(jsonData.message, StatusCodes.Status403Forbidden); } - - string role = jsonData["result"]?.ToString(); + //string role = jsonData["result"]?.ToString(); + string role = jsonData.result.privilege; var nodeId = string.Empty; var profileAdmin = new GetUserOCAllDto(); profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken); @@ -2021,6 +2177,82 @@ namespace BMA.EHR.Leave.Service.Controllers var rawData = await _leaveRequestRepository.GetCancelLeaveRequestForAdminAsync(req.Year, req.Type, req.Status, role, nodeId, profileAdmin?.Node); + // ถ้ามีการรักษาการ + if (jsonData.result.isAct) + { + var posActs = jsonData.result.posMasterActs; + foreach(var act in posActs) + { + var actRole = act.privilege; + string actNodeId = string.Empty; + int? actNode = null; + + if (role == "NORMAL" || role == "CHILD") + { + actNodeId = act.child4DnaId != null ? + act.child4DnaId.Value.ToString("D") : + act.child3DnaId != null ? + act.child3DnaId.Value.ToString("D") : + act.child2DnaId != null ? + act.child2DnaId.Value.ToString("D") : + act.child1DnaId != null ? + act.child1DnaId.Value.ToString("D") : + act.rootDnaId != null ? + act.rootDnaId.Value.ToString("D") : + ""; + actNode = act.child4DnaId != null ? + 4 : + act.child3DnaId != null ? + 3 : + act.child2DnaId != null ? + 2 : + act.child1DnaId != null ? + 1 : + act.rootDnaId != null ? + 0 : + null; + } + else if (role == "BROTHER") + { + actNodeId = act.child3DnaId != null ? + act.child3DnaId.Value.ToString("D") : + act.child2DnaId != null ? + act.child2DnaId.Value.ToString("D") : + act.child1DnaId != null ? + act.rootDnaId!.Value.ToString("D") : + act.rootDnaId != null ? + act.rootDnaId.Value.ToString("D") : + ""; + actNode = act.child4DnaId != null ? + 4 : + act.child3DnaId != null ? + 4 : + act.child2DnaId != null ? + 3 : + act.child1DnaId != null ? + 2 : + act.rootDnaId != null ? + 0 : + null; + } + else if (role == "ROOT" /*|| role == "PARENT"*/) + { + actNodeId = act.rootDnaId!.Value.ToString("D"); + actNode = 0; + } + + var rawDataAct = await _leaveRequestRepository.GetCancelLeaveRequestForAdminAsync(req.Year, req.Type, req.Status, actRole, actNodeId, actNode); + if (rawDataAct != null) + { + if (rawData != null) + rawData = rawData.Union(rawDataAct).ToList(); + else + rawData = rawDataAct; + } + } + } + + var recCount = rawData.Count; if (req.Keyword != "")