This commit is contained in:
parent
44cd46effc
commit
3ba0607a80
5 changed files with 189 additions and 116 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Reflection.Metadata;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Reflection.Metadata;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Responses;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
|
|
@ -9,6 +10,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories.Reports
|
||||
|
|
@ -21,20 +23,23 @@ namespace BMA.EHR.Application.Repositories.Reports
|
|||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly OrganizationCommonRepository _organizationCommonRepository;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public RetireReportRepository(IApplicationDBContext dbContext,
|
||||
MinIOService documentService,
|
||||
OrganizationCommonRepository organizationCommonRepository,
|
||||
IWebHostEnvironment hostEnvironment)
|
||||
MinIOService documentService,
|
||||
OrganizationCommonRepository organizationCommonRepository,
|
||||
IWebHostEnvironment hostEnvironment,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_hostingEnvironment = hostEnvironment;
|
||||
_organizationCommonRepository = organizationCommonRepository;
|
||||
_documentService = documentService;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -64,12 +69,33 @@ namespace BMA.EHR.Application.Repositories.Reports
|
|||
//}
|
||||
|
||||
#region รายงานประกาศเกษียณ
|
||||
public async Task<dynamic> GetProfileRetirementdAsync(Guid retireId)
|
||||
public async Task<dynamic> GetProfileRetirementdAsync(Guid retireId, string token)
|
||||
{
|
||||
var retire = await _dbContext.Set<RetirementPeriod>()
|
||||
.Include(x => x.RetirementProfiles)
|
||||
.FirstOrDefaultAsync(x => x.Id == retireId);
|
||||
// var retires = new List<dynamic>();
|
||||
var apiUrl = $"{_configuration["API"]}/org/root/search/sort";
|
||||
dynamic rootOrder = new List<string>();
|
||||
dynamic posTypeNameOrder = new List<string>();
|
||||
dynamic posLevelNameOrder = new List<string>();
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
||||
var _res = await client.SendAsync(_req);
|
||||
var _result = await _res.Content.ReadAsStringAsync();
|
||||
|
||||
var org = JsonConvert.DeserializeObject<dynamic>(_result);
|
||||
|
||||
if (org != null && org.result != null)
|
||||
{
|
||||
rootOrder = org.result.root;
|
||||
posTypeNameOrder = org.result.posTypeNameOrder;
|
||||
posLevelNameOrder = org.result.posLevelNameOrder;
|
||||
}
|
||||
}
|
||||
if (retire == null)
|
||||
{
|
||||
var retireHistorys = await _dbContext.Set<RetirementPeriodHistory>().AsQueryable()
|
||||
|
|
@ -121,16 +147,39 @@ namespace BMA.EHR.Application.Repositories.Reports
|
|||
profiles = profiles.OrderBy(x => x.order).ToList();
|
||||
}
|
||||
var mapProfiles = new List<ProfileRetireJsonRequest>();
|
||||
string previousRoot = null;
|
||||
string previousPosTypeName = null;
|
||||
string previousPosLevelName = null;
|
||||
if (profiles.Count > 0)
|
||||
{
|
||||
mapProfiles = profiles.Select((profile, index) => new ProfileRetireJsonRequest
|
||||
mapProfiles = profiles
|
||||
.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
|
||||
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
|
||||
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? ""))
|
||||
.Select((profile, index) =>
|
||||
{
|
||||
order = (index + 1).ToString().ToThaiNumber(),
|
||||
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
|
||||
root = profile.root,
|
||||
position = profile.position != "" && profile.position != null ? profile.position : "-",
|
||||
posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-",
|
||||
reason = profile.reason != "" && profile.reason != null ? profile.reason : "-",
|
||||
bool isDuplicateRoot = profile.root == previousRoot;
|
||||
previousRoot = profile.root;
|
||||
bool isDuplicatePosType = profile.posTypeName == previousPosTypeName;
|
||||
previousPosTypeName = profile.posTypeName;
|
||||
bool isDuplicatePosLevel = profile.posLevelName == previousPosLevelName;
|
||||
previousPosLevelName = profile.posLevelName;
|
||||
return new ProfileRetireJsonRequest
|
||||
{
|
||||
order = (index + 1).ToString().ToThaiNumber(),
|
||||
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
|
||||
root = (isDuplicateRoot ? "" : profile.root + "\n") +
|
||||
(isDuplicatePosType ? "" : profile.posTypeName + "\n") +
|
||||
(isDuplicatePosLevel ? "" : profile.posLevelName),
|
||||
child = (profile.posExecutiveName == null ? "" : profile.posExecutiveName + "\n") +
|
||||
(profile.child4 == null ? "" : profile.child4 + "\n") +
|
||||
(profile.child3 == null ? "" : profile.child3 + "\n") +
|
||||
(profile.child2 == null ? "" : profile.child2 + "\n") +
|
||||
(profile.child1 == null ? "" : profile.child1),
|
||||
position = profile.position != "" && profile.position != null ? profile.position : "-",
|
||||
posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-",
|
||||
reason = profile.reason != "" && profile.reason != null ? profile.reason : "-",
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
string SignDate = retireHistorys.SignDate != null ? DateTime.Parse(retireHistorys.SignDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber() : "-";
|
||||
|
|
@ -208,16 +257,39 @@ namespace BMA.EHR.Application.Repositories.Reports
|
|||
// retires.Add(data);
|
||||
// }
|
||||
var mapProfiles = new List<ProfileRetireJsonRequest>();
|
||||
string previousRoot = null;
|
||||
string previousPosTypeName = null;
|
||||
string previousPosLevelName = null;
|
||||
if (profile_retire.Count > 0)
|
||||
{
|
||||
mapProfiles = profile_retire.Select((profile, index) => new ProfileRetireJsonRequest
|
||||
mapProfiles = profile_retire
|
||||
.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
|
||||
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
|
||||
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? ""))
|
||||
.Select((profile, index) =>
|
||||
{
|
||||
order = (index + 1).ToString().ToThaiNumber(),
|
||||
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
|
||||
root = profile.root,
|
||||
position = profile.position != "" && profile.position != null ? profile.position : "-",
|
||||
posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-",
|
||||
reason = profile.reason != "" && profile.reason != null ? profile.reason : "-",
|
||||
bool isDuplicateRoot = profile.root == previousRoot;
|
||||
previousRoot = profile.root;
|
||||
bool isDuplicatePosType = profile.posTypeName == previousPosTypeName;
|
||||
previousPosTypeName = profile.posTypeName;
|
||||
bool isDuplicatePosLevel = profile.posLevelName == previousPosLevelName;
|
||||
previousPosLevelName = profile.posLevelName;
|
||||
return new ProfileRetireJsonRequest
|
||||
{
|
||||
order = (index + 1).ToString().ToThaiNumber(),
|
||||
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
|
||||
root = (isDuplicateRoot ? "" : profile.root + "\n") +
|
||||
(isDuplicatePosType ? "" : profile.posTypeName + "\n") +
|
||||
(isDuplicatePosLevel ? "" : profile.posLevelName),
|
||||
child = (profile.posExecutiveName == null ? "" : profile.posExecutiveName + "\n") +
|
||||
(profile.child4 == null ? "" : profile.child4 + "\n") +
|
||||
(profile.child3 == null ? "" : profile.child3 + "\n") +
|
||||
(profile.child2 == null ? "" : profile.child2 + "\n") +
|
||||
(profile.child1 == null ? "" : profile.child1),
|
||||
position = profile.position != "" && profile.position != null ? profile.position : "-",
|
||||
posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-",
|
||||
reason = profile.reason != "" && profile.reason != null ? profile.reason : "-",
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
string SignDate = retire.SignDate != null ? DateTime.Parse(retire.SignDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber() : "-";
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
public string? posNo { get; set; }
|
||||
public string? root { get; set; }
|
||||
public string? reason { get; set; }
|
||||
public string? child { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue