เพิ่มรายการรักษาการ #2431

This commit is contained in:
Suphonchai Phoonsawat 2026-04-17 15:35:29 +07:00
parent 34ec9bb77c
commit 7bafbf5001
4 changed files with 398 additions and 23 deletions

View file

@ -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<GetPermissionWithActingResultDto?> 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<GetPermissionWithActingResultDto>(apiResult);
return raw;
}
return null;
}
}
catch
{
throw;
}
}
public async Task<dynamic> GetPermissionOrgAPIAsync(string action, string system, string profileId)
{
try

View file

@ -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<ActingPermission> 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();
}
}

View file

@ -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<ActionResult<ResponseObject>> 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<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
var jsonData = await _permission.GetPermissionWithActingAPIAsync("LIST", "SYS_CHECKIN_SPECIAL");
//var jsonData = JsonConvert.DeserializeObject<GetPermissionWithActingResultDto>(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();

View file

@ -1352,14 +1352,14 @@ namespace BMA.EHR.Leave.Service.Controllers
public async Task<ActionResult<ResponseObject>> GetLeaveRequestCalendarAdminAsync(
[FromBody] GetLeaveRequestCalendarDto req)
{
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_LEAVE_LIST");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
var jsonData = await _permission.GetPermissionWithActingAPIAsync("LIST", "SYS_LEAVE_LIST");
//var jsonData = JsonConvert.DeserializeObject<GetPermissionWithActingResultDto>(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<ActionResult<ResponseObject>> GetLeaveRequestForAdminAsync(
[FromBody] GetLeaveRequestForAdminDto req)
{
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_LEAVE_LIST");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
var jsonData = await _permission.GetPermissionWithActingAPIAsync("LIST", "SYS_LEAVE_LIST");
//var jsonData = JsonConvert.DeserializeObject<GetPermissionWithActingResultDto>(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<GetLeaveRequestForAdminResultDto>();
foreach (var item in rawData)
@ -1976,14 +2132,14 @@ namespace BMA.EHR.Leave.Service.Controllers
public async Task<ActionResult<ResponseObject>> GetCancelLeaveRequestForAdminAsync(
[FromBody] GetLeaveRequestForAdminDto req)
{
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_LEAVE_LIST");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
var jsonData = await _permission.GetPermissionWithActingAPIAsync("LIST", "SYS_LEAVE_LIST");
//var jsonData = JsonConvert.DeserializeObject<GetPermissionWithActingResultDto>(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 != "")