report retire sort
Some checks failed
release-dev / release-dev (push) Failing after 11s

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

View file

@ -6,102 +6,102 @@ on:
- "retirement-[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
env:
REGISTRY: docker.frappet.com
IMAGE_NAME: ehr/bma-ehr-retirement-service
DEPLOY_HOST: frappet.com
DEPLOY_PORT: 10102
# COMPOSE_PATH: /home/frappet/docker/bma-ehr
COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-retirement
TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0
REGISTRY: docker.frappet.com
IMAGE_NAME: ehr/bma-ehr-retirement-service
DEPLOY_HOST: frappet.com
DEPLOY_PORT: 10102
# COMPOSE_PATH: /home/frappet/docker/bma-ehr
COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-retirement
TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0
jobs:
# act workflow_dispatch -W .github/workflows/release_retirement.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357
release-dev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set output tags
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Gen Version
id: gen_ver
run: |
if [[ $GITHUB_REF == 'refs/tags/'* ]]; then
IMAGE_VER=${{ steps.vars.outputs.tag }}
else
IMAGE_VER=${{ github.event.inputs.IMAGE_VER }}
fi
if [[ $IMAGE_VER == '' ]]; then
IMAGE_VER='test-vBeta'
fi
echo '::set-output name=image_ver::'$IMAGE_VER
- name: Check Version
run: |
echo $GITHUB_REF
echo ${{ steps.gen_ver.outputs.image_ver }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login in to registry
uses: docker/login-action@v2
with:
registry: ${{env.REGISTRY}}
username: ${{secrets.DOCKER_USER}}
password: ${{secrets.DOCKER_PASS}}
- name: Build and load local docker image
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64
file: BMA.EHR.Retirement.Service/Dockerfile
push: true
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
# act workflow_dispatch -W .github/workflows/release_retirement.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357
release-dev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set output tags
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Gen Version
id: gen_ver
run: |
if [[ $GITHUB_REF == 'refs/tags/'* ]]; then
IMAGE_VER=${{ steps.vars.outputs.tag }}
else
IMAGE_VER=${{ github.event.inputs.IMAGE_VER }}
fi
if [[ $IMAGE_VER == '' ]]; then
IMAGE_VER='test-vBeta'
fi
echo '::set-output name=image_ver::'$IMAGE_VER
- name: Check Version
run: |
echo $GITHUB_REF
echo ${{ steps.gen_ver.outputs.image_ver }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login in to registry
uses: docker/login-action@v2
with:
registry: ${{env.REGISTRY}}
username: ${{secrets.DOCKER_USER}}
password: ${{secrets.DOCKER_PASS}}
- name: Build and load local docker image
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64
file: BMA.EHR.Retirement.Service/Dockerfile
push: true
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
- name: Reload docker compose
uses: appleboy/ssh-action@v0.1.8
with:
host: ${{env.DEPLOY_HOST}}
username: frappet
password: ${{ secrets.SSH_PASSWORD }}
port: ${{env.DEPLOY_PORT}}
script: |
cd "${{env.COMPOSE_PATH}}"
docker compose pull
docker compose up -d
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
- name: Notify Discord Success
if: success()
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d '{
"embeds": [{
"title": "✅ Deployment Success!",
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
"color": 3066993,
"footer": {
"text": "Release Notification",
"icon_url": "https://example.com/success-icon.png"
},
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}]
}' \
${{ secrets.DISCORD_WEBHOOK }}
- name: Reload docker compose
uses: appleboy/ssh-action@v0.1.8
with:
host: ${{env.DEPLOY_HOST}}
username: frappet
password: ${{ secrets.SSH_PASSWORD }}
port: ${{env.DEPLOY_PORT}}
script: |
cd "${{env.COMPOSE_PATH}}"
docker compose pull
docker compose up -d
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
# - name: Notify Discord Success
# if: success()
# run: |
# curl -H "Content-Type: application/json" \
# -X POST \
# -d '{
# "embeds": [{
# "title": "✅ Deployment Success!",
# "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
# "color": 3066993,
# "footer": {
# "text": "Release Notification",
# "icon_url": "https://example.com/success-icon.png"
# },
# "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
# }]
# }' \
# ${{ secrets.DISCORD_WEBHOOK }}
- name: Notify Discord Failure
if: failure()
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d '{
"embeds": [{
"title": "❌ Deployment Failed!",
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
"color": 15158332,
"footer": {
"text": "Release Notification",
"icon_url": "https://example.com/failure-icon.png"
},
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}]
}' \
${{ secrets.DISCORD_WEBHOOK }}
# - name: Notify Discord Failure
# if: failure()
# run: |
# curl -H "Content-Type: application/json" \
# -X POST \
# -d '{
# "embeds": [{
# "title": "❌ Deployment Failed!",
# "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
# "color": 15158332,
# "footer": {
# "text": "Release Notification",
# "icon_url": "https://example.com/failure-icon.png"
# },
# "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
# }]
# }' \
# ${{ 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.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() : "-";

View file

@ -8,6 +8,7 @@
public string? posNo { get; set; }
public string? root { 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}")]
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)
{
var reportfile = string.Empty;

View file

@ -2127,7 +2127,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpGet("31/{exportType}/{Id}")]
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)
{
var reportfile = string.Empty;