From 4cb5ff7102656e0e3c0a3d1ee57477f49a988987 Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 30 Oct 2024 13:49:42 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=A2=E0=B8=81?= =?UTF-8?q?=E0=B9=80=E0=B8=A5=E0=B8=B4=E0=B8=81=E0=B8=A5=E0=B8=B2=E0=B8=AD?= =?UTF-8?q?=E0=B8=AD=E0=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release_Retirement.yaml | 36 +- .github/workflows/release_discipline.yaml | 36 +- .github/workflows/release_placement.yaml | 36 +- .../Controllers/PlacementController.cs | 4 + .../Controllers/RetirementResignController.cs | 786 ++++++++++++------ .../Requests/RetirementReasonCancelRequest.cs | 11 + 6 files changed, 621 insertions(+), 288 deletions(-) create mode 100644 BMA.EHR.Retirement.Service/Requests/RetirementReasonCancelRequest.cs diff --git a/.github/workflows/release_Retirement.yaml b/.github/workflows/release_Retirement.yaml index 02bfe31e..3b55f2ff 100644 --- a/.github/workflows/release_Retirement.yaml +++ b/.github/workflows/release_Retirement.yaml @@ -69,21 +69,21 @@ jobs: docker compose pull docker compose up -d echo "${{ steps.gen_ver.outputs.image_ver }}"> success - # - uses: snow-actions/line-notify@v1.1.0 - # if: success() - # with: - # access_token: ${{ env.TOKEN_LINE }} - # message: | - # -Success✅✅✅ - # Image: ${{env.IMAGE_NAME}} - # Version: ${{ github.event.inputs.IMAGE_VER }} - # By: ${{secrets.DOCKER_USER}} - # - uses: snow-actions/line-notify@v1.1.0 - # if: failure() - # with: - # access_token: ${{ env.TOKEN_LINE }} - # message: | - # -Failure❌❌❌ - # Image: ${{env.IMAGE_NAME}} - # Version: ${{ github.event.inputs.IMAGE_VER }} - # By: ${{secrets.DOCKER_USER}} + - uses: snow-actions/line-notify@v1.1.0 + if: success() + with: + access_token: ${{ env.TOKEN_LINE }} + message: | + -Success✅✅✅ + Image: ${{env.IMAGE_NAME}} + Version: ${{ github.event.inputs.IMAGE_VER }} + By: ${{secrets.DOCKER_USER}} + - uses: snow-actions/line-notify@v1.1.0 + if: failure() + with: + access_token: ${{ env.TOKEN_LINE }} + message: | + -Failure❌❌❌ + Image: ${{env.IMAGE_NAME}} + Version: ${{ github.event.inputs.IMAGE_VER }} + By: ${{secrets.DOCKER_USER}} diff --git a/.github/workflows/release_discipline.yaml b/.github/workflows/release_discipline.yaml index 59f6f5e9..d3bb9e88 100644 --- a/.github/workflows/release_discipline.yaml +++ b/.github/workflows/release_discipline.yaml @@ -69,21 +69,21 @@ jobs: docker compose pull docker compose up -d echo "${{ steps.gen_ver.outputs.image_ver }}"> success - # - uses: snow-actions/line-notify@v1.1.0 - # if: success() - # with: - # access_token: ${{ env.TOKEN_LINE }} - # message: | - # -Success✅✅✅ - # Image: ${{env.IMAGE_NAME}} - # Version: ${{ github.event.inputs.IMAGE_VER }} - # By: ${{secrets.DOCKER_USER}} - # - uses: snow-actions/line-notify@v1.1.0 - # if: failure() - # with: - # access_token: ${{ env.TOKEN_LINE }} - # message: | - # -Failure❌❌❌ - # Image: ${{env.IMAGE_NAME}} - # Version: ${{ github.event.inputs.IMAGE_VER }} - # By: ${{secrets.DOCKER_USER}} + - uses: snow-actions/line-notify@v1.1.0 + if: success() + with: + access_token: ${{ env.TOKEN_LINE }} + message: | + -Success✅✅✅ + Image: ${{env.IMAGE_NAME}} + Version: ${{ github.event.inputs.IMAGE_VER }} + By: ${{secrets.DOCKER_USER}} + - uses: snow-actions/line-notify@v1.1.0 + if: failure() + with: + access_token: ${{ env.TOKEN_LINE }} + message: | + -Failure❌❌❌ + Image: ${{env.IMAGE_NAME}} + Version: ${{ github.event.inputs.IMAGE_VER }} + By: ${{secrets.DOCKER_USER}} diff --git a/.github/workflows/release_placement.yaml b/.github/workflows/release_placement.yaml index 53c65a53..2931b2b7 100644 --- a/.github/workflows/release_placement.yaml +++ b/.github/workflows/release_placement.yaml @@ -69,21 +69,21 @@ jobs: docker compose pull docker compose up -d echo "${{ steps.gen_ver.outputs.image_ver }}"> success - # - uses: snow-actions/line-notify@v1.1.0 - # if: success() - # with: - # access_token: ${{ env.TOKEN_LINE }} - # message: | - # -Success✅✅✅ - # Image: ${{env.IMAGE_NAME}} - # Version: ${{ github.event.inputs.IMAGE_VER }} - # By: ${{secrets.DOCKER_USER}} - # - uses: snow-actions/line-notify@v1.1.0 - # if: failure() - # with: - # access_token: ${{ env.TOKEN_LINE }} - # message: | - # -Failure❌❌❌ - # Image: ${{env.IMAGE_NAME}} - # Version: ${{ github.event.inputs.IMAGE_VER }} - # By: ${{secrets.DOCKER_USER}} + - uses: snow-actions/line-notify@v1.1.0 + if: success() + with: + access_token: ${{ env.TOKEN_LINE }} + message: | + -Success✅✅✅ + Image: ${{env.IMAGE_NAME}} + Version: ${{ github.event.inputs.IMAGE_VER }} + By: ${{secrets.DOCKER_USER}} + - uses: snow-actions/line-notify@v1.1.0 + if: failure() + with: + access_token: ${{ env.TOKEN_LINE }} + message: | + -Failure❌❌❌ + Image: ${{env.IMAGE_NAME}} + Version: ${{ github.event.inputs.IMAGE_VER }} + By: ${{secrets.DOCKER_USER}} diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index 9821fb26..444ebf6e 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -186,6 +186,7 @@ namespace BMA.EHR.Placement.Service.Controllers CitizenId = x.CitizenId, ExamNumber = x.ExamNumber, posmasterId = x.posmasterId, + rootIdOld = x.rootIdOld, root = x.root, rootId = x.rootId, rootShortName = x.rootShortName, @@ -239,6 +240,7 @@ namespace BMA.EHR.Placement.Service.Controllers p.profileId, p.ExamNumber, p.posmasterId, + p.rootIdOld, p.root, p.rootId, p.rootShortName, @@ -298,6 +300,7 @@ namespace BMA.EHR.Placement.Service.Controllers CitizenId = x.CitizenId, ExamNumber = x.ExamNumber, posmasterId = x.posmasterId, + rootIdOld = x.rootIdOld, root = x.root, rootId = x.rootId, rootShortName = x.rootShortName, @@ -351,6 +354,7 @@ namespace BMA.EHR.Placement.Service.Controllers p.profileId, p.ExamNumber, p.posmasterId, + p.rootIdOld, p.root, p.rootId, p.rootShortName, diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index a1602967..6e2d2009 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -153,7 +153,7 @@ namespace BMA.EHR.Retirement.Service.Controllers p.RejectReason, p.CancelReason, p.Status, - p.RetirementResignCancels,//xxxxxxxxxxxxxxxxxxxxxxxxx + statusCancel = p.RetirementResignCancels.FirstOrDefault() == null ? null : p.RetirementResignCancels.FirstOrDefault().Status, p.IsActive, }) .ToListAsync(); @@ -218,7 +218,7 @@ namespace BMA.EHR.Retirement.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet()] - public async Task> GetListByAdmin() + public async Task> GetListByAdmin(string type) { var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_RESIGN"); var jsonData = JsonConvert.DeserializeObject(getPermission); @@ -227,6 +227,7 @@ namespace BMA.EHR.Retirement.Service.Controllers return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } var retirementResigns = await _context.RetirementResigns.AsQueryable() + .Where(x => x.Status == type.Trim().ToUpper()) .OrderByDescending(x => x.CreatedAt) .Select(p => new { @@ -247,6 +248,7 @@ namespace BMA.EHR.Retirement.Service.Controllers p.PositionNumberOld, p.OrganizationPositionOld, p.RemarkHorizontal, + statusCancel = p.RetirementResignCancels.FirstOrDefault().Status ?? null, p.ApproveReason, p.RejectReason, p.CancelReason, @@ -267,7 +269,7 @@ namespace BMA.EHR.Retirement.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("cancel")] - public async Task> GetListByAdminCancel() + public async Task> GetListByAdminCancel(string type) { var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_RESIGN"); var jsonData = JsonConvert.DeserializeObject(getPermission); @@ -276,6 +278,7 @@ namespace BMA.EHR.Retirement.Service.Controllers return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } var retirementResigns = await _context.RetirementResignCancels.AsQueryable() + .Where(x => x.Status == type.Trim().ToUpper()) .OrderByDescending(x => x.CreatedAt) .Select(p => new { @@ -296,6 +299,7 @@ namespace BMA.EHR.Retirement.Service.Controllers p.PositionNumberOld, p.OrganizationPositionOld, p.RemarkHorizontal, + statusMain = p.RetirementResign.Status, p.ApproveReason, p.RejectReason, p.CancelReason, @@ -319,10 +323,374 @@ namespace BMA.EHR.Retirement.Service.Controllers [HttpGet("{id:length(36)}")] public async Task> GetDetailByUser(Guid id) { - var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_RESIGN"); - var createdUserId = await _context.RetirementResigns.AsQueryable() - .Where(x => x.CreatedUserId == UserId) + var dataMain = await _context.RetirementResigns.AsQueryable() + .Where(x => x.Id == id) + .Select(p => new + { + p.Status, + }) .FirstOrDefaultAsync(); + if (dataMain == null) + return Error(GlobalMessages.RetirementResignNotFound, 404); + + if(dataMain.Status != "CANCEL"){ + var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_RESIGN"); + var createdUserId = await _context.RetirementResigns.AsQueryable() + .Where(x => x.Id == id) + .Where(x => x.CreatedUserId == UserId) + .FirstOrDefaultAsync(); + if (getWorkflow == false && createdUserId == null) + { + var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_RESIGN"); + var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData["status"]?.ToString() != "200") + { + return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + } + } + var data = await _context.RetirementResigns.AsQueryable() + .Where(x => x.Id == id) + .Select(p => new + { + p.Id, + p.prefix, + p.firstName, + p.lastName, + p.profileId, + p.Location, + p.SendDate, + p.ActiveDate, + p.Reason, + p.Status, + salary = p.AmountOld, + p.ApproveReason, + p.RejectReason, + p.IsActive, + p.CreatedAt, + p.PositionTypeOld, + p.PositionLevelOld, + p.PositionNumberOld, + p.OrganizationPositionOld, + p.OligarchReject, + p.OligarchApproveReason, + p.OligarchRejectReason, + p.OligarchRejectDate, + p.CommanderReject, + p.CommanderApproveReason, + p.CommanderRejectReason, + p.CommanderRejectDate, + p.OfficerReject, + p.OfficerApproveReason, + p.OfficerRejectReason, + p.OfficerRejectDate, + p.RemarkHorizontal, + p.rootOld, + p.rootOldId, + p.rootShortNameOld, + p.child1Old, + p.child1OldId, + p.child1ShortNameOld, + p.child2Old, + p.child2OldId, + p.child2ShortNameOld, + p.child3Old, + p.child3OldId, + p.child3ShortNameOld, + p.child4Old, + p.child4OldId, + p.child4ShortNameOld, + p.PositionOld, + p.posMasterNoOld, + p.posTypeOldId, + p.posTypeNameOld, + p.posLevelOldId, + p.posLevelNameOld, + p.IsNoDebt, + p.IsNoBurden, + p.IsDiscipline, + p.CancelReason, + RetirementResignCancels = p.RetirementResignCancels.FirstOrDefault(), + // Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id, + RetirementResignDocs = p.RetirementResignDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), + // RetirementResignDebtDocs = p.RetirementResignDebtDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), + }) + .FirstOrDefaultAsync(); + if (data == null) + return Error(GlobalMessages.RetirementResignNotFound, 404); + + var retirementResignDocs = new List(); + foreach (var doc in data.RetirementResignDocs) + { + var _doc = new + { + FileName = doc.FileName, + PathName = await _documentService.ImagesPath(doc.Id), + doc.Id, + }; + retirementResignDocs.Add(_doc); + } + // var retirementResignDebtDocs = new List(); + // foreach (var doc in data.RetirementResignDebtDocs) + // { + // var _doc = new + // { + // FileName = doc.FileName, + // PathName = await _documentService.ImagesPath(doc.Id), + // doc.Id, + // }; + // retirementResignDebtDocs.Add(_doc); + // } + var _data = new + { + data.Id, + data.profileId, + data.prefix, + // data.PrefixId, + data.firstName, + data.lastName, + data.Location, + data.SendDate, + data.ActiveDate, + data.Reason, + data.Status, + data.salary, + data.PositionTypeOld, + data.PositionLevelOld, + data.PositionNumberOld, + data.OrganizationPositionOld, + data.ApproveReason, + data.RejectReason, + data.IsActive, + data.CreatedAt, + data.OligarchReject, + data.OligarchApproveReason, + data.OligarchRejectReason, + data.OligarchRejectDate, + data.CommanderReject, + data.CommanderApproveReason, + data.CommanderRejectReason, + data.CommanderRejectDate, + data.OfficerReject, + data.OfficerApproveReason, + data.OfficerRejectReason, + data.OfficerRejectDate, + data.RemarkHorizontal, + data.rootOld, + data.rootOldId, + data.rootShortNameOld, + data.child1Old, + data.child1OldId, + data.child1ShortNameOld, + data.child2Old, + data.child2OldId, + data.child2ShortNameOld, + data.child3Old, + data.child3OldId, + data.child3ShortNameOld, + data.child4Old, + data.child4OldId, + data.child4ShortNameOld, + data.PositionOld, + data.posMasterNoOld, + data.posTypeOldId, + data.posTypeNameOld, + data.posLevelOldId, + data.posLevelNameOld, + data.IsNoDebt, + data.IsNoBurden, + data.IsDiscipline, + data.CancelReason, + idCancel = data.RetirementResignCancels?.Id ?? Guid.Empty, + statusCancel = data.RetirementResignCancels?.Status ?? null, + // Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar), + Docs = retirementResignDocs, + // DocDebts = retirementResignDebtDocs, + }; + + return Success(_data); + } + else{ + + var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "RETIREMENT_CANCEL"); + var createdUserId = await _context.RetirementResignCancels.AsQueryable() + .Where(x => x.CreatedUserId == UserId) + .Where(x => x.Id == id) + .FirstOrDefaultAsync(); + if (getWorkflow == false && createdUserId == null) + { + var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_RESIGN"); + var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData["status"]?.ToString() != "200") + { + return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + } + } + var data = await _context.RetirementResignCancels.AsQueryable() + .Where(x => x.RetirementResign.Id == id) + .Select(p => new + { + p.Id, + p.prefix, + p.firstName, + p.lastName, + p.profileId, + p.Location, + p.SendDate, + p.ActiveDate, + p.Reason, + p.Status, + salary = p.AmountOld, + p.ApproveReason, + p.RejectReason, + p.IsActive, + p.CreatedAt, + p.PositionTypeOld, + p.PositionLevelOld, + p.PositionNumberOld, + p.OrganizationPositionOld, + p.OligarchReject, + p.OligarchApproveReason, + p.OligarchRejectReason, + p.OligarchRejectDate, + p.CommanderReject, + p.CommanderApproveReason, + p.CommanderRejectReason, + p.CommanderRejectDate, + p.OfficerReject, + p.OfficerApproveReason, + p.OfficerRejectReason, + p.OfficerRejectDate, + p.RemarkHorizontal, + p.rootOld, + p.rootOldId, + p.rootShortNameOld, + p.child1Old, + p.child1OldId, + p.child1ShortNameOld, + p.child2Old, + p.child2OldId, + p.child2ShortNameOld, + p.child3Old, + p.child3OldId, + p.child3ShortNameOld, + p.child4Old, + p.child4OldId, + p.child4ShortNameOld, + p.PositionOld, + p.posMasterNoOld, + p.posTypeOldId, + p.posTypeNameOld, + p.posLevelOldId, + p.posLevelNameOld, + p.IsNoDebt, + p.IsNoBurden, + p.IsDiscipline, + p.CancelReason, + idMain = p.RetirementResign.Id, + statusMain = p.RetirementResign.Status, + RetirementResignDocs = p.RetirementResign.RetirementResignDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), + }) + .FirstOrDefaultAsync(); + if (data == null) + return Error(GlobalMessages.RetirementResignNotFound, 404); + + var retirementResignDocs = new List(); + foreach (var doc in data.RetirementResignDocs) + { + var _doc = new + { + FileName = doc.FileName, + PathName = await _documentService.ImagesPath(doc.Id), + doc.Id, + }; + retirementResignDocs.Add(_doc); + } + var _data = new + { + data.Id, + data.profileId, + data.prefix, + // data.PrefixId, + data.firstName, + data.lastName, + data.Location, + data.SendDate, + data.ActiveDate, + data.Reason, + data.Status, + data.salary, + data.PositionTypeOld, + data.PositionLevelOld, + data.PositionNumberOld, + data.OrganizationPositionOld, + data.ApproveReason, + data.RejectReason, + data.IsActive, + data.CreatedAt, + data.OligarchReject, + data.OligarchApproveReason, + data.OligarchRejectReason, + data.OligarchRejectDate, + data.CommanderReject, + data.CommanderApproveReason, + data.CommanderRejectReason, + data.CommanderRejectDate, + data.OfficerReject, + data.OfficerApproveReason, + data.OfficerRejectReason, + data.OfficerRejectDate, + data.RemarkHorizontal, + data.rootOld, + data.rootOldId, + data.rootShortNameOld, + data.child1Old, + data.child1OldId, + data.child1ShortNameOld, + data.child2Old, + data.child2OldId, + data.child2ShortNameOld, + data.child3Old, + data.child3OldId, + data.child3ShortNameOld, + data.child4Old, + data.child4OldId, + data.child4ShortNameOld, + data.PositionOld, + data.posMasterNoOld, + data.posTypeOldId, + data.posTypeNameOld, + data.posLevelOldId, + data.posLevelNameOld, + data.IsNoDebt, + data.IsNoBurden, + data.IsDiscipline, + data.CancelReason, + data.idMain, + data.statusMain, + // Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar), + Docs = retirementResignDocs, + // DocDebts = retirementResignDebtDocs, + }; + return Success(_data); + } + } + + /// + /// get รายละเอียดลาออก + /// + /// Id ลาออก + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("cancel/{id:length(36)}")] + public async Task> GetDetailByUserCancel(Guid id) + { + var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "RETIREMENT_CANCEL"); + var createdUserId = await _context.RetirementResignCancels.AsQueryable() + .Where(x => x.CreatedUserId == UserId) + .FirstOrDefaultAsync(); if (getWorkflow == false && createdUserId == null) { var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_RESIGN"); @@ -332,7 +700,7 @@ namespace BMA.EHR.Retirement.Service.Controllers return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } } - var data = await _context.RetirementResigns.AsQueryable() + var data = await _context.RetirementResignCancels.AsQueryable() .Where(x => x.Id == id) .Select(p => new { @@ -393,9 +761,9 @@ namespace BMA.EHR.Retirement.Service.Controllers p.IsNoBurden, p.IsDiscipline, p.CancelReason, - // Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id, - RetirementResignDocs = p.RetirementResignDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), - // RetirementResignDebtDocs = p.RetirementResignDebtDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), + idMain = p.RetirementResign.Id, + statusMain = p.RetirementResign.Status, + RetirementResignDocs = p.RetirementResign.RetirementResignDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), }) .FirstOrDefaultAsync(); if (data == null) @@ -412,17 +780,6 @@ namespace BMA.EHR.Retirement.Service.Controllers }; retirementResignDocs.Add(_doc); } - // var retirementResignDebtDocs = new List(); - // foreach (var doc in data.RetirementResignDebtDocs) - // { - // var _doc = new - // { - // FileName = doc.FileName, - // PathName = await _documentService.ImagesPath(doc.Id), - // doc.Id, - // }; - // retirementResignDebtDocs.Add(_doc); - // } var _data = new { data.Id, @@ -483,109 +840,15 @@ namespace BMA.EHR.Retirement.Service.Controllers data.IsNoBurden, data.IsDiscipline, data.CancelReason, + data.idMain, + data.statusMain, // Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar), Docs = retirementResignDocs, // DocDebts = retirementResignDebtDocs, }; - return Success(_data); } - /// - /// get รายละเอียดลาออก - /// - /// Id ลาออก - /// - /// - /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง - /// ไม่ได้ Login เข้าระบบ - /// เมื่อเกิดข้อผิดพลาดในการทำงาน - [HttpGet("cancel/{id:length(36)}")] - public async Task> GetDetailByUserCancel(Guid id) - { - var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "RETIREMENT_CANCEL"); - var createdUserId = await _context.RetirementResigns.AsQueryable() - .Where(x => x.CreatedUserId == UserId) - .FirstOrDefaultAsync(); - if (getWorkflow == false && createdUserId == null) - { - var getPermission = await _permission.GetPermissionAPIAsync("GET", "RETIREMENT_CANCEL"); - var jsonData = JsonConvert.DeserializeObject(getPermission); - if (jsonData["status"]?.ToString() != "200") - { - return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); - } - } - var data = await _context.RetirementResigns.AsQueryable() - .Where(x => x.Id == id) - .Select(p => new - { - p.Id, - p.prefix, - p.firstName, - p.lastName, - p.profileId, - p.Location, - p.SendDate, - p.ActiveDate, - p.Reason, - p.Status, - salary = p.AmountOld, - p.ApproveReason, - p.RejectReason, - p.IsActive, - p.CreatedAt, - p.PositionTypeOld, - p.PositionLevelOld, - p.PositionNumberOld, - p.OrganizationPositionOld, - p.OligarchReject, - p.OligarchApproveReason, - p.OligarchRejectReason, - p.OligarchRejectDate, - p.CommanderReject, - p.CommanderApproveReason, - p.CommanderRejectReason, - p.CommanderRejectDate, - p.OfficerReject, - p.OfficerApproveReason, - p.OfficerRejectReason, - p.OfficerRejectDate, - p.RemarkHorizontal, - p.rootOld, - p.rootOldId, - p.rootShortNameOld, - p.child1Old, - p.child1OldId, - p.child1ShortNameOld, - p.child2Old, - p.child2OldId, - p.child2ShortNameOld, - p.child3Old, - p.child3OldId, - p.child3ShortNameOld, - p.child4Old, - p.child4OldId, - p.child4ShortNameOld, - p.PositionOld, - p.posMasterNoOld, - p.posTypeOldId, - p.posTypeNameOld, - p.posLevelOldId, - p.posLevelNameOld, - p.IsNoDebt, - p.IsNoBurden, - p.IsDiscipline, - p.CancelReason, - RetirementResignDocs = p.RetirementResignDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), - }) - .FirstOrDefaultAsync(); - if (data == null) - return Error(GlobalMessages.RetirementResignNotFound, 404); - - return Success(data); - } - /// /// สร้างการลาออก /// @@ -773,7 +1036,7 @@ namespace BMA.EHR.Retirement.Service.Controllers /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน - [HttpPut("cancel/{id:length(36)}")] + [HttpPut("update-cancel/{id:length(36)}")] public async Task> PutCancel([FromForm] RetirementResignRequest req, Guid id) { var updated = await _context.RetirementResignCancels @@ -956,7 +1219,7 @@ namespace BMA.EHR.Retirement.Service.Controllers posLevelOldId = updated.posLevelOldId, posLevelNameOld = updated.posLevelNameOld, RetirementResign = updated, - Status = "PENDING", + Status = "WAITTING", CreatedFullName = FullName ?? "System Administrator", CreatedUserId = UserId ?? "", CreatedAt = DateTime.Now, @@ -964,6 +1227,7 @@ namespace BMA.EHR.Retirement.Service.Controllers LastUpdateUserId = UserId ?? "", LastUpdatedAt = DateTime.Now, }; + await _context.RetirementResignCancels.AddAsync(retirementResignCancel); await _context.SaveChangesAsync(); using (var client = new HttpClient()) { @@ -1123,25 +1387,25 @@ namespace BMA.EHR.Retirement.Service.Controllers updated.LastUpdateFullName = FullName ?? "System Administrator"; updated.LastUpdateUserId = UserId ?? ""; updated.LastUpdatedAt = DateTime.Now; - await _repositoryNoti.PushNotificationAsync( - Guid.Parse("08dc432c-2bc5-4b81-8089-9c057c51192c"), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากการเจ้าหน้าที่", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากการเจ้าหน้าที่", - "", - "", - true - ); - if (updated.profileId != null) - { - await _repositoryNoti.PushNotificationAsync( - Guid.Parse(updated.profileId), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากการเจ้าหน้าที่", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากการเจ้าหน้าที่", - "", - "", - true - ); - } + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse("08dc432c-2bc5-4b81-8089-9c057c51192c"), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากการเจ้าหน้าที่", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากการเจ้าหน้าที่", + // "", + // "", + // true + // ); + // if (updated.profileId != null) + // { + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse(updated.profileId), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากการเจ้าหน้าที่", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากการเจ้าหน้าที่", + // "", + // "", + // true + // ); + // } await _context.SaveChangesAsync(); return Success(); @@ -1172,25 +1436,25 @@ namespace BMA.EHR.Retirement.Service.Controllers updated.LastUpdateFullName = FullName ?? "System Administrator"; updated.LastUpdateUserId = UserId ?? ""; updated.LastUpdatedAt = DateTime.Now; - await _repositoryNoti.PushNotificationAsync( - Guid.Parse("08dc432c-2bc5-4b81-8089-9c057c51192c"), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากการเจ้าหน้าที่", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากการเจ้าหน้าที่", - "", - "", - true - ); - if (updated.profileId != null) - { - await _repositoryNoti.PushNotificationAsync( - Guid.Parse(updated.profileId), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากการเจ้าหน้าที่", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากการเจ้าหน้าที่", - "", - "", - true - ); - } + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse("08dc432c-2bc5-4b81-8089-9c057c51192c"), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากการเจ้าหน้าที่", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากการเจ้าหน้าที่", + // "", + // "", + // true + // ); + // if (updated.profileId != null) + // { + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse(updated.profileId), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากการเจ้าหน้าที่", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากการเจ้าหน้าที่", + // "", + // "", + // true + // ); + // } await _context.SaveChangesAsync(); return Success(); @@ -1219,25 +1483,25 @@ namespace BMA.EHR.Retirement.Service.Controllers updated.LastUpdateFullName = FullName ?? "System Administrator"; updated.LastUpdateUserId = UserId ?? ""; updated.LastUpdatedAt = DateTime.Now; - await _repositoryNoti.PushNotificationAsync( - Guid.Parse("08dc4307-0adc-4bcd-8213-5479bb010236"), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", - "", - "", - true - ); - if (updated.profileId != null) - { - await _repositoryNoti.PushNotificationAsync( - Guid.Parse(updated.profileId), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", - "", - "", - true - ); - } + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse("08dc4307-0adc-4bcd-8213-5479bb010236"), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", + // "", + // "", + // true + // ); + // if (updated.profileId != null) + // { + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse(updated.profileId), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", + // "", + // "", + // true + // ); + // } await _context.SaveChangesAsync(); return Success(); @@ -1268,25 +1532,25 @@ namespace BMA.EHR.Retirement.Service.Controllers updated.LastUpdateFullName = FullName ?? "System Administrator"; updated.LastUpdateUserId = UserId ?? ""; updated.LastUpdatedAt = DateTime.Now; - await _repositoryNoti.PushNotificationAsync( - Guid.Parse("08dc4307-0adc-4bcd-8213-5479bb010236"), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา", - "", - "", - true - ); - if (updated.profileId != null) - { - await _repositoryNoti.PushNotificationAsync( - Guid.Parse(updated.profileId), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา", - "", - "", - true - ); - } + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse("08dc4307-0adc-4bcd-8213-5479bb010236"), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา", + // "", + // "", + // true + // ); + // if (updated.profileId != null) + // { + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse(updated.profileId), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา", + // "", + // "", + // true + // ); + // } await _context.SaveChangesAsync(); return Success(); @@ -1314,25 +1578,25 @@ namespace BMA.EHR.Retirement.Service.Controllers updated.LastUpdateFullName = FullName ?? "System Administrator"; updated.LastUpdateUserId = UserId ?? ""; updated.LastUpdatedAt = DateTime.Now; - await _repositoryNoti.PushNotificationAsync( - Guid.Parse("08dc3db9-257d-470d-8256-3dc24f6fa332"), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", - "", - "", - true - ); - if (updated.profileId != null) - { - await _repositoryNoti.PushNotificationAsync( - Guid.Parse(updated.profileId), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", - "", - "", - true - ); - } + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse("08dc3db9-257d-470d-8256-3dc24f6fa332"), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", + // "", + // "", + // true + // ); + // if (updated.profileId != null) + // { + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse(updated.profileId), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", + // "", + // "", + // true + // ); + // } await _context.SaveChangesAsync(); return Success(); @@ -1363,25 +1627,79 @@ namespace BMA.EHR.Retirement.Service.Controllers updated.LastUpdateFullName = FullName ?? "System Administrator"; updated.LastUpdateUserId = UserId ?? ""; updated.LastUpdatedAt = DateTime.Now; - await _repositoryNoti.PushNotificationAsync( - Guid.Parse("08dc3db9-257d-470d-8256-3dc24f6fa332"), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", - "", - "", - true - ); - if (updated.profileId != null) - { - await _repositoryNoti.PushNotificationAsync( - Guid.Parse(updated.profileId), - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้มีอำนาจ", - $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้มีอำนาจ", - "", - "", - true - ); - } + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse("08dc3db9-257d-470d-8256-3dc24f6fa332"), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ", + // "", + // "", + // true + // ); + // if (updated.profileId != null) + // { + // await _repositoryNoti.PushNotificationAsync( + // Guid.Parse(updated.profileId), + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้มีอำนาจ", + // $"คำขอลาออกของ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้มีอำนาจ", + // "", + // "", + // true + // ); + // } + await _context.SaveChangesAsync(); + + return Success(); + } + + /// + /// ผู้บังคับบัญชา อนุมัติคำลาออก + /// + /// Id คำลาออก + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("commander-cancel/reject/{id:length(36)}")] + public async Task> CommanderConfirmCancel([FromBody] RetirementReasonCancelRequest req, Guid id) + { + var updated = await _context.RetirementResignCancels + .FirstOrDefaultAsync(x => x.Id == id); + if (updated == null) + return Error(GlobalMessages.RetirementResignNotFound, 404); + + updated.CommanderReject = req.Reject; + updated.CommanderApproveReason = req.Reason; + updated.LastUpdateFullName = FullName ?? "System Administrator"; + updated.LastUpdateUserId = UserId ?? ""; + updated.LastUpdatedAt = DateTime.Now; + await _context.SaveChangesAsync(); + + return Success(); + } + /// + /// ผู้มีอำนาจ อนุมัติคำลาออก + /// + /// Id คำลาออก + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("oligarch-cancel/reject/{id:length(36)}")] + public async Task> OligarchConfirmCancel([FromBody] RetirementReasonCancelRequest req, Guid id) + { + var updated = await _context.RetirementResignCancels + .FirstOrDefaultAsync(x => x.Id == id); + if (updated == null) + return Error(GlobalMessages.RetirementResignNotFound, 404); + + updated.Status = "APPROVE"; + updated.OligarchReject = req.Reject; + updated.OligarchApproveReason = req.Reason; + updated.LastUpdateFullName = FullName ?? "System Administrator"; + updated.LastUpdateUserId = UserId ?? ""; + updated.LastUpdatedAt = DateTime.Now; await _context.SaveChangesAsync(); return Success(); @@ -2273,7 +2591,7 @@ namespace BMA.EHR.Retirement.Service.Controllers .Where(x => req.refIds.Contains(x.Id.ToString())) .Where(x => x.Status.ToUpper() == "REPORT") .ToListAsync(); - placementProfiles.ForEach(profile => profile.Status = "PENDING"); + placementProfiles.ForEach(profile => profile.Status = "APPROVE"); await _context.SaveChangesAsync(); return Success(); } diff --git a/BMA.EHR.Retirement.Service/Requests/RetirementReasonCancelRequest.cs b/BMA.EHR.Retirement.Service/Requests/RetirementReasonCancelRequest.cs new file mode 100644 index 00000000..643ae0ad --- /dev/null +++ b/BMA.EHR.Retirement.Service/Requests/RetirementReasonCancelRequest.cs @@ -0,0 +1,11 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Retirement.Service.Requests +{ + public class RetirementReasonCancelRequest + { + public string Reason { get; set; } + public bool Reject { get; set; } + } +}