From 3ba0607a80cedbd78b8810e3982426ff22d30bb1 Mon Sep 17 00:00:00 2001 From: moss <> Date: Thu, 27 Mar 2025 04:42:52 +0700 Subject: [PATCH] report retire sort --- .github/workflows/release_Retirement.yaml | 190 +++++++++--------- .../Reports/RetireReportRepository.cs | 110 ++++++++-- .../Responses/ProfileRetireJsonRequest.cs | 1 + .../Controllers/RetireReportController.cs | 2 +- .../Controllers/RetirementController.cs | 2 +- 5 files changed, 189 insertions(+), 116 deletions(-) diff --git a/.github/workflows/release_Retirement.yaml b/.github/workflows/release_Retirement.yaml index 4d644cb3..4e936de9 100644 --- a/.github/workflows/release_Retirement.yaml +++ b/.github/workflows/release_Retirement.yaml @@ -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 }} diff --git a/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs b/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs index ff5fa3e3..bbe6aea4 100644 --- a/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs @@ -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 GetProfileRetirementdAsync(Guid retireId) + public async Task GetProfileRetirementdAsync(Guid retireId, string token) { var retire = await _dbContext.Set() .Include(x => x.RetirementProfiles) .FirstOrDefaultAsync(x => x.Id == retireId); // var retires = new List(); + var apiUrl = $"{_configuration["API"]}/org/root/search/sort"; + dynamic rootOrder = new List(); + dynamic posTypeNameOrder = new List(); + dynamic posLevelNameOrder = new List(); + 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(_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().AsQueryable() @@ -121,16 +147,39 @@ namespace BMA.EHR.Application.Repositories.Reports profiles = profiles.OrderBy(x => x.order).ToList(); } var mapProfiles = new List(); + 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>().IndexOf(x.root)) + .ThenBy(x => posTypeNameOrder.ToObject>().IndexOf(x.posTypeName ?? "")) + .ThenBy(x => posLevelNameOrder.ToObject>().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(); + 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>().IndexOf(x.root)) + .ThenBy(x => posTypeNameOrder.ToObject>().IndexOf(x.posTypeName ?? "")) + .ThenBy(x => posLevelNameOrder.ToObject>().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() : "-"; diff --git a/BMA.EHR.Application/Responses/ProfileRetireJsonRequest.cs b/BMA.EHR.Application/Responses/ProfileRetireJsonRequest.cs index bcdf04ec..f690d2c3 100644 --- a/BMA.EHR.Application/Responses/ProfileRetireJsonRequest.cs +++ b/BMA.EHR.Application/Responses/ProfileRetireJsonRequest.cs @@ -8,6 +8,7 @@ public string? posNo { get; set; } public string? root { get; set; } public string? reason { get; set; } + public string? child { get; set; } } } diff --git a/BMA.EHR.Report.Service/Controllers/RetireReportController.cs b/BMA.EHR.Report.Service/Controllers/RetireReportController.cs index dd329dde..c5c2fa1a 100644 --- a/BMA.EHR.Report.Service/Controllers/RetireReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/RetireReportController.cs @@ -44,7 +44,7 @@ namespace BMA.EHR.Report.Service.Controllers [HttpGet("{exportType}/{Id}")] public async Task> 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; diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs index aa9f1c0a..4fecb0ba 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs @@ -2127,7 +2127,7 @@ namespace BMA.EHR.Retirement.Service.Controllers [HttpGet("31/{exportType}/{Id}")] public async Task> 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;