edit query
This commit is contained in:
parent
9e8fe1b30a
commit
4ba48d0e70
2 changed files with 27 additions and 64 deletions
|
|
@ -9,6 +9,7 @@ using BMA.EHR.Domain.Models.Organizations;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Nest;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace BMA.EHR.Application.Repositories
|
namespace BMA.EHR.Application.Repositories
|
||||||
|
|
@ -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
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -734,41 +735,25 @@ namespace BMA.EHR.Application.Repositories
|
||||||
role = role,
|
role = role,
|
||||||
nodeId = nodeId,
|
nodeId = nodeId,
|
||||||
node = node,
|
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);
|
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
|
||||||
if (apiResult != null)
|
if (apiResult != null)
|
||||||
{
|
{
|
||||||
var raw = JsonConvert.DeserializeObject<SearchProfileResultDto>(apiResult);
|
var raw = JsonConvert.DeserializeObject<dynamic>(apiResult);
|
||||||
if (raw != null && raw.Result != null)
|
if (raw != null && raw.Result != null)
|
||||||
{
|
{
|
||||||
profiles.AddRange(raw.Result);
|
profiles.AddRange(raw.Result.data);
|
||||||
|
total = raw.Result.total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return profiles;
|
return new { data = profiles, total = total };
|
||||||
|
|
||||||
//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();
|
|
||||||
}
|
}
|
||||||
catch
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -790,41 +775,25 @@ namespace BMA.EHR.Application.Repositories
|
||||||
role = role,
|
role = role,
|
||||||
nodeId = nodeId,
|
nodeId = nodeId,
|
||||||
node = node,
|
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);
|
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
|
||||||
if (apiResult != null)
|
if (apiResult != null)
|
||||||
{
|
{
|
||||||
var raw = JsonConvert.DeserializeObject<SearchProfileResultDto>(apiResult);
|
var raw = JsonConvert.DeserializeObject<dynamic>(apiResult);
|
||||||
if (raw != null && raw.Result != null)
|
if (raw != null && raw.Result != null)
|
||||||
{
|
{
|
||||||
profiles.AddRange(raw.Result);
|
profiles.AddRange(raw.Result.data);
|
||||||
|
total = raw.Result.total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return profiles;
|
return new { data = profiles, total = total };
|
||||||
|
|
||||||
|
|
||||||
//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();
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1718,17 +1718,14 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
{
|
{
|
||||||
nodeId = profileAdmin?.RootDnaId;
|
nodeId = profileAdmin?.RootDnaId;
|
||||||
}
|
}
|
||||||
var profile = await _userProfileRepository.SearchProfile(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", role, nodeId, profileAdmin?.Node);
|
var profile = await _userProfileRepository.SearchProfile(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", req.Page, req.PageSize, role, nodeId, profileAdmin?.Node);
|
||||||
|
|
||||||
var pagedProfile = profile.Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList();
|
|
||||||
|
|
||||||
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||||
|
|
||||||
var resultSet = new List<SearchProfileResultDto>();
|
var resultSet = new List<SearchProfileResultDto>();
|
||||||
|
|
||||||
foreach (var p in pagedProfile)
|
foreach (var p in profile.data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
|
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
|
||||||
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
|
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
|
||||||
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
|
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
|
||||||
|
|
@ -1747,7 +1744,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
resultSet.Add(res);
|
resultSet.Add(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Success(new { data = resultSet, total = profile.Count });
|
return Success(new { data = resultSet, total = profile.total });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1907,17 +1904,14 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
{
|
{
|
||||||
nodeId = profileAdmin?.RootDnaId;
|
nodeId = profileAdmin?.RootDnaId;
|
||||||
}
|
}
|
||||||
var profile = await _userProfileRepository.SearchProfileEmployee(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", role, nodeId, profileAdmin?.Node);
|
var profile = await _userProfileRepository.SearchProfileEmployee(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", req.Page, req.PageSize, role, nodeId, profileAdmin?.Node);
|
||||||
|
|
||||||
var pagedProfile = profile.Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList();
|
|
||||||
|
|
||||||
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||||
|
|
||||||
var resultSet = new List<SearchProfileResultDto>();
|
var resultSet = new List<SearchProfileResultDto>();
|
||||||
|
|
||||||
foreach (var p in pagedProfile)
|
foreach (var p in profile.data)
|
||||||
{
|
{
|
||||||
|
|
||||||
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
|
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
|
||||||
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
|
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
|
||||||
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
|
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
|
||||||
|
|
@ -1936,7 +1930,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
resultSet.Add(res);
|
resultSet.Add(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Success(new { data = resultSet, total = profile.Count });
|
return Success(new { data = resultSet, total = profile.total });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue