checkpoint #852 (1,2)

This commit is contained in:
AdisakKanthawilang 2025-01-10 19:26:19 +07:00
parent 564a23988d
commit b636233bfd
3 changed files with 314 additions and 100 deletions

View file

@ -3,6 +3,7 @@ using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Application.Responses;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Commands.Core;
using BMA.EHR.Domain.Models.HR;
using BMA.EHR.Domain.Models.Insignias;
using BMA.EHR.Domain.Models.MetaData;
@ -14,7 +15,9 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
using System.Net.Http.Headers;
namespace BMA.EHR.Application.Repositories.Reports
{
@ -743,31 +746,81 @@ namespace BMA.EHR.Application.Repositories.Reports
}
//44-บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ
public async Task<dynamic> GetSummaryCoinReport(Guid id)
public async Task<dynamic> GetSummaryCoinReport(Guid id, string type = null, int node = -1, Guid nodeId = default)
{
var period = await _dbContext.Set<InsigniaPeriod>()
.FirstOrDefaultAsync(x => x.Id == id);
if (period == null)
throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
var data_insignia = await _dbContext.Set<InsigniaRequestProfile>()
//.Include(x => x.Profile)
.Where(x => x.Request.Period.Id == period.Id)
.Where(x => x.IsApprove == true)
.Where(x => x.Status == "PENDING")
.Where(x => x.RequestInsignia.InsigniaType != null)
.Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ")
.Select(x => new
{
//Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name,
Gendor = x.Gender, //_userProfileRepository.GetOfficerProfileById(x.ProfileId, AccessToken).Gender ?? "",
RequestInsigniaName = x.RequestInsignia.Name,
InsigniaInitial = $"{x.RequestInsignia.Name}({x.RequestInsignia.ShortName})",
OcId = x.Request.OrganizationId
})
.ToListAsync();
/* var data_insignia = await _dbContext.Set<InsigniaRequestProfile>()
//.Include(x => x.Profile)
.Where(x => x.Request.Period.Id == period.Id)
.Where(x => x.IsApprove == true)
.Where(x => x.Status == "PENDING")
.Where(x => x.RequestInsignia.InsigniaType != null)
.Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ")
.Select(x => new
{
//Gendor = x.Profile.Gender == null ? null : x.Profile.Gender.Name,
Gendor = x.Gender, //_userProfileRepository.GetOfficerProfileById(x.ProfileId, AccessToken).Gender ?? "",
RequestInsigniaName = x.RequestInsignia.Name,
InsigniaInitial = $"{x.RequestInsignia.Name}({x.RequestInsignia.ShortName})",
OcId = x.Request.OrganizationId
})
.ToListAsync();*/
var data_insigniaQuery = _dbContext.Set<InsigniaRequestProfile>()
.Where(x => x.Request.Period.Id == period.Id)
.Where(x => x.IsApprove == true)
.Where(x => x.Status == "PENDING")
.Where(x => x.RequestInsignia.InsigniaType != null)
.Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ");
var insignia = (from r in data_insignia
if (type == "officer")
{
data_insigniaQuery = data_insigniaQuery.Where(r => r.ProfileType == "officer");
}
else if (type == "employee")
{
data_insigniaQuery = data_insigniaQuery.Where(r => r.ProfileType == "employee");
}
switch (node)
{
case 0:
data_insigniaQuery = data_insigniaQuery.Where(r => r.RootId == nodeId);
break;
case 1:
data_insigniaQuery = data_insigniaQuery.Where(r => r.Child1Id == nodeId);
break;
case 2:
data_insigniaQuery = data_insigniaQuery.Where(r => r.Child2Id == nodeId);
break;
case 3:
data_insigniaQuery = data_insigniaQuery.Where(r => r.Child3Id == nodeId);
break;
case 4:
data_insigniaQuery = data_insigniaQuery.Where(r => r.Child4Id == nodeId);
break;
default:
break;
}
var data = await data_insigniaQuery
.Select(x => new
{
Gendor = x.Gender, // Gender as is, directly from x.Gender
RequestInsigniaName = x.RequestInsignia.Name, // Name of the Insignia
InsigniaInitial = $"{x.RequestInsignia.Name}({x.RequestInsignia.ShortName})", // Insignia's full name and short name
OcId = x.Request.OrganizationId // Organization ID
})
.ToListAsync();
var insignia = (from r in data
group r by new { OcId = r.OcId, InsigniaInitial = r.InsigniaInitial } into g
select new
{
@ -832,7 +885,7 @@ namespace BMA.EHR.Application.Repositories.Reports
}
//45-บัญชีแสดงรายชื่อผู้ขอพระราชทานเหรียญจักรพรรดิมาลา
public async Task<dynamic> GetCoinReport(Guid id)
public async Task<dynamic> GetCoinReport(Guid id, string type = null, int node = -1, Guid nodeId = default)
{
var period = await _dbContext.Set<InsigniaPeriod>()
.FirstOrDefaultAsync(x => x.Id == id);
@ -856,45 +909,89 @@ namespace BMA.EHR.Application.Repositories.Reports
&& r.Status == "PENDING"
&& r.RequestInsignia.InsigniaType != null
&& r.RequestInsignia.InsigniaType.Name != "เหรียญบำเหน็จในราชการ"
select new
select new
{
Male = r.Gender == "ชาย" ? 1 : 0,
Female = r.Gender == "หญิง" ? 1 : 0,
})
.Distinct()
.ToList();
var data = (from r in await _dbContext.Set<InsigniaRequestProfile>()
//.Include(x => x.Profile)
//.ThenInclude(x => x.Gender)
//.Include(x => x.Profile)
//.ThenInclude(x => x.Prefix)
.Include(x => x.Request)
.ThenInclude(x => x.Period)
.Include(x => x.Request)
//.ThenInclude(x => x.Organization)
.Include(x => x.RequestInsignia)
.ThenInclude(x => x.InsigniaType)
.ToListAsync()
where r.Request.Period == period
&& r.IsApprove == true
&& r.Status == "PENDING"
&& r.RequestInsignia.InsigniaType != null
&& r.RequestInsignia.InsigniaType.Name != "เหรียญบำเหน็จในราชการ"
select new
{
InsigniaInitial = r.RequestInsignia.ShortName,
InsigniaName = r.RequestInsignia.Name,
ProfileId = r.ProfileId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
// $"{r.Profile.Prefix?.Name}{r.Profile.FirstName} {r.Profile.LastName}",
Gender = r.Gender,
Male = gender.Sum(x => x.Male),
Female = gender.Sum(x => x.Female),
InsigniaId = r.RequestInsignia.Id,
OCName = _userProfileRepository.GetOc(r.Request.OrganizationId, 0, AccessToken).Root, //_organizationCommonRepository.GetOrganizationNameFullPath(g.Key.OcId, false, false),
})
.Distinct()
.ToList();
var dataQuery = _dbContext.Set<InsigniaRequestProfile>()
.Include(x => x.Request)
.ThenInclude(x => x.Period)
.Include(x => x.Request)
/*.ThenInclude(x => x.Organization)*/
.Include(x => x.RequestInsignia)
.ThenInclude(x => x.InsigniaType)
.Where(r => r.Request.Period == period
&& r.IsApprove == true
&& r.Status == "PENDING"
&& r.RequestInsignia.InsigniaType != null
&& r.RequestInsignia.InsigniaType.Name != "เหรียญบำเหน็จในราชการ");
if (type == "officer")
{
dataQuery = dataQuery.Where(r => r.ProfileType == "officer");
}
else if (type == "employee")
{
dataQuery = dataQuery.Where(r => r.ProfileType == "employee");
}
switch (node)
{
case 0:
dataQuery = dataQuery.Where(r => r.RootId == nodeId);
break;
case 1:
dataQuery = dataQuery.Where(r => r.Child1Id == nodeId);
break;
case 2:
dataQuery = dataQuery.Where(r => r.Child2Id == nodeId);
break;
case 3:
dataQuery = dataQuery.Where(r => r.Child3Id == nodeId);
break;
case 4:
dataQuery = dataQuery.Where(r => r.Child4Id == nodeId);
break;
default:
break;
}
// Grouping by ProfileId and InsigniaId, and calculating the sum for Male and Female
var data = await dataQuery
.GroupBy(r => new
{
r.RequestInsignia.ShortName,
r.RequestInsignia.Name,
r.ProfileId,
r.Prefix,
r.FirstName,
r.LastName,
r.Gender,
r.RequestInsignia.Id,
r.Request.OrganizationId
})
.Select(group => new
{
InsigniaInitial = group.Key.ShortName,
InsigniaName = group.Key.Name,
ProfileId = group.Key.ProfileId,
FullName = $"{group.Key.Prefix}{group.Key.FirstName} {group.Key.LastName}",
Gender = group.Key.Gender,
Male = group.Count(r => r.Gender == "Male"), // Count male entries
Female = group.Count(r => r.Gender == "Female"), // Count female entries
InsigniaId = group.Key.Id,
OCName = _userProfileRepository.GetOc(group.Key.OrganizationId, 0, AccessToken).Root
})
.Distinct()
.ToListAsync();
// loop to add temp row with 50 rows per page
var insigniaList = data.Select(x => new { InsigniaId = x.InsigniaId, InsigniaInitial = x.InsigniaInitial, InsigniaName = x.InsigniaName })
@ -959,6 +1056,115 @@ namespace BMA.EHR.Application.Repositories.Reports
return s_data;
}
//47-บัญชีระดับผลการประเมินผลการปฏิบัติราชการในรอบ 5 ปี
public async Task<dynamic> GetEvaluationResultReport(Guid id, string type = null, int node = -1, Guid nodeId = default)
{
var period = await _dbContext.Set<InsigniaPeriod>()
.FirstOrDefaultAsync(x => x.Id == id);
if (period == null)
throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
var data_insigniaQuery = _dbContext.Set<InsigniaRequestProfile>()
.Where(x => x.Request.Period.Id == period.Id)
.Where(x => x.IsApprove == true)
.Where(x => x.Status == "PENDING")
.Where(x => x.RequestInsignia.InsigniaType != null);
/*.Where(x => x.RequestInsignia.InsigniaType.Name == "เหรียญบำเหน็จในราชการ");*/
if (type == "officer")
{
data_insigniaQuery = data_insigniaQuery.Where(r => r.ProfileType == "officer");
}
else if (type == "employee")
{
data_insigniaQuery = data_insigniaQuery.Where(r => r.ProfileType == "employee");
}
switch (node)
{
case 0:
data_insigniaQuery = data_insigniaQuery.Where(r => r.RootId == nodeId);
break;
case 1:
data_insigniaQuery = data_insigniaQuery.Where(r => r.Child1Id == nodeId);
break;
case 2:
data_insigniaQuery = data_insigniaQuery.Where(r => r.Child2Id == nodeId);
break;
case 3:
data_insigniaQuery = data_insigniaQuery.Where(r => r.Child3Id == nodeId);
break;
case 4:
data_insigniaQuery = data_insigniaQuery.Where(r => r.Child4Id == nodeId);
break;
default:
break;
}
var data = await data_insigniaQuery
.Select(x => new
{
FullName = $"{x.Prefix}{x.FirstName} {x.LastName}",
RequestInsigniaName = x.RequestInsignia.Name, // Name of the Insignia
})
.ToListAsync();
/* var seq = 1;
foreach (var d in response!.result)
{
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.person.id}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
_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<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
};
seq++;
resultData.Add(receiver);
}
}*/
var insignia = data.Select((r, index) => new
{
RowNo = (index + 1).ToNumericText().ToThaiNumber(),
FullName = r.FullName,
RequestInsigniaName = r.RequestInsigniaName,
ResultY1APR = "-",
ResultY1OCT = "-",
ResultY2APR = "-",
ResultY2OCT = "-",
ResultY3APR = "-",
ResultY3OCT = "-",
ResultY4APR = "-",
ResultY4OCT = "-",
ResultY5APR = "-",
ResultY5OCT = "-",
Remark = "",
}).ToList();
return insignia;
}
//noti ยื่นเสนอคน
public async Task NotifyInsignia()
{