report retire sort

This commit is contained in:
moss 2025-03-27 04:42:52 +07:00
parent 44cd46effc
commit 3e6c140877
5 changed files with 189 additions and 116 deletions

View file

@ -68,40 +68,40 @@ jobs:
docker compose pull docker compose pull
docker compose up -d docker compose up -d
echo "${{ steps.gen_ver.outputs.image_ver }}"> success echo "${{ steps.gen_ver.outputs.image_ver }}"> success
- name: Notify Discord Success # - name: Notify Discord Success
if: success() # if: success()
run: | # run: |
curl -H "Content-Type: application/json" \ # curl -H "Content-Type: application/json" \
-X POST \ # -X POST \
-d '{ # -d '{
"embeds": [{ # "embeds": [{
"title": "✅ Deployment Success!", # "title": "✅ Deployment Success!",
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", # "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
"color": 3066993, # "color": 3066993,
"footer": { # "footer": {
"text": "Release Notification", # "text": "Release Notification",
"icon_url": "https://example.com/success-icon.png" # "icon_url": "https://example.com/success-icon.png"
}, # },
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" # "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}] # }]
}' \ # }' \
${{ secrets.DISCORD_WEBHOOK }} # ${{ secrets.DISCORD_WEBHOOK }}
- name: Notify Discord Failure # - name: Notify Discord Failure
if: failure() # if: failure()
run: | # run: |
curl -H "Content-Type: application/json" \ # curl -H "Content-Type: application/json" \
-X POST \ # -X POST \
-d '{ # -d '{
"embeds": [{ # "embeds": [{
"title": "❌ Deployment Failed!", # "title": "❌ Deployment Failed!",
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`", # "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
"color": 15158332, # "color": 15158332,
"footer": { # "footer": {
"text": "Release Notification", # "text": "Release Notification",
"icon_url": "https://example.com/failure-icon.png" # "icon_url": "https://example.com/failure-icon.png"
}, # },
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" # "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}] # }]
}' \ # }' \
${{ secrets.DISCORD_WEBHOOK }} # ${{ secrets.DISCORD_WEBHOOK }}

View file

@ -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.Common.Interfaces;
using BMA.EHR.Application.Responses; using BMA.EHR.Application.Responses;
using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Extensions;
@ -9,6 +10,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace BMA.EHR.Application.Repositories.Reports namespace BMA.EHR.Application.Repositories.Reports
@ -21,6 +23,7 @@ namespace BMA.EHR.Application.Repositories.Reports
private readonly IWebHostEnvironment _hostingEnvironment; private readonly IWebHostEnvironment _hostingEnvironment;
private readonly MinIOService _documentService; private readonly MinIOService _documentService;
private readonly OrganizationCommonRepository _organizationCommonRepository; private readonly OrganizationCommonRepository _organizationCommonRepository;
private readonly IConfiguration _configuration;
#endregion #endregion
@ -29,12 +32,14 @@ namespace BMA.EHR.Application.Repositories.Reports
public RetireReportRepository(IApplicationDBContext dbContext, public RetireReportRepository(IApplicationDBContext dbContext,
MinIOService documentService, MinIOService documentService,
OrganizationCommonRepository organizationCommonRepository, OrganizationCommonRepository organizationCommonRepository,
IWebHostEnvironment hostEnvironment) IWebHostEnvironment hostEnvironment,
IConfiguration configuration)
{ {
_dbContext = dbContext; _dbContext = dbContext;
_hostingEnvironment = hostEnvironment; _hostingEnvironment = hostEnvironment;
_organizationCommonRepository = organizationCommonRepository; _organizationCommonRepository = organizationCommonRepository;
_documentService = documentService; _documentService = documentService;
_configuration = configuration;
} }
#endregion #endregion
@ -64,12 +69,33 @@ namespace BMA.EHR.Application.Repositories.Reports
//} //}
#region #region
public async Task<dynamic> GetProfileRetirementdAsync(Guid retireId) public async Task<dynamic> GetProfileRetirementdAsync(Guid retireId, string token)
{ {
var retire = await _dbContext.Set<RetirementPeriod>() var retire = await _dbContext.Set<RetirementPeriod>()
.Include(x => x.RetirementProfiles) .Include(x => x.RetirementProfiles)
.FirstOrDefaultAsync(x => x.Id == retireId); .FirstOrDefaultAsync(x => x.Id == retireId);
// var retires = new List<dynamic>(); // 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) if (retire == null)
{ {
var retireHistorys = await _dbContext.Set<RetirementPeriodHistory>().AsQueryable() var retireHistorys = await _dbContext.Set<RetirementPeriodHistory>().AsQueryable()
@ -121,16 +147,39 @@ namespace BMA.EHR.Application.Repositories.Reports
profiles = profiles.OrderBy(x => x.order).ToList(); profiles = profiles.OrderBy(x => x.order).ToList();
} }
var mapProfiles = new List<ProfileRetireJsonRequest>(); var mapProfiles = new List<ProfileRetireJsonRequest>();
string previousRoot = null;
string previousPosTypeName = null;
string previousPosLevelName = null;
if (profiles.Count > 0) 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) =>
{
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(), order = (index + 1).ToString().ToThaiNumber(),
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}", fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
root = profile.root, 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 : "-", position = profile.position != "" && profile.position != null ? profile.position : "-",
posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-", posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-",
reason = profile.reason != "" && profile.reason != null ? profile.reason : "-", reason = profile.reason != "" && profile.reason != null ? profile.reason : "-",
};
}).ToList(); }).ToList();
} }
string SignDate = retireHistorys.SignDate != null ? DateTime.Parse(retireHistorys.SignDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber() : "-"; 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); // retires.Add(data);
// } // }
var mapProfiles = new List<ProfileRetireJsonRequest>(); var mapProfiles = new List<ProfileRetireJsonRequest>();
string previousRoot = null;
string previousPosTypeName = null;
string previousPosLevelName = null;
if (profile_retire.Count > 0) 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) =>
{
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(), order = (index + 1).ToString().ToThaiNumber(),
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}", fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
root = profile.root, 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 : "-", position = profile.position != "" && profile.position != null ? profile.position : "-",
posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-", posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-",
reason = profile.reason != "" && profile.reason != null ? profile.reason : "-", reason = profile.reason != "" && profile.reason != null ? profile.reason : "-",
};
}).ToList(); }).ToList();
} }
string SignDate = retire.SignDate != null ? DateTime.Parse(retire.SignDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber() : "-"; string SignDate = retire.SignDate != null ? DateTime.Parse(retire.SignDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber() : "-";

View file

@ -8,6 +8,7 @@
public string? posNo { get; set; } public string? posNo { get; set; }
public string? root { get; set; } public string? root { get; set; }
public string? reason { get; set; } public string? reason { get; set; }
public string? child { get; set; }
} }
} }

View file

@ -44,7 +44,7 @@ namespace BMA.EHR.Report.Service.Controllers
[HttpGet("{exportType}/{Id}")] [HttpGet("{exportType}/{Id}")]
public async Task<ActionResult<ResponseObject>> GetProfileRetirement([FromRoute] Guid Id, string exportType = "pdf") public async Task<ActionResult<ResponseObject>> GetProfileRetirement([FromRoute] Guid Id, string exportType = "pdf")
{ {
var retire = await _service.GetProfileRetirementdAsync(Id); var retire = await _service.GetProfileRetirementdAsync(Id,token);
if (retire != null) if (retire != null)
{ {
var reportfile = string.Empty; var reportfile = string.Empty;

View file

@ -2127,7 +2127,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpGet("31/{exportType}/{Id}")] [HttpGet("31/{exportType}/{Id}")]
public async Task<ActionResult<ResponseObject>> GetProfileRetirement([FromRoute] Guid Id, string exportType = "pdf") public async Task<ActionResult<ResponseObject>> GetProfileRetirement([FromRoute] Guid Id, string exportType = "pdf")
{ {
var retire = await _service.GetProfileRetirementdAsync(Id); var retire = await _service.GetProfileRetirementdAsync(Id,token);
if (retire != null) if (retire != null)
{ {
var reportfile = string.Empty; var reportfile = string.Empty;