edit query

This commit is contained in:
kittapath 2025-10-09 21:43:25 +07:00
parent 9e8fe1b30a
commit 4ba48d0e70
2 changed files with 27 additions and 64 deletions

View file

@ -9,6 +9,7 @@ using BMA.EHR.Domain.Models.Organizations;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Nest;
using Newtonsoft.Json;
namespace BMA.EHR.Application.Repositories
@ -532,7 +533,7 @@ namespace BMA.EHR.Application.Repositories
nodeId = nodeId,
role = role,
revisionId = revisionId,
reqNode = reqNode,
reqNode = reqNode,
reqNodeId = reqNodeId
};
@ -686,7 +687,7 @@ namespace BMA.EHR.Application.Repositories
}
}
public async Task<List<GetProfileByKeycloakIdRootDto>> GetEmployeeByAdminRole(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId )
public async Task<List<GetProfileByKeycloakIdRootDto>> GetEmployeeByAdminRole(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId)
{
try
{
@ -720,7 +721,7 @@ namespace BMA.EHR.Application.Repositories
}
}
public async Task<List<SearchProfileDto>> SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken, string? role, string? nodeId, int? node)
public async Task<dynamic> SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken, int page, int pageSize, string? role, string? nodeId, int? node)
{
try
{
@ -734,41 +735,25 @@ namespace BMA.EHR.Application.Repositories
role = role,
nodeId = nodeId,
node = node,
page = page,
pageSize = pageSize,
};
var profiles = new List<SearchProfileDto>();
var profiles = new List<dynamic>();
var total = 0;
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<SearchProfileResultDto>(apiResult);
var raw = JsonConvert.DeserializeObject<dynamic>(apiResult);
if (raw != null && raw.Result != null)
{
profiles.AddRange(raw.Result);
profiles.AddRange(raw.Result.data);
total = raw.Result.total;
}
}
return profiles;
//var data = _dbContext.Set<Profile>().AsQueryable()
// .Where(x => x.ProfileType == "officer");
//if (citizenId != null)
// data = data.Where(x => x.CitizenId!.Contains(citizenId));
//if (firstName != null)
// data = data.Where(x => x.FirstName!.Contains(firstName));
//if (lastName != null)
// data = data.Where(x => x.LastName!.Contains(lastName));
//data = data.Include(x => x.Prefix)
// .Include(x => x.Position)
// .Include(x => x.PositionLevel)
// .Include(x => x.PosNo);
//return await data.ToListAsync();
return new { data = profiles, total = total };
}
catch
{
@ -776,7 +761,7 @@ namespace BMA.EHR.Application.Repositories
}
}
public async Task<List<SearchProfileDto>> SearchProfileEmployee(string? citizenId, string? firstName, string? lastName, string accessToken, string? role, string? nodeId, int? node)
public async Task<dynamic> SearchProfileEmployee(string? citizenId, string? firstName, string? lastName, string accessToken, int page, int pageSize, string? role, string? nodeId, int? node)
{
try
{
@ -790,41 +775,25 @@ namespace BMA.EHR.Application.Repositories
role = role,
nodeId = nodeId,
node = node,
page = page,
pageSize = pageSize,
};
var profiles = new List<SearchProfileDto>();
var profiles = new List<dynamic>();
var total = 0;
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<SearchProfileResultDto>(apiResult);
var raw = JsonConvert.DeserializeObject<dynamic>(apiResult);
if (raw != null && raw.Result != null)
{
profiles.AddRange(raw.Result);
profiles.AddRange(raw.Result.data);
total = raw.Result.total;
}
}
return profiles;
//var data = _dbContext.Set<Profile>().AsQueryable()
// .Where(x => x.ProfileType == "employee");
//if (citizenId != null)
// data = data.Where(x => x.CitizenId!.Contains(citizenId));
//if (firstName != null)
// data = data.Where(x => x.FirstName!.Contains(firstName));
//if (lastName != null)
// data = data.Where(x => x.LastName!.Contains(lastName));
//data = data.Include(x => x.Prefix);
////.Include(x => x.PosNoEmployee);
//return await data.ToListAsync();
return new { data = profiles, total = total };
}
catch
{

View file

@ -1718,17 +1718,14 @@ namespace BMA.EHR.Leave.Service.Controllers
{
nodeId = profileAdmin?.RootDnaId;
}
var profile = await _userProfileRepository.SearchProfile(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", role, nodeId, profileAdmin?.Node);
var pagedProfile = profile.Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList();
var profile = await _userProfileRepository.SearchProfile(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", req.Page, req.PageSize, role, nodeId, profileAdmin?.Node);
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
var resultSet = new List<SearchProfileResultDto>();
foreach (var p in pagedProfile)
foreach (var p in profile.data)
{
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
@ -1747,7 +1744,7 @@ namespace BMA.EHR.Leave.Service.Controllers
resultSet.Add(res);
}
return Success(new { data = resultSet, total = profile.Count });
return Success(new { data = resultSet, total = profile.total });
}
/// <summary>
@ -1907,17 +1904,14 @@ namespace BMA.EHR.Leave.Service.Controllers
{
nodeId = profileAdmin?.RootDnaId;
}
var profile = await _userProfileRepository.SearchProfileEmployee(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", role, nodeId, profileAdmin?.Node);
var pagedProfile = profile.Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList();
var profile = await _userProfileRepository.SearchProfileEmployee(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", req.Page, req.PageSize, role, nodeId, profileAdmin?.Node);
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
var resultSet = new List<SearchProfileResultDto>();
foreach (var p in pagedProfile)
foreach (var p in profile.data)
{
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
@ -1936,7 +1930,7 @@ namespace BMA.EHR.Leave.Service.Controllers
resultSet.Add(res);
}
return Success(new { data = resultSet, total = profile.Count });
return Success(new { data = resultSet, total = profile.total });
}
/// <summary>