From e96f606c85f3082a596d70b27c9f3430a92439ac Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 25 May 2026 17:20:07 +0700 Subject: [PATCH 01/42] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20format=20?= =?UTF-8?q?=E0=B8=9F=E0=B8=B4=E0=B8=A7=20posMasterNo=20(5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PlacementAppointmentController.cs | 2 +- .../Controllers/PlacementOfficerController.cs | 2 +- .../Controllers/PlacementRepatriationController.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs index ff010a2a..df4be162 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs @@ -554,7 +554,7 @@ namespace BMA.EHR.Placement.Service.Controllers placementAppointment.positionAreaOld = org.result.positionArea; placementAppointment.PositionLevelOld = org.result.posLevelName; placementAppointment.PositionTypeOld = org.result.posTypeName; - placementAppointment.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo; + placementAppointment.PositionNumberOld = org.result.posNo; placementAppointment.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") + (org.result.child3 == null ? "" : org.result.child3 + "\n") + (org.result.child2 == null ? "" : org.result.child2 + "\n") + diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs index e05f03f3..867935e9 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs @@ -493,7 +493,7 @@ namespace BMA.EHR.Placement.Service.Controllers placementOfficer.positionAreaOld = org.result.positionArea; placementOfficer.PositionLevelOld = org.result.posLevelName; placementOfficer.PositionTypeOld = org.result.posTypeName; - placementOfficer.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo; + placementOfficer.PositionNumberOld = org.result.posNo; placementOfficer.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") + (org.result.child3 == null ? "" : org.result.child3 + "\n") + (org.result.child2 == null ? "" : org.result.child2 + "\n") + diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs index 26da4786..e9c45532 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs @@ -374,7 +374,7 @@ namespace BMA.EHR.Placement.Service.Controllers placementRepatriation.positionAreaOld = org.result.positionArea; placementRepatriation.PositionLevelOld = org.result.posLevelName; placementRepatriation.PositionTypeOld = org.result.posTypeName; - placementRepatriation.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo; + placementRepatriation.PositionNumberOld = org.result.posNo; placementRepatriation.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") + (org.result.child3 == null ? "" : org.result.child3 + "\n") + (org.result.child2 == null ? "" : org.result.child2 + "\n") + From f50ad38503b1440cd6ed3797b415963428b40d2c Mon Sep 17 00:00:00 2001 From: harid Date: Mon, 25 May 2026 18:08:13 +0700 Subject: [PATCH 02/42] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20log=20api=20candidate/report/excecute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PlacementController.cs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index db3e9e86..9daf1b9d 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -2198,8 +2198,11 @@ namespace BMA.EHR.Placement.Service.Controllers [HttpPost("candidate/report/excecute")] public async Task> PostReportExecuteCandidate([FromBody] ReportExecuteRequest req) { + Console.WriteLine($"[CandidateReportExcecute] Starting execution at {DateTime.Now}"); + try { + Console.WriteLine($"[CandidateReportExcecute] Request received with {req?.refIds?.Length ?? 0} refIds"); var placementProfile = await _context.PlacementProfiles .Include(x => x.PlacementCertificates) .Include(x => x.PlacementEducations) @@ -2207,8 +2210,15 @@ namespace BMA.EHR.Placement.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); + Console.WriteLine($"[CandidateReportExcecute] Found {placementProfile?.Count ?? 0} placement profiles"); + if (placementProfile == null) + { + Console.Error.WriteLine("[CandidateReportExcecute] PlacementProfile is null - returning NotFound"); return NotFound(); + } + + Console.WriteLine("[CandidateReportExcecute] Building resultData from placement profiles and refIds"); var resultData = (from p in placementProfile join r in req.refIds @@ -2366,6 +2376,9 @@ namespace BMA.EHR.Placement.Service.Controllers }, }).ToList(); + Console.WriteLine($"[CandidateReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records"); + + Console.WriteLine($"[CandidateReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile"); var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; using (var client = new HttpClient()) { @@ -2377,8 +2390,10 @@ namespace BMA.EHR.Placement.Service.Controllers data = resultData }); var _result = await _res.Content.ReadAsStringAsync(); + Console.WriteLine($"[CandidateReportExcecute] External API response status: {_res.StatusCode}"); if (_res.IsSuccessStatusCode) { + Console.WriteLine("[CandidateReportExcecute] External API call successful - updating placement profiles"); placementProfile.ForEach(profile => { profile.PlacementStatus = "DONE"; @@ -2392,17 +2407,27 @@ namespace BMA.EHR.Placement.Service.Controllers profile.templateDoc = req.refIds[0].remark; } }); + Console.WriteLine($"[CandidateReportExcecute] Saving changes to database for {placementProfile.Count} profiles"); await _context.SaveChangesAsync(); + Console.WriteLine("[CandidateReportExcecute] Database save completed successfully"); + } + else + { + Console.Error.WriteLine($"[CandidateReportExcecute] External API call failed with status: {_res.StatusCode}"); + Console.Error.WriteLine($"[CandidateReportExcecute] Response content: {_result}"); } } // // update placementstatus // placementProfile.ForEach(profile => profile.PlacementStatus = "DONE"); // await _context.SaveChangesAsync(); + Console.WriteLine($"[CandidateReportExcecute] Process completed successfully at {DateTime.Now}"); return Success(); } - catch + catch (Exception ex) { + Console.Error.WriteLine($"[CandidateReportExcecute] Error occurred: {ex.Message}"); + Console.Error.WriteLine($"[CandidateReportExcecute] Stack trace: {ex.StackTrace}"); throw; } } From 6a38f000babb5c4d83e0c52b1b6cc4ef8111d8c5 Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 25 May 2026 18:17:07 +0700 Subject: [PATCH 03/42] #2505 --- .../Controllers/PlacementAppointmentController.cs | 6 ++++++ .../Controllers/PlacementController.cs | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs index 786222b1..a8c2bd4c 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs @@ -1011,7 +1011,9 @@ namespace BMA.EHR.Placement.Service.Controllers positionExecutive = p.PositionExecutive, positionExecutiveField = p.positionExecutiveField, positionArea = p.positionArea, + positionTypeId = p.posTypeId, positionType = p.posTypeName, + positionLevelId = p.posLevelId, positionLevel = p.posLevelName, posmasterId = p.posmasterId, positionId = p.positionId, @@ -1225,7 +1227,9 @@ namespace BMA.EHR.Placement.Service.Controllers positionExecutive = p.PositionExecutive, positionExecutiveField = p.positionExecutiveField, positionArea = p.positionArea, + positionTypeId = p.posTypeId, positionType = p.posTypeName, + positionLevelId = p.posLevelId, positionLevel = p.posLevelName, posmasterId = p.posmasterId, positionId = p.positionId, @@ -1856,7 +1860,9 @@ namespace BMA.EHR.Placement.Service.Controllers positionExecutive = p.PositionExecutive, positionExecutiveField = p.positionExecutiveField, positionArea = p.positionArea, + positionTypeId = p.posTypeId, positionType = p.posTypeName, + positionLevelId = p.posLevelId, positionLevel = p.posLevelName, posmasterId = p.posmasterId, positionId = p.positionId, diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index db3e9e86..85d4def6 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -2604,7 +2604,9 @@ namespace BMA.EHR.Placement.Service.Controllers positionExecutive = p.PositionExecutive, positionExecutiveField = p.positionExecutiveField, positionArea = p.positionArea, + positionTypeId = p.posTypeId, positionType = p.posTypeName, + positionLevelId = p.posLevelId, positionLevel = p.posLevelName, posmasterId = p.posmasterId, positionId = p.positionId, @@ -2847,7 +2849,9 @@ namespace BMA.EHR.Placement.Service.Controllers positionExecutive = p.PositionExecutive, positionExecutiveField = p.positionExecutiveField, positionArea = p.positionArea, + positionTypeId = p.posTypeId, positionType = p.posTypeName, + positionLevelId = p.posLevelId, positionLevel = p.posLevelName, posmasterId = p.posmasterId, positionId = p.positionId, From 3f98e0741994b41004da16ec49bf7f32dd1cc810 Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 27 May 2026 17:40:30 +0700 Subject: [PATCH 04/42] =?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 05/42] =?UTF-8?q?API=20=E0=B8=A5=E0=B8=9A=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B9=80=E0=B8=89?= =?UTF-8?q?=E0=B8=9E=E0=B8=B2=E0=B8=B0=E0=B8=AA=E0=B8=B4=E0=B8=97=E0=B8=98?= =?UTF-8?q?=E0=B8=B4=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(); + } + /// /// อนุมัติคำลาออก /// From a48f3fa804dc2bfa156396a02d40f3dda054ddd2 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 29 May 2026 10:25:11 +0700 Subject: [PATCH 06/42] fix issue #2534 --- .../CheckInJobStatusRepository.cs | 4 ++- .../Controllers/LeaveRequestController.cs | 2 ++ BMA.EHR.Leave/appsettings.json | 34 +++++++++++-------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/CheckInJobStatusRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/CheckInJobStatusRepository.cs index 85c575d3..e0967a5c 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/CheckInJobStatusRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/CheckInJobStatusRepository.cs @@ -119,10 +119,11 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants /// public async Task> GetStalePendingOrProcessingJobsAsync(int timeoutMinutes = 30) { + //var cutoffDate = DateTime.Now.AddMinutes(-timeoutMinutes); var cutoffDate = DateTime.Now.AddMinutes(-timeoutMinutes); var staleJobs = await _dbContext.Set() .Where(x => (x.Status == "PENDING" || x.Status == "PROCESSING") - && x.CreatedDate < cutoffDate) + && x.CreatedDate <= cutoffDate) .OrderBy(x => x.CreatedDate) .ToListAsync(); @@ -135,6 +136,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants public async Task> GetStalePendingOrProcessingJobsByUserAsync(Guid userId, int timeoutMinutes = 30) { var cutoffDate = DateTime.Now.AddMinutes(-timeoutMinutes); + //var cutoffDate = new DateTime(2026, 5, 28, 23, 59, 59); var staleJobs = await _dbContext.Set() .Where(x => x.KeycloakUserId == userId && (x.Status == "PENDING" || x.Status == "PROCESSING") diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index 15d054ce..771895f5 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -3086,6 +3086,7 @@ namespace BMA.EHR.Leave.Service.Controllers leaveBeginningDict.TryGetValue(leaveType.Id, out var leaveData); var approve = leaveData?.LeaveDaysUsed ?? 0; + var approveCount = leaveData?.LeaveCount ?? 0; // fix issue : SIT ระบบบันทึกการลา>> สิทธิ์การลา(โอนสิทธิ์การลา) #974 var extendLeave = 0.0; @@ -3108,6 +3109,7 @@ namespace BMA.EHR.Leave.Service.Controllers LeaveCountApprove = approve, LeaveCountReject = reject, LeaveCountDelete = delete, + LeaveCountApproveCount = approveCount, }; result.Add(data); } diff --git a/BMA.EHR.Leave/appsettings.json b/BMA.EHR.Leave/appsettings.json index 7c098db0..84791566 100644 --- a/BMA.EHR.Leave/appsettings.json +++ b/BMA.EHR.Leave/appsettings.json @@ -23,15 +23,15 @@ "ExamConnection": "Server=192.168.1.63;User ID=root;Password=12345678;Port=3306;Database=hrms_exam;Allow User Variables=True;Convert Zero Datetime=True;Pooling=True;", "LeaveConnection": "Server=192.168.1.63;User ID=root;Password=12345678;Port=3306;Database=hrms_leave;Allow User Variables=True;Convert Zero Datetime=True;Pooling=True;" - // "DefaultConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=3306;database=hrms;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;", - // "ExamConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=3306;database=hrms_exam;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;", - // "LeaveConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=3306;database=hrms_leave;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;" +// "DefaultConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=13306;database=hrms;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;", +// "ExamConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=13306;database=hrms_exam;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;", +// "LeaveConnection": "server=127.0.0.1;user=root;password=ey2qVVyyqGYw8CyA7h8X72559r2Ad84K;port=13306;database=hrms_leave;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;Connection Timeout=180;" }, "Jwt": { "Key": "j7C9RO_p4nRtuwCH4z9Db_A_6We42tkD_p4lZtDrezc", "Issuer": "https://hrmsbkk-id.case-collection.com/realms/hrms" - // "Key": "xY2VR-EFvvNPsMs39u8ooVBWQL6mPwrNJOh3koJFTgU", - // "Issuer": "https://hrms-id.bangkok.go.th/realms/hrms" +// "Key": "xY2VR-EFvvNPsMs39u8ooVBWQL6mPwrNJOh3koJFTgU", +// "Issuer": "https://hrms-id.bangkok.go.th/realms/hrms" }, "EPPlus": { "ExcelPackage": { @@ -43,6 +43,10 @@ "AccessKey": "iwvzjyjgz0BKtLPmMpPu", "SecretKey": "Yv56vwctYdIspDknRJ46xztcBDzteGF3elZiDcAr", "BucketName": "hrms-fpt" +// "Endpoint": "https://hrms-s3.bangkok.go.th/", +// "AccessKey": "frappet", +// "SecretKey": "FPTadmin2357", +// "BucketName": "bma-ehr-fpt" }, "Protocol": "HTTPS", "Node": { @@ -54,11 +58,11 @@ "Password": "12345678", "Queue": "hrms-checkin-queue-dev", "URL": "http://192.168.1.63:9122/api/queues/%2F/" - // "Host": "172.27.17.68", - // "User": "admin", - // "Password": "admin123456", - // "Queue": "hrms-checkin-queue", - // "URL": "http://172.27.17.68:9122/api/queues/%2F/" +// "Host": "172.27.17.68", +// "User": "admin", +// "Password": "admin123456", +// "Queue": "hrms-checkin-queue", +// "URL": "http://172.27.17.68:9122/api/queues/%2F/" }, "Mail": { "Server": "mail.bangkok.go.th", @@ -72,10 +76,10 @@ "API": "https://hrmsbkk.case-collection.com/api/v1", "APIV2": "https://hrmsbkk.case-collection.com/api/v2", "VITE_URL_MGT": "https://hrmsbkk-mgt.case-collection.com", - // "Domain": "https://hrms-exam.bangkok.go.th", - // "APIPROBATION": "https://hrms.bangkok.go.th/api/v1/probation", - // "API": "https://hrms.bangkok.go.th/api/v1", - // "APIV2": "https://hrms.bangkok.go.th/api/v2", - // "VITE_URL_MGT": "https://hrms-mgt.bangkok.go.th", +// "Domain": "https://hrms.bangkok.go.th", +// "APIPROBATION": "https://hrms.bangkok.go.th/api/v1/probation", +// "API": "https://hrms.bangkok.go.th/api/v1", +// "APIV2": "https://hrms.bangkok.go.th/api/v2", +// "VITE_URL_MGT": "https://hrms-mgt.bangkok.go.th", "API_KEY": "fKRL16yyEgbyTEJdsMw2h64tGSCmkW685PRtM3CygzX1JOSdptT9UJtpgWwKM8FybRTJups3GTFwj27ZRvlPdIkv3XgCoVJaD5LmR06ozuEPvCCRSdp2WFthg08V5xHc56fTPfZLpr1VmXrhd6dvYhHIqKkQUJR02Rlkss11cLRWEQOssEFVA4xdu2J5DIRO1EM5m7wRRvEwcDB4mYRXD9HH52SMq6iYqUWEWsMwLdbk7QW9yYESUEuzMW5gWrb6vIeWZxJV5bTz1PcWUyR7eO9Fyw1F5DiQYc9JgzTC1mW7cv31fEtTtrfbJYKIb5EbWilqIEUKC6A0UKBDDek35ML0006cqRVm0pvdOH6jeq7VQyYrhdXe59dBEyhYGUIfozoVBvW7Up4QBuOMjyPjSqJPlMBKwaseptfrblxQV1AOOivSBpf1ZcQyOZ8JktRtKUDSuXsmG0lsXwFlI3JCeSHdpVdgZWFYcJPegqfrB6KotR02t9AVkpLs1ZWrixwz" } From ad70043264016381685f94bd153938439e8755e8 Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 29 May 2026 14:56:16 +0700 Subject: [PATCH 07/42] =?UTF-8?q?=E0=B8=81=E0=B8=A3=E0=B8=AD=E0=B8=87?= =?UTF-8?q?=E0=B8=AA=E0=B8=96=E0=B8=B2=E0=B8=99=E0=B8=B0=E0=B8=82=E0=B8=AD?= =?UTF-8?q?=E0=B8=A5=E0=B8=B2=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=9D=E0=B8=B1?= =?UTF-8?q?=E0=B9=88=E0=B8=87=20user=20#1586?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/RetirementResignController.cs | 2 +- .../Controllers/RetirementResignEmployeeController.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index b610d350..09f7f08b 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -151,7 +151,7 @@ namespace BMA.EHR.Retirement.Service.Controllers return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404); var retirementResigns = await _context.RetirementResigns.AsQueryable() - .Where(x => x.profileId == org.result.profileId) + .Where(x => x.Status != "DELETE" && x.profileId == org.result.profileId) .OrderByDescending(x => x.CreatedAt) .Select(p => new { diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs index 72cd80d1..1b7cef1c 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs @@ -89,7 +89,7 @@ namespace BMA.EHR.Retirement.Service.Controllers return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404); var retirementResignEmployees = await _context.RetirementResignEmployees.AsQueryable() - .Where(x => x.profileId == org.result.profileId) + .Where(x => x.Status != "DELETE" && x.profileId == org.result.profileId) .OrderByDescending(x => x.CreatedAt) .Select(p => new { From 71a4748d39bc29b1eb9cd6bf2f60520ba88654df Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 29 May 2026 15:32:26 +0700 Subject: [PATCH 08/42] =?UTF-8?q?Job:=20=E0=B8=AD=E0=B8=B1=E0=B8=9E?= =?UTF-8?q?=E0=B9=80=E0=B8=94=E0=B8=97=E0=B8=AA=E0=B8=96=E0=B8=B2=E0=B8=99?= =?UTF-8?q?=E0=B8=B0=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=AA=E0=B8=AD=E0=B8=9A?= =?UTF-8?q?=E0=B8=9C=E0=B9=88=E0=B8=B2=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88?= =?UTF-8?q?=E0=B8=A5=E0=B8=B2=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B9=84=E0=B8=9B?= =?UTF-8?q?=E0=B9=81=E0=B8=A5=E0=B9=89=E0=B8=A7=E0=B9=81=E0=B8=95=E0=B9=88?= =?UTF-8?q?=E0=B8=A2=E0=B8=B1=E0=B8=87=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B8=AA?= =?UTF-8?q?=E0=B9=88=E0=B8=87=E0=B9=84=E0=B8=9B=E0=B8=AD=E0=B8=AD=E0=B8=81?= =?UTF-8?q?=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=20?= =?UTF-8?q?=E0=B8=97=E0=B8=B3=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B8=97=E0=B8=B8?= =?UTF-8?q?=E0=B8=81=E0=B8=A7=E0=B8=B1=E0=B8=99=E0=B9=80=E0=B8=A7=E0=B8=A5?= =?UTF-8?q?=E0=B8=B2=2005:00=20=E0=B8=99.=20#2518?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/PlacementRepository.cs | 95 ++++++++++++++++++- BMA.EHR.Placement.Service/Program.cs | 3 + 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/BMA.EHR.Application/Repositories/PlacementRepository.cs b/BMA.EHR.Application/Repositories/PlacementRepository.cs index 49f1175c..82b71b79 100644 --- a/BMA.EHR.Application/Repositories/PlacementRepository.cs +++ b/BMA.EHR.Application/Repositories/PlacementRepository.cs @@ -2,6 +2,9 @@ using BMA.EHR.Domain.Models.Placement; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using System.Net.Http.Headers; +using Newtonsoft.Json; namespace BMA.EHR.Application.Repositories { @@ -11,15 +14,17 @@ namespace BMA.EHR.Application.Repositories private readonly IApplicationDBContext _dbContext; private readonly IHttpContextAccessor _httpContextAccessor; + private readonly IConfiguration _configuration; #endregion #region " Constructor and Destructor " - public PlacementRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor) + public PlacementRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor, IConfiguration configuration) : base(dbContext, httpContextAccessor) { _dbContext = dbContext; _httpContextAccessor = httpContextAccessor; + _configuration = configuration; } #endregion @@ -76,6 +81,94 @@ namespace BMA.EHR.Application.Repositories return data; } + /// + /// Job อัพเดทสถานะผู้สอบผ่านที่ลาออกไปแล้วแต่ยังไม่ส่งไปออกคำสั่ง + /// ทำงานทุกวันเวลา 05:00 น. + /// + public async Task UpdateStatusPlacementProfiles() + { + Console.WriteLine("[Job:UpdateStatusPlacementProfiles] === STARTED ==="); + + var officerProfileIds = await _dbContext.Set() + .Where(p => !string.IsNullOrEmpty(p.profileId) + && p.IsOfficer == true + && p.PlacementStatus != "DONE" + // && p.Id == Guid.Parse("08deb7de-3030-4d1b-8519-8148584949fc") + ) + .Select(p => p.profileId) + .ToListAsync(); + + if (!officerProfileIds.Any()) + { + Console.WriteLine("[Job:UpdateStatusPlacementProfiles] No profiles to process"); + return; + } + + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] พบข้าราชการที่สอบผ่านทั้งหมด {officerProfileIds.Count} คน ที่ยังไม่ส่งไปออกคำสั่ง"); + + var apiUrl = $"{_configuration["API"]}/org/dotnet/check-isLeave"; + List leaveProfileIds = new(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + var payload = new + { + profileIds = officerProfileIds.Distinct().ToList() + }; + var jsonPayload = JsonConvert.SerializeObject(payload); + var content = new StringContent(jsonPayload, System.Text.Encoding.UTF8, "application/json"); + + try + { + var response = await client.PostAsync(apiUrl, content); + var result = await response.Content.ReadAsStringAsync(); + var responseObj = JsonConvert.DeserializeAnonymousType(result, new + { + status = 0, + message = "", + result = new List() + }); + + leaveProfileIds = responseObj.result ?? new(); + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] พบ {leaveProfileIds.Count} รายการที่ลาออก"); + } + catch (Exception ex) + { + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] Call API failed: {ex.Message}"); + return; + } + } + + if (leaveProfileIds.Any()) + { + var batchSize = 500; + var totalUpdated = 0; + var totalBatches = (int)Math.Ceiling((double)leaveProfileIds.Count / batchSize); + + for (int i = 0; i < totalBatches; i++) + { + var batch = leaveProfileIds.Skip(i * batchSize).Take(batchSize).ToList(); + + var profilesToUpdate = await _dbContext.Set() + .Where(p => !string.IsNullOrEmpty(p.profileId) && batch.Contains(p.profileId)) + .ToListAsync(); + + foreach (var profile in profilesToUpdate) + { + profile.IsOfficer = false; + } + + await _dbContext.SaveChangesAsync(); + + totalUpdated += profilesToUpdate.Count; + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] Batch {i + 1}/{totalBatches} → อัปเดต {profilesToUpdate.Count} รายการ"); + } + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] อัปเดตรวมทั้งหมด {totalUpdated} รายการ → IsOfficer = false"); + } + Console.WriteLine("[Job:UpdateStatusPlacementProfiles] === COMPLETED ==="); + } + #endregion } } diff --git a/BMA.EHR.Placement.Service/Program.cs b/BMA.EHR.Placement.Service/Program.cs index f954f343..bd4eb6e8 100644 --- a/BMA.EHR.Placement.Service/Program.cs +++ b/BMA.EHR.Placement.Service/Program.cs @@ -21,6 +21,7 @@ using System.Text; using System.Transactions; using BMA.EHR.Placement.Service.Filters; using BMA.EHR.Application.Repositories.Reports; +using BMA.EHR.Application.Repositories; var builder = WebApplication.CreateBuilder(args); { @@ -164,6 +165,8 @@ var app = builder.Build(); if (manager != null) { manager.AddOrUpdate("แจ้งเตือนระบบทดลองงาน", Job.FromExpression(x => x.NotifyProbation()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local); + // Job: อัพเดทสถานะผู้สอบผ่านที่ลาออกไปแล้วแต่ยังไม่ส่งไปออกคำสั่ง ทำงานทุกวันเวลา 05:00 น. + manager.AddOrUpdate("ประมวลผลข้าราชการฯ กทม.", Job.FromExpression(x => x.UpdateStatusPlacementProfiles()), Cron.Daily(5), TimeZoneInfo.Local); } // apply migrations From 8ae822d05baace38fa1cc232211d66c9f098b90a Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 29 May 2026 15:46:29 +0700 Subject: [PATCH 09/42] leave report #2524 --- .../Controllers/LeaveReportController.cs | 50 ++++++++++++++++--- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index abdf5f2b..cfc84ef0 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -2444,6 +2444,15 @@ namespace BMA.EHR.Leave.Service.Controllers var workTotal = 0; var seminarTotal = 0; + var wfaTotal = 0; //ปฏิบัติงานนอกสถานที่ + var outOfficeTotal = 0; //ขออนุญาติิิออกนอกสถานที่ + var oneStopSrvrTotal = 0; //จุดบริการด่วนมหานคร + var otherTotal = 0; //อื่นๆ + + + + + var defaultRound = await _dutyTimeRepository.GetDefaultAsync(); if (defaultRound == null) { @@ -2627,10 +2636,18 @@ namespace BMA.EHR.Leave.Service.Controllers workTotal += 1; if (!timeStamps.IsLocationCheckIn) { - if (timeStamps.CheckInLocationName == "ปฏิบัติงานที่บ้าน") + if (timeStamps.CheckInLocationName!.Contains("ปฏิบัติงานที่บ้าน")) wfhTotal += 1; else if (timeStamps.CheckInLocationName == "ไปประชุม / อบรม / สัมมนา") seminarTotal += 1; + else if (timeStamps.CheckInLocationName.Contains("ปฏิบัติงานนอกสถานที่")) + wfaTotal += 1; + else if (timeStamps.CheckInLocationName.Contains("ขออนุญาตออกนอกสถานที่")) + outOfficeTotal += 1; + else if (timeStamps.CheckInLocationName.Contains("ปฏิบัติงานในจุดบริการด่วนมหานคร")) + oneStopSrvrTotal += 1; + else if (timeStamps.CheckInLocationName.Contains("อื่นๆ")) + otherTotal += 1; } } @@ -2781,19 +2798,36 @@ namespace BMA.EHR.Leave.Service.Controllers worksheet.Cells[lastRow + 2, 8].Value = "อบรม ประชุม สัมมนาฯ"; worksheet.Cells[lastRow + 2, 9].Value = seminarTotal; worksheet.Cells[lastRow + 2, 10].Value = "คน"; + worksheet.Cells[lastRow + 3, 8].Value = "ปฎิบัติงานนอกสถานที่"; + worksheet.Cells[lastRow + 3, 9].Value = wfaTotal; + worksheet.Cells[lastRow + 3, 10].Value = "คน"; + worksheet.Cells[lastRow + 4, 8].Value = "ขออนุญาตออกนอกสถานที่"; + worksheet.Cells[lastRow + 4, 9].Value = outOfficeTotal; + worksheet.Cells[lastRow + 4, 10].Value = "คน"; + worksheet.Cells[lastRow + 5, 8].Value = "ปฎิบัติงานในจุดบริการด่วนมหานคร"; + worksheet.Cells[lastRow + 5, 9].Value = oneStopSrvrTotal; + worksheet.Cells[lastRow + 5, 10].Value = "คน"; + worksheet.Cells[lastRow + 6, 8].Value = "อื่นๆ"; + worksheet.Cells[lastRow + 6, 9].Value = otherTotal; + worksheet.Cells[lastRow + 6, 10].Value = "คน"; + + + + + worksheet.Cells[lastRow + 3, 2].Value = "ลาป่วย/ลากิจ"; worksheet.Cells[lastRow + 3, 5].Value = sickTotal; worksheet.Cells[lastRow + 3, 6].Value = "คน"; worksheet.Cells[lastRow + 4, 2].Value = "มาสาย"; worksheet.Cells[lastRow + 4, 5].Value = lateTotal; worksheet.Cells[lastRow + 4, 6].Value = "คน"; - worksheet.Cells[lastRow + 6, 2].Value = "เรียน"; - worksheet.Cells[lastRow + 7, 2].Value = "เพื่อโปรดทราบ"; - worksheet.Cells[lastRow + 7, 9].Value = "ทราบ"; - worksheet.Cells[lastRow + 7, 9].Style.Font.Bold = true; - worksheet.Cells[lastRow + 7, 9].Style.Font.Size = 22; - worksheet.Cells[lastRow + 8, 2].Value = "................................"; - worksheet.Cells[lastRow + 8, 9].Value = "................................"; + worksheet.Cells[lastRow + 8, 2].Value = "เรียน"; + worksheet.Cells[lastRow + 9, 2].Value = "เพื่อโปรดทราบ"; + worksheet.Cells[lastRow + 9, 9].Value = "ทราบ"; + worksheet.Cells[lastRow + 9, 9].Style.Font.Bold = true; + worksheet.Cells[lastRow + 9, 9].Style.Font.Size = 22; + worksheet.Cells[lastRow + 10, 2].Value = "................................"; + worksheet.Cells[lastRow + 10, 9].Value = "................................"; worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); var fileBytes = package.GetAsByteArray(); return File(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "TimeStampRecords.xlsx"); From efc96dfb6d1620d91e84d4a4f94a899f9540f502 Mon Sep 17 00:00:00 2001 From: Adisak Date: Thu, 4 Jun 2026 09:37:29 +0700 Subject: [PATCH 10/42] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20format=20?= =?UTF-8?q?=E0=B8=9F=E0=B8=B4=E0=B8=A7=20posMasterNo=20(6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PlacementAppointmentEmployeeController.cs | 2 +- .../Controllers/RetirementOtherController.cs | 2 +- .../Controllers/RetirementResignController.cs | 2 +- .../Controllers/RetirementResignEmployeeController.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentEmployeeController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentEmployeeController.cs index 971cd526..12325ecb 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentEmployeeController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentEmployeeController.cs @@ -542,7 +542,7 @@ namespace BMA.EHR.Placement.Service.Controllers placementAppointment.positionOld = org.result.position; placementAppointment.PositionLevelOld = org.result.posLevelName; placementAppointment.PositionTypeOld = org.result.posTypeName; - placementAppointment.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo; + placementAppointment.PositionNumberOld = org.result.posNo; placementAppointment.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") + (org.result.child3 == null ? "" : org.result.child3 + "\n") + (org.result.child2 == null ? "" : org.result.child2 + "\n") + diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs index 3f36af1d..697af6eb 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs @@ -448,7 +448,7 @@ namespace BMA.EHR.Retirement.Service.Controllers retirementOther.positionAreaOld = org.result.positionArea; retirementOther.PositionLevelOld = org.result.posLevelName; retirementOther.PositionTypeOld = org.result.posTypeName; - retirementOther.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo; + retirementOther.PositionNumberOld = org.result.posNo; retirementOther.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") + (org.result.child3 == null ? "" : org.result.child3 + "\n") + (org.result.child2 == null ? "" : org.result.child2 + "\n") + diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index b3c42f88..a97c5db8 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -1290,7 +1290,7 @@ namespace BMA.EHR.Retirement.Service.Controllers retirementResign.positionAreaOld = org.result.positionArea; retirementResign.PositionLevelOld = org.result.posLevelName; retirementResign.PositionTypeOld = org.result.posTypeName; - retirementResign.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo; + retirementResign.PositionNumberOld = org.result.posNo; retirementResign.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") + (org.result.child3 == null ? "" : org.result.child3 + "\n") + (org.result.child2 == null ? "" : org.result.child2 + "\n") + diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs index 7db20848..88c29364 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs @@ -1227,7 +1227,7 @@ namespace BMA.EHR.Retirement.Service.Controllers retirementResignEmployee.PositionOld = org.result.position; retirementResignEmployee.PositionLevelOld = org.result.posLevelName; retirementResignEmployee.PositionTypeOld = org.result.posTypeName; - retirementResignEmployee.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo; + retirementResignEmployee.PositionNumberOld = org.result.posNo; retirementResignEmployee.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") + (org.result.child3 == null ? "" : org.result.child3 + "\n") + (org.result.child2 == null ? "" : org.result.child2 + "\n") + From afa5c853938bad5a056e8d290d81393115924f10 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 4 Jun 2026 10:01:11 +0700 Subject: [PATCH 11/42] fix #2545 --- .../LeaveRequests/LeaveRequestRepository.cs | 17 +++++++++++++++++ .../Controllers/LeaveReportController.cs | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index dee940fe..3070ee88 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -1952,6 +1952,23 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests return 0; } + public async Task GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) + { + var data = await _dbContext.Set().AsQueryable().AsNoTracking() + .Include(x => x.Type) + .Where(x => x.KeycloakUserId == keycloakUserId) + .Where(x => x.Type.Id == leaveTypeId) + .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ?? x.CreatedAt) < endDate)) + //.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) + .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") + .ToListAsync(); + + if (data.Count > 0) + return data.Sum(x => x.LeaveTotal); + else + return 0; + } + public async Task GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate) { var data = await _dbContext.Set().AsQueryable().AsNoTracking() diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index cfc84ef0..29676230 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -164,7 +164,7 @@ namespace BMA.EHR.Leave.Service.Controllers if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31)) thisYear = thisYear + 1; var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId); - var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); + var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); if (leaveData != null) { sumLeave += leaveData.BeginningLeaveDays; @@ -346,7 +346,7 @@ namespace BMA.EHR.Leave.Service.Controllers //var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); - var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); + var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); if (leaveData != null) { sumLeave += leaveData.BeginningLeaveDays; From d3a174faa065c7b1de5b2b1f519c415c04939923 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 4 Jun 2026 10:10:31 +0700 Subject: [PATCH 12/42] log placementReceive --- .../Controllers/PlacementReceiveController.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs index 0447ff4c..7ad56249 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs @@ -514,9 +514,8 @@ namespace BMA.EHR.Placement.Service.Controllers { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - + Console.Write($"[PlacementReceiveController] Check-Citizen API-Key : {_configuration["API_KEY"]}"); + client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _res = await client.PostAsJsonAsync(apiUrlCheckCitizen, new { @@ -541,6 +540,7 @@ namespace BMA.EHR.Placement.Service.Controllers using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + Console.Write("[PlacementReceiveController] Check-Position"); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); var _res = await client.SendAsync(_req); @@ -831,7 +831,7 @@ namespace BMA.EHR.Placement.Service.Controllers client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _res = await client.PostAsJsonAsync(apiUrlCheckCitizen, new From 1f7951dc4c8e079626953b4305bad78868bd44d3 Mon Sep 17 00:00:00 2001 From: Adisak Date: Thu, 4 Jun 2026 10:15:33 +0700 Subject: [PATCH 13/42] =?UTF-8?q?update=20=E0=B8=A5=E0=B8=B2=E0=B8=AD?= =?UTF-8?q?=E0=B8=AD=E0=B8=81=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/RetirementResignController.cs | 2 +- .../Controllers/RetirementResignEmployeeController.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index f07cd36d..0ed6cc8a 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -1439,7 +1439,7 @@ namespace BMA.EHR.Retirement.Service.Controllers retirementResign.positionAreaOld = org.result.positionArea; retirementResign.PositionLevelOld = org.result.posLevelName; retirementResign.PositionTypeOld = org.result.posTypeName; - retirementResign.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo; + retirementResign.PositionNumberOld = org.result.posNo; retirementResign.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") + (org.result.child3 == null ? "" : org.result.child3 + "\n") + (org.result.child2 == null ? "" : org.result.child2 + "\n") + diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs index bd61425c..20fa5402 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs @@ -1381,7 +1381,7 @@ namespace BMA.EHR.Retirement.Service.Controllers retirementResignEmployee.PositionOld = org.result.position; retirementResignEmployee.PositionLevelOld = org.result.posLevelName; retirementResignEmployee.PositionTypeOld = org.result.posTypeName; - retirementResignEmployee.PositionNumberOld = org.result.nodeShortName + " " + org.result.posMasterNo; + retirementResignEmployee.PositionNumberOld = org.result.posNo; retirementResignEmployee.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") + (org.result.child3 == null ? "" : org.result.child3 + "\n") + (org.result.child2 == null ? "" : org.result.child2 + "\n") + From d6a7f1a5cab0ceabe39c76fbc73b72052889818f Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 4 Jun 2026 11:34:06 +0700 Subject: [PATCH 14/42] =?UTF-8?q?fix=20=E0=B9=81=E0=B8=81=E0=B9=89?= =?UTF-8?q?=E0=B9=84=E0=B8=82=E0=B8=A7=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B5?= =?UTF-8?q?=E0=B9=88=E0=B8=A2=E0=B8=B7=E0=B9=88=E0=B8=99=E0=B8=82=E0=B8=AD?= =?UTF-8?q?=E0=B8=A5=E0=B8=B2=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B9=81=E0=B8=A5?= =?UTF-8?q?=E0=B9=89=E0=B8=A7=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9?= =?UTF-8?q?=E0=B8=A5=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B9=80=E0=B8=9B=E0=B8=A5?= =?UTF-8?q?=E0=B8=B5=E0=B9=88=E0=B8=A2=E0=B8=99=20#2547?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/RetirementResignController.cs | 9 ++++++++- .../Controllers/RetirementResignEmployeeController.cs | 9 ++++++++- .../Requests/RetirementResignEmployeeRequest.cs | 2 +- .../Requests/RetirementResignRequest.cs | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index 0ed6cc8a..32331859 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -1513,7 +1513,14 @@ namespace BMA.EHR.Retirement.Service.Controllers return Error(GlobalMessages.RetirementResignNotFound, 404); updated.Location = req.Location; - updated.ActiveDate = req.ActiveDate; + if (req.SendDate != null) + { + updated.SendDate = req.SendDate; + } + if (req.ActiveDate != null) + { + updated.ActiveDate = req.ActiveDate; + } // updated.Reason = req.Reason; updated.Remark = req.Remark; updated.ReasonResign = req.Reason; diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs index 20fa5402..62014b1b 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs @@ -1450,7 +1450,14 @@ namespace BMA.EHR.Retirement.Service.Controllers return Error(GlobalMessages.RetirementResignEmployeeNotFound, 404); updated.Location = req.Location; - updated.ActiveDate = req.ActiveDate; + if (req.SendDate != null) + { + updated.SendDate = req.SendDate; + } + if (req.ActiveDate != null) + { + updated.ActiveDate = req.ActiveDate; + } // updated.Reason = req.Reason; updated.Remark = req.Remark; updated.ReasonResign = req.Reason; diff --git a/BMA.EHR.Retirement.Service/Requests/RetirementResignEmployeeRequest.cs b/BMA.EHR.Retirement.Service/Requests/RetirementResignEmployeeRequest.cs index dd883d0d..e1b1a3cf 100644 --- a/BMA.EHR.Retirement.Service/Requests/RetirementResignEmployeeRequest.cs +++ b/BMA.EHR.Retirement.Service/Requests/RetirementResignEmployeeRequest.cs @@ -6,7 +6,7 @@ namespace BMA.EHR.Retirement.Service.Requests public class RetirementResignEmployeeRequest { public string? Location { get; set; } - // public DateTime? SendDate { get; set; } + public DateTime? SendDate { get; set; } public DateTime? ActiveDate { get; set; } public string? Reason { get; set; } public string? Remark { get; set; } diff --git a/BMA.EHR.Retirement.Service/Requests/RetirementResignRequest.cs b/BMA.EHR.Retirement.Service/Requests/RetirementResignRequest.cs index acef05aa..e862e6dd 100644 --- a/BMA.EHR.Retirement.Service/Requests/RetirementResignRequest.cs +++ b/BMA.EHR.Retirement.Service/Requests/RetirementResignRequest.cs @@ -6,7 +6,7 @@ namespace BMA.EHR.Retirement.Service.Requests public class RetirementResignRequest { public string? Location { get; set; } - // public DateTime? SendDate { get; set; } + public DateTime? SendDate { get; set; } public DateTime? ActiveDate { get; set; } public string? Reason { get; set; } public string? Remark { get; set; } From fe5c2cd7c1b9c54971214cf99e47e48a3e5b7749 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 4 Jun 2026 11:52:26 +0700 Subject: [PATCH 15/42] fix #2547 --- .../Controllers/RetirementResignController.cs | 4 ---- .../Controllers/RetirementResignEmployeeController.cs | 4 ---- 2 files changed, 8 deletions(-) diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index 32331859..2dd451ab 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -1517,10 +1517,6 @@ namespace BMA.EHR.Retirement.Service.Controllers { updated.SendDate = req.SendDate; } - if (req.ActiveDate != null) - { - updated.ActiveDate = req.ActiveDate; - } // updated.Reason = req.Reason; updated.Remark = req.Remark; updated.ReasonResign = req.Reason; diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs index 62014b1b..064220d4 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs @@ -1454,10 +1454,6 @@ namespace BMA.EHR.Retirement.Service.Controllers { updated.SendDate = req.SendDate; } - if (req.ActiveDate != null) - { - updated.ActiveDate = req.ActiveDate; - } // updated.Reason = req.Reason; updated.Remark = req.Remark; updated.ReasonResign = req.Reason; From a956f0b0ddbbe4900d86f349652546afada67101 Mon Sep 17 00:00:00 2001 From: Adisak Date: Thu, 4 Jun 2026 16:53:14 +0700 Subject: [PATCH 16/42] update --- .../Controllers/PlacementOfficerController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs index 867935e9..baaafee2 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs @@ -148,6 +148,7 @@ namespace BMA.EHR.Placement.Service.Controllers p.child4OldId, p.child4ShortNameOld, p.PositionOld, + p.PositionNumberOld, p.PositionExecutiveOld, p.positionExecutiveFieldOld, p.positionAreaOld, From 4c44bdf237d9d1a815fcca08658b01210bf70e3b Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 4 Jun 2026 19:05:09 +0700 Subject: [PATCH 17/42] =?UTF-8?q?fix=20=E0=B8=AD=E0=B8=B1=E0=B8=9E?= =?UTF-8?q?=E0=B9=80=E0=B8=94=E0=B8=97=E0=B8=AA=E0=B8=96=E0=B8=B2=E0=B8=99?= =?UTF-8?q?=E0=B8=B0=E0=B8=9A=E0=B8=B8=E0=B8=84=E0=B8=84=E0=B8=A5=E0=B8=A0?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=99=E0=B8=AD=E0=B8=81=20#2518?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/PlacementRepository.cs | 112 ++++++++++++++---- 1 file changed, 88 insertions(+), 24 deletions(-) diff --git a/BMA.EHR.Application/Repositories/PlacementRepository.cs b/BMA.EHR.Application/Repositories/PlacementRepository.cs index 82b71b79..2b40d702 100644 --- a/BMA.EHR.Application/Repositories/PlacementRepository.cs +++ b/BMA.EHR.Application/Repositories/PlacementRepository.cs @@ -8,6 +8,17 @@ using Newtonsoft.Json; namespace BMA.EHR.Application.Repositories { + /// + /// Response model จาก Org API (check-isLeave) + /// + public class OrgProfileResult + { + public string citizenId { get; set; } = ""; + public string? profileId { get; set; } + public bool isLeave { get; set; } + public bool isActive { get; set; } + } + public class PlacementRepository : GenericRepository { #region " Fields " @@ -83,39 +94,43 @@ namespace BMA.EHR.Application.Repositories /// /// Job อัพเดทสถานะผู้สอบผ่านที่ลาออกไปแล้วแต่ยังไม่ส่งไปออกคำสั่ง + /// และอัพเดทบุคคลภายนอกที่เข้ามาอยู่ในระบบแล้ว /// ทำงานทุกวันเวลา 05:00 น. /// public async Task UpdateStatusPlacementProfiles() { Console.WriteLine("[Job:UpdateStatusPlacementProfiles] === STARTED ==="); - var officerProfileIds = await _dbContext.Set() - .Where(p => !string.IsNullOrEmpty(p.profileId) - && p.IsOfficer == true + // 1. Query ทั้ง 2 กรณี: ทุกคนที่ยังไม่ DONE + var allCitizenIds = await _dbContext.Set() + .Where(p => !string.IsNullOrEmpty(p.CitizenId) && p.PlacementStatus != "DONE" - // && p.Id == Guid.Parse("08deb7de-3030-4d1b-8519-8148584949fc") + // && p.CitizenId == "2536721883131" ) - .Select(p => p.profileId) + .Select(p => new { p.CitizenId, p.IsOfficer }) .ToListAsync(); - if (!officerProfileIds.Any()) + if (!allCitizenIds.Any()) { Console.WriteLine("[Job:UpdateStatusPlacementProfiles] No profiles to process"); return; } - Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] พบข้าราชการที่สอบผ่านทั้งหมด {officerProfileIds.Count} คน ที่ยังไม่ส่งไปออกคำสั่ง"); + var officerCount = allCitizenIds.Count(x => x.IsOfficer == true); + var notOfficerCount = allCitizenIds.Count(x => x.IsOfficer == false); + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] พบข้าราชการ {officerCount} คน, บุคคลภายนอก {notOfficerCount} คน"); + // 2. ส่ง citizenIds ทั้งหมดไป Org API ครั้งเดียว + var citizenIds = allCitizenIds.Select(x => x.CitizenId).Distinct().ToList(); var apiUrl = $"{_configuration["API"]}/org/dotnet/check-isLeave"; - List leaveProfileIds = new(); + + List orgResults = new(); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var payload = new - { - profileIds = officerProfileIds.Distinct().ToList() - }; + + var payload = new { citizenIds }; var jsonPayload = JsonConvert.SerializeObject(payload); var content = new StringContent(jsonPayload, System.Text.Encoding.UTF8, "application/json"); @@ -123,15 +138,16 @@ namespace BMA.EHR.Application.Repositories { var response = await client.PostAsync(apiUrl, content); var result = await response.Content.ReadAsStringAsync(); + var responseObj = JsonConvert.DeserializeAnonymousType(result, new { status = 0, message = "", - result = new List() + result = new List() }); - leaveProfileIds = responseObj.result ?? new(); - Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] พบ {leaveProfileIds.Count} รายการที่ลาออก"); + orgResults = responseObj?.result ?? new(); + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] Org API ตอบกลับ {orgResults.Count} รายการ"); } catch (Exception ex) { @@ -140,18 +156,35 @@ namespace BMA.EHR.Application.Repositories } } - if (leaveProfileIds.Any()) + if (!orgResults.Any()) { - var batchSize = 500; - var totalUpdated = 0; - var totalBatches = (int)Math.Ceiling((double)leaveProfileIds.Count / batchSize); + Console.WriteLine("[Job:UpdateStatusPlacementProfiles] ไม่มีรายการต้องอัปเดต"); + Console.WriteLine("[Job:UpdateStatusPlacementProfiles] === COMPLETED ==="); + return; + } + // 3. แยกข้อมูลตามเงื่อนไข + var leaveCitizenIds = orgResults.Where(x => x.isLeave).Select(x => x.citizenId).ToList(); + var inSystemProfiles = orgResults.Where(x => x.isActive && !x.isLeave && !string.IsNullOrEmpty(x.profileId)).ToList(); + + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] ลาออก {leaveCitizenIds.Count} รายการ, อยู่ที่ทะเบียนประวัติ {inSystemProfiles.Count} รายการ"); + + // 4. Split Batch Update (500 รายการ/batch) + var batchSize = 500; + var totalUpdated = 0; + + // 4.1 Update คนลาออก → IsOfficer = false + if (leaveCitizenIds.Any()) + { + var totalBatches = (int)Math.Ceiling((double)leaveCitizenIds.Count / batchSize); for (int i = 0; i < totalBatches; i++) { - var batch = leaveProfileIds.Skip(i * batchSize).Take(batchSize).ToList(); + var batch = leaveCitizenIds.Skip(i * batchSize).Take(batchSize).ToList(); var profilesToUpdate = await _dbContext.Set() - .Where(p => !string.IsNullOrEmpty(p.profileId) && batch.Contains(p.profileId)) + .Where(p => !string.IsNullOrEmpty(p.CitizenId) + && batch.Contains(p.CitizenId) + && p.IsOfficer == true) .ToListAsync(); foreach (var profile in profilesToUpdate) @@ -160,12 +193,43 @@ namespace BMA.EHR.Application.Repositories } await _dbContext.SaveChangesAsync(); - totalUpdated += profilesToUpdate.Count; - Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] Batch {i + 1}/{totalBatches} → อัปเดต {profilesToUpdate.Count} รายการ"); + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] [ลาออก] Batch {i + 1}/{totalBatches} → อัปเดต {profilesToUpdate.Count} รายการ"); } - Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] อัปเดตรวมทั้งหมด {totalUpdated} รายการ → IsOfficer = false"); } + + // 4.2 Update คนที่อยู่ในทะเบียนประวัติ → profileId + IsOfficer = true + if (inSystemProfiles.Any()) + { + var totalBatches = (int)Math.Ceiling((double)inSystemProfiles.Count / batchSize); + for (int i = 0; i < totalBatches; i++) + { + var batch = inSystemProfiles.Skip(i * batchSize).Take(batchSize).ToList(); + var batchCitizenIds = batch.Select(x => x.citizenId).ToList(); + + var profilesToUpdate = await _dbContext.Set() + .Where(p => !string.IsNullOrEmpty(p.CitizenId) + && batchCitizenIds.Contains(p.CitizenId) + && p.IsOfficer == false) + .ToListAsync(); + + foreach (var profile in profilesToUpdate) + { + var orgProfile = batch.FirstOrDefault(x => x.citizenId == profile.CitizenId); + if (orgProfile != null) + { + profile.profileId = orgProfile.profileId; + profile.IsOfficer = true; + } + } + + await _dbContext.SaveChangesAsync(); + totalUpdated += profilesToUpdate.Count; + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] [เข้าระบบ] Batch {i + 1}/{totalBatches} → อัปเดต {profilesToUpdate.Count} รายการ"); + } + } + + Console.WriteLine($"[Job:UpdateStatusPlacementProfiles] อัปเดตรวมทั้งหมด {totalUpdated} รายการ"); Console.WriteLine("[Job:UpdateStatusPlacementProfiles] === COMPLETED ==="); } From e09a6d0ea605339c4777528bb9b682dd84893207 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 5 Jun 2026 05:47:25 +0700 Subject: [PATCH 18/42] =?UTF-8?q?fix=20:=20Add=20LeaveLastTotal=20?= =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B9=83=E0=B8=AB?= =?UTF-8?q?=E0=B9=89=E0=B9=84=E0=B8=9B=E0=B9=83=E0=B8=8A=E0=B9=89=E0=B9=83?= =?UTF-8?q?=E0=B8=99=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99?= =?UTF-8?q?=20=E0=B8=82=E0=B8=AD=E0=B8=87=E0=B9=80=E0=B8=94=E0=B8=B4?= =?UTF-8?q?=E0=B8=A1=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B8=A1=E0=B8=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BMA.EHR.Leave/Controllers/LeaveReportController.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 29676230..1a3793cb 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -217,6 +217,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveNumber = data.LeaveNumber.ToThaiNumber(), LeaveLastStart = lastLeaveRequest == null ? "" : lastLeaveRequest.LeaveStartDate.Date.ToThaiShortDate().ToThaiNumber(), LeaveLastEnd = lastLeaveRequest == null ? "" : lastLeaveRequest.LeaveEndDate.Date.ToThaiShortDate().ToThaiNumber(), + + LeaveLastTotal = lastLeaveRequest == null ? "0".ToThaiNumber() : lastLeaveRequest.LeaveTotal.ToString().ToThaiNumber(), LeaveSummary = sumLeave.ToString().ToThaiNumber(), LeaveRemain = (data.Type.Limit - sumLeave).ToString().ToThaiNumber(), From db3d531aa9422c4032ec0427cfe190884273c11b Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 5 Jun 2026 11:01:06 +0700 Subject: [PATCH 19/42] =?UTF-8?q?fix=20=E0=B8=99=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=A5=E0=B8=87=E0=B9=80=E0=B8=A7?= =?UTF-8?q?=E0=B8=A5=E0=B8=B2=E0=B8=99=E0=B8=AD=E0=B8=81=E0=B8=AA=E0=B8=96?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88=20[=E0=B8=AD?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=99=E0=B9=86]=20#2524?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BMA.EHR.Leave/Controllers/LeaveReportController.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 1a3793cb..1b76947c 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -2648,8 +2648,9 @@ namespace BMA.EHR.Leave.Service.Controllers outOfficeTotal += 1; else if (timeStamps.CheckInLocationName.Contains("ปฏิบัติงานในจุดบริการด่วนมหานคร")) oneStopSrvrTotal += 1; - else if (timeStamps.CheckInLocationName.Contains("อื่นๆ")) - otherTotal += 1; + else otherTotal += 1; + // else if (timeStamps.CheckInLocationName.Contains("อื่นๆ")) + // otherTotal += 1; } } From d75cf39d7bfa5285950d7854a19780ea706ebf95 Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 5 Jun 2026 17:35:59 +0700 Subject: [PATCH 20/42] =?UTF-8?q?update=20Job=20=E0=B8=84=E0=B8=99?= =?UTF-8?q?=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=A5=E0=B8=B2=E0=B8=AD=E0=B8=AD?= =?UTF-8?q?=E0=B8=81=20clear=20profileId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BMA.EHR.Application/Repositories/PlacementRepository.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/BMA.EHR.Application/Repositories/PlacementRepository.cs b/BMA.EHR.Application/Repositories/PlacementRepository.cs index 2b40d702..eb7c3617 100644 --- a/BMA.EHR.Application/Repositories/PlacementRepository.cs +++ b/BMA.EHR.Application/Repositories/PlacementRepository.cs @@ -189,6 +189,7 @@ namespace BMA.EHR.Application.Repositories foreach (var profile in profilesToUpdate) { + profile.profileId = null; profile.IsOfficer = false; } From 7d2be029b6dde4438c6878264c68f0c6e9568547 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 11 Jun 2026 11:42:18 +0700 Subject: [PATCH 21/42] =?UTF-8?q?api=20=E0=B8=84=E0=B8=B3=E0=B8=AA?= =?UTF-8?q?=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=AD=E0=B8=99=E0=B8=B8=E0=B8=8D?= =?UTF-8?q?=E0=B8=B2=E0=B8=95=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B8=A5=E0=B8=B2?= =?UTF-8?q?=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B9=84=E0=B8=9B=E0=B8=A3=E0=B8=B1?= =?UTF-8?q?=E0=B8=9A=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=E0=B8=97=E0=B8=AB=E0=B8=B2=E0=B8=A3=20#248?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 +- .../Controllers/RetirementResignController.cs | 188 ++++++++++++++++++ 2 files changed, 195 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7391825f..f60d8ec1 100644 --- a/.gitignore +++ b/.gitignore @@ -373,4 +373,10 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd + +# VS Code C# Dev Kit cache +*.lscache + +# Claude Code +.claude/ \ No newline at end of file diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index 2dd451ab..03871f9f 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -2975,6 +2975,194 @@ namespace BMA.EHR.Retirement.Service.Controllers return Success(); } + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-48 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command48/report")] + public async Task> PostReport48([FromBody] ReportPersonRequest req) + { + var resigns = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + resigns.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + await _context.SaveChangesAsync(); + return Success(); + } + /// + /// ลบรายชื่อออกคำสั่ง C-PM-48 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command48/report/delete")] + public async Task> PostReportDelete48([FromBody] ReportPersonRequest req) + { + var resigns = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + resigns.ForEach(profile => profile.Status = "APPROVE"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-48 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command48/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportAttachment48([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.RetirementResigns + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + CitizenId = r.CitizenId == null ? "-" : r.CitizenId.ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + PositionName = p.PositionOld ?? "-", + Organization = p.OrganizationPositionOld ?? "-", + PositionLevel = p.PositionLevelOld ?? "-", + PositionType = p.PositionTypeOld ?? "-", + PositionNumber = p.PositionNumberOld == null ? "-" : p.PositionNumberOld.ToThaiNumber(), + ActiveDate = p.ActiveDate == null ? "-" : p.ActiveDate.Value.ToThaiShortDate2().ToThaiNumber(), + Salary = p.AmountOld == null ? "-" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + Remark = p.Reason ?? "-", + RemarkHorizontal = r.RemarkHorizontal == null ? "-" : r.RemarkHorizontal.ToThaiNumber(), + RemarkVertical = r.RemarkVertical == null ? "-" : r.RemarkVertical.ToThaiNumber() + }).ToList(); + + var result = new List(); + + foreach (var r in report_data) + { + result.Add(r); + string? _null = null; + if (r.RemarkHorizontal != null && r.RemarkHorizontal != "") + { + result.Add(new + { + No = _null, + FullName = r.RemarkHorizontal, + CitizenId = _null, + PositionName = _null, + Organization = _null, + PositionLevel = _null, + PositionType = _null, + PositionNumber = _null, + ActiveDate = _null, + Salary = _null, + Remark = _null, + RemarkHorizontal = _null, + RemarkVertical = _null, + }); + } + } + return Success(result); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-48 คำสั่งอนุญาตให้ลาออกไปรับราชการทหาร + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command48/report/excecute")] + public async Task> PostReportExecute48([FromBody] ReportExecuteRequest req) + { + var data = await _context.RetirementResigns + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + amount = r.amount, + amountSpecial = r.amountSpecial, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + positionExecutive = p.PositionExecutiveOld, + positionExecutiveField = p.positionExecutiveFieldOld, + positionArea = p.positionAreaOld, + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + isLeave = p.IsCancel == true ? false : true, + leaveReason = p.ReasonResign == "อื่น ๆ" + ? string.IsNullOrWhiteSpace(p.Remark) ? p.ReasonResign : $"{p.ReasonResign}({p.Remark})" + : p.ReasonResign, + dateLeave = r.commandDateAffect, + commandId = r.commandId, + isGovernment = false, + orgRoot = p.rootOld, + orgChild1 = p.child1Old, + orgChild2 = p.child2Old, + orgChild3 = p.child3Old, + orgChild4 = p.child4Old, + commandNo = r.commandNo, + commandYear = r.commandYear, + posNo = p.posMasterNoOld?.ToString(), + posNoAbb = p.child4ShortNameOld != null ? $"{p.child4ShortNameOld}" : + p.child3ShortNameOld != null ? $"{p.child3ShortNameOld}" : + p.child2ShortNameOld != null ? $"{p.child2ShortNameOld}" : + p.child1ShortNameOld != null ? $"{p.child1ShortNameOld}" : + p.rootShortNameOld != null ? $"{p.rootShortNameOld}" : "", + commandDateAffect = r.commandDateAffect, + commandDateSign = r.commandDateSign, + positionName = p.PositionOld, + commandCode = r.commandCode, + commandName = r.commandName, + remark = r.remark, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + } + return Success(); + } + /// /// ส่งรายชื่อออกคำสั่ง C-PM-41 /// From 4a8d349415a0d0c20bdddeae290b519d4cd32ca2 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 18 Jun 2026 11:47:11 +0700 Subject: [PATCH 22/42] =?UTF-8?q?Linear=20Flow=20(=E0=B8=97=E0=B8=94?= =?UTF-8?q?=E0=B8=AA=E0=B8=AD=E0=B8=9A=E0=B9=80=E0=B8=89=E0=B8=9E=E0=B8=B2?= =?UTF-8?q?=E0=B8=B0=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87?= =?UTF-8?q?=20C-PM-01)=20#224?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PlacementController.cs | 95 +++++++++++-------- 1 file changed, 56 insertions(+), 39 deletions(-) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index b01cf975..d45803ec 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -1989,49 +1989,66 @@ namespace BMA.EHR.Placement.Service.Controllers }).ToList(); Console.WriteLine($"[RecruitReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records"); - - Console.WriteLine($"[RecruitReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile"); - var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // Console.WriteLine($"[RecruitReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile"); + // var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; + // 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.Post, apiUrl); + // var _res = await client.PostAsJsonAsync(apiUrl, new + // { + // data = resultData + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // Console.WriteLine($"[RecruitReportExcecute] External API response status: {_res.StatusCode}"); + // if (_res.IsSuccessStatusCode) + // { + // Console.WriteLine("[RecruitReportExcecute] External API call successful - updating placement profiles"); + // placementProfile.ForEach(profile => + // { + // profile.PlacementStatus = "DONE"; + // if (req.refIds.Length > 0) + // { + // profile.commandId = req.refIds[0].commandId; + // profile.refCommandCode = req.refIds[0].commandCode; + // profile.refCommandDate = req.refIds[0].commandDateAffect; + // profile.refCommandName = req.refIds[0].commandName; + // profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}"; + // profile.templateDoc = req.refIds[0].remark; + // } + // }); + // Console.WriteLine($"[RecruitReportExcecute] Saving changes to database for {placementProfile.Count} profiles"); + // await _context.SaveChangesAsync(); + // Console.WriteLine("[RecruitReportExcecute] Database save completed successfully"); + // } + // else + // { + // Console.Error.WriteLine($"[RecruitReportExcecute] External API call failed with status: {_res.StatusCode}"); + // Console.Error.WriteLine($"[RecruitReportExcecute] Response content: {_result}"); + // } + // } + #endregion + + // New: Linear Flow + placementProfile.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); - var _res = await client.PostAsJsonAsync(apiUrl, new + profile.PlacementStatus = "DONE"; + if (req.refIds.Length > 0) { - data = resultData - }); - var _result = await _res.Content.ReadAsStringAsync(); - Console.WriteLine($"[RecruitReportExcecute] External API response status: {_res.StatusCode}"); - if (_res.IsSuccessStatusCode) - { - Console.WriteLine("[RecruitReportExcecute] External API call successful - updating placement profiles"); - placementProfile.ForEach(profile => - { - profile.PlacementStatus = "DONE"; - if (req.refIds.Length > 0) - { - profile.commandId = req.refIds[0].commandId; - profile.refCommandCode = req.refIds[0].commandCode; - profile.refCommandDate = req.refIds[0].commandDateAffect; - profile.refCommandName = req.refIds[0].commandName; - profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}"; - profile.templateDoc = req.refIds[0].remark; - } - }); - Console.WriteLine($"[RecruitReportExcecute] Saving changes to database for {placementProfile.Count} profiles"); - await _context.SaveChangesAsync(); - Console.WriteLine("[RecruitReportExcecute] Database save completed successfully"); + profile.commandId = req.refIds[0].commandId; + profile.refCommandCode = req.refIds[0].commandCode; + profile.refCommandDate = req.refIds[0].commandDateAffect; + profile.refCommandName = req.refIds[0].commandName; + profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}"; + profile.templateDoc = req.refIds[0].remark; } - else - { - Console.Error.WriteLine($"[RecruitReportExcecute] External API call failed with status: {_res.StatusCode}"); - Console.Error.WriteLine($"[RecruitReportExcecute] Response content: {_result}"); - } - } - + }); + Console.WriteLine($"[RecruitReportExcecute] Saving changes to database for {placementProfile.Count} profiles"); + await _context.SaveChangesAsync(); Console.WriteLine($"[RecruitReportExcecute] Process completed successfully at {DateTime.Now}"); - return Success(); + return Success(resultData); } catch (Exception ex) { From 35179d8cfc71706b7de0a884541c8fbb09d1e748 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 18 Jun 2026 15:46:22 +0700 Subject: [PATCH 23/42] Linear Flow (C-PM-01, C-PM-02, C-PM-14) #224 --- .../Controllers/PlacementController.cs | 102 ++++--- .../Controllers/PlacementReceiveController.cs | 254 ++++++++++-------- 2 files changed, 194 insertions(+), 162 deletions(-) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index d45803ec..135d94ba 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -2395,51 +2395,67 @@ namespace BMA.EHR.Placement.Service.Controllers Console.WriteLine($"[CandidateReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records"); - Console.WriteLine($"[CandidateReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile"); - var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; - 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.Post, apiUrl); - var _res = await client.PostAsJsonAsync(apiUrl, new - { - data = resultData - }); - var _result = await _res.Content.ReadAsStringAsync(); - Console.WriteLine($"[CandidateReportExcecute] External API response status: {_res.StatusCode}"); - if (_res.IsSuccessStatusCode) - { - Console.WriteLine("[CandidateReportExcecute] External API call successful - updating placement profiles"); - placementProfile.ForEach(profile => - { - profile.PlacementStatus = "DONE"; - if (req.refIds.Length > 0) - { - profile.commandId = req.refIds[0].commandId; - profile.refCommandCode = req.refIds[0].commandCode; - profile.refCommandDate = req.refIds[0].commandDateAffect; - profile.refCommandName = req.refIds[0].commandName; - profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}"; - profile.templateDoc = req.refIds[0].remark; - } - }); - Console.WriteLine($"[CandidateReportExcecute] Saving changes to database for {placementProfile.Count} profiles"); - await _context.SaveChangesAsync(); - Console.WriteLine("[CandidateReportExcecute] Database save completed successfully"); - } - else - { - Console.Error.WriteLine($"[CandidateReportExcecute] External API call failed with status: {_res.StatusCode}"); - Console.Error.WriteLine($"[CandidateReportExcecute] Response content: {_result}"); - } - } + #region Old: Circular Flow + // Console.WriteLine($"[CandidateReportExcecute] Calling external API: {_configuration["API"]}/org/command/excexute/create-officer-profile"); + // var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; + // 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.Post, apiUrl); + // var _res = await client.PostAsJsonAsync(apiUrl, new + // { + // data = resultData + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // Console.WriteLine($"[CandidateReportExcecute] External API response status: {_res.StatusCode}"); + // if (_res.IsSuccessStatusCode) + // { + // Console.WriteLine("[CandidateReportExcecute] External API call successful - updating placement profiles"); + // placementProfile.ForEach(profile => + // { + // profile.PlacementStatus = "DONE"; + // if (req.refIds.Length > 0) + // { + // profile.commandId = req.refIds[0].commandId; + // profile.refCommandCode = req.refIds[0].commandCode; + // profile.refCommandDate = req.refIds[0].commandDateAffect; + // profile.refCommandName = req.refIds[0].commandName; + // profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}"; + // profile.templateDoc = req.refIds[0].remark; + // } + // }); + // Console.WriteLine($"[CandidateReportExcecute] Saving changes to database for {placementProfile.Count} profiles"); + // await _context.SaveChangesAsync(); + // Console.WriteLine("[CandidateReportExcecute] Database save completed successfully"); + // } + // else + // { + // Console.Error.WriteLine($"[CandidateReportExcecute] External API call failed with status: {_res.StatusCode}"); + // Console.Error.WriteLine($"[CandidateReportExcecute] Response content: {_result}"); + // } + // } + #endregion - // // update placementstatus - // placementProfile.ForEach(profile => profile.PlacementStatus = "DONE"); - // await _context.SaveChangesAsync(); + // New: Linear Flow + placementProfile.ForEach(profile => + { + profile.PlacementStatus = "DONE"; + if (req.refIds.Length > 0) + { + profile.commandId = req.refIds[0].commandId; + profile.refCommandCode = req.refIds[0].commandCode; + profile.refCommandDate = req.refIds[0].commandDateAffect; + profile.refCommandName = req.refIds[0].commandName; + profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}"; + profile.templateDoc = req.refIds[0].remark; + } + }); + Console.WriteLine($"[CandidateReportExcecute] Saving changes to database for {placementProfile.Count} profiles"); + await _context.SaveChangesAsync(); Console.WriteLine($"[CandidateReportExcecute] Process completed successfully at {DateTime.Now}"); - return Success(); + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } catch (Exception ex) { diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs index 7ad56249..32f91eae 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs @@ -1181,127 +1181,143 @@ namespace BMA.EHR.Placement.Service.Controllers [HttpPost("command/report/excecute")] public async Task> PostReportExecute([FromBody] ReportExecuteRequest req) { - var data = await _context.PlacementReceives - .Include(x => x.Avatar) - .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) - .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - - var resultData = (from p in data - join r in req.refIds - on p.Id.ToString() equals r.refId - select new - { - bodyProfile = new - { - rank = string.IsNullOrEmpty(p.rank) ? string.Empty : p.rank, - prefix = p.prefix == null ? string.Empty : p.prefix, - firstName = p.firstName == null ? string.Empty : p.firstName, - lastName = p.lastName == null ? string.Empty : p.lastName, - citizenId = p.citizenId == null ? string.Empty : p.citizenId, - position = p.position == null ? string.Empty : p.position, - posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId, - posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId, - email = (String?)null, - phone = p.TelephoneNumber == null ? string.Empty : p.TelephoneNumber, - keycloak = string.Empty, - isProbation = false, - isLeave = false, - dateRetire = (DateTime?)null, - dateAppoint = r.commandDateAffect, - dateStart = r.commandDateAffect, - govAgeAbsent = 0, - govAgePlus = 0, - birthDate = (p.DateOfBirth == null || p.DateOfBirth == DateTime.MinValue) ? (DateTime?)null : p.DateOfBirth, - reasonSameDate = (DateTime?)null, - ethnicity = p.Race == null ? string.Empty : p.Race, - telephoneNumber = (String?)null, - nationality = p.Nationality == null ? string.Empty : p.Nationality, - gender = p.Gender == null ? string.Empty : p.Gender, - relationship = p.Relationship == null ? string.Empty : p.Relationship, - religion = p.Religion == null ? string.Empty : p.Religion, - bloodGroup = p.BloodGroup == null ? string.Empty : p.BloodGroup, - registrationAddress = (String?)null, - registrationProvinceId = (String?)null, - registrationDistrictId = (String?)null, - registrationSubDistrictId = (String?)null, - registrationZipCode = (String?)null, - currentAddress = (String?)null, - currentProvinceId = (String?)null, - currentDistrictId = (String?)null, - currentSubDistrictId = (String?)null, - currentZipCode = (String?)null, - amount = r.amount, - amountSpecial = r.amountSpecial, - objectRefId = p.Avatar != null && p.Avatar?.ObjectRefId != null ? p.Avatar?.ObjectRefId.ToString("D") : null, - }, - bodySalarys = new - { - profileId = p.profileId, - amount = r.amount, - amountSpecial = r.amountSpecial, - positionSalaryAmount = r.positionSalaryAmount, - mouthSalaryAmount = r.mouthSalaryAmount, - positionExecutive = p.PositionExecutive, - positionExecutiveField = p.positionExecutiveField, - positionArea = p.positionArea, - positionType = p.posTypeName, - positionLevel = p.posLevelName, - commandId = r.commandId, - orgRoot = p.root, - orgChild1 = p.child1, - orgChild2 = p.child2, - orgChild3 = p.child3, - orgChild4 = p.child4, - commandNo = r.commandNo, - commandYear = r.commandYear, - posNo = p.posMasterNo?.ToString(), - posNoAbb = p.node == 4 ? $"{p.child4ShortName}" : - p.node == 3 ? $"{p.child3ShortName}" : - p.node == 2 ? $"{p.child2ShortName}" : - p.node == 1 ? $"{p.child1ShortName}" : - p.node == 0 ? $"{p.rootShortName}" : "", - commandDateAffect = r.commandDateAffect, - commandDateSign = r.commandDateSign, - positionName = p.position, - commandCode = r.commandCode, - commandName = r.commandName, - remark = r.remark, - }, - bodyPosition = new - { - posmasterId = p.posmasterId, - positionId = p.positionId, - positionName = p.position, - positionField = p.positionField, - posTypeId = p.posTypeId, - posLevelId = p.posLevelId, - posExecutiveId = p.posExecutiveId, - positionExecutiveField = p.positionExecutiveField, - positionArea = p.positionArea, - } - }).ToList(); - - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; - using (var client = new HttpClient()) + Console.WriteLine($"[ReceiveReportExcecute] Starting execution at {DateTime.Now}"); + try { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - // // var _result = await _res.Content.ReadAsStringAsync(); - // // if (_res.IsSuccessStatusCode) - // // { - // // data.ForEach(profile => profile.Status = "DONE"); - // // await _context.SaveChangesAsync(); - // // } + var data = await _context.PlacementReceives + .Include(x => x.Avatar) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + bodyProfile = new + { + rank = string.IsNullOrEmpty(p.rank) ? string.Empty : p.rank, + prefix = p.prefix == null ? string.Empty : p.prefix, + firstName = p.firstName == null ? string.Empty : p.firstName, + lastName = p.lastName == null ? string.Empty : p.lastName, + citizenId = p.citizenId == null ? string.Empty : p.citizenId, + position = p.position == null ? string.Empty : p.position, + posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId, + posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId, + email = (String?)null, + phone = p.TelephoneNumber == null ? string.Empty : p.TelephoneNumber, + keycloak = string.Empty, + isProbation = false, + isLeave = false, + dateRetire = (DateTime?)null, + dateAppoint = r.commandDateAffect, + dateStart = r.commandDateAffect, + govAgeAbsent = 0, + govAgePlus = 0, + birthDate = (p.DateOfBirth == null || p.DateOfBirth == DateTime.MinValue) ? (DateTime?)null : p.DateOfBirth, + reasonSameDate = (DateTime?)null, + ethnicity = p.Race == null ? string.Empty : p.Race, + telephoneNumber = (String?)null, + nationality = p.Nationality == null ? string.Empty : p.Nationality, + gender = p.Gender == null ? string.Empty : p.Gender, + relationship = p.Relationship == null ? string.Empty : p.Relationship, + religion = p.Religion == null ? string.Empty : p.Religion, + bloodGroup = p.BloodGroup == null ? string.Empty : p.BloodGroup, + registrationAddress = (String?)null, + registrationProvinceId = (String?)null, + registrationDistrictId = (String?)null, + registrationSubDistrictId = (String?)null, + registrationZipCode = (String?)null, + currentAddress = (String?)null, + currentProvinceId = (String?)null, + currentDistrictId = (String?)null, + currentSubDistrictId = (String?)null, + currentZipCode = (String?)null, + amount = r.amount, + amountSpecial = r.amountSpecial, + objectRefId = p.Avatar != null && p.Avatar?.ObjectRefId != null ? p.Avatar?.ObjectRefId.ToString("D") : null, + }, + bodySalarys = new + { + profileId = p.profileId, + amount = r.amount, + amountSpecial = r.amountSpecial, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + positionExecutive = p.PositionExecutive, + positionExecutiveField = p.positionExecutiveField, + positionArea = p.positionArea, + positionType = p.posTypeName, + positionLevel = p.posLevelName, + commandId = r.commandId, + orgRoot = p.root, + orgChild1 = p.child1, + orgChild2 = p.child2, + orgChild3 = p.child3, + orgChild4 = p.child4, + commandNo = r.commandNo, + commandYear = r.commandYear, + posNo = p.posMasterNo?.ToString(), + posNoAbb = p.node == 4 ? $"{p.child4ShortName}" : + p.node == 3 ? $"{p.child3ShortName}" : + p.node == 2 ? $"{p.child2ShortName}" : + p.node == 1 ? $"{p.child1ShortName}" : + p.node == 0 ? $"{p.rootShortName}" : "", + commandDateAffect = r.commandDateAffect, + commandDateSign = r.commandDateSign, + positionName = p.position, + commandCode = r.commandCode, + commandName = r.commandName, + remark = r.remark, + }, + bodyPosition = new + { + posmasterId = p.posmasterId, + positionId = p.positionId, + positionName = p.position, + positionField = p.positionField, + posTypeId = p.posTypeId, + posLevelId = p.posLevelId, + posExecutiveId = p.posExecutiveId, + positionExecutiveField = p.positionExecutiveField, + positionArea = p.positionArea, + } + }).ToList(); + + Console.WriteLine($"[ReceiveReportExcecute] resultData built successfully with {resultData?.Count ?? 0} records"); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // // // var _result = await _res.Content.ReadAsStringAsync(); + // // // if (_res.IsSuccessStatusCode) + // // // { + // // // data.ForEach(profile => profile.Status = "DONE"); + // // // await _context.SaveChangesAsync(); + // // // } + // } + #endregion + + // New: Linear Flow + data.ForEach(profile => profile.Status = "DONE"); + Console.WriteLine($"[ReceiveReportExcecute] Saving changes to database for {data.Count} profiles"); + await _context.SaveChangesAsync(); + Console.WriteLine($"[ReceiveReportExcecute] Process completed successfully at {DateTime.Now}"); + return Success(resultData); + } + catch (Exception ex) + { + Console.Error.WriteLine($"[ReceiveReportExcecute] Error occurred: {ex.Message}"); + Console.Error.WriteLine($"[ReceiveReportExcecute] Stack trace: {ex.StackTrace}"); + throw; } - return Success(); } } } From e926866918be0f75d5aa96c84610ec0178f54a60 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 18 Jun 2026 18:32:06 +0700 Subject: [PATCH 24/42] Linear Flow (PlacementService) #224 --- .../PlacementAppointmentController.cs | 264 +++++++++++------- .../Controllers/PlacementController.cs | 141 +++++----- .../Controllers/PlacementOfficerController.cs | 66 +++-- .../PlacementRepatriationController.cs | 46 +-- .../PlacementTransferController.cs | 46 +-- 5 files changed, 319 insertions(+), 244 deletions(-) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs index a8c2bd4c..50114759 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs @@ -1041,24 +1041,32 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => profile.Status = "DONE"); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1257,24 +1265,32 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => profile.Status = "DONE"); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1457,24 +1473,32 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-current"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-current"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => profile.Status = "DONE"); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1662,24 +1686,32 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-current"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-current"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => profile.Status = "DONE"); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1890,24 +1922,32 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => profile.Status = "DONE"); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -2053,24 +2093,32 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => profile.Status = "DONE"); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } } } diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index 135d94ba..9557ae00 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -2645,9 +2645,6 @@ namespace BMA.EHR.Placement.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.PlacementStatus = "DONE"); - await _context.SaveChangesAsync(); var resultData = (from p in data join r in req.refIds @@ -2692,24 +2689,32 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => profile.PlacementStatus = "DONE"); - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // //// var _result = await _res.Content.ReadAsStringAsync(); + // //// if (_res.IsSuccessStatusCode) + // //// { + // //// data.ForEach(profile => profile.PlacementStatus = "DONE"); + // //// await _context.SaveChangesAsync(); + // //// } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.PlacementStatus = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -2890,9 +2895,6 @@ namespace BMA.EHR.Placement.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.PlacementStatus = "DONE"); - await _context.SaveChangesAsync(); var resultData = (from p in data join r in req.refIds @@ -2937,24 +2939,32 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => profile.PlacementStatus = "DONE"); - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // //// var _result = await _res.Content.ReadAsStringAsync(); + // //// if (_res.IsSuccessStatusCode) + // //// { + // //// data.ForEach(profile => profile.PlacementStatus = "DONE"); + // //// await _context.SaveChangesAsync(); + // //// } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.PlacementStatus = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -3120,9 +3130,6 @@ namespace BMA.EHR.Placement.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.PlacementStatus = "DONE"); - await _context.SaveChangesAsync(); var resultData = (from p in data join r in req.refIds @@ -3165,24 +3172,32 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => profile.PlacementStatus = "DONE"); - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // //// var _result = await _res.Content.ReadAsStringAsync(); + // //// if (_res.IsSuccessStatusCode) + // //// { + // //// data.ForEach(profile => profile.PlacementStatus = "DONE"); + // //// await _context.SaveChangesAsync(); + // //// } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.PlacementStatus = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs index baaafee2..8fcb51cf 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs @@ -760,16 +760,6 @@ namespace BMA.EHR.Placement.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - var firstRef = req.refIds.FirstOrDefault(); - var commandNoText = firstRef != null ? $"{firstRef.commandNo}/{firstRef.commandYear.ToThaiYear()}" : null; - foreach (var profile in data) - { - profile.Status = "DONE"; - profile.commandNo = commandNoText; - } - await _context.SaveChangesAsync(); - var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId @@ -811,28 +801,42 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // //// var _result = await _res.Content.ReadAsStringAsync(); + // //// if (_res.IsSuccessStatusCode) + // //// { + // //// foreach (var profile in data) + // //// { + // //// profile.Status = "DONE"; + // //// profile.commandNo = resultData.Count > 0 ? $"{resultData[0].commandNo}/{resultData[0].commandYear.ToThaiYear()}" : null; + // //// } + // //// await _context.SaveChangesAsync(); + // //// } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var firstRef = req.refIds.FirstOrDefault(); + var commandNoText = firstRef != null ? $"{firstRef.commandNo}/{firstRef.commandYear.ToThaiYear()}" : null; + data.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// foreach (var profile in data) - //// { - //// profile.Status = "DONE"; - //// profile.commandNo = resultData.Count > 0 ? $"{resultData[0].commandNo}/{resultData[0].commandYear.ToThaiYear()}" : null; - //// } - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + profile.Status = "DONE"; + profile.commandNo = commandNoText; + }); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } } } diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs index e9c45532..b56fc804 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs @@ -623,9 +623,6 @@ namespace BMA.EHR.Placement.Service.Controllers var data = await _context.PlacementRepatriations .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); string? _null = null; var resultData = (from p in data @@ -668,25 +665,32 @@ namespace BMA.EHR.Placement.Service.Controllers commandName = r.commandName, remark = r.remark, }).ToList(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // // // var _result = await _res.Content.ReadAsStringAsync(); + // // // if (_res.IsSuccessStatusCode) + // // // { + // // // data.ForEach(profile => profile.Status = "DONE"); + // // // await _context.SaveChangesAsync(); + // // // } + // } + #endregion - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - // // var _result = await _res.Content.ReadAsStringAsync(); - // // if (_res.IsSuccessStatusCode) - // // { - // // data.ForEach(profile => profile.Status = "DONE"); - // // await _context.SaveChangesAsync(); - // // } - } - return Success(); + // New: Linear Flow - Task #224ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } } } diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs index a8786b51..73741918 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs @@ -1148,9 +1148,6 @@ namespace BMA.EHR.Placement.Service.Controllers var data = await _context.PlacementTransfers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); var resultData = (from p in data join r in req.refIds @@ -1194,24 +1191,31 @@ namespace BMA.EHR.Placement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - // // var _result = await _res.Content.ReadAsStringAsync(); - // // if (_res.IsSuccessStatusCode) - // // { - // // data.ForEach(profile => profile.Status = "DONE"); - // // await _context.SaveChangesAsync(); - // // } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // // // var _result = await _res.Content.ReadAsStringAsync(); + // // // if (_res.IsSuccessStatusCode) + // // // { + // // // data.ForEach(profile => profile.Status = "DONE"); + // // // await _context.SaveChangesAsync(); + // // // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } From 71966eb4e99548054b529313cecc7ea350a552c0 Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 19 Jun 2026 09:22:33 +0700 Subject: [PATCH 25/42] Linear Flow (RetirementService) #224 --- .../Controllers/RetirementOtherController.cs | 94 ++++++------ .../Controllers/RetirementOutController.cs | 62 ++++---- .../Controllers/RetirementResignController.cs | 136 ++++++++++-------- .../RetirementResignEmployeeController.cs | 100 +++++++------ 4 files changed, 213 insertions(+), 179 deletions(-) diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs index 697af6eb..4880f3b6 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs @@ -846,9 +846,6 @@ namespace BMA.EHR.Retirement.Service.Controllers var data = await _context.RetirementOthers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); string? _null = null; var resultData = (from p in data @@ -912,24 +909,32 @@ namespace BMA.EHR.Retirement.Service.Controllers orgChild4New = p.child4 }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - // // var _result = await _res.Content.ReadAsStringAsync(); - // // if (_res.IsSuccessStatusCode) - // // { - // // data.ForEach(profile => profile.Status = "DONE"); - // // await _context.SaveChangesAsync(); - // // } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // // // var _result = await _res.Content.ReadAsStringAsync(); + // // // if (_res.IsSuccessStatusCode) + // // // { + // // // data.ForEach(profile => profile.Status = "DONE"); + // // // await _context.SaveChangesAsync(); + // // // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1098,9 +1103,6 @@ namespace BMA.EHR.Retirement.Service.Controllers var data = await _context.RetirementOthers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); string? _null = null; var resultData = (from p in data @@ -1164,24 +1166,32 @@ namespace BMA.EHR.Retirement.Service.Controllers orgChild4New = p.child4 }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - // // var _result = await _res.Content.ReadAsStringAsync(); - // // if (_res.IsSuccessStatusCode) - // // { - // // data.ForEach(profile => profile.Status = "DONE"); - // // await _context.SaveChangesAsync(); - // // } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // // // var _result = await _res.Content.ReadAsStringAsync(); + // // // if (_res.IsSuccessStatusCode) + // // // { + // // // data.ForEach(profile => profile.Status = "DONE"); + // // // await _context.SaveChangesAsync(); + // // // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } } } diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs index a8c9d8e2..ae528316 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs @@ -642,10 +642,6 @@ namespace BMA.EHR.Retirement.Service.Controllers var data = await _context.RetirementOuts .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId @@ -688,31 +684,39 @@ namespace BMA.EHR.Retirement.Service.Controllers resignId = p.Id, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; - if (data.Count > 0) - { - if (data[0].profileType == "EMPLOYEE") - { - apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave"; - } - } - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - // // var _result = await _res.Content.ReadAsStringAsync(); - // // if (_res.IsSuccessStatusCode) - // // { - // // data.ForEach(profile => profile.Status = "DONE"); - // // await _context.SaveChangesAsync(); - // // } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + // if (data.Count > 0) + // { + // if (data[0].profileType == "EMPLOYEE") + // { + // apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave"; + // } + // } + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // // // var _result = await _res.Content.ReadAsStringAsync(); + // // // if (_res.IsSuccessStatusCode) + // // // { + // // // data.ForEach(profile => profile.Status = "DONE"); + // // // await _context.SaveChangesAsync(); + // // // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } } } diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index 03871f9f..1b434380 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -2907,10 +2907,6 @@ namespace BMA.EHR.Retirement.Service.Controllers var data = await _context.RetirementResigns .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId @@ -2955,24 +2951,32 @@ namespace BMA.EHR.Retirement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - // // var _result = await _res.Content.ReadAsStringAsync(); - // // if (_res.IsSuccessStatusCode) - // // { - // // data.ForEach(profile => profile.Status = "DONE"); - // // await _context.SaveChangesAsync(); - // // } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // // // var _result = await _res.Content.ReadAsStringAsync(); + // // // if (_res.IsSuccessStatusCode) + // // // { + // // // data.ForEach(profile => profile.Status = "DONE"); + // // // await _context.SaveChangesAsync(); + // // // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -3102,10 +3106,6 @@ namespace BMA.EHR.Retirement.Service.Controllers var data = await _context.RetirementResigns .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId @@ -3149,18 +3149,26 @@ namespace BMA.EHR.Retirement.Service.Controllers remark = r.remark, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -3298,11 +3306,6 @@ namespace BMA.EHR.Retirement.Service.Controllers .Include(x => x.RetirementResign) .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - data.ForEach(profile => profile.RetirementResign.Status = "CANCEL"); - await _context.SaveChangesAsync(); - string? _null = null; var resultData = (from p in data join r in req.refIds @@ -3346,7 +3349,8 @@ namespace BMA.EHR.Retirement.Service.Controllers resignId = p.RetirementResign.Id, }).ToList(); - var baseAPIOrg = _configuration["API"]; + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; //var reportDone = false; //if (data.Where(profile => profile.Status == "DONE").Any()) //{ @@ -3354,23 +3358,23 @@ namespace BMA.EHR.Retirement.Service.Controllers //} //if (reportDone == true) //{ - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - // // var _result = await _res.Content.ReadAsStringAsync(); - // // if (_res.IsSuccessStatusCode) - // // { - // // data.ForEach(profile => profile.Status = "DONE"); - // // data.ForEach(profile => profile.RetirementResign.Status = "CANCEL"); - // // await _context.SaveChangesAsync(); - // // } - } + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // // // var _result = await _res.Content.ReadAsStringAsync(); + // // // if (_res.IsSuccessStatusCode) + // // // { + // // // data.ForEach(profile => profile.Status = "DONE"); + // // // data.ForEach(profile => profile.RetirementResign.Status = "CANCEL"); + // // // await _context.SaveChangesAsync(); + // // // } + // } //} //else //{ @@ -3392,7 +3396,15 @@ namespace BMA.EHR.Retirement.Service.Controllers // } // } //} - return Success(); + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => profile.RetirementResign.Status = "CANCEL"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } #region 33-แบบฟอร์มหนังสือขอลาออกจากราชการ diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs index 064220d4..4449099b 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs @@ -2405,10 +2405,6 @@ namespace BMA.EHR.Retirement.Service.Controllers var data = await _context.RetirementResignEmployees .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId @@ -2451,24 +2447,32 @@ namespace BMA.EHR.Retirement.Service.Controllers resignId = p.Id, }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - // // var _result = await _res.Content.ReadAsStringAsync(); - // // if (_res.IsSuccessStatusCode) - // // { - // // data.ForEach(profile => profile.Status = "DONE"); - // // await _context.SaveChangesAsync(); - // // } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // // // var _result = await _res.Content.ReadAsStringAsync(); + // // // if (_res.IsSuccessStatusCode) + // // // { + // // // data.ForEach(profile => profile.Status = "DONE"); + // // // await _context.SaveChangesAsync(); + // // // } + // } + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -2604,11 +2608,6 @@ namespace BMA.EHR.Retirement.Service.Controllers .Include(x => x.RetirementResignEmployee) .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL"); - await _context.SaveChangesAsync(); - string? _null = null; var resultData = (from p in data join r in req.refIds @@ -2650,7 +2649,8 @@ namespace BMA.EHR.Retirement.Service.Controllers resignId = p.RetirementResignEmployee.Id }).ToList(); - var baseAPIOrg = _configuration["API"]; + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; //var reportDone = false; //if (data.Where(profile => profile.Status == "DONE").Any()) //{ @@ -2659,23 +2659,23 @@ namespace BMA.EHR.Retirement.Service.Controllers //if (reportDone == true) //{ - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - // // var _result = await _res.Content.ReadAsStringAsync(); - // // if (_res.IsSuccessStatusCode) - // // { - // // data.ForEach(profile => profile.Status = "DONE"); - // // data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL"); - // // await _context.SaveChangesAsync(); - // // } - } + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // // // var _result = await _res.Content.ReadAsStringAsync(); + // // // if (_res.IsSuccessStatusCode) + // // // { + // // // data.ForEach(profile => profile.Status = "DONE"); + // // // data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL"); + // // // await _context.SaveChangesAsync(); + // // // } + // } //} //else //{ @@ -2697,7 +2697,15 @@ namespace BMA.EHR.Retirement.Service.Controllers // } // } //} - return Success(); + #endregion + + // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL"); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// From 2cdae3578e5a4c64b9e7f16e2b07026fa1172bd6 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 19 Jun 2026 10:51:18 +0700 Subject: [PATCH 26/42] issue #2551 --- .../LeaveRequests/LeaveBeginingRepository.cs | 126 +- ...eginning ProfileId Year TypeId.Designer.cs | 1816 +++++++++++++++++ ...ex LeaveBeginning ProfileId Year TypeId.cs | 28 + .../LeaveDb/LeaveDbContextModelSnapshot.cs | 4 + .../Persistence/LeaveDbContext.cs | 13 + .../Controllers/LeaveRequestController.cs | 24 + BMA.EHR.Leave/Program.cs | 25 +- 7 files changed, 1996 insertions(+), 40 deletions(-) create mode 100644 BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.Designer.cs create mode 100644 BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.cs diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs index 35b18090..7cf4dee7 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs @@ -9,6 +9,7 @@ using BMA.EHR.Domain.Shared; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using System.Collections.Concurrent; namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests { @@ -23,6 +24,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests private readonly IConfiguration _configuration; private readonly EmailSenderService _emailSenderService; + /// + /// Keyed locks to serialize get-or-create for LeaveBeginning rows by (ProfileId, LeaveYear, LeaveTypeId). + /// Prevents duplicate inserts when concurrent requests (e.g. UI calling /user/check twice) hit the same key. + /// + private static readonly ConcurrentDictionary _getOrAddLocks = new(); + #endregion #region " Constructor and Destuctor " @@ -121,6 +128,27 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests await _dbContext.SaveChangesAsync(); } + public async Task ProcessEarlyLeaveRequest(int year) + { + // Get Early Leave Request + var leaveReq = await _dbContext.Set() + .Include(x => x.Type) + .Where(x => x.LeaveStatus == "APPROVE") + .Where(x => x.LeaveStartDate.Year == year || x.LeaveEndDate.Year == year) + .ToListAsync(); + + foreach (var leave in leaveReq) + { + await GetByYearAndTypeIdForUserAsync(year, leave.Type.Id, leave.KeycloakUserId); + } + } + + public async Task ProcessEarlyLeaveRequestSchedule() + { + int year = DateTime.Now.Year; + await ProcessEarlyLeaveRequest(year); + } + public async Task GetByYearAndTypeIdForUserAsync(int year, Guid typeId, Guid userId) { // var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); @@ -134,17 +162,13 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests var leaveType = await _dbContext.Set().FirstOrDefaultAsync(x => x.Id == typeId); - var data = await _dbContext.Set() - .Include(x => x.LeaveType) - .FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); - - if (data == null) + LeaveBeginning Factory() { var limit = 0.0; - var prev = await _dbContext.Set() + var prev = _dbContext.Set() .Include(x => x.LeaveType) - .FirstOrDefaultAsync(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); + .FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); var prevRemain = 0.0; if (prev != null) @@ -170,7 +194,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests limit = 0.0; } - data = new LeaveBeginning + return new LeaveBeginning { LeaveYear = year, LeaveTypeId = typeId, @@ -186,12 +210,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests Child3DnaId = pf.Child3DnaId, Child4DnaId = pf.Child4DnaId }; - - _dbContext.Set().Add(data); - await _dbContext.SaveChangesAsync(); } - return data; + return await GetOrAddForUserAsync(year, typeId, pf.Id, Factory); } public async Task GetByYearAndTypeIdForUser(int year, Guid typeId, GetProfileByKeycloakIdDto? pf) @@ -200,17 +221,13 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests var leaveType = await _dbContext.Set().FirstOrDefaultAsync(x => x.Id == typeId); - var data = await _dbContext.Set() - .Include(x => x.LeaveType) - .FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); - - if (data == null) + LeaveBeginning Factory() { var limit = 0.0; - var prev = await _dbContext.Set() + var prev = _dbContext.Set() .Include(x => x.LeaveType) - .FirstOrDefaultAsync(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); + .FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); var prevRemain = 0.0; if (prev != null) @@ -236,7 +253,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests limit = 0.0; } - data = new LeaveBeginning + return new LeaveBeginning { LeaveYear = year, LeaveTypeId = typeId, @@ -252,12 +269,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests Child3DnaId = pf.Child3DnaId, Child4DnaId = pf.Child4DnaId }; - - _dbContext.Set().Add(data); - await _dbContext.SaveChangesAsync(); } - return data; + return await GetOrAddForUserAsync(year, typeId, pf.Id, Factory); } public async Task GetByYearAndTypeIdForUser2Async(int year, Guid typeId, Guid userId) @@ -273,17 +287,13 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests var leaveType = await _dbContext.Set().FirstOrDefaultAsync(x => x.Id == typeId); - var data = await _dbContext.Set() - .Include(x => x.LeaveType) - .FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); - - if (data == null) + LeaveBeginning Factory() { var limit = 0.0; - var prev = await _dbContext.Set() + var prev = _dbContext.Set() .Include(x => x.LeaveType) - .FirstOrDefaultAsync(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); + .FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); var prevRemain = 0.0; if (prev != null) @@ -309,7 +319,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests limit = 0.0; } - data = new LeaveBeginning + return new LeaveBeginning { LeaveYear = year, LeaveTypeId = typeId, @@ -325,17 +335,59 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests Child3DnaId = pf.Child3DnaId, Child4DnaId = pf.Child4DnaId }; - - _dbContext.Set().Add(data); - await _dbContext.SaveChangesAsync(); } - return data; + return await GetOrAddForUserAsync(year, typeId, pf.Id, Factory); + } + + /// + /// Get-or-create a LeaveBeginning row for (ProfileId, LeaveYear, LeaveTypeId) with concurrency protection. + /// Uses a keyed SemaphoreSlim to serialize within-process requests, and re-queries after acquiring the lock. + /// If a cross-process insert wins (unique index violation), the duplicate key exception is caught and the row + /// created by the winner is returned. + /// + private async Task GetOrAddForUserAsync(int year, Guid typeId, Guid profileId, Func factory) + { + var key = $"{profileId}_{year}_{typeId}"; + var semaphore = _getOrAddLocks.GetOrAdd(key, _ => new SemaphoreSlim(1, 1)); + await semaphore.WaitAsync(); + try + { + // Re-query inside the lock — another thread may have created it while we waited. + var existing = await _dbContext.Set() + .Include(x => x.LeaveType) + .FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == profileId); + if (existing != null) + { + return existing; + } + + var entity = factory(); + _dbContext.Set().Add(entity); + try + { + await _dbContext.SaveChangesAsync(); + return entity; + } + catch (DbUpdateException) + { + // Cross-process/cross-server race hit the unique index (IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId). + // Detach the failed insert and return the row created by the winner. + _dbContext.Detach(entity); + var winner = await _dbContext.Set() + .Include(x => x.LeaveType) + .FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == profileId); + return winner; + } + } + finally + { + semaphore.Release(); + } } public async Task> GetAllByYearAndTypeAsync(int year, Guid typeId, List userIdList) { - var updateList = new List(); var result = new List(); diff --git a/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.Designer.cs b/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.Designer.cs new file mode 100644 index 00000000..d2d336f9 --- /dev/null +++ b/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.Designer.cs @@ -0,0 +1,1816 @@ +// +using System; +using BMA.EHR.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BMA.EHR.Infrastructure.Migrations.LeaveDb +{ + [DbContext(typeof(LeaveDbContext))] + [Migration("20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId")] + partial class AddUniqueIndexLeaveBeginningProfileIdYearTypeId + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Documents.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("CreatedDate") + .HasColumnType("datetime(6)"); + + b.Property("Detail") + .IsRequired() + .HasColumnType("text"); + + b.Property("FileName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("FileSize") + .HasColumnType("int"); + + b.Property("FileType") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("ObjectRefId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.ToTable("Document"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("Code") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รหัสประเภทการลา"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Limit") + .HasColumnType("int") + .HasComment("จำนวนวันลาสูงสุดประจำปี"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ชื่อประเภทการลา"); + + b.HasKey("Id"); + + b.ToTable("LeaveTypes"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveBeginning", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("BeginningLeaveCount") + .HasColumnType("int") + .HasComment("จำนวนครั้งที่ลายกมา"); + + b.Property("BeginningLeaveDays") + .HasColumnType("double") + .HasComment("จำนวนวันลายกมา"); + + b.Property("Child1DnaId") + .HasColumnType("char(36)"); + + b.Property("Child2DnaId") + .HasColumnType("char(36)"); + + b.Property("Child3DnaId") + .HasColumnType("char(36)"); + + b.Property("Child4DnaId") + .HasColumnType("char(36)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("FirstName") + .HasColumnType("longtext"); + + b.Property("LastName") + .HasColumnType("longtext"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("LeaveCount") + .HasColumnType("int") + .HasComment("จำนวนครั้งที่ลาสะสม"); + + b.Property("LeaveDays") + .HasColumnType("double") + .HasComment("จำนวนวันลาทั้งหมด"); + + b.Property("LeaveDaysUsed") + .HasColumnType("double") + .HasComment("จำนวนวันลาที่ใช้ไป"); + + b.Property("LeaveTypeId") + .HasColumnType("char(36)") + .HasComment("รหัสประเภทการลา"); + + b.Property("LeaveYear") + .HasColumnType("int") + .HasComment("ปีงบประมาณ"); + + b.Property("Prefix") + .HasColumnType("longtext"); + + b.Property("ProfileId") + .HasColumnType("char(36)") + .HasComment("รหัส Profile ในระบบทะเบียนประวัติ"); + + b.Property("RootDnaId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("LeaveTypeId"); + + b.HasIndex("ProfileId", "LeaveYear", "LeaveTypeId") + .IsUnique() + .HasDatabaseName("IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId"); + + b.ToTable("LeaveBeginnings"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("DocumentId") + .HasColumnType("char(36)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("LeaveRequestId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("LeaveRequestId"); + + b.ToTable("LeaveDocuments"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("AbsentDayAt") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("AbsentDayGetIn") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("AbsentDayLocation") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("AbsentDayRegistorDate") + .HasColumnType("datetime(6)"); + + b.Property("AbsentDaySummon") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Amount") + .HasColumnType("double"); + + b.Property("ApproveStep") + .HasColumnType("longtext") + .HasComment("step การอนุมัติ st1 = จทน.อนุมัตื,st2 = ผู้บังคับบัญชา อนุมัติ "); + + b.Property("BirthDate") + .HasColumnType("datetime(6)"); + + b.Property("CancelLeaveWrote") + .HasColumnType("longtext") + .HasComment("เขียนที่ (ขอยกเลิก)"); + + b.Property("Child1") + .HasColumnType("longtext"); + + b.Property("Child1DnaId") + .HasColumnType("char(36)"); + + b.Property("Child1Id") + .HasColumnType("char(36)"); + + b.Property("Child2") + .HasColumnType("longtext"); + + b.Property("Child2DnaId") + .HasColumnType("char(36)"); + + b.Property("Child2Id") + .HasColumnType("char(36)"); + + b.Property("Child3") + .HasColumnType("longtext"); + + b.Property("Child3DnaId") + .HasColumnType("char(36)"); + + b.Property("Child3Id") + .HasColumnType("char(36)"); + + b.Property("Child4") + .HasColumnType("longtext"); + + b.Property("Child4DnaId") + .HasColumnType("char(36)"); + + b.Property("Child4Id") + .HasColumnType("char(36)"); + + b.Property("CitizenId") + .HasColumnType("longtext"); + + b.Property("CommanderPosition") + .HasColumnType("longtext"); + + b.Property("CoupleDayCountryHistory") + .HasColumnType("longtext"); + + b.Property("CoupleDayEndDateHistory") + .HasColumnType("datetime(6)"); + + b.Property("CoupleDayLevel") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CoupleDayLevelCountry") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CoupleDayName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CoupleDayPosition") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CoupleDayStartDateHistory") + .HasColumnType("datetime(6)"); + + b.Property("CoupleDaySumTotalHistory") + .HasColumnType("longtext"); + + b.Property("CoupleDayTotalHistory") + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("DateAppoint") + .HasColumnType("datetime(6)"); + + b.Property("DateSendLeave") + .HasColumnType("datetime(6)"); + + b.Property("Dear") + .HasColumnType("longtext") + .HasComment("เรียนใคร"); + + b.Property("FirstName") + .HasColumnType("longtext"); + + b.Property("Gender") + .HasColumnType("longtext"); + + b.Property("HajjDayStatus") + .HasColumnType("tinyint(1)"); + + b.Property("KeycloakUserId") + .HasColumnType("char(36)"); + + b.Property("LastName") + .HasColumnType("longtext"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("LeaveAddress") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สถานที่ติดต่อขณะลา"); + + b.Property("LeaveBirthDate") + .HasColumnType("datetime(6)"); + + b.Property("LeaveCancelComment") + .HasColumnType("longtext") + .HasComment("เหตุผลในการขอยกเลิก"); + + b.Property("LeaveCancelDocumentId") + .HasColumnType("char(36)"); + + b.Property("LeaveCancelStatus") + .HasColumnType("longtext") + .HasComment("สถานะของคำขอยกเลิก"); + + b.Property("LeaveComment") + .HasColumnType("longtext") + .HasComment("ความเห็นของผู้บังคับบัญชา"); + + b.Property("LeaveDetail") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รายละเอียดการลา"); + + b.Property("LeaveDirectorComment") + .HasColumnType("longtext") + .HasComment("ความเห็นของผู้อำนวยการสำนัก"); + + b.Property("LeaveDraftDocumentId") + .HasColumnType("char(36)"); + + b.Property("LeaveEndDate") + .HasColumnType("datetime(6)") + .HasComment("วัน เดือน ปีสิ้นสุดลา"); + + b.Property("LeaveGovernmentDate") + .HasColumnType("datetime(6)"); + + b.Property("LeaveLast") + .HasColumnType("datetime(6)"); + + b.Property("LeaveNumber") + .IsRequired() + .HasColumnType("longtext") + .HasComment("หมายเลขที่ติดต่อขณะลา"); + + b.Property("LeaveRange") + .HasColumnType("longtext") + .HasComment("ช่วงของการลาของวันเริ่ม เช่น ลาทั้งวัน ครึ่งวันเช้า ครึ่งวันบ่าย"); + + b.Property("LeaveRangeEnd") + .HasColumnType("longtext") + .HasComment("ช่วงของการลาของวันสิ้นสุด เช่น ลาทั้งวัน ครึ่งวันเช้า ครึ่งวันบ่าย"); + + b.Property("LeaveSalary") + .HasColumnType("int"); + + b.Property("LeaveSalaryText") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("LeaveStartDate") + .HasColumnType("datetime(6)") + .HasComment("วัน เดือน ปีเริ่มต้นลา"); + + b.Property("LeaveStatus") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สถานะของคำร้อง"); + + b.Property("LeaveSubTypeName") + .HasColumnType("longtext"); + + b.Property("LeaveTotal") + .HasColumnType("double"); + + b.Property("LeaveTypeCode") + .HasColumnType("longtext") + .HasComment("code ของประเภทการลา"); + + b.Property("LeaveWrote") + .IsRequired() + .HasColumnType("longtext") + .HasComment("เขียนที่"); + + b.Property("OrdainDayBuddhistLentAddress") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OrdainDayBuddhistLentName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OrdainDayLocationAddress") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OrdainDayLocationName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OrdainDayLocationNumber") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OrdainDayOrdination") + .HasColumnType("datetime(6)"); + + b.Property("OrdainDayStatus") + .HasColumnType("tinyint(1)"); + + b.Property("OrganizationName") + .HasColumnType("longtext") + .HasComment("สังกัดผู้ยื่นขอ"); + + b.Property("PositionLevelName") + .HasColumnType("longtext") + .HasComment("ระดับผู้ยื่นขอ"); + + b.Property("PositionName") + .HasColumnType("longtext") + .HasComment("ตำแหน่งผู้ยื่นขอ"); + + b.Property("Prefix") + .HasColumnType("longtext"); + + b.Property("ProfileId") + .HasColumnType("char(36)"); + + b.Property("ProfileType") + .HasColumnType("longtext"); + + b.Property("RestDayCurrentTotal") + .HasColumnType("double"); + + b.Property("RestDayOldTotal") + .HasColumnType("double"); + + b.Property("Root") + .HasColumnType("longtext"); + + b.Property("RootDnaId") + .HasColumnType("char(36)"); + + b.Property("RootId") + .HasColumnType("char(36)"); + + b.Property("StudyDayCountry") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDayDegreeLevel") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDayScholarship") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDaySubject") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDayTrainingName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDayTrainingSubject") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDayUniversityName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("TypeId") + .HasColumnType("char(36)"); + + b.Property("WifeDayDateBorn") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("WifeDayName") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("LeaveCancelDocumentId"); + + b.HasIndex("LeaveDraftDocumentId"); + + b.HasIndex("TypeId"); + + b.ToTable("LeaveRequests"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequestApprover", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("ApproveStatus") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ApproveType") + .HasColumnType("longtext"); + + b.Property("Comment") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IsAct") + .HasColumnType("tinyint(1)"); + + b.Property("KeyId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("KeycloakId") + .HasColumnType("char(36)"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("LeaveRequestId") + .HasColumnType("char(36)"); + + b.Property("OrganizationName") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สังกัด"); + + b.Property("PosExecutiveName") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ตำแหน่งทางการบริหาร"); + + b.Property("PositionLevelName") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ประเภทระดับตำแหน่ง"); + + b.Property("PositionName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PositionSign") + .HasColumnType("longtext") + .HasComment("ตำแหน่งใต้ลายเช็นต์"); + + b.Property("Prefix") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProfileId") + .HasColumnType("char(36)"); + + b.Property("Seq") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("LeaveRequestId"); + + b.ToTable("LeaveRequestApprovers"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.AdditionalCheckRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CheckDate") + .HasColumnType("datetime(6)") + .HasComment("*วันที่ลงเวลา"); + + b.Property("CheckInEdit") + .HasColumnType("tinyint(1)") + .HasComment("*ขอลงเวลาช่วงเช้า"); + + b.Property("CheckOutEdit") + .HasColumnType("tinyint(1)") + .HasComment("*ขอลงเวลาช่วงบ่าย"); + + b.Property("Child1DnaId") + .HasColumnType("char(36)"); + + b.Property("Child2DnaId") + .HasColumnType("char(36)"); + + b.Property("Child3DnaId") + .HasColumnType("char(36)"); + + b.Property("Child4DnaId") + .HasColumnType("char(36)"); + + b.Property("Comment") + .HasColumnType("longtext") + .HasComment("หมายเหตุในการการอนุมัติ/ไม่อนุมัติ"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext") + .HasComment("*หมายเหตุขอลงเวลาพิเศษ"); + + b.Property("FirstName") + .HasColumnType("longtext"); + + b.Property("KeycloakUserId") + .HasColumnType("char(36)") + .HasComment("รหัส User ของ Keycloak ที่ร้องขอ"); + + b.Property("LastName") + .HasColumnType("longtext"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Latitude") + .HasColumnType("double"); + + b.Property("Longitude") + .HasColumnType("double"); + + b.Property("POI") + .HasColumnType("longtext"); + + b.Property("Prefix") + .HasColumnType("longtext"); + + b.Property("RootDnaId") + .HasColumnType("char(36)"); + + b.Property("Status") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สถานะการอนุมัติ"); + + b.HasKey("Id"); + + b.ToTable("AdditionalCheckRequests"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.CheckInJobStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("AdditionalData") + .HasColumnType("longtext") + .HasComment("ข้อมูลเพิ่มเติม (JSON)"); + + b.Property("CheckInId") + .HasColumnType("char(36)") + .HasComment("CheckInId สำหรับ Check-Out"); + + b.Property("CheckType") + .HasColumnType("longtext") + .HasComment("ประเภทการลงเวลา: CHECK_IN, CHECK_OUT"); + + b.Property("CompletedDate") + .HasColumnType("datetime(6)") + .HasComment("วันเวลาที่เสร็จสิ้นการประมวลผล"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedDate") + .HasColumnType("datetime(6)") + .HasComment("วันเวลาที่สร้างงาน"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("ErrorMessage") + .HasColumnType("longtext") + .HasComment("ข้อความแสดงข้อผิดพลาด"); + + b.Property("KeycloakUserId") + .HasColumnType("char(36)") + .HasComment("รหัส User ของ Keycloak"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("ProcessingDate") + .HasColumnType("datetime(6)") + .HasComment("วันเวลาที่เริ่มประมวลผล"); + + b.Property("Status") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สถานะงาน: PENDING, PROCESSING, COMPLETED, FAILED"); + + b.Property("TaskId") + .HasColumnType("char(36)") + .HasComment("Task ID สำหรับติดตามสถานะงาน"); + + b.HasKey("Id"); + + b.ToTable("CheckInJobStatuses"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.DutyTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext") + .HasComment("คำอธิบาย"); + + b.Property("EndTimeAfternoon") + .IsRequired() + .HasColumnType("longtext") + .HasComment("เวลาออกงานช่วงบ่าย"); + + b.Property("EndTimeMorning") + .IsRequired() + .HasColumnType("longtext") + .HasComment("เวลาออกงานช่วงเช้า"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)") + .HasComment("สถานะการเปิดใช้งาน (เปิด/ปิด)"); + + b.Property("IsDefault") + .HasColumnType("tinyint(1)") + .HasComment("สถานะว่ารอบใดเป็นค่า Default ของข้าราชการ (สำหรับทุกคนที่ยังไม่ได้ทำการเลือกรอบ)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("StartTimeAfternoon") + .IsRequired() + .HasColumnType("longtext") + .HasComment("เวลาเข้างานช่วงบ่าย"); + + b.Property("StartTimeMorning") + .IsRequired() + .HasColumnType("longtext") + .HasComment("เวลาเข้างานช่วงเช้า"); + + b.HasKey("Id"); + + b.ToTable("DutyTimes"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.LeaveProcessJobStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CompletedDate") + .HasColumnType("datetime(6)") + .HasComment("วันเวลาที่เสร็จสิ้นการประมวลผล"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedDate") + .HasColumnType("datetime(6)") + .HasComment("วันเวลาที่สร้างงาน"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("EndDate") + .HasColumnType("datetime(6)") + .HasComment("วันสิ้นสุด"); + + b.Property("ErrorMessage") + .HasColumnType("longtext") + .HasComment("ข้อความแสดงข้อผิดพลาด"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("ProcessingDate") + .HasColumnType("datetime(6)") + .HasComment("วันเวลาที่เริ่มประมวลผล"); + + b.Property("RootDnaId") + .HasColumnType("char(36)") + .HasComment("รหัส Root DNA Id"); + + b.Property("StartDate") + .HasColumnType("datetime(6)") + .HasComment("วันเริ่มต้น"); + + b.Property("Status") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สถานะงาน: PENDING, PROCESSING, COMPLETED, FAILED"); + + b.HasKey("Id"); + + b.ToTable("LeaveProcessJobStatuses"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.ProcessUserTimeStamp", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CheckIn") + .HasColumnType("datetime(6)") + .HasComment("วัน เวลา เข้างาน"); + + b.Property("CheckInImageUrl") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รูปถ่ายสถานที่ Check-In"); + + b.Property("CheckInLat") + .HasColumnType("double") + .HasComment("พิกัดละติจูด Check-In"); + + b.Property("CheckInLocationName") + .HasColumnType("longtext") + .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-In"); + + b.Property("CheckInLon") + .HasColumnType("double") + .HasComment("พิกัดลองจิจูด Check-In"); + + b.Property("CheckInPOI") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-In"); + + b.Property("CheckInRemark") + .HasColumnType("longtext") + .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-In"); + + b.Property("CheckInStatus") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สถานะ Check-In"); + + b.Property("CheckOut") + .HasColumnType("datetime(6)") + .HasComment("วัน เวลา ออกงาน"); + + b.Property("CheckOutImageUrl") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รูปถ่ายสถานที่ Check-Out"); + + b.Property("CheckOutLat") + .HasColumnType("double") + .HasComment("พิกัดละติจูด Check-Out"); + + b.Property("CheckOutLocationName") + .HasColumnType("longtext") + .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-Out"); + + b.Property("CheckOutLon") + .HasColumnType("double") + .HasComment("พิกัดลองจิจูด Check-Out"); + + b.Property("CheckOutPOI") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-Out"); + + b.Property("CheckOutRemark") + .HasColumnType("longtext") + .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-Out"); + + b.Property("CheckOutStatus") + .HasColumnType("longtext") + .HasComment("สถานะ Check-Out"); + + b.Property("Child1") + .HasColumnType("longtext"); + + b.Property("Child1DnaId") + .HasColumnType("char(36)"); + + b.Property("Child1Id") + .HasColumnType("char(36)"); + + b.Property("Child2") + .HasColumnType("longtext"); + + b.Property("Child2DnaId") + .HasColumnType("char(36)"); + + b.Property("Child2Id") + .HasColumnType("char(36)"); + + b.Property("Child3") + .HasColumnType("longtext"); + + b.Property("Child3DnaId") + .HasColumnType("char(36)"); + + b.Property("Child3Id") + .HasColumnType("char(36)"); + + b.Property("Child4") + .HasColumnType("longtext"); + + b.Property("Child4DnaId") + .HasColumnType("char(36)"); + + b.Property("Child4Id") + .HasColumnType("char(36)"); + + b.Property("CitizenId") + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("EditReason") + .HasColumnType("longtext") + .HasComment("เหตุผลการอนุมัติ/ไม่อนุมัติขอลงเวลาพิเศษ"); + + b.Property("EditStatus") + .HasColumnType("longtext") + .HasComment("สถานะการของลงเวลาพิเศษ"); + + b.Property("FirstName") + .HasColumnType("longtext"); + + b.Property("Gender") + .HasColumnType("longtext"); + + b.Property("IsLocationCheckIn") + .HasColumnType("tinyint(1)") + .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-In"); + + b.Property("IsLocationCheckOut") + .HasColumnType("tinyint(1)") + .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-Out"); + + b.Property("IsProcess") + .HasColumnType("tinyint(1)") + .HasComment("นำไปประมวลผลแล้วหรือยัง"); + + b.Property("KeycloakUserId") + .HasColumnType("char(36)") + .HasComment("รหัส User ของ Keycloak"); + + b.Property("LastName") + .HasColumnType("longtext"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Prefix") + .HasColumnType("longtext"); + + b.Property("ProfileId") + .HasColumnType("char(36)"); + + b.Property("ProfileType") + .HasColumnType("longtext"); + + b.Property("Root") + .HasColumnType("longtext"); + + b.Property("RootDnaId") + .HasColumnType("char(36)"); + + b.Property("RootId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.ToTable("ProcessUserTimeStamps"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserCalendar", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("Calendar") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ปฏิทินการทำงานของ ขรก ปกติ หรือ 6 วันต่อสัปดาห์"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("ProfileId") + .HasColumnType("char(36)") + .HasComment("รหัส Profile ในระบบทะเบียนประวัติ"); + + b.HasKey("Id"); + + b.ToTable("UserCalendars"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserDutyTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("Child1DnaId") + .HasColumnType("char(36)"); + + b.Property("Child2DnaId") + .HasColumnType("char(36)"); + + b.Property("Child3DnaId") + .HasColumnType("char(36)"); + + b.Property("Child4DnaId") + .HasColumnType("char(36)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("DutyTimeId") + .HasColumnType("char(36)") + .HasComment("รหัสรอบการลงเวลา"); + + b.Property("EffectiveDate") + .HasColumnType("datetime(6)") + .HasComment("วันที่มีผล"); + + b.Property("IsProcess") + .HasColumnType("tinyint(1)") + .HasComment("ทำการประมวลผลแล้วหรือยัง"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("ProfileId") + .HasColumnType("char(36)") + .HasComment("รหัส Profile ในระบบทะเบียนประวัติ"); + + b.Property("Remark") + .HasColumnType("longtext") + .HasComment("หมายเหตุ"); + + b.Property("RootDnaId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("DutyTimeId"); + + b.ToTable("UserDutyTimes"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserTimeStamp", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CheckIn") + .HasColumnType("datetime(6)") + .HasComment("วัน เวลา เข้างาน"); + + b.Property("CheckInImageUrl") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รูปถ่ายสถานที่ Check-In"); + + b.Property("CheckInLat") + .HasColumnType("double") + .HasComment("พิกัดละติจูด Check-In"); + + b.Property("CheckInLocationName") + .HasColumnType("longtext") + .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-In"); + + b.Property("CheckInLon") + .HasColumnType("double") + .HasComment("พิกัดลองจิจูด Check-In"); + + b.Property("CheckInPOI") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-In"); + + b.Property("CheckInRemark") + .HasColumnType("longtext") + .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-In"); + + b.Property("CheckOut") + .HasColumnType("datetime(6)") + .HasComment("วัน เวลา ออกงาน"); + + b.Property("CheckOutImageUrl") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รูปถ่ายสถานที่ Check-Out"); + + b.Property("CheckOutLat") + .HasColumnType("double") + .HasComment("พิกัดละติจูด Check-Out"); + + b.Property("CheckOutLocationName") + .HasColumnType("longtext") + .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-Out"); + + b.Property("CheckOutLon") + .HasColumnType("double") + .HasComment("พิกัดลองจิจูด Check-Out"); + + b.Property("CheckOutPOI") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-Out"); + + b.Property("CheckOutRemark") + .HasColumnType("longtext") + .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-Out"); + + b.Property("Child1") + .HasColumnType("longtext"); + + b.Property("Child1DnaId") + .HasColumnType("char(36)"); + + b.Property("Child1Id") + .HasColumnType("char(36)"); + + b.Property("Child2") + .HasColumnType("longtext"); + + b.Property("Child2DnaId") + .HasColumnType("char(36)"); + + b.Property("Child2Id") + .HasColumnType("char(36)"); + + b.Property("Child3") + .HasColumnType("longtext"); + + b.Property("Child3DnaId") + .HasColumnType("char(36)"); + + b.Property("Child3Id") + .HasColumnType("char(36)"); + + b.Property("Child4") + .HasColumnType("longtext"); + + b.Property("Child4DnaId") + .HasColumnType("char(36)"); + + b.Property("Child4Id") + .HasColumnType("char(36)"); + + b.Property("CitizenId") + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("FirstName") + .HasColumnType("longtext"); + + b.Property("Gender") + .HasColumnType("longtext"); + + b.Property("IsLocationCheckIn") + .HasColumnType("tinyint(1)") + .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-In"); + + b.Property("IsLocationCheckOut") + .HasColumnType("tinyint(1)") + .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-Out"); + + b.Property("IsProcess") + .HasColumnType("tinyint(1)") + .HasComment("นำไปประมวลผลแล้วหรือยัง"); + + b.Property("KeycloakUserId") + .HasColumnType("char(36)") + .HasComment("รหัส User ของ Keycloak"); + + b.Property("LastName") + .HasColumnType("longtext"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Prefix") + .HasColumnType("longtext"); + + b.Property("ProfileId") + .HasColumnType("char(36)"); + + b.Property("ProfileType") + .HasColumnType("longtext"); + + b.Property("Root") + .HasColumnType("longtext"); + + b.Property("RootDnaId") + .HasColumnType("char(36)"); + + b.Property("RootId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.ToTable("UserTimeStamps"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveBeginning", b => + { + b.HasOne("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", "LeaveType") + .WithMany() + .HasForeignKey("LeaveTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LeaveType"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveDocument", b => + { + b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "Document") + .WithMany() + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", "LeaveRequest") + .WithMany("LeaveDocument") + .HasForeignKey("LeaveRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("LeaveRequest"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b => + { + b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "LeaveCancelDocument") + .WithMany() + .HasForeignKey("LeaveCancelDocumentId"); + + b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "LeaveDraftDocument") + .WithMany() + .HasForeignKey("LeaveDraftDocumentId"); + + b.HasOne("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", "Type") + .WithMany() + .HasForeignKey("TypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LeaveCancelDocument"); + + b.Navigation("LeaveDraftDocument"); + + b.Navigation("Type"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequestApprover", b => + { + b.HasOne("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", "LeaveRequest") + .WithMany("Approvers") + .HasForeignKey("LeaveRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LeaveRequest"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserDutyTime", b => + { + b.HasOne("BMA.EHR.Domain.Models.Leave.TimeAttendants.DutyTime", "DutyTime") + .WithMany() + .HasForeignKey("DutyTimeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DutyTime"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b => + { + b.Navigation("Approvers"); + + b.Navigation("LeaveDocument"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.cs b/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.cs new file mode 100644 index 00000000..deabdd48 --- /dev/null +++ b/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BMA.EHR.Infrastructure.Migrations.LeaveDb +{ + /// + public partial class AddUniqueIndexLeaveBeginningProfileIdYearTypeId : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateIndex( + name: "IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId", + table: "LeaveBeginnings", + columns: new[] { "ProfileId", "LeaveYear", "LeaveTypeId" }, + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId", + table: "LeaveBeginnings"); + } + } +} diff --git a/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs b/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs index 99694a78..053f6d99 100644 --- a/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs +++ b/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs @@ -226,6 +226,10 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasIndex("LeaveTypeId"); + b.HasIndex("ProfileId", "LeaveYear", "LeaveTypeId") + .IsUnique() + .HasDatabaseName("IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId"); + b.ToTable("LeaveBeginnings"); }); diff --git a/BMA.EHR.Infrastructure/Persistence/LeaveDbContext.cs b/BMA.EHR.Infrastructure/Persistence/LeaveDbContext.cs index 10064197..115a2ffc 100644 --- a/BMA.EHR.Infrastructure/Persistence/LeaveDbContext.cs +++ b/BMA.EHR.Infrastructure/Persistence/LeaveDbContext.cs @@ -61,5 +61,18 @@ namespace BMA.EHR.Infrastructure.Persistence { base.Entry(entity).State = EntityState.Detached; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + // Composite unique index on the natural key for LeaveBeginning. + // Prevents duplicate rows when concurrent requests (e.g. UI calling /user/check twice) + // race through the get-or-create flow in LeaveBeginningRepository. + modelBuilder.Entity() + .HasIndex(b => new { b.ProfileId, b.LeaveYear, b.LeaveTypeId }) + .HasDatabaseName("IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId") + .IsUnique(); + } } } diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index 5fbca2cc..85c19b79 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -1016,6 +1016,30 @@ namespace BMA.EHR.Leave.Service.Controllers }); } + /// + /// ทดสอบประมวลผล beginning + /// + /// + /// + [HttpGet("process-beginning/{year:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [AllowAnonymous] + public async Task> ProcessBeginningByYearAsync([FromRoute] int year) + { + try + { + await _leaveBeginningRepository.ProcessEarlyLeaveRequest(year); + return Success(); + } + catch (Exception e) + { + return Error(e); + } + } + + /// /// LV2_003 - เช็คการยืนขอลา (USER) /// diff --git a/BMA.EHR.Leave/Program.cs b/BMA.EHR.Leave/Program.cs index 3dd83203..5a396430 100644 --- a/BMA.EHR.Leave/Program.cs +++ b/BMA.EHR.Leave/Program.cs @@ -18,6 +18,7 @@ using System.Text; using Hangfire; using Hangfire.MySql; using System.Transactions; +using BMA.EHR.Application.Repositories.Leaves.LeaveRequests; using BMA.EHR.Leave.Service.Filters; using Hangfire.Common; using BMA.EHR.Application.Repositories.Leaves.TimeAttendants; @@ -194,10 +195,28 @@ app.UseHangfireDashboard("/hangfire", new DashboardOptions() var manager = new RecurringJobManager(); if (manager != null) { - manager.AddOrUpdate("ปรับปรุงรอบการลงเวลาทำงาน", Job.FromExpression(x => x.UpdateUserDutyTime()), "0 1 * * *", bangkokTimeZone); + manager.AddOrUpdate("ปรับปรุงรอบการลงเวลาทำงาน", Job.FromExpression(x => x.UpdateUserDutyTime()), "0 1 * * *", + new RecurringJobOptions + { + TimeZone = bangkokTimeZone, + QueueName = "leave" + }); // ทำความสะอาดข้อมูล CheckIn Job Status ที่เก่ากว่า 30 วัน - รันทุกวันเวลา 02:00 น. - manager.AddOrUpdate("ทำความสะอาดข้อมูล CheckIn Job Status", Job.FromExpression(x => x.CleanupOldJobsAsync(30)), "0 2 * * *", bangkokTimeZone); - + manager.AddOrUpdate("ทำความสะอาดข้อมูล CheckIn Job Status", Job.FromExpression(x => x.CleanupOldJobsAsync(30)), "0 2 * * *", + new RecurringJobOptions + { + TimeZone = bangkokTimeZone, + QueueName = "leave" + }); + + manager.AddOrUpdate("Proceess Beginning สำหรับการลาล่วงหน้า", Job.FromExpression(x => x.ProcessEarlyLeaveRequestSchedule()), "0 1 1 10 *", + new RecurringJobOptions + { + TimeZone = bangkokTimeZone, + QueueName = "leave" + }); + + // ตรวจสอบและ mark งาน CheckIn ที่ค้างเกิน 30 นาทีเป็น FAILED - รันทุก 15 นาที // manager.AddOrUpdate("ตรวจสอบงาน CheckIn ที่ค้างเกินเวลา", Job.FromExpression(x => x.MarkStaleJobsAsFailedAsync(30)), "*/15 * * * *", // new RecurringJobOptions From 6843e3ff3f4e8aa2632f35170aad684c21d4acf5 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 19 Jun 2026 11:11:46 +0700 Subject: [PATCH 27/42] fix #2551 Error --- ...eginning ProfileId Year TypeId.Designer.cs | 1816 ----------------- ...ex LeaveBeginning ProfileId Year TypeId.cs | 28 - .../LeaveDb/LeaveDbContextModelSnapshot.cs | 32 +- .../Persistence/LeaveDbContext.cs | 13 - 4 files changed, 14 insertions(+), 1875 deletions(-) delete mode 100644 BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.Designer.cs delete mode 100644 BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.cs diff --git a/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.Designer.cs b/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.Designer.cs deleted file mode 100644 index d2d336f9..00000000 --- a/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.Designer.cs +++ /dev/null @@ -1,1816 +0,0 @@ -// -using System; -using BMA.EHR.Infrastructure.Persistence; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace BMA.EHR.Infrastructure.Migrations.LeaveDb -{ - [DbContext(typeof(LeaveDbContext))] - [Migration("20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId")] - partial class AddUniqueIndexLeaveBeginningProfileIdYearTypeId - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Documents.Document", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)"); - - b.Property("CreatedDate") - .HasColumnType("datetime(6)"); - - b.Property("Detail") - .IsRequired() - .HasColumnType("text"); - - b.Property("FileName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("varchar(255)"); - - b.Property("FileSize") - .HasColumnType("int"); - - b.Property("FileType") - .IsRequired() - .HasMaxLength(128) - .HasColumnType("varchar(128)"); - - b.Property("ObjectRefId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.ToTable("Document"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("Code") - .IsRequired() - .HasColumnType("longtext") - .HasComment("รหัสประเภทการลา"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("Limit") - .HasColumnType("int") - .HasComment("จำนวนวันลาสูงสุดประจำปี"); - - b.Property("Name") - .IsRequired() - .HasColumnType("longtext") - .HasComment("ชื่อประเภทการลา"); - - b.HasKey("Id"); - - b.ToTable("LeaveTypes"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveBeginning", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("BeginningLeaveCount") - .HasColumnType("int") - .HasComment("จำนวนครั้งที่ลายกมา"); - - b.Property("BeginningLeaveDays") - .HasColumnType("double") - .HasComment("จำนวนวันลายกมา"); - - b.Property("Child1DnaId") - .HasColumnType("char(36)"); - - b.Property("Child2DnaId") - .HasColumnType("char(36)"); - - b.Property("Child3DnaId") - .HasColumnType("char(36)"); - - b.Property("Child4DnaId") - .HasColumnType("char(36)"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("FirstName") - .HasColumnType("longtext"); - - b.Property("LastName") - .HasColumnType("longtext"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("LeaveCount") - .HasColumnType("int") - .HasComment("จำนวนครั้งที่ลาสะสม"); - - b.Property("LeaveDays") - .HasColumnType("double") - .HasComment("จำนวนวันลาทั้งหมด"); - - b.Property("LeaveDaysUsed") - .HasColumnType("double") - .HasComment("จำนวนวันลาที่ใช้ไป"); - - b.Property("LeaveTypeId") - .HasColumnType("char(36)") - .HasComment("รหัสประเภทการลา"); - - b.Property("LeaveYear") - .HasColumnType("int") - .HasComment("ปีงบประมาณ"); - - b.Property("Prefix") - .HasColumnType("longtext"); - - b.Property("ProfileId") - .HasColumnType("char(36)") - .HasComment("รหัส Profile ในระบบทะเบียนประวัติ"); - - b.Property("RootDnaId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.HasIndex("LeaveTypeId"); - - b.HasIndex("ProfileId", "LeaveYear", "LeaveTypeId") - .IsUnique() - .HasDatabaseName("IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId"); - - b.ToTable("LeaveBeginnings"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveDocument", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("DocumentId") - .HasColumnType("char(36)"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("LeaveRequestId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.HasIndex("DocumentId"); - - b.HasIndex("LeaveRequestId"); - - b.ToTable("LeaveDocuments"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("AbsentDayAt") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("AbsentDayGetIn") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("AbsentDayLocation") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("AbsentDayRegistorDate") - .HasColumnType("datetime(6)"); - - b.Property("AbsentDaySummon") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Amount") - .HasColumnType("double"); - - b.Property("ApproveStep") - .HasColumnType("longtext") - .HasComment("step การอนุมัติ st1 = จทน.อนุมัตื,st2 = ผู้บังคับบัญชา อนุมัติ "); - - b.Property("BirthDate") - .HasColumnType("datetime(6)"); - - b.Property("CancelLeaveWrote") - .HasColumnType("longtext") - .HasComment("เขียนที่ (ขอยกเลิก)"); - - b.Property("Child1") - .HasColumnType("longtext"); - - b.Property("Child1DnaId") - .HasColumnType("char(36)"); - - b.Property("Child1Id") - .HasColumnType("char(36)"); - - b.Property("Child2") - .HasColumnType("longtext"); - - b.Property("Child2DnaId") - .HasColumnType("char(36)"); - - b.Property("Child2Id") - .HasColumnType("char(36)"); - - b.Property("Child3") - .HasColumnType("longtext"); - - b.Property("Child3DnaId") - .HasColumnType("char(36)"); - - b.Property("Child3Id") - .HasColumnType("char(36)"); - - b.Property("Child4") - .HasColumnType("longtext"); - - b.Property("Child4DnaId") - .HasColumnType("char(36)"); - - b.Property("Child4Id") - .HasColumnType("char(36)"); - - b.Property("CitizenId") - .HasColumnType("longtext"); - - b.Property("CommanderPosition") - .HasColumnType("longtext"); - - b.Property("CoupleDayCountryHistory") - .HasColumnType("longtext"); - - b.Property("CoupleDayEndDateHistory") - .HasColumnType("datetime(6)"); - - b.Property("CoupleDayLevel") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("CoupleDayLevelCountry") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("CoupleDayName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("CoupleDayPosition") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("CoupleDayStartDateHistory") - .HasColumnType("datetime(6)"); - - b.Property("CoupleDaySumTotalHistory") - .HasColumnType("longtext"); - - b.Property("CoupleDayTotalHistory") - .HasColumnType("longtext"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("DateAppoint") - .HasColumnType("datetime(6)"); - - b.Property("DateSendLeave") - .HasColumnType("datetime(6)"); - - b.Property("Dear") - .HasColumnType("longtext") - .HasComment("เรียนใคร"); - - b.Property("FirstName") - .HasColumnType("longtext"); - - b.Property("Gender") - .HasColumnType("longtext"); - - b.Property("HajjDayStatus") - .HasColumnType("tinyint(1)"); - - b.Property("KeycloakUserId") - .HasColumnType("char(36)"); - - b.Property("LastName") - .HasColumnType("longtext"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("LeaveAddress") - .IsRequired() - .HasColumnType("longtext") - .HasComment("สถานที่ติดต่อขณะลา"); - - b.Property("LeaveBirthDate") - .HasColumnType("datetime(6)"); - - b.Property("LeaveCancelComment") - .HasColumnType("longtext") - .HasComment("เหตุผลในการขอยกเลิก"); - - b.Property("LeaveCancelDocumentId") - .HasColumnType("char(36)"); - - b.Property("LeaveCancelStatus") - .HasColumnType("longtext") - .HasComment("สถานะของคำขอยกเลิก"); - - b.Property("LeaveComment") - .HasColumnType("longtext") - .HasComment("ความเห็นของผู้บังคับบัญชา"); - - b.Property("LeaveDetail") - .IsRequired() - .HasColumnType("longtext") - .HasComment("รายละเอียดการลา"); - - b.Property("LeaveDirectorComment") - .HasColumnType("longtext") - .HasComment("ความเห็นของผู้อำนวยการสำนัก"); - - b.Property("LeaveDraftDocumentId") - .HasColumnType("char(36)"); - - b.Property("LeaveEndDate") - .HasColumnType("datetime(6)") - .HasComment("วัน เดือน ปีสิ้นสุดลา"); - - b.Property("LeaveGovernmentDate") - .HasColumnType("datetime(6)"); - - b.Property("LeaveLast") - .HasColumnType("datetime(6)"); - - b.Property("LeaveNumber") - .IsRequired() - .HasColumnType("longtext") - .HasComment("หมายเลขที่ติดต่อขณะลา"); - - b.Property("LeaveRange") - .HasColumnType("longtext") - .HasComment("ช่วงของการลาของวันเริ่ม เช่น ลาทั้งวัน ครึ่งวันเช้า ครึ่งวันบ่าย"); - - b.Property("LeaveRangeEnd") - .HasColumnType("longtext") - .HasComment("ช่วงของการลาของวันสิ้นสุด เช่น ลาทั้งวัน ครึ่งวันเช้า ครึ่งวันบ่าย"); - - b.Property("LeaveSalary") - .HasColumnType("int"); - - b.Property("LeaveSalaryText") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("LeaveStartDate") - .HasColumnType("datetime(6)") - .HasComment("วัน เดือน ปีเริ่มต้นลา"); - - b.Property("LeaveStatus") - .IsRequired() - .HasColumnType("longtext") - .HasComment("สถานะของคำร้อง"); - - b.Property("LeaveSubTypeName") - .HasColumnType("longtext"); - - b.Property("LeaveTotal") - .HasColumnType("double"); - - b.Property("LeaveTypeCode") - .HasColumnType("longtext") - .HasComment("code ของประเภทการลา"); - - b.Property("LeaveWrote") - .IsRequired() - .HasColumnType("longtext") - .HasComment("เขียนที่"); - - b.Property("OrdainDayBuddhistLentAddress") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("OrdainDayBuddhistLentName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("OrdainDayLocationAddress") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("OrdainDayLocationName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("OrdainDayLocationNumber") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("OrdainDayOrdination") - .HasColumnType("datetime(6)"); - - b.Property("OrdainDayStatus") - .HasColumnType("tinyint(1)"); - - b.Property("OrganizationName") - .HasColumnType("longtext") - .HasComment("สังกัดผู้ยื่นขอ"); - - b.Property("PositionLevelName") - .HasColumnType("longtext") - .HasComment("ระดับผู้ยื่นขอ"); - - b.Property("PositionName") - .HasColumnType("longtext") - .HasComment("ตำแหน่งผู้ยื่นขอ"); - - b.Property("Prefix") - .HasColumnType("longtext"); - - b.Property("ProfileId") - .HasColumnType("char(36)"); - - b.Property("ProfileType") - .HasColumnType("longtext"); - - b.Property("RestDayCurrentTotal") - .HasColumnType("double"); - - b.Property("RestDayOldTotal") - .HasColumnType("double"); - - b.Property("Root") - .HasColumnType("longtext"); - - b.Property("RootDnaId") - .HasColumnType("char(36)"); - - b.Property("RootId") - .HasColumnType("char(36)"); - - b.Property("StudyDayCountry") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("StudyDayDegreeLevel") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("StudyDayScholarship") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("StudyDaySubject") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("StudyDayTrainingName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("StudyDayTrainingSubject") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("StudyDayUniversityName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TypeId") - .HasColumnType("char(36)"); - - b.Property("WifeDayDateBorn") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("WifeDayName") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.HasIndex("LeaveCancelDocumentId"); - - b.HasIndex("LeaveDraftDocumentId"); - - b.HasIndex("TypeId"); - - b.ToTable("LeaveRequests"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequestApprover", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("ApproveStatus") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("ApproveType") - .HasColumnType("longtext"); - - b.Property("Comment") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("IsAct") - .HasColumnType("tinyint(1)"); - - b.Property("KeyId") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("KeycloakId") - .HasColumnType("char(36)"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("LeaveRequestId") - .HasColumnType("char(36)"); - - b.Property("OrganizationName") - .IsRequired() - .HasColumnType("longtext") - .HasComment("สังกัด"); - - b.Property("PosExecutiveName") - .IsRequired() - .HasColumnType("longtext") - .HasComment("ตำแหน่งทางการบริหาร"); - - b.Property("PositionLevelName") - .IsRequired() - .HasColumnType("longtext") - .HasComment("ประเภทระดับตำแหน่ง"); - - b.Property("PositionName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PositionSign") - .HasColumnType("longtext") - .HasComment("ตำแหน่งใต้ลายเช็นต์"); - - b.Property("Prefix") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("ProfileId") - .HasColumnType("char(36)"); - - b.Property("Seq") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("LeaveRequestId"); - - b.ToTable("LeaveRequestApprovers"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.AdditionalCheckRequest", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("CheckDate") - .HasColumnType("datetime(6)") - .HasComment("*วันที่ลงเวลา"); - - b.Property("CheckInEdit") - .HasColumnType("tinyint(1)") - .HasComment("*ขอลงเวลาช่วงเช้า"); - - b.Property("CheckOutEdit") - .HasColumnType("tinyint(1)") - .HasComment("*ขอลงเวลาช่วงบ่าย"); - - b.Property("Child1DnaId") - .HasColumnType("char(36)"); - - b.Property("Child2DnaId") - .HasColumnType("char(36)"); - - b.Property("Child3DnaId") - .HasColumnType("char(36)"); - - b.Property("Child4DnaId") - .HasColumnType("char(36)"); - - b.Property("Comment") - .HasColumnType("longtext") - .HasComment("หมายเหตุในการการอนุมัติ/ไม่อนุมัติ"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("Description") - .IsRequired() - .HasColumnType("longtext") - .HasComment("*หมายเหตุขอลงเวลาพิเศษ"); - - b.Property("FirstName") - .HasColumnType("longtext"); - - b.Property("KeycloakUserId") - .HasColumnType("char(36)") - .HasComment("รหัส User ของ Keycloak ที่ร้องขอ"); - - b.Property("LastName") - .HasColumnType("longtext"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("Latitude") - .HasColumnType("double"); - - b.Property("Longitude") - .HasColumnType("double"); - - b.Property("POI") - .HasColumnType("longtext"); - - b.Property("Prefix") - .HasColumnType("longtext"); - - b.Property("RootDnaId") - .HasColumnType("char(36)"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext") - .HasComment("สถานะการอนุมัติ"); - - b.HasKey("Id"); - - b.ToTable("AdditionalCheckRequests"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.CheckInJobStatus", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("AdditionalData") - .HasColumnType("longtext") - .HasComment("ข้อมูลเพิ่มเติม (JSON)"); - - b.Property("CheckInId") - .HasColumnType("char(36)") - .HasComment("CheckInId สำหรับ Check-Out"); - - b.Property("CheckType") - .HasColumnType("longtext") - .HasComment("ประเภทการลงเวลา: CHECK_IN, CHECK_OUT"); - - b.Property("CompletedDate") - .HasColumnType("datetime(6)") - .HasComment("วันเวลาที่เสร็จสิ้นการประมวลผล"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedDate") - .HasColumnType("datetime(6)") - .HasComment("วันเวลาที่สร้างงาน"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("ErrorMessage") - .HasColumnType("longtext") - .HasComment("ข้อความแสดงข้อผิดพลาด"); - - b.Property("KeycloakUserId") - .HasColumnType("char(36)") - .HasComment("รหัส User ของ Keycloak"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("ProcessingDate") - .HasColumnType("datetime(6)") - .HasComment("วันเวลาที่เริ่มประมวลผล"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext") - .HasComment("สถานะงาน: PENDING, PROCESSING, COMPLETED, FAILED"); - - b.Property("TaskId") - .HasColumnType("char(36)") - .HasComment("Task ID สำหรับติดตามสถานะงาน"); - - b.HasKey("Id"); - - b.ToTable("CheckInJobStatuses"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.DutyTime", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("Description") - .IsRequired() - .HasColumnType("longtext") - .HasComment("คำอธิบาย"); - - b.Property("EndTimeAfternoon") - .IsRequired() - .HasColumnType("longtext") - .HasComment("เวลาออกงานช่วงบ่าย"); - - b.Property("EndTimeMorning") - .IsRequired() - .HasColumnType("longtext") - .HasComment("เวลาออกงานช่วงเช้า"); - - b.Property("IsActive") - .HasColumnType("tinyint(1)") - .HasComment("สถานะการเปิดใช้งาน (เปิด/ปิด)"); - - b.Property("IsDefault") - .HasColumnType("tinyint(1)") - .HasComment("สถานะว่ารอบใดเป็นค่า Default ของข้าราชการ (สำหรับทุกคนที่ยังไม่ได้ทำการเลือกรอบ)"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("StartTimeAfternoon") - .IsRequired() - .HasColumnType("longtext") - .HasComment("เวลาเข้างานช่วงบ่าย"); - - b.Property("StartTimeMorning") - .IsRequired() - .HasColumnType("longtext") - .HasComment("เวลาเข้างานช่วงเช้า"); - - b.HasKey("Id"); - - b.ToTable("DutyTimes"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.LeaveProcessJobStatus", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("CompletedDate") - .HasColumnType("datetime(6)") - .HasComment("วันเวลาที่เสร็จสิ้นการประมวลผล"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedDate") - .HasColumnType("datetime(6)") - .HasComment("วันเวลาที่สร้างงาน"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("EndDate") - .HasColumnType("datetime(6)") - .HasComment("วันสิ้นสุด"); - - b.Property("ErrorMessage") - .HasColumnType("longtext") - .HasComment("ข้อความแสดงข้อผิดพลาด"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("ProcessingDate") - .HasColumnType("datetime(6)") - .HasComment("วันเวลาที่เริ่มประมวลผล"); - - b.Property("RootDnaId") - .HasColumnType("char(36)") - .HasComment("รหัส Root DNA Id"); - - b.Property("StartDate") - .HasColumnType("datetime(6)") - .HasComment("วันเริ่มต้น"); - - b.Property("Status") - .IsRequired() - .HasColumnType("longtext") - .HasComment("สถานะงาน: PENDING, PROCESSING, COMPLETED, FAILED"); - - b.HasKey("Id"); - - b.ToTable("LeaveProcessJobStatuses"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.ProcessUserTimeStamp", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("CheckIn") - .HasColumnType("datetime(6)") - .HasComment("วัน เวลา เข้างาน"); - - b.Property("CheckInImageUrl") - .IsRequired() - .HasColumnType("longtext") - .HasComment("รูปถ่ายสถานที่ Check-In"); - - b.Property("CheckInLat") - .HasColumnType("double") - .HasComment("พิกัดละติจูด Check-In"); - - b.Property("CheckInLocationName") - .HasColumnType("longtext") - .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-In"); - - b.Property("CheckInLon") - .HasColumnType("double") - .HasComment("พิกัดลองจิจูด Check-In"); - - b.Property("CheckInPOI") - .IsRequired() - .HasColumnType("longtext") - .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-In"); - - b.Property("CheckInRemark") - .HasColumnType("longtext") - .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-In"); - - b.Property("CheckInStatus") - .IsRequired() - .HasColumnType("longtext") - .HasComment("สถานะ Check-In"); - - b.Property("CheckOut") - .HasColumnType("datetime(6)") - .HasComment("วัน เวลา ออกงาน"); - - b.Property("CheckOutImageUrl") - .IsRequired() - .HasColumnType("longtext") - .HasComment("รูปถ่ายสถานที่ Check-Out"); - - b.Property("CheckOutLat") - .HasColumnType("double") - .HasComment("พิกัดละติจูด Check-Out"); - - b.Property("CheckOutLocationName") - .HasColumnType("longtext") - .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-Out"); - - b.Property("CheckOutLon") - .HasColumnType("double") - .HasComment("พิกัดลองจิจูด Check-Out"); - - b.Property("CheckOutPOI") - .IsRequired() - .HasColumnType("longtext") - .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-Out"); - - b.Property("CheckOutRemark") - .HasColumnType("longtext") - .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-Out"); - - b.Property("CheckOutStatus") - .HasColumnType("longtext") - .HasComment("สถานะ Check-Out"); - - b.Property("Child1") - .HasColumnType("longtext"); - - b.Property("Child1DnaId") - .HasColumnType("char(36)"); - - b.Property("Child1Id") - .HasColumnType("char(36)"); - - b.Property("Child2") - .HasColumnType("longtext"); - - b.Property("Child2DnaId") - .HasColumnType("char(36)"); - - b.Property("Child2Id") - .HasColumnType("char(36)"); - - b.Property("Child3") - .HasColumnType("longtext"); - - b.Property("Child3DnaId") - .HasColumnType("char(36)"); - - b.Property("Child3Id") - .HasColumnType("char(36)"); - - b.Property("Child4") - .HasColumnType("longtext"); - - b.Property("Child4DnaId") - .HasColumnType("char(36)"); - - b.Property("Child4Id") - .HasColumnType("char(36)"); - - b.Property("CitizenId") - .HasColumnType("longtext"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("EditReason") - .HasColumnType("longtext") - .HasComment("เหตุผลการอนุมัติ/ไม่อนุมัติขอลงเวลาพิเศษ"); - - b.Property("EditStatus") - .HasColumnType("longtext") - .HasComment("สถานะการของลงเวลาพิเศษ"); - - b.Property("FirstName") - .HasColumnType("longtext"); - - b.Property("Gender") - .HasColumnType("longtext"); - - b.Property("IsLocationCheckIn") - .HasColumnType("tinyint(1)") - .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-In"); - - b.Property("IsLocationCheckOut") - .HasColumnType("tinyint(1)") - .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-Out"); - - b.Property("IsProcess") - .HasColumnType("tinyint(1)") - .HasComment("นำไปประมวลผลแล้วหรือยัง"); - - b.Property("KeycloakUserId") - .HasColumnType("char(36)") - .HasComment("รหัส User ของ Keycloak"); - - b.Property("LastName") - .HasColumnType("longtext"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("Prefix") - .HasColumnType("longtext"); - - b.Property("ProfileId") - .HasColumnType("char(36)"); - - b.Property("ProfileType") - .HasColumnType("longtext"); - - b.Property("Root") - .HasColumnType("longtext"); - - b.Property("RootDnaId") - .HasColumnType("char(36)"); - - b.Property("RootId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.ToTable("ProcessUserTimeStamps"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserCalendar", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("Calendar") - .IsRequired() - .HasColumnType("longtext") - .HasComment("ปฏิทินการทำงานของ ขรก ปกติ หรือ 6 วันต่อสัปดาห์"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("ProfileId") - .HasColumnType("char(36)") - .HasComment("รหัส Profile ในระบบทะเบียนประวัติ"); - - b.HasKey("Id"); - - b.ToTable("UserCalendars"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserDutyTime", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("Child1DnaId") - .HasColumnType("char(36)"); - - b.Property("Child2DnaId") - .HasColumnType("char(36)"); - - b.Property("Child3DnaId") - .HasColumnType("char(36)"); - - b.Property("Child4DnaId") - .HasColumnType("char(36)"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("DutyTimeId") - .HasColumnType("char(36)") - .HasComment("รหัสรอบการลงเวลา"); - - b.Property("EffectiveDate") - .HasColumnType("datetime(6)") - .HasComment("วันที่มีผล"); - - b.Property("IsProcess") - .HasColumnType("tinyint(1)") - .HasComment("ทำการประมวลผลแล้วหรือยัง"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("ProfileId") - .HasColumnType("char(36)") - .HasComment("รหัส Profile ในระบบทะเบียนประวัติ"); - - b.Property("Remark") - .HasColumnType("longtext") - .HasComment("หมายเหตุ"); - - b.Property("RootDnaId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.HasIndex("DutyTimeId"); - - b.ToTable("UserDutyTimes"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserTimeStamp", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("char(36)") - .HasColumnOrder(0) - .HasComment("PrimaryKey") - .HasAnnotation("Relational:JsonPropertyName", "id"); - - b.Property("CheckIn") - .HasColumnType("datetime(6)") - .HasComment("วัน เวลา เข้างาน"); - - b.Property("CheckInImageUrl") - .IsRequired() - .HasColumnType("longtext") - .HasComment("รูปถ่ายสถานที่ Check-In"); - - b.Property("CheckInLat") - .HasColumnType("double") - .HasComment("พิกัดละติจูด Check-In"); - - b.Property("CheckInLocationName") - .HasColumnType("longtext") - .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-In"); - - b.Property("CheckInLon") - .HasColumnType("double") - .HasComment("พิกัดลองจิจูด Check-In"); - - b.Property("CheckInPOI") - .IsRequired() - .HasColumnType("longtext") - .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-In"); - - b.Property("CheckInRemark") - .HasColumnType("longtext") - .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-In"); - - b.Property("CheckOut") - .HasColumnType("datetime(6)") - .HasComment("วัน เวลา ออกงาน"); - - b.Property("CheckOutImageUrl") - .IsRequired() - .HasColumnType("longtext") - .HasComment("รูปถ่ายสถานที่ Check-Out"); - - b.Property("CheckOutLat") - .HasColumnType("double") - .HasComment("พิกัดละติจูด Check-Out"); - - b.Property("CheckOutLocationName") - .HasColumnType("longtext") - .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-Out"); - - b.Property("CheckOutLon") - .HasColumnType("double") - .HasComment("พิกัดลองจิจูด Check-Out"); - - b.Property("CheckOutPOI") - .IsRequired() - .HasColumnType("longtext") - .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-Out"); - - b.Property("CheckOutRemark") - .HasColumnType("longtext") - .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-Out"); - - b.Property("Child1") - .HasColumnType("longtext"); - - b.Property("Child1DnaId") - .HasColumnType("char(36)"); - - b.Property("Child1Id") - .HasColumnType("char(36)"); - - b.Property("Child2") - .HasColumnType("longtext"); - - b.Property("Child2DnaId") - .HasColumnType("char(36)"); - - b.Property("Child2Id") - .HasColumnType("char(36)"); - - b.Property("Child3") - .HasColumnType("longtext"); - - b.Property("Child3DnaId") - .HasColumnType("char(36)"); - - b.Property("Child3Id") - .HasColumnType("char(36)"); - - b.Property("Child4") - .HasColumnType("longtext"); - - b.Property("Child4DnaId") - .HasColumnType("char(36)"); - - b.Property("Child4Id") - .HasColumnType("char(36)"); - - b.Property("CitizenId") - .HasColumnType("longtext"); - - b.Property("CreatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(100) - .HasComment("สร้างข้อมูลเมื่อ"); - - b.Property("CreatedFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(104) - .HasComment("ชื่อ User ที่สร้างข้อมูล"); - - b.Property("CreatedUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(101) - .HasComment("User Id ที่สร้างข้อมูล"); - - b.Property("FirstName") - .HasColumnType("longtext"); - - b.Property("Gender") - .HasColumnType("longtext"); - - b.Property("IsLocationCheckIn") - .HasColumnType("tinyint(1)") - .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-In"); - - b.Property("IsLocationCheckOut") - .HasColumnType("tinyint(1)") - .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-Out"); - - b.Property("IsProcess") - .HasColumnType("tinyint(1)") - .HasComment("นำไปประมวลผลแล้วหรือยัง"); - - b.Property("KeycloakUserId") - .HasColumnType("char(36)") - .HasComment("รหัส User ของ Keycloak"); - - b.Property("LastName") - .HasColumnType("longtext"); - - b.Property("LastUpdateFullName") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("varchar(200)") - .HasColumnOrder(105) - .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdateUserId") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("varchar(40)") - .HasColumnOrder(103) - .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); - - b.Property("LastUpdatedAt") - .HasColumnType("datetime(6)") - .HasColumnOrder(102) - .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); - - b.Property("Prefix") - .HasColumnType("longtext"); - - b.Property("ProfileId") - .HasColumnType("char(36)"); - - b.Property("ProfileType") - .HasColumnType("longtext"); - - b.Property("Root") - .HasColumnType("longtext"); - - b.Property("RootDnaId") - .HasColumnType("char(36)"); - - b.Property("RootId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.ToTable("UserTimeStamps"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveBeginning", b => - { - b.HasOne("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", "LeaveType") - .WithMany() - .HasForeignKey("LeaveTypeId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("LeaveType"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveDocument", b => - { - b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "Document") - .WithMany() - .HasForeignKey("DocumentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", "LeaveRequest") - .WithMany("LeaveDocument") - .HasForeignKey("LeaveRequestId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Document"); - - b.Navigation("LeaveRequest"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b => - { - b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "LeaveCancelDocument") - .WithMany() - .HasForeignKey("LeaveCancelDocumentId"); - - b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "LeaveDraftDocument") - .WithMany() - .HasForeignKey("LeaveDraftDocumentId"); - - b.HasOne("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", "Type") - .WithMany() - .HasForeignKey("TypeId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("LeaveCancelDocument"); - - b.Navigation("LeaveDraftDocument"); - - b.Navigation("Type"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequestApprover", b => - { - b.HasOne("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", "LeaveRequest") - .WithMany("Approvers") - .HasForeignKey("LeaveRequestId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("LeaveRequest"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserDutyTime", b => - { - b.HasOne("BMA.EHR.Domain.Models.Leave.TimeAttendants.DutyTime", "DutyTime") - .WithMany() - .HasForeignKey("DutyTimeId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("DutyTime"); - }); - - modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b => - { - b.Navigation("Approvers"); - - b.Navigation("LeaveDocument"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.cs b/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.cs deleted file mode 100644 index deabdd48..00000000 --- a/BMA.EHR.Infrastructure/Migrations/LeaveDb/20260619032119_Add Unique Index LeaveBeginning ProfileId Year TypeId.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace BMA.EHR.Infrastructure.Migrations.LeaveDb -{ - /// - public partial class AddUniqueIndexLeaveBeginningProfileIdYearTypeId : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateIndex( - name: "IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId", - table: "LeaveBeginnings", - columns: new[] { "ProfileId", "LeaveYear", "LeaveTypeId" }, - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId", - table: "LeaveBeginnings"); - } - } -} diff --git a/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs b/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs index 053f6d99..929783f7 100644 --- a/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs +++ b/BMA.EHR.Infrastructure/Migrations/LeaveDb/LeaveDbContextModelSnapshot.cs @@ -50,7 +50,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("Document"); + b.ToTable("Document", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", b => @@ -116,7 +116,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("LeaveTypes"); + b.ToTable("LeaveTypes", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveBeginning", b => @@ -226,11 +226,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasIndex("LeaveTypeId"); - b.HasIndex("ProfileId", "LeaveYear", "LeaveTypeId") - .IsUnique() - .HasDatabaseName("IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId"); - - b.ToTable("LeaveBeginnings"); + b.ToTable("LeaveBeginnings", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveDocument", b => @@ -292,7 +288,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasIndex("LeaveRequestId"); - b.ToTable("LeaveDocuments"); + b.ToTable("LeaveDocuments", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b => @@ -671,7 +667,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasIndex("TypeId"); - b.ToTable("LeaveRequests"); + b.ToTable("LeaveRequests", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequestApprover", b => @@ -790,7 +786,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasIndex("LeaveRequestId"); - b.ToTable("LeaveRequestApprovers"); + b.ToTable("LeaveRequestApprovers", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.AdditionalCheckRequest", b => @@ -905,7 +901,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("AdditionalCheckRequests"); + b.ToTable("AdditionalCheckRequests", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.CheckInJobStatus", b => @@ -998,7 +994,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("CheckInJobStatuses"); + b.ToTable("CheckInJobStatuses", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.DutyTime", b => @@ -1083,7 +1079,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("DutyTimes"); + b.ToTable("DutyTimes", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.LeaveProcessJobStatus", b => @@ -1168,7 +1164,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("LeaveProcessJobStatuses"); + b.ToTable("LeaveProcessJobStatuses", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.ProcessUserTimeStamp", b => @@ -1379,7 +1375,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("ProcessUserTimeStamps"); + b.ToTable("ProcessUserTimeStamps", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserCalendar", b => @@ -1440,7 +1436,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("UserCalendars"); + b.ToTable("UserCalendars", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserDutyTime", b => @@ -1529,7 +1525,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasIndex("DutyTimeId"); - b.ToTable("UserDutyTimes"); + b.ToTable("UserDutyTimes", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserTimeStamp", b => @@ -1723,7 +1719,7 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb b.HasKey("Id"); - b.ToTable("UserTimeStamps"); + b.ToTable("UserTimeStamps", (string)null); }); modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveBeginning", b => diff --git a/BMA.EHR.Infrastructure/Persistence/LeaveDbContext.cs b/BMA.EHR.Infrastructure/Persistence/LeaveDbContext.cs index 115a2ffc..10064197 100644 --- a/BMA.EHR.Infrastructure/Persistence/LeaveDbContext.cs +++ b/BMA.EHR.Infrastructure/Persistence/LeaveDbContext.cs @@ -61,18 +61,5 @@ namespace BMA.EHR.Infrastructure.Persistence { base.Entry(entity).State = EntityState.Detached; } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - - // Composite unique index on the natural key for LeaveBeginning. - // Prevents duplicate rows when concurrent requests (e.g. UI calling /user/check twice) - // race through the get-or-create flow in LeaveBeginningRepository. - modelBuilder.Entity() - .HasIndex(b => new { b.ProfileId, b.LeaveYear, b.LeaveTypeId }) - .HasDatabaseName("IX_LeaveBeginnings_ProfileId_LeaveYear_LeaveTypeId") - .IsUnique(); - } } } From 030098c0b9e90ddb95c7cd78c7ffef504225a3e7 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 19 Jun 2026 11:50:36 +0700 Subject: [PATCH 28/42] fix fiscal Year #2551 --- .../LeaveRequests/LeaveBeginingRepository.cs | 84 ++++++++++++++++++- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs index 7cf4dee7..c98ca11e 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs @@ -130,16 +130,19 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests public async Task ProcessEarlyLeaveRequest(int year) { - // Get Early Leave Request + // Get Early Leave Request (กรองตามปีงบประมาณ: 1 ต.ค. (year-1) – 30 ก.ย. (year)) + var fiscalStart = new DateTime(year - 1, 10, 1); + var fiscalEnd = new DateTime(year, 9, 30); + var leaveReq = await _dbContext.Set() .Include(x => x.Type) .Where(x => x.LeaveStatus == "APPROVE") - .Where(x => x.LeaveStartDate.Year == year || x.LeaveEndDate.Year == year) + .Where(x => x.LeaveStartDate.Date <= fiscalEnd && x.LeaveEndDate.Date >= fiscalStart) .ToListAsync(); foreach (var leave in leaveReq) { - await GetByYearAndTypeIdForUserAsync(year, leave.Type.Id, leave.KeycloakUserId); + await GetByYearAndTypeIdForUserWithUpdateAsync(year, leave.Type.Id, leave.KeycloakUserId); } } @@ -215,6 +218,81 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests return await GetOrAddForUserAsync(year, typeId, pf.Id, Factory); } + public async Task GetByYearAndTypeIdForUserWithUpdateAsync(int year, Guid typeId, Guid userId) + { + // var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + var pf = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(userId, AccessToken); + if (pf == null) + { + throw new Exception(GlobalMessages.DataNotFound); + } + + var govAge = (pf?.DateStart?.Date ?? DateTime.Now.Date).DiffDay(DateTime.Now.Date); + + var leaveType = await _dbContext.Set().FirstOrDefaultAsync(x => x.Id == typeId); + + + var limit = 0.0; + + var prev = _dbContext.Set() + .Include(x => x.LeaveType) + .FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); + + var prevRemain = 0.0; + if (prev != null) + { + prevRemain = prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0); + } + + if (govAge >= 180) + { + if (govAge >= 3650) + { + limit = 10 + prevRemain; + if (limit > 30) limit = 30; + } + else + { + limit = 10 + prevRemain; + if (limit > 20) limit = 20; + } + } + else + { + limit = 0.0; + } + + var data = await _dbContext.Set() + .Where(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == pf.Id) + .FirstOrDefaultAsync(); + + if (data != null) + { + data.LeaveDays = leaveType?.Code == "LV-005" ? limit : 0; + await _dbContext.SaveChangesAsync(); + } + + // return new LeaveBeginning + // { + // LeaveYear = year, + // LeaveTypeId = typeId, + // ProfileId = pf.Id, + // Prefix = pf.Prefix, + // FirstName = pf.FirstName, + // LastName = pf.LastName, + // LeaveDaysUsed = 0, + // LeaveDays = leaveType?.Code == "LV-005" ? limit : 0, + // RootDnaId = pf.RootDnaId, + // Child1DnaId = pf.Child1DnaId, + // Child2DnaId = pf.Child2DnaId, + // Child3DnaId = pf.Child3DnaId, + // Child4DnaId = pf.Child4DnaId + // }; + return data; + + } + + public async Task GetByYearAndTypeIdForUser(int year, Guid typeId, GetProfileByKeycloakIdDto? pf) { var govAge = (pf?.DateStart?.Date ?? DateTime.Now.Date).DiffDay(DateTime.Now.Date); From 5d090fa7bdd89fda778b9be4b23dc8b2d8f67e68 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 22 Jun 2026 10:18:21 +0700 Subject: [PATCH 29/42] #2551 --- .../LeaveRequests/LeaveBeginingRepository.cs | 9 +++- .../LeaveRequests/LeaveRequestRepository.cs | 51 ++++++++++++++++--- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs index c98ca11e..c2ba8abb 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs @@ -172,11 +172,15 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests var prev = _dbContext.Set() .Include(x => x.LeaveType) .FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); + + // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) + var isCurrentYear = DateTime.Now.Year == year; + var prevRemain = 0.0; if (prev != null) { - prevRemain = prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0); + prevRemain = isCurrentYear ? prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0) : 0.0; } if (govAge >= 180) @@ -239,6 +243,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests .FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); var prevRemain = 0.0; + + + if (prev != null) { prevRemain = prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0); diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index 3070ee88..05737cfa 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -1937,12 +1937,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests public async Task GetSumApproveLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) { + // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) + var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; + var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalEnd = new DateTime(fiscalYear, 9, 30); + var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.Type.Id == leaveTypeId) - .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate)) - //.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) + .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ?? x.CreatedAt) <= endDate)) + .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") .ToListAsync(); @@ -1954,12 +1959,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests public async Task GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) { + // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) + var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; + var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalEnd = new DateTime(fiscalYear, 9, 30); + var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.Type.Id == leaveTypeId) .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ?? x.CreatedAt) < endDate)) - //.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) + .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") .ToListAsync(); @@ -1971,12 +1981,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests public async Task GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate) { + // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) + var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; + var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalEnd = new DateTime(fiscalYear, 9, 30); + var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.ProfileId == profileId) .Where(x => x.Type.Id == leaveTypeId) .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate)) - //.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) + .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") .ToListAsync(); @@ -1988,12 +2003,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests public async Task GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate) { + // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) + var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; + var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalEnd = new DateTime(fiscalYear, 9, 30); + var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.ProfileId == profileId) .Where(x => x.Type.Id == leaveTypeId) .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate)) - //.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) + .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") .ToListAsync(); @@ -2002,12 +2022,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests public async Task GetSumApproveLeaveCountByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) { + // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) + var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; + var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalEnd = new DateTime(fiscalYear, 9, 30); + var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.Type.Id == leaveTypeId) .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate)) - //.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) + .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") .ToListAsync(); @@ -2024,13 +2049,18 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests /// public async Task GetSumDraftLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) { + // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) + var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; + var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalEnd = new DateTime(fiscalYear, 9, 30); + var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.Type.Id == leaveTypeId) .Where(x => ((x.DateSendLeave ?? x.CreatedAt).Date >= startDate && (x.DateSendLeave ?? x.CreatedAt).Date < endDate)) - //.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) + .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) .Where(x => x.LeaveStatus == "DRAFT") .ToListAsync(); @@ -2050,12 +2080,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests /// public async Task GetSumNewLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) { + // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) + var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; + var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalEnd = new DateTime(fiscalYear, 9, 30); + var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.Type.Id == leaveTypeId) .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) < endDate)) - //.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) + .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) .Where(x => (x.LeaveStatus == "NEW" || x.LeaveStatus == "PENDING")) .ToListAsync(); From fcea84bdb8bb0ea626e423ac9de3c22dcedb9f91 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 22 Jun 2026 10:54:59 +0700 Subject: [PATCH 30/42] fix fiscal start and end date #2551 --- .../Leaves/LeaveRequests/LeaveBeginingRepository.cs | 10 ++++++++-- BMA.EHR.Leave/Controllers/LeaveReportController.cs | 6 +++++- BMA.EHR.Leave/Controllers/LeaveRequestController.cs | 10 +++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs index c2ba8abb..add1361b 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveBeginingRepository.cs @@ -313,11 +313,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests var prev = _dbContext.Set() .Include(x => x.LeaveType) .FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); + + // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) + var isCurrentYear = DateTime.Now.Year == year; var prevRemain = 0.0; if (prev != null) { - prevRemain = prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0); + prevRemain = isCurrentYear ? prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0) : 0.0; } if (govAge >= 180) @@ -379,11 +382,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests var prev = _dbContext.Set() .Include(x => x.LeaveType) .FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id); + + // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) + var isCurrentYear = DateTime.Now.Year == year; var prevRemain = 0.0; if (prev != null) { - prevRemain = prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0); + prevRemain = isCurrentYear ? prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0) : 0.0; } if (govAge >= 180) diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 1b76947c..0bd07075 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -155,6 +155,10 @@ namespace BMA.EHR.Leave.Service.Controllers var lastLeaveRequest = await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync2(data.KeycloakUserId, data.Type.Id, data.CreatedAt); + + var fiscalYear = data.LeaveStartDate.Month >= 10 ? data.LeaveStartDate.Year + 1 : data.LeaveStartDate.Year; + var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalEnd = new DateTime(fiscalYear, 9, 30); var startFiscalYear = (new DateTime(data.LeaveStartDate.Year - 1, 10, 1)).Date; var endFiscalYear = (data.DateSendLeave ?? data.CreatedAt); @@ -164,7 +168,7 @@ namespace BMA.EHR.Leave.Service.Controllers if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31)) thisYear = thisYear + 1; var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId); - var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); + var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, endFiscalYear); if (leaveData != null) { sumLeave += leaveData.BeginningLeaveDays; diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index 85c19b79..c6eac2ef 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -2903,16 +2903,20 @@ namespace BMA.EHR.Leave.Service.Controllers orgName += $" {rawData.Root}"; var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, rawData.Type.Id, rawData.KeycloakUserId); + + var fiscalYear = rawData.LeaveStartDate.Month >= 10 ? rawData.LeaveStartDate.Year + 1 : rawData.LeaveStartDate.Year; + var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalEnd = new DateTime(fiscalYear, 9, 30); var startFiscalYear = new DateTime(rawData.LeaveStartDate.Year - 1, 10, 1); var endFiscalYear = rawData.DateSendLeave ?? rawData.CreatedAt; var endFiscalYear2 = new DateTime(rawData.LeaveStartDate.Year, 9, 30); //var endFiscalYear3 = rawData.DateSendLeave ?? rawData.CreatedAt; - var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, startFiscalYear, endFiscalYear); + var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, endFiscalYear); // วันลาแบบร่างและที่ยื่นลาไปแล้ว - var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, startFiscalYear, endFiscalYear2); - var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, startFiscalYear, endFiscalYear2); + var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd); + var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd); //var leaveSummary = leaveData == null ? 0.0 : leaveData.LeaveDaysUsed; if (leaveData != null) From be1f6dd84e9a63261635997135c57b8842d3a6ef Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 22 Jun 2026 11:10:29 +0700 Subject: [PATCH 31/42] #2551 --- BMA.EHR.Leave/Controllers/LeaveReportController.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 0bd07075..764ba1a5 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -338,21 +338,25 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var startFiscalYear = new DateTime(data.LeaveStartDate.Year - 1, 10, 1); - var endFiscalYear = data.CreatedAt; + var endFiscalYear = (data.DateSendLeave ?? data.CreatedAt); + + var fiscalYear = data.LeaveStartDate.Month >= 10 ? data.LeaveStartDate.Year + 1 : data.LeaveStartDate.Year; + var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalEnd = new DateTime(fiscalYear, 9, 30); var thisYear = data.LeaveStartDate.Year; var toDay = data.LeaveStartDate.Date; if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31)) thisYear = thisYear + 1; - var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId); + var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(fiscalYear, data.Type.Id, data.KeycloakUserId); //var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, rawData.Type.Id, rawData.KeycloakUserId); //var leaveSummary = leaveData == null ? 0.0 : leaveData.LeaveDaysUsed; //var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); - var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); + var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, endFiscalYear); if (leaveData != null) { sumLeave += leaveData.BeginningLeaveDays; From baf828ac854fcad6c7151326fafc900a7ee67932 Mon Sep 17 00:00:00 2001 From: harid Date: Mon, 22 Jun 2026 13:21:33 +0700 Subject: [PATCH 32/42] fix #2571 --- .../Controllers/RetirementOtherController.cs | 6 +----- BMA.EHR.Retirement.Service/Requests/OrgRequest.cs | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs index 4880f3b6..868aac4f 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs @@ -449,11 +449,7 @@ namespace BMA.EHR.Retirement.Service.Controllers retirementOther.PositionLevelOld = org.result.posLevelName; retirementOther.PositionTypeOld = org.result.posTypeName; retirementOther.PositionNumberOld = org.result.posNo; - retirementOther.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "\n") + - (org.result.child3 == null ? "" : org.result.child3 + "\n") + - (org.result.child2 == null ? "" : org.result.child2 + "\n") + - (org.result.child1 == null ? "" : org.result.child1 + "\n") + - (org.result.root == null ? "" : org.result.root); + retirementOther.OrganizationOld = org.result.org ?? ""; retirementOther.OrganizationPositionOld = org.result.position + "\n" + (retirementOther.PositionExecutiveOld == null ? "" : (retirementOther.positionExecutiveField == null ? retirementOther.PositionExecutiveOld + "\n" : retirementOther.PositionExecutiveOld + "(" + retirementOther.positionExecutiveField + ")" + "\n")) + retirementOther.OrganizationOld; diff --git a/BMA.EHR.Retirement.Service/Requests/OrgRequest.cs b/BMA.EHR.Retirement.Service/Requests/OrgRequest.cs index d68ed4a1..0dda38be 100644 --- a/BMA.EHR.Retirement.Service/Requests/OrgRequest.cs +++ b/BMA.EHR.Retirement.Service/Requests/OrgRequest.cs @@ -54,5 +54,6 @@ namespace BMA.EHR.Retirement.Service.Requests public DateTime? leaveDate { get; set; } public string? education { get; set; } public double? salary { get; set; } + public string? org { get; set; } } } \ No newline at end of file From f4f56b1c21ee9b608ec75eb87d14fef4ce40844a Mon Sep 17 00:00:00 2001 From: harid Date: Mon, 22 Jun 2026 16:36:06 +0700 Subject: [PATCH 33/42] =?UTF-8?q?api=20=E0=B8=A5=E0=B8=9A=E0=B8=82?= =?UTF-8?q?=E0=B9=89=E0=B8=AD=E0=B8=84=E0=B8=A7=E0=B8=B2=E0=B8=A1=20noti?= =?UTF-8?q?=20#1599?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MessageQueue/NotificationRepository.cs | 38 +++++++++++++++++++ .../Controllers/MessageController.cs | 25 ++++++++++++ 2 files changed, 63 insertions(+) diff --git a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs index a9d5ceb7..9a8d71e3 100644 --- a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs +++ b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs @@ -187,6 +187,44 @@ namespace BMA.EHR.Application.Repositories.MessageQueue } } + private async Task GetMyProfileIdAsync() + { + var apiUrl = $"{_configuration["API"]}/org/dotnet/get-profileId"; + var response = await GetExternalAPIAsync(apiUrl, AccessToken!, _configuration["API_KEY"]!); + + if (string.IsNullOrWhiteSpace(response)) + return string.Empty; + + var org = JsonConvert.DeserializeObject(response); + if (org == null || org.result == null) + return string.Empty; + + return org.result.profileId ?? string.Empty; + } + + public async Task DeleteAllMyNotificationsAsync() + { + try + { + var profileId = await GetMyProfileIdAsync(); + if (string.IsNullOrEmpty(profileId)) + return 0; + + var notifications = await _dbContext.Set() + .Where(x => x.ReceiverUserId == Guid.Parse(profileId)) + .Where(x => x.DeleteDate == null) + .ToListAsync(); + + _dbContext.Set().RemoveRange(notifications); + await _dbContext.SaveChangesAsync(); + return notifications.Count; + } + catch + { + throw; + } + } + public async Task PushNotificationAsync(Guid ReceiverUserId, string Subject, string Body, string Payload = "", string NotiLink = "", bool IsSendInbox = false, bool IsSendMail = false) { try diff --git a/BMA.EHR.Placement.Service/Controllers/MessageController.cs b/BMA.EHR.Placement.Service/Controllers/MessageController.cs index c4434eb1..9c8ffdfd 100644 --- a/BMA.EHR.Placement.Service/Controllers/MessageController.cs +++ b/BMA.EHR.Placement.Service/Controllers/MessageController.cs @@ -184,6 +184,31 @@ namespace BMA.EHR.Placement.Service.Controllers } } + /// + /// ลบ Notification ทั้งหมดของ user ที่ login (Hard delete) + /// + /// จำนวนรายการที่ถูกลบ + /// เมื่อทำการลบข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpDelete("my-notifications")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PermanentDeleteAllMyNotificationsAsync() + { + try + { + var affectedRows = await _notificationRepository.DeleteAllMyNotificationsAsync(); + + return Success(affectedRows); + } + catch + { + throw; + } + } + #endregion } From bc29952e836600d0ea25c966e8b055089d489509 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 22 Jun 2026 22:22:11 +0700 Subject: [PATCH 34/42] fix #2551 --- .../LeaveRequests/LeaveRequestRepository.cs | 82 ++++++------------- .../Controllers/LeaveBeginningController.cs | 4 +- .../Controllers/LeaveReportController.cs | 6 +- .../Controllers/LeaveRequestController.cs | 26 ++++-- 4 files changed, 50 insertions(+), 68 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index 05737cfa..6363e258 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -1935,19 +1935,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests return 0; } - public async Task GetSumApproveLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) + public async Task GetSumApproveLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate) { - // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) - var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; - var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); - var fiscalEnd = new DateTime(fiscalYear, 9, 30); - + // startDate/endDate คือขอบเขตปีงบประมาณ (fiscalStart/fiscalEnd) ที่ caller ส่งมา + // ใช้ LeaveStartDate เป็นหลักในการ filter เพื่อให้กรณียื่นลาล่วงหน้าข้ามปีงบประมาณ + // ถูกนับในปีงบประมาณของวันลาจริง (ไม่ใช้วันที่ยื่นลา) var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.Type.Id == leaveTypeId) - .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ?? x.CreatedAt) <= endDate)) - .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) + .Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate) + .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") .ToListAsync(); @@ -1957,19 +1955,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests return 0; } - public async Task GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) + public async Task GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate,DateTime sendLeaveDate) { - // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) - var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; - var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); - var fiscalEnd = new DateTime(fiscalYear, 9, 30); - var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.Type.Id == leaveTypeId) - .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ?? x.CreatedAt) < endDate)) - .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) + .Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate) + .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") .ToListAsync(); @@ -1979,19 +1972,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests return 0; } - public async Task GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate) + public async Task GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate,DateTime sendLeaveDate) { - // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) - var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; - var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); - var fiscalEnd = new DateTime(fiscalYear, 9, 30); - var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.ProfileId == profileId) .Where(x => x.Type.Id == leaveTypeId) - .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate)) - .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) + .Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate) + .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") .ToListAsync(); @@ -2001,38 +1989,28 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests return 0; } - public async Task GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate) + public async Task GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate) { - // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) - var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; - var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); - var fiscalEnd = new DateTime(fiscalYear, 9, 30); - var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.ProfileId == profileId) .Where(x => x.Type.Id == leaveTypeId) - .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate)) - .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) + .Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate) + .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") .ToListAsync(); return data.Count; } - public async Task GetSumApproveLeaveCountByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) + public async Task GetSumApproveLeaveCountByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate) { - // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) - var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; - var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); - var fiscalEnd = new DateTime(fiscalYear, 9, 30); - var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.Type.Id == leaveTypeId) - .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate)) - .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) + .Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate) + .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) .Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING") .ToListAsync(); @@ -2046,21 +2024,16 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests /// /// /// + /// /// - public async Task GetSumDraftLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) + public async Task GetSumDraftLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate) { - // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) - var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; - var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); - var fiscalEnd = new DateTime(fiscalYear, 9, 30); - var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.Type.Id == leaveTypeId) - .Where(x => ((x.DateSendLeave ?? x.CreatedAt).Date >= startDate - && (x.DateSendLeave ?? x.CreatedAt).Date < endDate)) - .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) + .Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate) + .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) .Where(x => x.LeaveStatus == "DRAFT") .ToListAsync(); @@ -2078,19 +2051,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests /// /// /// - public async Task GetSumNewLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) + public async Task GetSumNewLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate,DateTime sendLeaveDate) { - // คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.) - var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year; - var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); - var fiscalEnd = new DateTime(fiscalYear, 9, 30); - var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.Type.Id == leaveTypeId) - .Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) < endDate)) - .Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date) + .Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate) + .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) .Where(x => (x.LeaveStatus == "NEW" || x.LeaveStatus == "PENDING")) .ToListAsync(); diff --git a/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs b/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs index 2aa4988f..a3b0c124 100644 --- a/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs @@ -410,8 +410,8 @@ namespace BMA.EHR.Leave.Service.Controllers if (req.LeaveDaysUsed is null || req.LeaveCount is null) { - var systemLeaveDays = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(req.ProfileId, req.LeaveTypeId, startFiscalDate, endFiscalDate); - var systemLeaveCount = await _leaveRequestRepository.GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(req.ProfileId, req.LeaveTypeId, startFiscalDate, endFiscalDate); + var systemLeaveDays = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(req.ProfileId, req.LeaveTypeId, startFiscalDate, endFiscalDate,endFiscalDate.AddDays(1)); + var systemLeaveCount = await _leaveRequestRepository.GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(req.ProfileId, req.LeaveTypeId, startFiscalDate, endFiscalDate,endFiscalDate.AddDays(1)); leaveBeginning.LeaveDaysUsed = req.BeginningLeaveDays + systemLeaveDays; leaveBeginning.LeaveCount = req.BeginningLeaveCount + systemLeaveCount; diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 764ba1a5..a2d32dda 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -162,13 +162,14 @@ namespace BMA.EHR.Leave.Service.Controllers var startFiscalYear = (new DateTime(data.LeaveStartDate.Year - 1, 10, 1)).Date; var endFiscalYear = (data.DateSendLeave ?? data.CreatedAt); + var sendLeaveDate = data.DateSendLeave ?? data.CreatedAt; var thisYear = data.LeaveStartDate.Year; var toDay = data.LeaveStartDate.Date; if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31)) thisYear = thisYear + 1; var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId); - var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, endFiscalYear); + var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, endFiscalYear, sendLeaveDate); if (leaveData != null) { sumLeave += leaveData.BeginningLeaveDays; @@ -355,8 +356,9 @@ namespace BMA.EHR.Leave.Service.Controllers //var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); + var sendLeaveDate = data.DateSendLeave ?? data.CreatedAt; - var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, endFiscalYear); + var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, endFiscalYear, sendLeaveDate); if (leaveData != null) { sumLeave += leaveData.BeginningLeaveDays; diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index c6eac2ef..e5b0ecd1 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -927,9 +927,10 @@ namespace BMA.EHR.Leave.Service.Controllers // var lastSalary = profile.ProfileSalary; var leaveLast = await _leaveRequestRepository.GetLeaveLastByTypeForUserAsync(userId, req.Type); + - var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(userId, req.Type, startFiscalDate, endFiscalDate); - var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(userId, req.Type, startFiscalDate, endFiscalDate); + var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(userId, req.Type, startFiscalDate, endFiscalDate,endFiscalDate.AddDays(1)); + var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(userId, req.Type, startFiscalDate, endFiscalDate,endFiscalDate.AddDays(1)); var result = new GetUserLeaveProfileResultDto { @@ -1684,11 +1685,13 @@ namespace BMA.EHR.Leave.Service.Controllers var rawData = await _leaveRequestRepository.GetByIdAsync(id); var thisYear = DateTime.Now.Year; + if (rawData == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } + var fiscalYear = rawData.LeaveStartDate.Month >= 10 ? rawData.LeaveStartDate.Year + 1 : rawData.LeaveStartDate.Year; // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken); var profile = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(rawData.KeycloakUserId, AccessToken); @@ -1734,10 +1737,15 @@ namespace BMA.EHR.Leave.Service.Controllers var restDayOld = 0.0; //restDayOld = govAge < 180 ? 0 : leaveData == null ? 0 : (leaveData.LeaveDays + leaveData.BeginningLeaveDays - 10); + + + restDayOld = govAge < 180 ? 0 : leaveData == null ? 0 : (leaveData.LeaveDays - 10); if (restDayOld < 0) restDayOld = 0; var restDayCurrent = govAge < 180 ? 0 : 10; + if (thisYear < fiscalYear) + restDayOld = 0; var result = new GetLeaveRequestByIdDto { @@ -2903,20 +2911,22 @@ namespace BMA.EHR.Leave.Service.Controllers orgName += $" {rawData.Root}"; var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, rawData.Type.Id, rawData.KeycloakUserId); + + var currentYear = DateTime.Now.Year; var fiscalYear = rawData.LeaveStartDate.Month >= 10 ? rawData.LeaveStartDate.Year + 1 : rawData.LeaveStartDate.Year; - var fiscalStart = new DateTime(fiscalYear - 1, 10, 1); + var fiscalStart = new DateTime((fiscalYear - 1), 10, 1); var fiscalEnd = new DateTime(fiscalYear, 9, 30); var startFiscalYear = new DateTime(rawData.LeaveStartDate.Year - 1, 10, 1); - var endFiscalYear = rawData.DateSendLeave ?? rawData.CreatedAt; + var sendLeaveDate = rawData.DateSendLeave ?? rawData.CreatedAt; var endFiscalYear2 = new DateTime(rawData.LeaveStartDate.Year, 9, 30); //var endFiscalYear3 = rawData.DateSendLeave ?? rawData.CreatedAt; - var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, endFiscalYear); + var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate); // วันลาแบบร่างและที่ยื่นลาไปแล้ว - var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd); - var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd); + var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate); + var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate); //var leaveSummary = leaveData == null ? 0.0 : leaveData.LeaveDaysUsed; if (leaveData != null) @@ -2929,6 +2939,8 @@ namespace BMA.EHR.Leave.Service.Controllers { leaveLimit = leaveData == null ? 0.0 : leaveData.LeaveDays; extendLeave = leaveLimit <= 0 ? 0 : leaveLimit - 10; + if (thisYear < fiscalYear) + extendLeave = 0; } var result = new GetLeaveRequestForAdminByIdDto From a2dc4b5b826dbf93f8ceffb97a248d85d44395bf Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 22 Jun 2026 22:41:21 +0700 Subject: [PATCH 35/42] fix param fiscalEndDate #2551 --- BMA.EHR.Leave/Controllers/LeaveReportController.cs | 4 ++-- BMA.EHR.Leave/Controllers/LeaveRequestController.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index a2d32dda..11458917 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -169,7 +169,7 @@ namespace BMA.EHR.Leave.Service.Controllers if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31)) thisYear = thisYear + 1; var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId); - var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, endFiscalYear, sendLeaveDate); + var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate); if (leaveData != null) { sumLeave += leaveData.BeginningLeaveDays; @@ -358,7 +358,7 @@ namespace BMA.EHR.Leave.Service.Controllers var sendLeaveDate = data.DateSendLeave ?? data.CreatedAt; - var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, endFiscalYear, sendLeaveDate); + var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate); if (leaveData != null) { sumLeave += leaveData.BeginningLeaveDays; diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index e5b0ecd1..9b1140cd 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -2925,8 +2925,8 @@ namespace BMA.EHR.Leave.Service.Controllers var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate); // วันลาแบบร่างและที่ยื่นลาไปแล้ว - var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate); - var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, sendLeaveDate); + var leaveDraftSummary = await _leaveRequestRepository.GetSumDraftLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, fiscalEnd.AddDays(1)); + var leaveWaitingSummary = await _leaveRequestRepository.GetSumNewLeaveTotalByTypeAndRangeForUser2(rawData.KeycloakUserId, rawData.Type.Id, fiscalStart, fiscalEnd, fiscalEnd.AddDays(1)); //var leaveSummary = leaveData == null ? 0.0 : leaveData.LeaveDaysUsed; if (leaveData != null) From ae417e4777b14af640b4b740c07acf629f3d8402 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 22 Jun 2026 23:13:51 +0700 Subject: [PATCH 36/42] add API #1600 --- BMA.EHR.Leave/Controllers/LeaveController.cs | 142 ++++++++++++++++++ .../DTOs/AdditionalCheck/ApproveRequestDto.cs | 17 +++ 2 files changed, 159 insertions(+) diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index f04c00ce..7e6bad99 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -3818,6 +3818,148 @@ namespace BMA.EHR.Leave.Service.Controllers return Success(); } + + [HttpPut("admin/edit/approve-list")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> ApproveRequestListAsync([FromBody] List reqs) + { + var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_CHECKIN_SPECIAL"); + var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData["status"]?.ToString() != "200") + { + return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + } + + foreach (var req in reqs) + { + if (req.Reason == null || req.Reason == string.Empty) + { + return Error("กรุณากรอกเหตุผล", StatusCodes.Status400BadRequest); + } + + var requestData = await _additionalCheckRequestRepository.GetByIdAsync(req.RecId); + if (requestData == null) + { + return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); + } + + requestData.Status = "APPROVE"; + requestData.Comment = req.Reason; + await _additionalCheckRequestRepository.UpdateAsync(requestData); + + // change user timestamp + var processTimeStamp = await _processUserTimeStampRepository.GetTimestampByDateAsync(requestData.KeycloakUserId, requestData.CheckDate.Date); + + var profile = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(requestData.KeycloakUserId, AccessToken); + + if (processTimeStamp == null) + { + processTimeStamp = new ProcessUserTimeStamp + { + KeycloakUserId = requestData.KeycloakUserId, + CheckIn = DateTime.Parse($"{requestData.CheckDate.Date.ToString("yyyy-MM-dd")} {req.CheckInTime}"), + CheckOut = DateTime.Parse($"{requestData.CheckDate.Date.ToString("yyyy-MM-dd")} {req.CheckOutTime}"), + CheckInRemark = req.Reason, + CheckOutRemark = req.Reason, + + CheckInLat = 0, + CheckInLon = 0, + CheckOutLat = 0, + CheckOutLon = 0, + CheckInPOI = "", + CheckOutPOI = "", + CheckInStatus = req.CheckInStatus, + CheckOutStatus = req.CheckOutStatus, + + Prefix = profile.Prefix, + FirstName = profile.FirstName, + LastName = profile.LastName, + + // Add ข้อมูลจาก profile + CitizenId = profile.CitizenId, + ProfileType = profile.ProfileType, + Root = profile.Root, + RootId = profile.RootId, + Child1 = profile.Child1, + Child1Id = profile.Child1Id, + Child2 = profile.Child2, + Child2Id = profile.Child2Id, + Child3 = profile.Child3, + Child3Id = profile.Child3Id, + Child4 = profile.Child4, + Child4Id = profile.Child4Id, + Gender = profile.Gender, + ProfileId = profile.Id, + + + }; + + processTimeStamp.EditStatus = "APPROVE"; + processTimeStamp.EditReason = req.Reason; + + if (requestData.CheckInEdit) + { + processTimeStamp.CheckInPOI = requestData.POI ?? ""; + processTimeStamp.CheckInLat = requestData.Latitude ?? 0; + processTimeStamp.CheckInLon = requestData.Longitude ?? 0; + } + + if (requestData.CheckOutEdit) + { + processTimeStamp.CheckOutPOI = requestData.POI ?? ""; + processTimeStamp.CheckOutLat = requestData.Latitude ?? 0; + processTimeStamp.CheckOutLon = requestData.Longitude ?? 0; + } + + await _processUserTimeStampRepository.AddAsync(processTimeStamp); + } + else + { + if (requestData.CheckInEdit) + { + processTimeStamp.CheckIn = DateTime.Parse($"{requestData.CheckDate.Date.ToString("yyyy-MM-dd")} {req.CheckInTime}"); + processTimeStamp.CheckInRemark = req.Reason; + //processTimeStamp.CheckInLat = 0; + //processTimeStamp.CheckInLon = 0; + //processTimeStamp.CheckInPOI = "ลงเวลากรณีพิเศษ"; + processTimeStamp.CheckInStatus = req.CheckInStatus; + + processTimeStamp.CheckInPOI = requestData.POI ?? ""; + processTimeStamp.CheckInLat = requestData.Latitude ?? 0; + processTimeStamp.CheckInLon = requestData.Longitude ?? 0; + } + + if (requestData.CheckOutEdit) + { + processTimeStamp.CheckOut = DateTime.Parse($"{requestData.CheckDate.Date.ToString("yyyy-MM-dd")} {req.CheckOutTime}"); + processTimeStamp.CheckOutRemark = req.Reason; + //processTimeStamp.CheckOutLat = 0; + //processTimeStamp.CheckOutLon = 0; + //processTimeStamp.CheckOutPOI = "ลงเวลากรณีพิเศษ"; + processTimeStamp.CheckOutStatus = req.CheckOutStatus; + + processTimeStamp.CheckOutPOI = requestData.POI ?? ""; + processTimeStamp.CheckOutLat = requestData.Latitude ?? 0; + processTimeStamp.CheckOutLon = requestData.Longitude ?? 0; + } + + + processTimeStamp.EditStatus = "APPROVE"; + processTimeStamp.EditReason = req.Reason; + + await _processUserTimeStampRepository.UpdateAsync(processTimeStamp); + } + + var recvId = new List { profile.Id }; + await _notificationRepository.PushNotificationsAsync(recvId.ToArray(), "ลงเวลากรณีพิเศษ", + "การขอลงเวลากรณีพิเศษของคุณได้รับการอนุมัติ", "", "", true, false); + } + return Success(); + } + + /// /// LV1_020 - ไม่อนุมัติลงเวลากรณีพิเศษ (ADMIN) /// diff --git a/BMA.EHR.Leave/DTOs/AdditionalCheck/ApproveRequestDto.cs b/BMA.EHR.Leave/DTOs/AdditionalCheck/ApproveRequestDto.cs index 7b50313b..f40ad39a 100644 --- a/BMA.EHR.Leave/DTOs/AdditionalCheck/ApproveRequestDto.cs +++ b/BMA.EHR.Leave/DTOs/AdditionalCheck/ApproveRequestDto.cs @@ -12,4 +12,21 @@ public string Reason { get; set; } } + + public class ApproveRequestListItemDto + { + /// + /// id ของ record รายการคำขอลงเวลาพิเศษนั้นๆ + /// + public Guid RecId { get; set; } + public string CheckInTime { get; set; } + + public string CheckOutTime { get; set; } + + public string CheckInStatus { get; set; } + + public string CheckOutStatus { get; set; } + + public string Reason { get; set; } + } } From 5f678b289809e23aaa4e23585bbc5115f87f60d7 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 23 Jun 2026 11:25:42 +0700 Subject: [PATCH 37/42] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9B?= =?UTF-8?q?=E0=B8=B1=E0=B8=8D=E0=B8=AB=E0=B8=B2=20RabbitMQ=20=E0=B8=9B?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=A1=E0=B8=A7=E0=B8=A5=E0=B8=9C=E0=B8=A5?= =?UTF-8?q?=E0=B9=83=E0=B8=99=E0=B8=84=E0=B8=B4=E0=B8=A7=E0=B8=8A=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=20=E0=B9=81=E0=B8=A5=E0=B8=B0=E0=B8=A3=E0=B8=AD?= =?UTF-8?q?=E0=B8=84=E0=B8=B4=E0=B8=A7=E0=B8=99=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CHANGELOG-checkin-speedup.md | 83 +++++++++++++++++++ BMA.EHR.CheckInConsumer/Program.cs | 75 ++++++++++++----- BMA.EHR.CheckInConsumer/appsettings.json | 5 +- 3 files changed, 139 insertions(+), 24 deletions(-) create mode 100644 BMA.EHR.CheckInConsumer/CHANGELOG-checkin-speedup.md diff --git a/BMA.EHR.CheckInConsumer/CHANGELOG-checkin-speedup.md b/BMA.EHR.CheckInConsumer/CHANGELOG-checkin-speedup.md new file mode 100644 index 00000000..7b20dd1b --- /dev/null +++ b/BMA.EHR.CheckInConsumer/CHANGELOG-checkin-speedup.md @@ -0,0 +1,83 @@ +# สรุปการปรับปรุงระบบลงเวลา (CheckInConsumer) + +วันที่แก้ไข: 23 มิถุนายน 2026 + +--- + +## ปัญหาเดิม + +ตอนที่พนักงานลงเวลาพร้อมกันจำนวนมาก (ประมาณ 2,000 รายการ) ระบบประมวลผลทีละรายการ ทำให้ต้องรอคิวนานถึง **22 นาที** กว่าจะประมวลผลเสร็จทั้งหมด + +เปรียบเทียบเหมือน **โต๊ะบัญชี 1 คน รับคิวทีละคน** ทั้งที่มีคนรอ 2,000 คน → คิวยาวมาก + +--- + +## วิธีที่แก้ (เข้าใจง่าย ๆ) + +### 1. เพิ่มคนช่วยประมวลผลพร้อมกัน (Concurrency) +- **ก่อน:** ประมวลผลทีละรายการ (เหมือนมีโต๊ะบัญชี 1 โต๊ะ) +- **หลัง:** ประมวลผลพร้อมกันได้สูงสุด **5 รายการ** (เหมือนเปิดโต๊ะบัญชี 5 โต๊ะ) + +> ผลที่ได้: เวลารอคิวลดลงจาก **22 นาที → ประมาณ 4–5 นาที** + +### 2. จัดคิวล่วงหน้าให้ RabbitMQ (Prefetch) +- **ก่อน:** ระบบดึงข้อมูลมาทีละชิ้น ทำให้เสียเวลารอส่งต่อ +- **หลัง:** ระบบดึงข้อมูลมาเป็นชุด ๆ ละ 20 ชิ้นไว้เตรียมพร้อม → ลดเวลารอระหว่างรายการ + +### 3. ลดเวลารอเมื่อ API มีปัญหา (Timeout) +- **ก่อน:** ถ้า API ค้าง ระบบจะรอนานถึง **5 นาที** ต่อรายการ +- **หลัง:** ลดเหลือ **1 นาที** → รายการที่มีปัญหาจะถูกปฏิเสธเร็วขึ้น ไม่ทำให้คิวค้าง + +### 4. ปรับปรุงการเชื่อมต่อ HTTP +- เปลี่ยนระบบเชื่อมต่อให้รองรับการส่งคำขอหลายรายการพร้อมกันโดยไม่สะดุด + +--- + +## ตัวเลขเปรียบเทียบ + +| รายการ | ก่อนแก้ | หลังแก้ | +|---|---|---| +| จำนวนรายการที่ประมวลผลพร้อมกัน | 1 | 5 | +| เวลารอคิวสูงสุด (2,000 รายการ) | ~22 นาที | ~4–5 นาที | +| เวลารอเมื่อ API มีปัญหา | 5 นาที | 1 นาที | + +--- + +## ไฟล์ที่แก้ไข + +1. **`Program.cs`** — โค้ดหลักของตัวประมวลผลคิว +2. **`appsettings.json`** — ไฟล์ตั้งค่าระบบ + +--- + +## วิธีปรับความเร็วเพิ่มเติม (ไม่ต้องเขียนโค้ดใหม่) + +ถ้าหลังทดสอบแล้วเห็นว่าระบบรับได้ และอยากให้เร็วขึ้นอีก ให้แก้ไขไฟล์ `appsettings.json` แล้ว restart โปรแกรมได้เลย: + +```json +{ + "MaxConcurrency": 10, ← เพิ่มจาก 5 เป็น 10 (ประมวลผลพร้อมกัน 10 รายการ) + "PrefetchCount": 50, ← ควรตั้งเป็น ประมาณ MaxConcurrency × 2 ขึ้นไป + "HttpTimeoutSeconds": 60 ← เวลารอ API วินาที +} +``` + +**ค่าที่ใช้และผลที่คาดการณ์:** +- `MaxConcurrency = 5` → ใช้เวลา ~4–5 นาที (ค่าเริ่มต้นปลอดภัย) +- `MaxConcurrency = 10` → ใช้เวลา ~2–3 นาที +- `MaxConcurrency = 20` → ใช้เวลา ~1–2 นาที (ต้องตรวจสอบว่าระบบหลังบ้านรับไหวก่อน) + +--- + +## ข้อควรระวัง / คำแนะนำ + +1. **ควรทดสอบในระบบทดสอบก่อน** โดยดูว่า + - ไม่มี error ในระบบหลัก (API) + - ฐานข้อมูลไม่ช้าผิดปกติ + - ไม่พบปัญหาลงเวลาซ้ำซ้อน + +2. ถ้าพบปัญหา เช่น + - มี error ใน API → **ลด** `MaxConcurrency` เหลือ 2 หรือ 3 + - ลงเวลาซ้ำ → แจ้งทีมเทคนิคเพื่อแก้ฝั่ง API เพิ่มเติม + +3. **ค่า `MaxConcurrency = 5` เป็นค่าปลอดภัย** เพราะระบบ API ด้านหลังยังมีข้อจำกัดอยู่บางส่วน หากต้องการเพิ่มให้สูงกว่านี้ (เช่น 20–50) ควรปรึกษาทีมเทคนิคเพื่อปรับปรุงฝั่ง API ก่อน diff --git a/BMA.EHR.CheckInConsumer/Program.cs b/BMA.EHR.CheckInConsumer/Program.cs index 95dac001..a0ff686c 100644 --- a/BMA.EHR.CheckInConsumer/Program.cs +++ b/BMA.EHR.CheckInConsumer/Program.cs @@ -18,6 +18,13 @@ var user = configuration["Rabbit:User"] ?? ""; var pass = configuration["Rabbit:Password"] ?? ""; var queue = configuration["Rabbit:Queue"] ?? "basic-queue"; +// Concurrency & prefetch (configurable via appsettings.json) +var maxConcurrency = int.TryParse(configuration["MaxConcurrency"], out var c) && c > 0 ? c : 5; +var prefetchCount = ushort.TryParse(configuration["PrefetchCount"], out var p) && p > 0 ? p : (ushort)20; +var httpTimeoutSec = int.TryParse(configuration["HttpTimeoutSeconds"], out var t) && t > 0 ? t : 60; + +WriteToConsole($"Config -> MaxConcurrency: {maxConcurrency}, PrefetchCount: {prefetchCount}, HttpTimeout: {httpTimeoutSec}s"); + // create connection var factory = new ConnectionFactory() { @@ -32,39 +39,61 @@ using var channel = connection.CreateModel(); channel.QueueDeclare(queue: queue, durable: true, exclusive: false, autoDelete: false, arguments: null); -// Create a SINGLE static HttpClient instance to prevent socket exhaustion -using var httpClient = new HttpClient(); -httpClient.Timeout = TimeSpan.FromSeconds(300); // 5 นาที +// Prefetch: RabbitMQ จะส่ง message หลายตัวมาที่ consumer พร้อมกัน (ลด network round-trip) +channel.BasicQos(prefetchSize: 0, prefetchCount: prefetchCount, global: false); + +// HttpClient แบบ SocketsHttpHandler พร้อม connection pooling รองรับ concurrent requests +var socketsHandler = new SocketsHttpHandler +{ + MaxConnectionsPerServer = maxConcurrency * 2, + PooledConnectionLifetime = TimeSpan.FromMinutes(2), + PooledConnectionIdleTimeout = TimeSpan.FromSeconds(30) +}; +using var httpClient = new HttpClient(socketsHandler); +httpClient.Timeout = TimeSpan.FromSeconds(httpTimeoutSec); + +// SemaphoreSlim คุมจำนวน message ที่ประมวลผลพร้อมกัน (เนื่องจาก API มีข้อจำกัดเรื่อง concurrency) +using var semaphore = new SemaphoreSlim(maxConcurrency, maxConcurrency); var consumer = new AsyncEventingBasicConsumer(channel); -consumer.Received += async (model, ea) => +consumer.Received += (model, ea) => { - try + // รอ semaphore ก่อนเริ่มประมวลผล + semaphore.WaitAsync().ContinueWith(async _ => { - var body = ea.Body.ToArray(); - var message = Encoding.UTF8.GetString(body); - - WriteToConsole($"Received message: {message}"); - - var success = await CallRestApi(message, httpClient, configuration); - - if (success) + try { - channel.BasicAck(ea.DeliveryTag, multiple: false); - WriteToConsole("Message processed successfully"); + var body = ea.Body.ToArray(); + var message = Encoding.UTF8.GetString(body); + + WriteToConsole($"Received message: {message}"); + + var success = await CallRestApi(message, httpClient, configuration); + + if (success) + { + channel.BasicAck(ea.DeliveryTag, multiple: false); + WriteToConsole("Message processed successfully"); + } + else + { + channel.BasicNack(ea.DeliveryTag, multiple: false, requeue: false); + WriteToConsole("Message processing failed - message rejected"); + } } - else + catch (Exception ex) { + WriteToConsole($"Error processing message: {ex.Message}"); channel.BasicNack(ea.DeliveryTag, multiple: false, requeue: false); - WriteToConsole("Message processing failed - message rejected"); } - } - catch (Exception ex) - { - WriteToConsole($"Error processing message: {ex.Message}"); - channel.BasicNack(ea.DeliveryTag, multiple: false, requeue: false); - } + finally + { + semaphore.Release(); + } + }, TaskScheduler.Default).ConfigureAwait(false); + + return Task.CompletedTask; }; channel.BasicConsume(queue: queue, autoAck: false, consumer: consumer); diff --git a/BMA.EHR.CheckInConsumer/appsettings.json b/BMA.EHR.CheckInConsumer/appsettings.json index 76f86c86..1fbba85b 100644 --- a/BMA.EHR.CheckInConsumer/appsettings.json +++ b/BMA.EHR.CheckInConsumer/appsettings.json @@ -5,5 +5,8 @@ "Password": "12345678", "Queue": "hrms-checkin-queue-dev" }, - "API": "https://localhost:7283/api/v1" + "API": "https://localhost:7283/api/v1", + "MaxConcurrency": 5, + "PrefetchCount": 20, + "HttpTimeoutSeconds": 60 } From 65ca175f980820fa1d56f7a8fcf5e73a3875a195 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 23 Jun 2026 11:38:40 +0700 Subject: [PATCH 38/42] fix Dockerfile --- BMA.EHR.CheckInConsumer/.dockerignore | 24 ++++++++++++++++++++++++ BMA.EHR.CheckInConsumer/Dockerfile | 22 ++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 BMA.EHR.CheckInConsumer/.dockerignore diff --git a/BMA.EHR.CheckInConsumer/.dockerignore b/BMA.EHR.CheckInConsumer/.dockerignore new file mode 100644 index 00000000..741ce7d4 --- /dev/null +++ b/BMA.EHR.CheckInConsumer/.dockerignore @@ -0,0 +1,24 @@ +# Build artifacts +bin/ +obj/ + +# IDE / tooling +Properties/ +.vs/ +.vscode/ +.idea/ + +# Source control +.git/ +.gitignore + +# Documentation +*.md + +# Docker +Dockerfile +.dockerignore + +# OS files +.DS_Store +Thumbs.db diff --git a/BMA.EHR.CheckInConsumer/Dockerfile b/BMA.EHR.CheckInConsumer/Dockerfile index 1c90d6f2..314f1b71 100644 --- a/BMA.EHR.CheckInConsumer/Dockerfile +++ b/BMA.EHR.CheckInConsumer/Dockerfile @@ -1,4 +1,4 @@ -## See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. +## See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. # ## This stage is used when running from VS in fast mode (Default for Debug configuration) #FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base @@ -34,25 +34,19 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build # กำหนด working directory ภายใน container WORKDIR /src -# คัดลอกไฟล์ .csproj และ restore dependencies -# COPY *.csproj ./ -COPY . ./ -RUN dotnet restore +# copy เฉพาะ .csproj ก่อน เพื่อใช้ layer caching (restore เร็ว เก็บ cache นาน) +COPY BMA.EHR.CheckInConsumer.csproj ./ +RUN dotnet restore "BMA.EHR.CheckInConsumer.csproj" -# คัดลอกไฟล์ทั้งหมดและ build +# คัดลอก source ที่เหลือแล้ว publish COPY . ./ -RUN dotnet build -c Release -o /app/build -# WORKDIR "/src/BMA.EHR.CheckInConsumer" -# RUN dotnet build "BMA.EHR.CheckInConsumer.csproj" -c Release -o /app/build +RUN dotnet publish "BMA.EHR.CheckInConsumer.csproj" -c Release -o /app/publish /p:UseAppHost=false -# ใช้ stage ใหม่สำหรับการ runtime +# ใช้ stage ใหม่สำหรับ runtime (image เล็กลง) FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime -# กำหนด working directory สำหรับ runtime WORKDIR /app -# คัดลอกไฟล์จาก build stage มายัง runtime stage -COPY --from=build /app/build . +COPY --from=build /app/publish . -# ระบุ entry point ของแอปพลิเคชัน ENTRYPOINT ["dotnet", "BMA.EHR.CheckInConsumer.dll"] From f6c8b4f754ac54e34ad7ce0cbbb5d6fe44dc1b9c Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 23 Jun 2026 11:45:28 +0700 Subject: [PATCH 39/42] Change Dockerfile --- BMA.EHR.CheckInConsumer/Dockerfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/BMA.EHR.CheckInConsumer/Dockerfile b/BMA.EHR.CheckInConsumer/Dockerfile index 314f1b71..81c430d9 100644 --- a/BMA.EHR.CheckInConsumer/Dockerfile +++ b/BMA.EHR.CheckInConsumer/Dockerfile @@ -21,6 +21,7 @@ #ARG BUILD_CONFIGURATION=Release #RUN dotnet publish "BMA.EHR.CheckInConsumer.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false # + ## This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) #FROM base AS final #WORKDIR /app @@ -29,17 +30,18 @@ # ใช้ official .NET SDK image สำหรับการ build +# Note: Build context = repository root (ตามที่ GitHub Actions ใช้) FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build -# กำหนด working directory ภายใน container WORKDIR /src # copy เฉพาะ .csproj ก่อน เพื่อใช้ layer caching (restore เร็ว เก็บ cache นาน) -COPY BMA.EHR.CheckInConsumer.csproj ./ +COPY BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj ./BMA.EHR.CheckInConsumer/ +WORKDIR /src/BMA.EHR.CheckInConsumer RUN dotnet restore "BMA.EHR.CheckInConsumer.csproj" # คัดลอก source ที่เหลือแล้ว publish -COPY . ./ +COPY BMA.EHR.CheckInConsumer/ ./ RUN dotnet publish "BMA.EHR.CheckInConsumer.csproj" -c Release -o /app/publish /p:UseAppHost=false # ใช้ stage ใหม่สำหรับ runtime (image เล็กลง) From bf5dc2cf190533b31556e47491022cc0c8820a49 Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 23 Jun 2026 18:24:30 +0700 Subject: [PATCH 40/42] =?UTF-8?q?=E0=B9=80=E0=B8=81=E0=B9=87=E0=B8=9A=20la?= =?UTF-8?q?stUpdate=20=E0=B8=AB=E0=B8=B2=E0=B8=81=E0=B8=A1=E0=B8=B5?= =?UTF-8?q?=E0=B9=80=E0=B8=8A=E0=B9=87=E0=B8=84=E0=B8=AD=E0=B8=AD=E0=B8=81?= =?UTF-8?q?=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=A2?= =?UTF-8?q?=E0=B9=89=E0=B8=AD=E0=B8=99=E0=B8=AB=E0=B8=A5=E0=B8=B1=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlacementAppointmentController.cs | 48 ++++++++++++++++--- .../Controllers/PlacementController.cs | 30 ++++++++++-- .../Controllers/PlacementOfficerController.cs | 3 ++ .../Controllers/PlacementReceiveController.cs | 8 +++- .../PlacementRepatriationController.cs | 8 +++- .../PlacementTransferController.cs | 8 +++- 6 files changed, 93 insertions(+), 12 deletions(-) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs index 50114759..a8d91874 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs @@ -1062,7 +1062,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -1286,7 +1292,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -1494,7 +1506,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -1707,7 +1725,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -1943,7 +1967,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -2114,7 +2144,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index 9557ae00..1e1d5417 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -2035,6 +2035,9 @@ namespace BMA.EHR.Placement.Service.Controllers placementProfile.ForEach(profile => { profile.PlacementStatus = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; if (req.refIds.Length > 0) { profile.commandId = req.refIds[0].commandId; @@ -2441,6 +2444,9 @@ namespace BMA.EHR.Placement.Service.Controllers placementProfile.ForEach(profile => { profile.PlacementStatus = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; if (req.refIds.Length > 0) { profile.commandId = req.refIds[0].commandId; @@ -2710,7 +2716,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.PlacementStatus = "DONE"); + data.ForEach(profile => + { + profile.PlacementStatus = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -2960,7 +2972,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.PlacementStatus = "DONE"); + data.ForEach(profile => + { + profile.PlacementStatus = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -3193,7 +3211,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.PlacementStatus = "DONE"); + data.ForEach(profile => + { + profile.PlacementStatus = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs index 8fcb51cf..7c26a018 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs @@ -832,6 +832,9 @@ namespace BMA.EHR.Placement.Service.Controllers { profile.Status = "DONE"; profile.commandNo = commandNoText; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; }); await _context.SaveChangesAsync(); diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs index 32f91eae..262d86bd 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs @@ -1306,7 +1306,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); Console.WriteLine($"[ReceiveReportExcecute] Saving changes to database for {data.Count} profiles"); await _context.SaveChangesAsync(); Console.WriteLine($"[ReceiveReportExcecute] Process completed successfully at {DateTime.Now}"); diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs index b56fc804..97e1e406 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs @@ -686,7 +686,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs index 73741918..843fa25a 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs @@ -1212,7 +1212,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = DateTime.Now; + }); // Return resultData for Node to process directly (Linear Flow) return Success(resultData); From 5021c00dd3a75ef5304c85332aaf3cb80147629a Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 24 Jun 2026 16:20:49 +0700 Subject: [PATCH 41/42] =?UTF-8?q?=E0=B9=80=E0=B8=81=E0=B9=87=E0=B8=9A=20la?= =?UTF-8?q?stUpdate=20=E0=B8=AB=E0=B8=B2=E0=B8=81=E0=B8=A1=E0=B8=B5?= =?UTF-8?q?=E0=B9=80=E0=B8=8A=E0=B9=87=E0=B8=84=E0=B8=AD=E0=B8=AD=E0=B8=81?= =?UTF-8?q?=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=A2?= =?UTF-8?q?=E0=B9=89=E0=B8=AD=E0=B8=99=E0=B8=AB=E0=B8=A5=E0=B8=B1=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlacementAppointmentController.cs | 18 ++++++++----- .../Controllers/PlacementController.cs | 15 +++++++---- .../Controllers/PlacementOfficerController.cs | 3 ++- .../Controllers/PlacementReceiveController.cs | 3 ++- .../PlacementRepatriationController.cs | 3 ++- .../PlacementTransferController.cs | 3 ++- .../Controllers/RetirementOtherController.cs | 18 +++++++++++-- .../Controllers/RetirementOutController.cs | 9 ++++++- .../Controllers/RetirementResignController.cs | 27 ++++++++++++++++--- .../RetirementResignEmployeeController.cs | 18 +++++++++++-- 10 files changed, 94 insertions(+), 23 deletions(-) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs index a8d91874..c7cbf249 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs @@ -1062,12 +1062,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.Status = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); @@ -1292,12 +1293,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.Status = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); @@ -1506,12 +1508,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.Status = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); @@ -1725,12 +1728,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.Status = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); @@ -1967,12 +1971,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.Status = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); @@ -2144,12 +2149,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.Status = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index 1e1d5417..af1d954e 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -2032,12 +2032,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow + var now = DateTime.Now; placementProfile.ForEach(profile => { profile.PlacementStatus = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; if (req.refIds.Length > 0) { profile.commandId = req.refIds[0].commandId; @@ -2441,12 +2442,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow + var now = DateTime.Now; placementProfile.ForEach(profile => { profile.PlacementStatus = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; if (req.refIds.Length > 0) { profile.commandId = req.refIds[0].commandId; @@ -2716,12 +2718,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.PlacementStatus = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); @@ -2972,12 +2975,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.PlacementStatus = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); @@ -3211,12 +3215,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.PlacementStatus = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs index 7c26a018..29d38df5 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs @@ -828,13 +828,14 @@ namespace BMA.EHR.Placement.Service.Controllers // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ var firstRef = req.refIds.FirstOrDefault(); var commandNoText = firstRef != null ? $"{firstRef.commandNo}/{firstRef.commandYear.ToThaiYear()}" : null; + var now = DateTime.Now; data.ForEach(profile => { profile.Status = "DONE"; profile.commandNo = commandNoText; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs index 262d86bd..31db814b 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs @@ -1306,12 +1306,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow + var now = DateTime.Now; data.ForEach(profile => { profile.Status = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); Console.WriteLine($"[ReceiveReportExcecute] Saving changes to database for {data.Count} profiles"); await _context.SaveChangesAsync(); diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs index 97e1e406..2cc8536d 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs @@ -686,12 +686,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.Status = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); await _context.SaveChangesAsync(); diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs index 843fa25a..a165be68 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs @@ -1212,12 +1212,13 @@ namespace BMA.EHR.Placement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + var now = DateTime.Now; data.ForEach(profile => { profile.Status = "DONE"; profile.LastUpdateFullName = FullName ?? "System Administrator"; profile.LastUpdateUserId = UserId ?? ""; - profile.LastUpdatedAt = DateTime.Now; + profile.LastUpdatedAt = now; }); // Return resultData for Node to process directly (Linear Flow) diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs index 868aac4f..b1580cf5 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs @@ -926,7 +926,14 @@ namespace BMA.EHR.Retirement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + var now = DateTime.Now; + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -1183,7 +1190,14 @@ namespace BMA.EHR.Retirement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + var now = DateTime.Now; + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs index ae528316..003166f9 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs @@ -712,7 +712,14 @@ namespace BMA.EHR.Retirement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + var now = DateTime.Now; + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index 1b434380..019451c5 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -2972,7 +2972,14 @@ namespace BMA.EHR.Retirement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + var now = DateTime.Now; + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -3164,7 +3171,14 @@ namespace BMA.EHR.Retirement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + var now = DateTime.Now; + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -3399,7 +3413,14 @@ namespace BMA.EHR.Retirement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + var now = DateTime.Now; + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); data.ForEach(profile => profile.RetirementResign.Status = "CANCEL"); await _context.SaveChangesAsync(); diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs index 4449099b..dd0d850b 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignEmployeeController.cs @@ -2468,7 +2468,14 @@ namespace BMA.EHR.Retirement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + var now = DateTime.Now; + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); await _context.SaveChangesAsync(); // Return resultData for Node to process directly (Linear Flow) @@ -2700,7 +2707,14 @@ namespace BMA.EHR.Retirement.Service.Controllers #endregion // New: Linear Flow - Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); + var now = DateTime.Now; + data.ForEach(profile => + { + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); data.ForEach(profile => profile.RetirementResignEmployee.Status = "CANCEL"); await _context.SaveChangesAsync(); From a2fe424b87e2c04ea399c73b41ca4c7585360a35 Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 26 Jun 2026 16:38:41 +0700 Subject: [PATCH 42/42] Linear Flow (DisciplineService) #224 --- .../Controllers/DisciplineResultController.cs | 751 +++++++++++------- .../PlacementAppointmentController.cs | 2 +- .../Controllers/RetirementOutController.cs | 2 +- 3 files changed, 472 insertions(+), 283 deletions(-) diff --git a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs index 35a9dfa2..f6697c2e 100644 --- a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs +++ b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs @@ -1028,10 +1028,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => { profile.Status = "REPORTED"; profile.CommandTypeId = null; }); - await _context.SaveChangesAsync(); - var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId @@ -1067,52 +1063,95 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // // คำสั่งไล่ออก หรือ ปลดออก Status หลังออกคำสั่งใช้ "REPORTED" เพื่อไม่ให้ส่งรายชื่อไปออกคำสั่งซ้ำได้ + // data.ForEach(profile => { profile.Status = "REPORTED"; profile.CommandTypeId = null; }); + // var _profile = new List(); + // DateTime _date = DateTime.Now; + // foreach (var item in data) + // { + // _profile.Add(new ProfileComplaintInvestigate + // { + // PersonId = item.PersonId, + // Prefix = item.Prefix, + // FirstName = item.FirstName, + // LastName = item.LastName, + // CitizenId = item.CitizenId, + // rootDnaId = item.rootDnaId, + // child1DnaId = item.child1DnaId, + // child2DnaId = item.child2DnaId, + // child3DnaId = item.child3DnaId, + // child4DnaId = item.child4DnaId, + // profileType = item.profileType, + // commandType = "C-PM-19", + // CreatedAt = _date, + // CreatedUserId = UserId, + // CreatedFullName = FullName, + // LastUpdatedAt = _date, + // LastUpdateUserId = UserId, + // LastUpdateFullName = FullName, + // }); + // } + // _context.ProfileComplaintInvestigate.AddRange(_profile); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow + var now = DateTime.Now; + data.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new + profile.Status = "REPORTED"; + profile.CommandTypeId = null; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + + var _profile = new List(); + foreach (var item in data) + { + _profile.Add(new ProfileComplaintInvestigate { - data = resultData, + PersonId = item.PersonId, + Prefix = item.Prefix, + FirstName = item.FirstName, + LastName = item.LastName, + CitizenId = item.CitizenId, + rootDnaId = item.rootDnaId, + child1DnaId = item.child1DnaId, + child2DnaId = item.child2DnaId, + child3DnaId = item.child3DnaId, + child4DnaId = item.child4DnaId, + profileType = item.profileType, + commandType = "C-PM-19", + CreatedAt = now, + CreatedUserId = UserId ?? "", + CreatedFullName = FullName ?? "System Administrator", + LastUpdatedAt = now, + LastUpdateUserId = UserId ?? "", + LastUpdateFullName = FullName ?? "System Administrator", }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - //// คำสั่งไล่ออก หรือ ปลดออก Status หลังออกคำสั่งใช้ "REPORTED" เพื่อไม่ให้ส่งรายชื่อไปออกคำสั่งซ้ำได้ - // data.ForEach(profile => { profile.Status = "REPORTED"; profile.CommandTypeId = null; }); - var _profile = new List(); - DateTime _date = DateTime.Now; - foreach (var item in data) - { - _profile.Add(new ProfileComplaintInvestigate - { - PersonId = item.PersonId, - Prefix = item.Prefix, - FirstName = item.FirstName, - LastName = item.LastName, - CitizenId = item.CitizenId, - rootDnaId = item.rootDnaId, - child1DnaId = item.child1DnaId, - child2DnaId = item.child2DnaId, - child3DnaId = item.child3DnaId, - child4DnaId = item.child4DnaId, - profileType = item.profileType, - commandType = "C-PM-19", - CreatedAt = _date, - CreatedUserId = UserId, - CreatedFullName = FullName, - LastUpdatedAt = _date, - LastUpdateUserId = UserId, - LastUpdateFullName = FullName, - }); - } - _context.ProfileComplaintInvestigate.AddRange(_profile); - await _context.SaveChangesAsync(); - } } - return Success(); + _context.ProfileComplaintInvestigate.AddRange(_profile); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1184,10 +1223,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => { profile.Status = "REPORTED"; profile.CommandTypeId = null; }); - await _context.SaveChangesAsync(); - var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId @@ -1223,52 +1258,95 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // // คำสั่งไล่ออก หรือ ปลดออก Status หลังออกคำสั่งใช้ "REPORTED" เพื่อไม่ให้ส่งรายชื่อไปออกคำสั่งซ้ำได้ + // data.ForEach(profile => { profile.Status = "REPORTED"; profile.CommandTypeId = null; }); + // var _profile = new List(); + // DateTime _date = DateTime.Now; + // foreach (var item in data) + // { + // _profile.Add(new ProfileComplaintInvestigate + // { + // PersonId = item.PersonId, + // Prefix = item.Prefix, + // FirstName = item.FirstName, + // LastName = item.LastName, + // CitizenId = item.CitizenId, + // rootDnaId = item.rootDnaId, + // child1DnaId = item.child1DnaId, + // child2DnaId = item.child2DnaId, + // child3DnaId = item.child3DnaId, + // child4DnaId = item.child4DnaId, + // profileType = item.profileType, + // commandType = "C-PM-20", + // CreatedAt = _date, + // CreatedUserId = UserId, + // CreatedFullName = FullName, + // LastUpdatedAt = _date, + // LastUpdateUserId = UserId, + // LastUpdateFullName = FullName, + // }); + // } + // _context.ProfileComplaintInvestigate.AddRange(_profile); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow + var now = DateTime.Now; + data.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new + profile.Status = "REPORTED"; + profile.CommandTypeId = null; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + + var _profile = new List(); + foreach (var item in data) + { + _profile.Add(new ProfileComplaintInvestigate { - data = resultData, + PersonId = item.PersonId, + Prefix = item.Prefix, + FirstName = item.FirstName, + LastName = item.LastName, + CitizenId = item.CitizenId, + rootDnaId = item.rootDnaId, + child1DnaId = item.child1DnaId, + child2DnaId = item.child2DnaId, + child3DnaId = item.child3DnaId, + child4DnaId = item.child4DnaId, + profileType = item.profileType, + commandType = "C-PM-20", + CreatedAt = now, + CreatedUserId = UserId ?? "", + CreatedFullName = FullName ?? "System Administrator", + LastUpdatedAt = now, + LastUpdateUserId = UserId ?? "", + LastUpdateFullName = FullName ?? "System Administrator", }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - //// คำสั่งไล่ออก หรือ ปลดออก Status หลังออกคำสั่งใช้ "REPORTED" เพื่อไม่ให้ส่งรายชื่อไปออกคำสั่งซ้ำได้ - // data.ForEach(profile => { profile.Status = "REPORTED"; profile.CommandTypeId = null; }); - var _profile = new List(); - DateTime _date = DateTime.Now; - foreach (var item in data) - { - _profile.Add(new ProfileComplaintInvestigate - { - PersonId = item.PersonId, - Prefix = item.Prefix, - FirstName = item.FirstName, - LastName = item.LastName, - CitizenId = item.CitizenId, - rootDnaId = item.rootDnaId, - child1DnaId = item.child1DnaId, - child2DnaId = item.child2DnaId, - child3DnaId = item.child3DnaId, - child4DnaId = item.child4DnaId, - profileType = item.profileType, - commandType = "C-PM-20", - CreatedAt = _date, - CreatedUserId = UserId, - CreatedFullName = FullName, - LastUpdatedAt = _date, - LastUpdateUserId = UserId, - LastUpdateFullName = FullName, - }); - } - _context.ProfileComplaintInvestigate.AddRange(_profile); - await _context.SaveChangesAsync(); - } } - return Success(); + _context.ProfileComplaintInvestigate.AddRange(_profile); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1418,10 +1496,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId @@ -1457,24 +1531,39 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => profile.Status = "DONE"); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow + var now = DateTime.Now; + data.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => profile.Status = "DONE"); - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1562,10 +1651,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.Status = "DONE"); - await _context.SaveChangesAsync(); - var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId @@ -1601,24 +1686,39 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => profile.Status = "DONE"); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow + var now = DateTime.Now; + data.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => profile.Status = "DONE"); - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + profile.Status = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1704,10 +1804,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); - await _context.SaveChangesAsync(); - string? _null = null; var resultData = (from p in data join r in req.refIds @@ -1743,24 +1839,40 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow + var now = DateTime.Now; + data.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1846,10 +1958,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); - await _context.SaveChangesAsync(); - string? _null = null; var resultData = (from p in data join r in req.refIds @@ -1885,24 +1993,40 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow + var now = DateTime.Now; + data.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -1988,10 +2112,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); - await _context.SaveChangesAsync(); - string? _null = null; var resultData = (from p in data join r in req.refIds @@ -2027,24 +2147,40 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow + var now = DateTime.Now; + data.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -2130,10 +2266,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); - await _context.SaveChangesAsync(); - string? _null = null; var resultData = (from p in data join r in req.refIds @@ -2169,24 +2301,40 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow + var now = DateTime.Now; + data.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -2272,10 +2420,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); - await _context.SaveChangesAsync(); - string? _null = null; var resultData = (from p in data join r in req.refIds @@ -2311,24 +2455,40 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow + var now = DateTime.Now; + data.ForEach(profile => { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); - //// await _context.SaveChangesAsync(); - //// } - } - return Success(); + profile.Status = "NEW"; + profile.CommandTypeId = null; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + return Success(resultData); } /// @@ -2424,15 +2584,21 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers [HttpPost("command32/report/excecute")] public async Task> PostReportCommand32Execute([FromBody] ReportExecuteRequest req) { + // C-PM-32 (คำสั่งยุติเรื่อง) ต้องยุติงานใน 2 track ที่เก็บอยู่คนละตาราง: + // - data / resultData = ฝั่ง "การสอบสวน" (DisciplineInvestigate_ProfileComplaint) + // - data1 / resultData1 = ฝั่ง "การพิจารณาลงโทษ" (DisciplineDisciplinary_ProfileComplaintInvestigate) + // บุคคลเดียวกัน (profileId เดียวกัน) อาจอยู่ในทั้ง 2 track จึงต้องส่งให้ org แยก 2 ครั้ง (ห้าม merge รวมครั้งเดียว) var data = await _context.DisciplineInvestigate_ProfileComplaints .Include(x => x.DisciplineInvestigate) // .Where(x => x.IsReport == "REPORT") .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); - // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ - data.ForEach(profile => profile.IsReport = "DONE"); - await _context.SaveChangesAsync(); + var data1 = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + // .Where(x => x.IsReport == "REPORT") + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); string? _null = null; var resultData = (from p in data @@ -2469,29 +2635,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - //// var _result = await _res.Content.ReadAsStringAsync(); - //// if (_res.IsSuccessStatusCode) - //// { - //// data.ForEach(profile => profile.IsReport = "DONE"); - //// await _context.SaveChangesAsync(); - //// } - } - - var data1 = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates - .Include(x => x.DisciplineDisciplinary) - // .Where(x => x.IsReport == "REPORT") - .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) - .ToListAsync(); var resultData1 = (from p in data1 join r in req.refIds on p.Id.ToString() equals r.refId @@ -2525,23 +2668,69 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers posNo = p.posMasterNo != null ? p.posMasterNo.ToString() : null, posNoAbb = p.child4ShortName != null ? p.child4ShortName : (p.child3ShortName != null ? p.child3ShortName : (p.child2ShortName != null ? p.child2ShortName : (p.child1ShortName != null ? p.child1ShortName : (p.rootShortName != null ? p.rootShortName : "")))), }).ToList(); - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData1, - }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - data1.ForEach(profile => profile.IsReport = "DONE"); - await _context.SaveChangesAsync(); - } - } - return Success(); + #region Old: Circular Flow + // var baseAPIOrg = _configuration["API"]; + // var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data.ForEach(profile => profile.IsReport = "DONE"); + // await _context.SaveChangesAsync(); + // } + // } + // using (var client = new HttpClient()) + // { + // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + // client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); + // var _res = await client.PostAsJsonAsync(apiUrlOrg, new + // { + // data = resultData1, + // }); + // var _result = await _res.Content.ReadAsStringAsync(); + // if (_res.IsSuccessStatusCode) + // { + // data1.ForEach(profile => profile.IsReport = "DONE"); + // await _context.SaveChangesAsync(); + // } + // } + #endregion + + // New: Linear Flow + var now = DateTime.Now; + data.ForEach(profile => + { + profile.IsReport = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + data1.ForEach(profile => + { + profile.IsReport = "DONE"; + profile.LastUpdateFullName = FullName ?? "System Administrator"; + profile.LastUpdateUserId = UserId ?? ""; + profile.LastUpdatedAt = now; + }); + await _context.SaveChangesAsync(); + + // Return resultData for Node to process directly (Linear Flow) + // + // NOTE สำหรับฝั่ง Node (C-PM-32 เท่านั้น): + // - response.result เป็น object { data, data1 } (ไม่ใช่ array เหมือนคำสั่งอื่น) + // data = รายการฝั่ง "การสอบสวน" → ยิง POST {API}/org/command/excexute/salary-leave-discipline ครั้งที่ 1 + // data1 = รายการฝั่ง "การพิจารณาลงโทษ" → ยิง POST {API}/org/command/excexute/salary-leave-discipline ครั้งที่ 2 + // - ต้องยิง 2 ครั้งตามลำดับ data ก่อน → data1 (ห้าม merge รวมในครั้งเดียว เพราะ profileId อาจซ้ำข้าม 2 track) + // - คำสั่งอื่น (C-PM-19/20/25/26/27/28/29/30/31) response.result เป็น array → ยิง org 1 ครั้ง + return Success(new { data = resultData, data1 = resultData1 }); } /// diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs index c7cbf249..fe2b519a 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs @@ -2074,7 +2074,7 @@ namespace BMA.EHR.Placement.Service.Controllers } /// - /// ออกคำสั่ง C-PM-47 + /// ออกคำสั่ง C-PM-47 โปรดเกล้าฯ แต่งตั้งให้ดำรงตำแหน่ง /// /// /// diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs index 003166f9..4ef0e395 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs @@ -629,7 +629,7 @@ namespace BMA.EHR.Retirement.Service.Controllers } /// - /// ออกคำสั่ง C-PM-18 คำสั่งให้ออกจากราชการ + /// ออกคำสั่ง C-PM-18 ให้ออกจากราชการ && C-PM-43 ให้ลูกจ้างออกจากราชการ /// /// ///