From e80f89117ce3b6fa36636e78a459e318e030dced Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 29 Jan 2026 13:22:41 +0700 Subject: [PATCH] Change Call Org --- .../LeaveRequests/LeaveRequestRepository.cs | 3 +- .../AdditionalCheckRequestRepository.cs | 3 +- .../Repositories/UserProfileRepository.cs | 23 +++++ .../DisciplineDirectorController.cs | 2 +- .../Controllers/LeaveRequestController.cs | 99 ++++++++++++------- 5 files changed, 93 insertions(+), 37 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index e0e519e8..57572c33 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -253,7 +253,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests public async Task> GetLeaveRequestByYearAsync(int year, Guid userId) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(userId, AccessToken); if (profile == null) { diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs index 64e1e745..3dca61e1 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs @@ -74,7 +74,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants await base.AddAsync(entity); var userId = UserId != null ? Guid.Parse(UserId) : Guid.Empty; - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken ?? ""); + // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken ?? ""); + var profile = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(userId, AccessToken ?? ""); // fix issue : SIT ระบบบันทึกเวลาปฏิบัติงาน>>ลงเวลากรณีพิเศษ (ไม่มีแจ้งเตือนไปยังผู้บังคับบัญชา) #969 // send noti + inbox + mail diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index b868a4e9..ebf5113f 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -209,6 +209,29 @@ namespace BMA.EHR.Application.Repositories } } + public async Task GetProfileByKeycloakIdNew2Async(Guid keycloakId, string? accessToken) + { + try + { + var apiPath = $"{_configuration["API"]}/org/dotnet/by-keycloak2/{keycloakId}"; + var apiKey = _configuration["API_KEY"]; + + var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey); + if (apiResult != null) + { + var raw = JsonConvert.DeserializeObject(apiResult); + if (raw != null) + return raw.Result; + } + + return null; + } + catch + { + throw; + } + } + public async Task GetProfileLeaveByKeycloakIdAsync(Guid keycloakId, string? accessToken) { diff --git a/BMA.EHR.Discipline.Service/Controllers/DisciplineDirectorController.cs b/BMA.EHR.Discipline.Service/Controllers/DisciplineDirectorController.cs index 202eaa44..c4bd24ae 100644 --- a/BMA.EHR.Discipline.Service/Controllers/DisciplineDirectorController.cs +++ b/BMA.EHR.Discipline.Service/Controllers/DisciplineDirectorController.cs @@ -392,7 +392,7 @@ namespace BMA.EHR.DisciplineDirector.Service.Controllers return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound); var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, token.Replace("Bearer ", "")); + var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(userId, token.Replace("Bearer ", "")); if (profile == null) return Error(GlobalMessages.DataNotFound); diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index 5d6c37c4..d0edb337 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -212,7 +212,8 @@ namespace BMA.EHR.Leave.Service.Controllers var thisYear = DateTime.Now.Year; - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(userId, AccessToken); if (profile == null) { @@ -377,11 +378,15 @@ namespace BMA.EHR.Leave.Service.Controllers break; case "LV-008": { - var lastSalary = profile.ProfileSalary; - var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount == null ? 0 : lastSalary.Amount; - var lastSalaryAmountText = lastSalary == null ? "" : lastSalary.Amount == null ? "" : ((int)lastSalary.Amount).ToThaiBahtText(false); - leaveRequest.LeaveSalary = (int)lastSalaryAmount; - leaveRequest.LeaveSalaryText = lastSalaryAmountText; + // var lastSalary = profile.ProfileSalary; + // var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount == null ? 0 : lastSalary.Amount; + // var lastSalaryAmountText = lastSalary == null ? "" : lastSalary.Amount == null ? "" : ((int)lastSalary.Amount).ToThaiBahtText(false); + // leaveRequest.LeaveSalary = (int)lastSalaryAmount; + // leaveRequest.LeaveSalaryText = lastSalaryAmountText; + leaveRequest.LeaveSalary = profile.Amount.HasValue && profile.Amount > 0 + ? (int)profile.Amount : 0; + leaveRequest.LeaveSalaryText = profile.Amount.HasValue && profile.Amount > 0 + ? ((int)profile.Amount).ToThaiBahtText(false) : ""; //leaveRequest.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value; //leaveRequest.LeaveSalaryText = // lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false); @@ -401,11 +406,15 @@ namespace BMA.EHR.Leave.Service.Controllers break; case "LV-010": { - var lastSalary = profile.ProfileSalary; - var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount == null ? 0 : lastSalary.Amount; - var lastSalaryAmountText = lastSalary == null ? "" : lastSalary.Amount == null ? "" : ((int)lastSalary.Amount).ToThaiBahtText(false); - leaveRequest.LeaveSalary = (int)lastSalaryAmount; - leaveRequest.LeaveSalaryText = lastSalaryAmountText; + // var lastSalary = profile.ProfileSalary; + // var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount == null ? 0 : lastSalary.Amount; + // var lastSalaryAmountText = lastSalary == null ? "" : lastSalary.Amount == null ? "" : ((int)lastSalary.Amount).ToThaiBahtText(false); + // leaveRequest.LeaveSalary = (int)lastSalaryAmount; + // leaveRequest.LeaveSalaryText = lastSalaryAmountText; + leaveRequest.LeaveSalary = profile.Amount.HasValue && profile.Amount > 0 + ? (int)profile.Amount : 0; + leaveRequest.LeaveSalaryText = profile.Amount.HasValue && profile.Amount > 0 + ? ((int)profile.Amount).ToThaiBahtText(false) : ""; //leaveRequest.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value; //leaveRequest.LeaveSalaryText = // lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false); @@ -491,7 +500,8 @@ namespace BMA.EHR.Leave.Service.Controllers foreach (var leave in leaves) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(leave.KeycloakUserId, AccessToken); + // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(leave.KeycloakUserId, AccessToken); + var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(leave.KeycloakUserId, AccessToken); if (profile != null) { leave.Prefix = profile.Prefix; @@ -551,7 +561,8 @@ namespace BMA.EHR.Leave.Service.Controllers // return Error("ไม่สามารถขอลาในช่วงเวลาเดียวกันได้"); // } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(userId, AccessToken); if (profile == null) { @@ -676,11 +687,15 @@ namespace BMA.EHR.Leave.Service.Controllers break; case "LV-008": { - var lastSalary = profile.ProfileSalary; + // var lastSalary = profile.ProfileSalary; - oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value; - oldData.LeaveSalaryText = - lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false); + // oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value; + // oldData.LeaveSalaryText = + // lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false); + oldData.LeaveSalary = profile.Amount.HasValue && profile.Amount > 0 + ? (int)profile.Amount : 0; + oldData.LeaveSalaryText = profile.Amount.HasValue && profile.Amount > 0 + ? ((int)profile.Amount).ToThaiBahtText(false) : ""; oldData.LeaveBirthDate = profile.BirthDate; oldData.LeaveGovernmentDate = profile.DateStart; @@ -696,12 +711,15 @@ namespace BMA.EHR.Leave.Service.Controllers break; case "LV-010": { - var lastSalary = profile.ProfileSalary; - - oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value; - oldData.LeaveSalaryText = - lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false); + // var lastSalary = profile.ProfileSalary; + // oldData.LeaveSalary = lastSalary == null ? 0 : (int)lastSalary.Amount.Value; + // oldData.LeaveSalaryText = + // lastSalary == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false); + oldData.LeaveSalary = profile.Amount.HasValue && profile.Amount > 0 + ? (int)profile.Amount : 0; + oldData.LeaveSalaryText = profile.Amount.HasValue && profile.Amount > 0 + ? ((int)profile.Amount).ToThaiBahtText(false) : ""; oldData.CoupleDayName = req.CoupleDayName ?? ""; oldData.CoupleDayPosition = req.CoupleDayPosition ?? ""; oldData.CoupleDayLevel = req.CoupleDayLevel ?? ""; @@ -844,7 +862,8 @@ namespace BMA.EHR.Leave.Service.Controllers if (toDay >= startFiscalDate && toDay <= endFiscalDate) thisYear = thisYear + 1; - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + var profile = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(userId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); @@ -887,7 +906,7 @@ namespace BMA.EHR.Leave.Service.Controllers var restCurrentDay = 10.0; var sumLeave = leaveData == null ? 0 : leaveData.LeaveDaysUsed; - var lastSalary = profile.ProfileSalary; + // var lastSalary = profile.ProfileSalary; var leaveLast = await _leaveRequestRepository.GetLeaveLastByTypeForUserAsync(userId, req.Type); @@ -912,8 +931,12 @@ namespace BMA.EHR.Leave.Service.Controllers RestDayTotalCurrent = restCurrentDay,// 10 วันเสมอ (LV-005) BirthDate = profile.BirthDate.Date, DateAppoint = profile.DateAppoint == null ? null : profile.DateAppoint.Value.Date, - Salary = lastSalary == null ? 0 : lastSalary.Amount == null ? 0 : (int)lastSalary.Amount.Value, - SalaryText = lastSalary == null ? "" : lastSalary.Amount == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false), + // Salary = lastSalary == null ? 0 : lastSalary.Amount == null ? 0 : (int)lastSalary.Amount.Value, + // SalaryText = lastSalary == null ? "" : lastSalary.Amount == null ? "" : ((int)lastSalary.Amount.Value).ToThaiBahtText(false), + Salary = profile.Amount.HasValue && profile.Amount > 0 + ? (int)profile.Amount : 0, + SalaryText = profile.Amount.HasValue && profile.Amount > 0 + ? ((int)profile.Amount).ToThaiBahtText(false) : "", LeaveLast = leaveLast == null ? null : leaveLast, TelephoneNumber = profile.TelephoneNumber ?? "", @@ -945,7 +968,8 @@ namespace BMA.EHR.Leave.Service.Controllers var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(userId, AccessToken); var govAge = (profile?.DateStart?.Date ?? DateTime.Now.Date).DiffDay(DateTime.Now.Date); var thisYear = DateTime.Now.Year; @@ -1495,7 +1519,8 @@ namespace BMA.EHR.Leave.Service.Controllers return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken); + // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken); + var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(rawData.KeycloakUserId, AccessToken); if (profile == null) { @@ -1507,8 +1532,8 @@ namespace BMA.EHR.Leave.Service.Controllers var userCalendar = await _userCalendarRepository.GetExist(profile.Id); var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar; - var lastSalary = profile.ProfileSalary; - var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount ?? 0; + // var lastSalary = profile.ProfileSalary; + // var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount ?? 0; var lastLeaveRequest = await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync(rawData.KeycloakUserId, @@ -1573,8 +1598,12 @@ namespace BMA.EHR.Leave.Service.Controllers LeaveBirthDate = profile.BirthDate, LeaveGovernmentDate = profile.DateAppoint == null ? null : profile.DateAppoint.Value, - LeaveSalary = lastSalary == null ? 0 : lastSalaryAmount, - LeaveSalaryText = lastSalary == null ? "" : ((int)lastSalaryAmount).ToThaiBahtText(false), + // LeaveSalary = lastSalary == null ? 0 : lastSalaryAmount, + // LeaveSalaryText = lastSalary == null ? "" : ((int)lastSalaryAmount).ToThaiBahtText(false), + LeaveSalary = profile.Amount.HasValue && profile.Amount > 0 + ? (int)profile.Amount : 0, + LeaveSalaryText = profile.Amount.HasValue && profile.Amount > 0 + ? ((int)profile.Amount).ToThaiBahtText(false) : "", WifeDayName = rawData.WifeDayName, WifeDayDateBorn = rawData.WifeDayDateBorn, @@ -2024,7 +2053,8 @@ namespace BMA.EHR.Leave.Service.Controllers return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(Guid.Parse(UserId!), AccessToken); + // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(Guid.Parse(UserId!), AccessToken); + var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(Guid.Parse(UserId!), AccessToken); if (profile == null) { @@ -2649,7 +2679,8 @@ namespace BMA.EHR.Leave.Service.Controllers var sendList = await _leaveRequestRepository.GetSumSendLeaveAsync(thisYear); var rejectList = await _leaveRequestRepository.GetSumRejectLeaveAsync(thisYear); var deleteList = await _leaveRequestRepository.GetSumDeleteLeaveAsync(thisYear); - var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + // var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + var pf = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(userId, AccessToken); if (pf == null) {