From 3f98e0741994b41004da16ec49bf7f32dd1cc810 Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 27 May 2026 17:40:30 +0700 Subject: [PATCH 1/2] =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97?= =?UTF-8?q?=E0=B8=B6=E0=B8=81=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9?= =?UTF-8?q?=E0=B8=A5=20CommandCode=20=E0=B9=83=E0=B8=99=20DisciplineDiscip?= =?UTF-8?q?linary=5FProfileComplaintInvestigates=20#2377?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DisciplineResultController.cs | 160 +++++++++++++++--- 1 file changed, 136 insertions(+), 24 deletions(-) diff --git a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs index 5301a5ae..35a9dfa2 100644 --- a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs +++ b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs @@ -968,12 +968,20 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command19/report")] - public async Task> PostReportCommand19([FromBody] ReportPersonRequest req) + public async Task> PostReportCommand19([FromBody] ReportPersonAndCommandRequest req) { var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates .Where(x => req.refIds.Contains(x.Id.ToString())) .ToListAsync(); - data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + // data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + data.ForEach(profile => + { + profile.Status = !string.IsNullOrEmpty(req.status) + ? req.status.Trim().ToUpper() : null; + profile.CommandTypeId = !string.IsNullOrEmpty(req.commandTypeId) && Guid.TryParse(req.commandTypeId, out var cmdTypeId) + ? cmdTypeId : null; + profile.CommandCode = req.commandCode ?? null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -993,7 +1001,13 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Status.ToUpper() == "REPORT") .ToListAsync(); - data.ForEach(profile => profile.Status = "NEW"); + // data.ForEach(profile => profile.Status = "NEW"); + data.ForEach(profile => + { + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.CommandCode = null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -1110,12 +1124,20 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command20/report")] - public async Task> PostReportcommand20([FromBody] ReportPersonRequest req) + public async Task> PostReportcommand20([FromBody] ReportPersonAndCommandRequest req) { var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates .Where(x => req.refIds.Contains(x.Id.ToString())) .ToListAsync(); - data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + // data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + data.ForEach(profile => + { + profile.Status = !string.IsNullOrEmpty(req.status) + ? req.status.Trim().ToUpper() : null; + profile.CommandTypeId = !string.IsNullOrEmpty(req.commandTypeId) && Guid.TryParse(req.commandTypeId, out var cmdTypeId) + ? cmdTypeId : null; + profile.CommandCode = req.commandCode ?? null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -1135,7 +1157,13 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Status.ToUpper() == "REPORT") .ToListAsync(); - data.ForEach(profile => profile.Status = "NEW"); + // data.ForEach(profile => profile.Status = "NEW"); + data.ForEach(profile => + { + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.CommandCode = null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -1602,14 +1630,22 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command27/report")] - public async Task> PostReportCommand27([FromBody] ReportPersonRequest req) + public async Task> PostReportCommand27([FromBody] ReportPersonAndCommandRequest req) { try { var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates .Where(x => req.refIds.Contains(x.Id.ToString())) .ToListAsync(); - data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + // data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + data.ForEach(profile => + { + profile.Status = !string.IsNullOrEmpty(req.status) + ? req.status.Trim().ToUpper() : null; + profile.CommandTypeId = !string.IsNullOrEmpty(req.commandTypeId) && Guid.TryParse(req.commandTypeId, out var cmdTypeId) + ? cmdTypeId : null; + profile.CommandCode = req.commandCode ?? null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -1636,7 +1672,13 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Status.ToUpper() == "REPORT") .ToListAsync(); - data.ForEach(profile => profile.Status = "NEW"); + // data.ForEach(profile => profile.Status = "NEW"); + data.ForEach(profile => + { + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.CommandCode = null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -1730,14 +1772,22 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command28/report")] - public async Task> PostReportCommand28([FromBody] ReportPersonRequest req) + public async Task> PostReportCommand28([FromBody] ReportPersonAndCommandRequest req) { try { var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates .Where(x => req.refIds.Contains(x.Id.ToString())) .ToListAsync(); - data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + // data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + data.ForEach(profile => + { + profile.Status = !string.IsNullOrEmpty(req.status) + ? req.status.Trim().ToUpper() : null; + profile.CommandTypeId = !string.IsNullOrEmpty(req.commandTypeId) && Guid.TryParse(req.commandTypeId, out var cmdTypeId) + ? cmdTypeId : null; + profile.CommandCode = req.commandCode ?? null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -1764,7 +1814,13 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Status.ToUpper() == "REPORT") .ToListAsync(); - data.ForEach(profile => profile.Status = "NEW"); + // data.ForEach(profile => profile.Status = "NEW"); + data.ForEach(profile => + { + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.CommandCode = null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -1858,14 +1914,22 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command29/report")] - public async Task> PostReportCommand29([FromBody] ReportPersonRequest req) + public async Task> PostReportCommand29([FromBody] ReportPersonAndCommandRequest req) { try { var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates .Where(x => req.refIds.Contains(x.Id.ToString())) .ToListAsync(); - data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + // data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + data.ForEach(profile => + { + profile.Status = !string.IsNullOrEmpty(req.status) + ? req.status.Trim().ToUpper() : null; + profile.CommandTypeId = !string.IsNullOrEmpty(req.commandTypeId) && Guid.TryParse(req.commandTypeId, out var cmdTypeId) + ? cmdTypeId : null; + profile.CommandCode = req.commandCode ?? null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -1892,7 +1956,13 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Status.ToUpper() == "REPORT") .ToListAsync(); - data.ForEach(profile => profile.Status = "NEW"); + // data.ForEach(profile => profile.Status = "NEW"); + data.ForEach(profile => + { + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.CommandCode = null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -1986,14 +2056,22 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command30/report")] - public async Task> PostReportCommand30([FromBody] ReportPersonRequest req) + public async Task> PostReportCommand30([FromBody] ReportPersonAndCommandRequest req) { try { var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates .Where(x => req.refIds.Contains(x.Id.ToString())) .ToListAsync(); - data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + // data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + data.ForEach(profile => + { + profile.Status = !string.IsNullOrEmpty(req.status) + ? req.status.Trim().ToUpper() : null; + profile.CommandTypeId = !string.IsNullOrEmpty(req.commandTypeId) && Guid.TryParse(req.commandTypeId, out var cmdTypeId) + ? cmdTypeId : null; + profile.CommandCode = req.commandCode ?? null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -2020,7 +2098,13 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Status.ToUpper() == "REPORT") .ToListAsync(); - data.ForEach(profile => profile.Status = "NEW"); + // data.ForEach(profile => profile.Status = "NEW"); + data.ForEach(profile => + { + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.CommandCode = null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -2114,14 +2198,22 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command31/report")] - public async Task> PostReportCommand31([FromBody] ReportPersonRequest req) + public async Task> PostReportCommand31([FromBody] ReportPersonAndCommandRequest req) { try { var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates .Where(x => req.refIds.Contains(x.Id.ToString())) .ToListAsync(); - data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + // data.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + data.ForEach(profile => + { + profile.Status = !string.IsNullOrEmpty(req.status) + ? req.status.Trim().ToUpper() : null; + profile.CommandTypeId = !string.IsNullOrEmpty(req.commandTypeId) && Guid.TryParse(req.commandTypeId, out var cmdTypeId) + ? cmdTypeId : null; + profile.CommandCode = req.commandCode ?? null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -2148,7 +2240,13 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Status.ToUpper() == "REPORT") .ToListAsync(); - data.ForEach(profile => profile.Status = "NEW"); + // data.ForEach(profile => profile.Status = "NEW"); + data.ForEach(profile => + { + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.CommandCode = null; + }); await _context.SaveChangesAsync(); return Success(); } @@ -2242,7 +2340,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command32/report")] - public async Task> PostReportCommand32([FromBody] ReportPersonRequest req) + public async Task> PostReportCommand32([FromBody] ReportPersonAndCommandRequest req) { try { @@ -2255,7 +2353,15 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Contains(x.Id.ToString())) .ToListAsync(); - data2.ForEach(profile => profile.IsReport = req.status.Trim().ToUpper()); + // data2.ForEach(profile => profile.IsReport = req.status.Trim().ToUpper()); + data2.ForEach(profile => + { + profile.Status = !string.IsNullOrEmpty(req.status) + ? req.status.Trim().ToUpper() : null; + profile.CommandTypeId = !string.IsNullOrEmpty(req.commandTypeId) && Guid.TryParse(req.commandTypeId, out var cmdTypeId) + ? cmdTypeId : null; + profile.CommandCode = req.commandCode ?? null; + }); await _context.SaveChangesAsync(); return Success(); @@ -2290,7 +2396,13 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers // .Where(x => x.IsReport == "REPORT") .ToListAsync(); - data2.ForEach(profile => profile.IsReport = "NEW"); + // data2.ForEach(profile => profile.IsReport = "NEW"); + data2.ForEach(profile => + { + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.CommandCode = null; + }); await _context.SaveChangesAsync(); return Success(); From dc5ac329e2518f6b37294905e8d2529ec5262f32 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 28 May 2026 14:53:32 +0700 Subject: [PATCH 2/2] =?UTF-8?q?API=20=E0=B8=A5=E0=B8=9A=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B9=80=E0=B8=89=E0=B8=9E?= =?UTF-8?q?=E0=B8=B2=E0=B8=B0=E0=B8=AA=E0=B8=B4=E0=B8=97=E0=B8=98=E0=B8=B4?= =?UTF-8?q?=E0=B9=8C=20OWNER=20=20#1586?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/UserProfileRepository.cs | 36 ++++++++++++ .../Controllers/LeaveReportController.cs | 4 +- .../Controllers/LeaveRequestController.cs | 39 +++++++++++++ .../Controllers/PlacementReceiveController.cs | 55 +++++++++++++++++++ .../PlacementTransferController.cs | 54 ++++++++++++++++++ .../Controllers/RetirementResignController.cs | 41 ++++++++++++++ .../RetirementResignEmployeeController.cs | 41 ++++++++++++++ 7 files changed, 268 insertions(+), 2 deletions(-) diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index 2d9ae7b4..aa89d9b9 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -1062,6 +1062,42 @@ namespace BMA.EHR.Application.Repositories } } + public async Task> GetEmployeeByAdminRolev2(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId, DateTime? startDate, DateTime? endDate) + { + try + { + var apiPath = $"{_configuration["API"]}/org/dotnet/employee-by-admin-rolev2"; + var apiKey = _configuration["API_KEY"]; + var body = new + { + node = node, + nodeId = nodeId, + role = role, + // isRetirement + reqNode = reqNode, + reqNodeId = reqNodeId, + date = endDate + }; + Console.WriteLine(body); + + var profiles = new List(); + + var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey); + if (apiResult != null) + { + var raw = JsonConvert.DeserializeObject(apiResult); + if (raw != null) + return raw.Result; + } + + return new List(); + } + catch + { + throw; + } + } + public async Task SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken, int page, int pageSize, string? role, string? nodeId, int? node,string? selectedNodeId,int? selectedNode ) { try diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index ec31f89a..abdf5f2b 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -1352,7 +1352,7 @@ namespace BMA.EHR.Leave.Service.Controllers } else { - profile = await _userProfileRepository.GetEmployeeByAdminRole(AccessToken, profileAdmin?.Node, nodeId, role, req.revisionId, req.node, req.nodeId, req.StartDate.Date, req.EndDate.Date); + profile = await _userProfileRepository.GetEmployeeByAdminRolev2(AccessToken, profileAdmin?.Node, nodeId, role, req.revisionId, req.node, req.nodeId, req.StartDate.Date, req.EndDate.Date); } // get leave day var leaveDays = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRange(req.StartDate, req.EndDate); @@ -2380,7 +2380,7 @@ namespace BMA.EHR.Leave.Service.Controllers } else { - profile = await _userProfileRepository.GetEmployeeByAdminRole(AccessToken, profileAdmin?.Node, nodeId, role, req.revisionId, req.node, req.nodeId, req.StartDate.Date, req.EndDate.Date); + profile = await _userProfileRepository.GetEmployeeByAdminRolev2(AccessToken, profileAdmin?.Node, nodeId, role, req.revisionId, req.node, req.nodeId, req.StartDate.Date, req.EndDate.Date); } // Child กรองตามที่ fe ส่งมาอีกชั้น if ((role == "ROOT" || role == "OWNER" || role == "CHILD" || role == "PARENT" || role == "BROTHER") /*&& req.node > profileAdmin?.Node*/) diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index 15d054ce..70b5c8c6 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -2134,6 +2134,45 @@ namespace BMA.EHR.Leave.Service.Controllers return Success(); } + /// + /// API ลบรายการการลา (ADMIN) + /// + /// + /// + /// เมื่อทำรายการสำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpDelete("admin/{id:guid}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> DeleteLeaveRequestForAdminAsync(Guid id) + { + var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_LEAVE_LIST"); + if (jsonData!.status != 200) + { + return Error(jsonData.message, StatusCodes.Status403Forbidden); + } + // ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น + if (jsonData.result.privilege != "OWNER") + { + return Error("ไม่มีสิทธิ์ในการลบรายการขอลา", StatusCodes.Status403Forbidden); + } + + var deleted = await _leaveRequestRepository.GetByIdAsync(id); + if (deleted == null) + return Error(GlobalMessages.DataNotFound); + + // ห้ามลบเฉพาะสถานะ APPROVE, DELETING, DELETE + if (new[] { "APPROVE", "DELETING", "DELETE" }.Contains(deleted.LeaveStatus)) + { + return Error("ไม่สามารถลบรายการขอลาสถานะนี้ได้"); + } + + await _leaveRequestRepository.DeleteAsync(deleted); + return Success(); + } + /// /// LV2_014 - รายการขอยกเลิกการลา (ADMIN) /// diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs index fa647940..0447ff4c 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs @@ -923,6 +923,61 @@ namespace BMA.EHR.Placement.Service.Controllers return Success(); } + /// + /// API ลบรายการรับโอน (ADMIN) + /// + /// Id รับโอน + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpDelete("admin/{id:length(36)}")] + public async Task> DeleteForAdminAsync(Guid id) + { + var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_TRANSFER_RECEIVE"); + if (jsonData!.status != 200) + { + return Error(jsonData.message, StatusCodes.Status403Forbidden); + } + // ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น + if (jsonData.result.privilege != "OWNER") + { + return Error("ไม่มีสิทธิ์ในการลบรายการรับโอน", StatusCodes.Status403Forbidden); + } + var deleted = await _context.PlacementReceives.AsQueryable() + .Include(x => x.PlacementReceiveDocs) + .ThenInclude(x => x.Document) + .FirstOrDefaultAsync(x => x.Id == id); + if (deleted == null) + return NotFound(); + + // ห้ามลบเฉพาะสถานะ REPORT, WAITING, DONE + if (new[] { "REPORT", "WAITING", "DONE" }.Contains(deleted.Status)) + { + return Error("ไม่สามารถลบรายการรับโอนสถานะนี้ได้"); + } + + var placementReceiveDocs = new List(); + foreach (var doc in deleted.PlacementReceiveDocs) + { + if (doc.Document != null) + placementReceiveDocs.Add(doc.Document.Id); + } + _context.PlacementReceiveDocs.RemoveRange(deleted.PlacementReceiveDocs); + await _context.SaveChangesAsync(); + _context.PlacementReceives.Remove(deleted); + foreach (var doc in placementReceiveDocs) + { + if (doc != null) + await _documentService.DeleteFileAsync(doc); + } + await _context.SaveChangesAsync(); + + return Success(); + } + + /// /// สั่งรายชื่อไปออกคำสั่ง /// diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs index b74a6bc5..a8786b51 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs @@ -932,6 +932,60 @@ namespace BMA.EHR.Placement.Service.Controllers return Success(); } + /// + /// API ลบรายการคำขอโอน (ADMIN) + /// + /// Id คำขอโอน + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpDelete("admin/{id:length(36)}")] + public async Task> DeleteForAdminAsync(Guid id) + { + var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_TRANSFER_REQ"); + if (jsonData!.status != 200) + { + return Error(jsonData.message, StatusCodes.Status403Forbidden); + } + // ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น + if (jsonData.result.privilege != "OWNER") + { + return Error("ไม่มีสิทธิ์ในการลบรายการคำขอโอน", StatusCodes.Status403Forbidden); + } + var deleted = await _context.PlacementTransfers.AsQueryable() + .Include(x => x.PlacementTransferDocs) + .ThenInclude(x => x.Document) + .FirstOrDefaultAsync(x => x.Id == id); + if (deleted == null) + return NotFound(); + + // ห้ามลบเฉพาะสถานะ REPORT, WAITING, DONE + if (new[] { "REPORT", "WAITING", "DONE" }.Contains(deleted.Status)) + { + return Error("ไม่สามารถลบรายการคำขอโอนสถานะนี้ได้"); + } + + var placementTransferDocs = new List(); + foreach (var doc in deleted.PlacementTransferDocs) + { + if (doc.Document != null) + placementTransferDocs.Add(doc.Document.Id); + } + _context.PlacementTransferDocs.RemoveRange(deleted.PlacementTransferDocs); + await _context.SaveChangesAsync(); + _context.PlacementTransfers.Remove(deleted); + foreach (var doc in placementTransferDocs) + { + if (doc != null) + await _documentService.DeleteFileAsync(doc); + } + await _context.SaveChangesAsync(); + + return Success(); + } + /// /// สั่งรายชื่อไปออกคำสั่ง /// diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index b3c42f88..b610d350 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -1811,6 +1811,47 @@ namespace BMA.EHR.Retirement.Service.Controllers return Success(); } + /// + /// API ลบรายการลาออก (ADMIN) + /// + /// Id ลาออก + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpDelete("admin/{id:length(36)}")] + public async Task> DeleteForAdminAsync(Guid id) + { + var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_RESIGN"); + if (jsonData!.status != 200) + { + return Error(jsonData.message, StatusCodes.Status403Forbidden); + } + // ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น + if (jsonData.result.privilege != "OWNER") + { + return Error("ไม่มีสิทธิ์ในการลบรายการลาออก", StatusCodes.Status403Forbidden); + } + var deleted = await _context.RetirementResigns.AsQueryable() + .FirstOrDefaultAsync(x => x.Id == id); + if (deleted == null) + return Error(GlobalMessages.RetirementResignNotFound, 404); + + // ห้ามลบเฉพาะสถานะ REPORT, WAITING, DONE, CANCELING, CANCEL + if (new[] { "REPORT", "WAITING", "DONE", "CANCELING", "CANCEL" }.Contains(deleted.Status)) + { + return Error("ไม่สามารถลบรายการลาออกสถานะนี้ได้"); + } + + deleted.Status = "DELETE"; + deleted.LastUpdateFullName = FullName ?? "System Administrator"; + deleted.LastUpdateUserId = UserId ?? ""; + deleted.LastUpdatedAt = DateTime.Now; + await _context.SaveChangesAsync(); + return Success(); + } + /// /// อนุมัติคำลาออก /// diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs index 7db20848..72cd80d1 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs @@ -1719,6 +1719,47 @@ namespace BMA.EHR.Retirement.Service.Controllers return Success(); } + /// + /// API ลบรายการลาออกลูกจ้าง (ADMIN) + /// + /// Id ลาออก + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpDelete("admin/{id:length(36)}")] + public async Task> DeleteForAdminAsync(Guid id) + { + var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_RESIGN_EMP"); + if (jsonData!.status != 200) + { + return Error(jsonData.message, StatusCodes.Status403Forbidden); + } + // ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น + if (jsonData.result.privilege != "OWNER") + { + return Error("ไม่มีสิทธิ์ในการลบรายการลาออกลูกจ้าง", StatusCodes.Status403Forbidden); + } + var deleted = await _context.RetirementResignEmployees.AsQueryable() + .FirstOrDefaultAsync(x => x.Id == id); + if (deleted == null) + return Error(GlobalMessages.RetirementResignEmployeeNotFound, 404); + + // ห้ามลบเฉพาะสถานะ REPORT, WAITING, DONE, CANCELING, CANCEL + if (new[] { "REPORT", "WAITING", "DONE", "CANCELING", "CANCEL" }.Contains(deleted.Status)) + { + return Error("ไม่สามารถลบรายการลาออกลูกจ้างสถานะนี้ได้"); + } + + deleted.Status = "DELETE"; + deleted.LastUpdateFullName = FullName ?? "System Administrator"; + deleted.LastUpdateUserId = UserId ?? ""; + deleted.LastUpdatedAt = DateTime.Now; + await _context.SaveChangesAsync(); + return Success(); + } + /// /// อนุมัติคำลาออก ///