From baf828ac854fcad6c7151326fafc900a7ee67932 Mon Sep 17 00:00:00 2001 From: harid Date: Mon, 22 Jun 2026 13:21:33 +0700 Subject: [PATCH 01/11] 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 02/11] =?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 03/11] 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 04/11] 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 05/11] 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 06/11] =?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 07/11] 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 08/11] 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 09/11] =?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 10/11] =?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 11/11] 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 ให้ลูกจ้างออกจากราชการ /// /// ///