fix bug report #1368, #1578

This commit is contained in:
Bright 2025-06-17 18:07:41 +07:00
parent 360580535a
commit e790b50f58
3 changed files with 215 additions and 21 deletions

View file

@ -1465,24 +1465,59 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
{
// var _nodeId = Guid.Parse(nodeId);
var data = new List<LeaveRequest>();
//if (role == "OWNER" || role == "CHILD")
//{
// data = await _dbContext.Set<LeaveRequest>().AsQueryable()
// .Include(x => x.Type)
// .Where(x => x.ProfileType == type.Trim().ToUpper())
// .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
// .Where(x => node == 4 ? x.Child4Id == Guid.Parse(nodeId) : (node == 3 ? x.Child3Id == Guid.Parse(nodeId) : (node == 2 ? x.Child2Id == Guid.Parse(nodeId) : (node == 1 ? x.Child1Id == Guid.Parse(nodeId) : (node == 0 ? x.RootId == Guid.Parse(nodeId) : (node == null ? true : true))))))
// .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING").ToListAsync();
//}
//else
//{
// data = await _dbContext.Set<LeaveRequest>().AsQueryable()
// .Include(x => x.Type)
// .Where(x => x.ProfileType == type.Trim().ToUpper())
// .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
// .Where(x => node == 4 ? x.Child4Id == Guid.Parse(nodeId) : (node == 3 ? x.Child3Id == Guid.Parse(nodeId) : (node == 2 ? x.Child2Id == Guid.Parse(nodeId) : (node == 1 ? x.Child1Id == Guid.Parse(nodeId) : (node == 0 ? x.RootId == Guid.Parse(nodeId) : (node == null ? true : true))))))
// .Where(x => node == 0 ? x.Child1Id == null : (node == 1 ? x.Child2Id == null : (node == 2 ? x.Child3Id == null : (node == 3 ? x.Child4Id == null : true))))
// .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING").ToListAsync();
//}
data = await _dbContext.Set<LeaveRequest>().AsQueryable()
.Include(x => x.Type)
.Where(x => x.ProfileType == type.Trim().ToUpper())
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING").ToListAsync();
if (role == "OWNER")
{
node = null;
}
if (role == "OWNER" || role == "CHILD")
{
data = await _dbContext.Set<LeaveRequest>().AsQueryable()
.Include(x => x.Type)
.Where(x => x.ProfileType == type.Trim().ToUpper())
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
.Where(x => node == 4 ? x.Child4Id == Guid.Parse(nodeId) : (node == 3 ? x.Child3Id == Guid.Parse(nodeId) : (node == 2 ? x.Child2Id == Guid.Parse(nodeId) : (node == 1 ? x.Child1Id == Guid.Parse(nodeId) : (node == 0 ? x.RootId == Guid.Parse(nodeId) : (node == null ? true : true))))))
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING").ToListAsync();
data = data.Where(x =>
node == 4 ? x.Child4DnaId == Guid.Parse(nodeId) :
node == 3 ? x.Child3DnaId == Guid.Parse(nodeId) :
node == 2 ? x.Child2DnaId == Guid.Parse(nodeId) :
node == 1 ? x.Child1DnaId == Guid.Parse(nodeId) :
node == 0 ? x.RootDnaId == Guid.Parse(nodeId) :
node == null ? true : true
).ToList();
}
else
else if (role == "ROOT")
{
data = await _dbContext.Set<LeaveRequest>().AsQueryable()
.Include(x => x.Type)
.Where(x => x.ProfileType == type.Trim().ToUpper())
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
.Where(x => node == 4 ? x.Child4Id == Guid.Parse(nodeId) : (node == 3 ? x.Child3Id == Guid.Parse(nodeId) : (node == 2 ? x.Child2Id == Guid.Parse(nodeId) : (node == 1 ? x.Child1Id == Guid.Parse(nodeId) : (node == 0 ? x.RootId == Guid.Parse(nodeId) : (node == null ? true : true))))))
.Where(x => node == 0 ? x.Child1Id == null : (node == 1 ? x.Child2Id == null : (node == 2 ? x.Child3Id == null : (node == 3 ? x.Child4Id == null : true))))
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING").ToListAsync();
data = data.Where(x => x.RootDnaId == Guid.Parse(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();
}
var res = (from d in data

View file

@ -523,6 +523,38 @@ namespace BMA.EHR.Application.Repositories
}
}
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileByAdminRole(string? accessToken, int? node, string? nodeId, string role, string? revisionId)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/officer-by-admin-role";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
role = role,
revisionId = revisionId,
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithKeycloakAllOfficerRetireFilterAndRevision(string? accessToken, int? node, string? nodeId, bool isAll, bool? isRetirement, string? revisionId)
{
try
@ -619,6 +651,39 @@ namespace BMA.EHR.Application.Repositories
throw;
}
}
public async Task<List<GetProfileByKeycloakIdRootDto>> GetEmployeeByAdminRole(string? accessToken, int? node, string? nodeId, string role, string? revisionId)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/employee-by-admin-role";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
role = role,
revisionId = revisionId,
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<List<SearchProfileDto>> SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken)
{
try