From be1c390bb878afc2767d7318bd5a7cb7dce80110 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 30 May 2024 09:32:34 +0700 Subject: [PATCH 1/3] =?UTF-8?q?fix=20:=20=E0=B8=95=E0=B9=88=E0=B8=AD=20API?= =?UTF-8?q?=20=E0=B8=A3=E0=B8=B0=E0=B8=A2=E0=B8=A2=E0=B8=A5=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/GenericRepository.cs | 2 + .../Leaves/GenericLeaveRepository.cs | 2 + .../LeaveRequests/LeaveRequestRepository.cs | 12 ++-- .../AdditionalCheckRequestRepository.cs | 4 +- .../Repositories/UserProfileRepository.cs | 29 +++++++--- .../Profiles/GetProfileByKeycloakIdDto.cs | 58 +++++++++++++++++++ .../GetProfileByKeycloakIdResultDto.cs | 11 ++++ .../Profiles/SearchProfileResultDto.cs | 2 +- .../Controllers/LeaveController.cs | 20 +++---- .../Controllers/LeaveRequestController.cs | 56 +++++++++--------- 10 files changed, 142 insertions(+), 54 deletions(-) create mode 100644 BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs create mode 100644 BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdResultDto.cs diff --git a/BMA.EHR.Application/Repositories/GenericRepository.cs b/BMA.EHR.Application/Repositories/GenericRepository.cs index a2dcc868..e7647057 100644 --- a/BMA.EHR.Application/Repositories/GenericRepository.cs +++ b/BMA.EHR.Application/Repositories/GenericRepository.cs @@ -43,6 +43,8 @@ namespace BMA.EHR.Application.Repositories protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); + protected string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"]; + #endregion #region " Methods " diff --git a/BMA.EHR.Application/Repositories/Leaves/GenericLeaveRepository.cs b/BMA.EHR.Application/Repositories/Leaves/GenericLeaveRepository.cs index 8b80c36e..712a49de 100644 --- a/BMA.EHR.Application/Repositories/Leaves/GenericLeaveRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/GenericLeaveRepository.cs @@ -37,6 +37,8 @@ namespace BMA.EHR.Application.Repositories.Leaves protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); + protected string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"]; + #endregion #region " Methods " diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index 1a9b3d61..24b07531 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -259,7 +259,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests throw new Exception(GlobalMessages.DataNotFound); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken ?? ""); if (profile == null) { throw new Exception(GlobalMessages.DataNotFound); @@ -292,7 +292,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests throw new Exception(GlobalMessages.DataNotFound); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken ?? ""); if (profile == null) { throw new Exception(GlobalMessages.DataNotFound); @@ -404,7 +404,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests throw new Exception("คำขอนี้ยังไม่ได้รับการอนุมัติจากผู้บังคับบัญชา ไม่สามารถทำรายการได้"); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId,AccessToken); if (profile == null) { throw new Exception(GlobalMessages.DataNotFound); @@ -464,7 +464,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests throw new Exception("คำขอนี้ยังไม่ได้รับการอนุมัติจากผู้บังคับบัญชา ไม่สามารถทำรายการได้"); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken); if (profile == null) { throw new Exception(GlobalMessages.DataNotFound); @@ -516,11 +516,11 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests return 0.0; } - public async Task GetSumApproveLeaveByRangeForUser(Guid keycloakUserId,DateTime startDate, DateTime endDate) + public async Task GetSumApproveLeaveByRangeForUser(Guid keycloakUserId, DateTime startDate, DateTime endDate) { var data = await _dbContext.Set().AsQueryable() .Include(x => x.Type) - .Where(x => x.KeycloakUserId == keycloakUserId) + .Where(x => x.KeycloakUserId == keycloakUserId) .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) .Where(x => x.LeaveStatus == "APPROVE") .ToListAsync(); diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs index 88f61ab3..f2c99845 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs @@ -72,7 +72,7 @@ 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); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken ?? ""); var profile_id = profile == null ? Guid.Empty : profile.Id; var rootOc = _userProfileRepository.GetRootOcId(profile_id); @@ -88,7 +88,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants // send inbox and notification var subject_str = $"มีการขออนุมัติลงเวลากรณีพิเศษ"; - var body_str = $"โปรดพิจารณาคำร้องขอลงเวลาในกรณีพิเศษจาก {profile.Prefix.Name}{profile.FirstName} {profile.LastName} ในวันที่ {entity.CheckDate.Date.ToThaiShortDate2()}"; + var body_str = $"โปรดพิจารณาคำร้องขอลงเวลาในกรณีพิเศษจาก {profile.Prefix}{profile.FirstName} {profile.LastName} ในวันที่ {entity.CheckDate.Date.ToThaiShortDate2()}"; var subject = subject_str; var body = body_str; diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index 69b15c8c..f2aa2ffb 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -61,18 +61,31 @@ namespace BMA.EHR.Application.Repositories return data; } - public async Task GetProfileByKeycloakIdAsync(Guid keycloakId) + public async Task GetProfileByKeycloakIdAsync(Guid keycloakId, string? accessToken) { try { - var data = await _dbContext.Set().AsQueryable() - .Include(p => p.Prefix) - .Include(p => p.Position) - .Include(p => p.PositionLevel) - .Include(p => p.Salaries) - .FirstOrDefaultAsync(p => p.KeycloakId == keycloakId); + var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak/{keycloakId}"; - return data; + + var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? ""); + if (apiResult != null) + { + var raw = JsonConvert.DeserializeObject(apiResult); + if (raw != null) + return raw.Result; + } + + return null; + + //var data = await _dbContext.Set().AsQueryable() + // .Include(p => p.Prefix) + // .Include(p => p.Position) + // .Include(p => p.PositionLevel) + // .Include(p => p.Salaries) + // .FirstOrDefaultAsync(p => p.KeycloakId == keycloakId); + + //return data; } catch { diff --git a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs new file mode 100644 index 00000000..951ce149 --- /dev/null +++ b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs @@ -0,0 +1,58 @@ +using BMA.EHR.Domain.Models.HR; + +namespace BMA.EHR.Application.Responses.Profiles +{ + public class GetProfileByKeycloakIdDto + { + public Guid Id { get; set; } + + public string? Prefix { get; set; } + public string? FirstName { get; set; } + public string? LastName { get; set; } + public string? CitizenId { get; set; } + + public DateTime BirthDate { get; set; } = DateTime.MinValue; + + public DateTime? DateStart { get; set; } = DateTime.MinValue; + + public DateTime? DateAppoint { get; set; } = DateTime.MinValue; + + public string? Position { get; set; } + + public Guid? OcId { get; set; } + + public PosType? PosType { get; set; } + + public PosLevel? PosLevel { get; set; } + + public string? Oc { get; set; } + + public List Salaries { get; set; } = new(); + + } + + public class PosLevel + { + public Guid Id { get; set; } + public DateTime CreatedAt { get; set; } + public Guid CreatedUserId { get; set; } + public DateTime LastUpdatedAt { get; set; } + public Guid LastUpdateUserId { get; set; } + public string CreatedFullName { get; set; } + public string LastUpdateFullName { get; set; } + public string PosLevelName { get; set; } + public string PosTypeId { get; set; } + } + + public class PosType + { + public Guid Id { get; set; } + public DateTime CreatedAt { get; set; } + public Guid CreatedUserId { get; set; } + public DateTime LastUpdatedAt { get; set; } + public Guid LastUpdateUserId { get; set; } + public string CreatedFullName { get; set; } + public string LastUpdateFullName { get; set; } + public string PosTypeName { get; set; } + } +} diff --git a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdResultDto.cs b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdResultDto.cs new file mode 100644 index 00000000..015781aa --- /dev/null +++ b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdResultDto.cs @@ -0,0 +1,11 @@ +namespace BMA.EHR.Application.Responses.Profiles +{ + public class GetProfileByKeycloakIdResultDto + { + public string Message { get; set; } = string.Empty; + + public int Status { get; set; } = -1; + + public GetProfileByKeycloakIdDto? Result { get; set; } + } +} diff --git a/BMA.EHR.Application/Responses/Profiles/SearchProfileResultDto.cs b/BMA.EHR.Application/Responses/Profiles/SearchProfileResultDto.cs index 95c26ed7..5adcb364 100644 --- a/BMA.EHR.Application/Responses/Profiles/SearchProfileResultDto.cs +++ b/BMA.EHR.Application/Responses/Profiles/SearchProfileResultDto.cs @@ -2,7 +2,7 @@ { public class SearchProfileResultDto { - public string Messsage { get; set; } = string.Empty; + public string Message { get; set; } = string.Empty; public int Status { get; set; } = -1; diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveController.cs index 3e71e0f6..9f4d067d 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveController.cs @@ -421,7 +421,7 @@ namespace BMA.EHR.Leave.Service.Controllers public async Task> CheckInAsync([FromForm] CheckTimeDto data) { var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); if (profile == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); @@ -583,7 +583,7 @@ namespace BMA.EHR.Leave.Service.Controllers { var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); @@ -751,7 +751,7 @@ namespace BMA.EHR.Leave.Service.Controllers } else { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(d.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(d.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); @@ -844,7 +844,7 @@ namespace BMA.EHR.Leave.Service.Controllers var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); @@ -973,7 +973,7 @@ namespace BMA.EHR.Leave.Service.Controllers { ProfileId = p.Id, CitizenId = p.CitizenId ?? "", - FullName = $"{p.Prefix ?? "" }{p.FirstName ?? ""} {p.LastName ?? ""}", + FullName = $"{p.Prefix ?? ""}{p.FirstName ?? ""} {p.LastName ?? ""}", StartTimeMorning = duty.StartTimeMorning, LeaveTimeAfterNoon = duty.EndTimeAfternoon, EffectiveDate = effectiveDate == null ? null : effectiveDate.EffectiveDate.Value.Date @@ -1129,7 +1129,7 @@ namespace BMA.EHR.Leave.Service.Controllers foreach (var data in rawData) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); @@ -1148,7 +1148,7 @@ namespace BMA.EHR.Leave.Service.Controllers var resObj = new GetAdditionalCheckRequestDto { Id = data.Id, - FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}", + FullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}", CreatedAt = data.CreatedAt, CheckDate = data.CheckDate, CheckInEdit = data.CheckInEdit, @@ -1365,7 +1365,7 @@ namespace BMA.EHR.Leave.Service.Controllers } else { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(d.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(d.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); @@ -1457,7 +1457,7 @@ namespace BMA.EHR.Leave.Service.Controllers foreach (var data in rawData) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); @@ -1661,7 +1661,7 @@ namespace BMA.EHR.Leave.Service.Controllers [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetLeaveSummaryByProfileAsync(Guid id, [FromBody] GetLeaveSummaryDto req) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(id); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(id, AccessToken); var thisYear = DateTime.Now.Year; var startDate = req.StartDate; diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveRequestController.cs index 0b56c97a..95579c11 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveRequestController.cs @@ -83,6 +83,8 @@ namespace BMA.EHR.Leave.Service.Controllers private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); + protected string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"]; + private Guid OcId { get @@ -122,7 +124,7 @@ namespace BMA.EHR.Leave.Service.Controllers var thisYear = DateTime.Now.Year; - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); if (profile == null) { @@ -307,8 +309,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveRequest.LeaveTypeCode = leaveType.Code; leaveRequest.Dear = approver; - leaveRequest.PositionName = profile.Position == null ? "" : profile.Position.Name; - leaveRequest.PositionLevelName = profile.PositionLevel == null ? "" : profile.PositionLevel.Name; + leaveRequest.PositionName = profile.Position == null ? "" : profile.Position; + leaveRequest.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName; leaveRequest.OrganizationName = profile.Oc ?? ""; @@ -349,7 +351,7 @@ namespace BMA.EHR.Leave.Service.Controllers // return Error("ไม่สามารถขอลาในช่วงเวลาเดียวกันได้"); // } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); if (profile == null) { @@ -533,8 +535,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveRequest.LeaveTypeCode = leaveType.Code; leaveRequest.Dear = approver; - leaveRequest.PositionName = profile.Position == null ? "" : profile.Position.Name; - leaveRequest.PositionLevelName = profile.PositionLevel == null ? "" : profile.PositionLevel.Name; + leaveRequest.PositionName = profile.Position == null ? "" : profile.Position; + leaveRequest.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName; leaveRequest.OrganizationName = profile.Oc ?? ""; @@ -594,7 +596,7 @@ namespace BMA.EHR.Leave.Service.Controllers var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); var thisYear = DateTime.Now.Year; - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); @@ -627,11 +629,11 @@ namespace BMA.EHR.Leave.Service.Controllers DateSendLeave = DateTime.Now.Date, LeaveTypeName = leaveType.Name, - FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}", + FullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}", Dear = approver, - PositionName = profile.Position == null ? "" : profile.Position.Name, - PositionLevelName = profile.PositionLevel == null ? "" : profile.PositionLevel.Name, + PositionName = profile.Position == null ? "" : profile.Position, + PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName, OrganizationName = profile.Oc ?? "", LeaveLimit = leaveType.Limit, @@ -664,7 +666,7 @@ namespace BMA.EHR.Leave.Service.Controllers { var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); var govAge = profile!.DateStart!.Value.Date.DiffDay(DateTime.Now.Date); @@ -813,7 +815,7 @@ namespace BMA.EHR.Leave.Service.Controllers foreach (var item in data) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(item.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(item.KeycloakUserId, AccessToken); var resData = new GetLeaveRequestCalendarResultDto { @@ -822,7 +824,7 @@ namespace BMA.EHR.Leave.Service.Controllers LeaveTypeId = item.Type.Id, DateSendLeave = item.CreatedAt.Date, Status = item.LeaveStatus, - FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}", + FullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}", LeaveStartDate = item.LeaveStartDate, LeaveEndDate = item.LeaveEndDate, KeycloakId = item.KeycloakUserId @@ -851,7 +853,7 @@ namespace BMA.EHR.Leave.Service.Controllers { var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); @@ -869,7 +871,7 @@ namespace BMA.EHR.Leave.Service.Controllers Id = item.Id, LeaveTypeId = item.Type.Id, LeaveTypeName = item.Type.Name, - FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}", + FullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}", DateSendLeave = item.CreatedAt.Date, IsDelete = item.LeaveStatus == "DELETE", Status = item.LeaveStatus, @@ -910,7 +912,7 @@ namespace BMA.EHR.Leave.Service.Controllers return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken); if (profile == null) { @@ -937,7 +939,7 @@ namespace BMA.EHR.Leave.Service.Controllers LeaveRange = rawData.LeaveRange ?? "", LeaveTypeName = rawData.Type.Name, LeaveTypeId = rawData.Type.Id, - FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}", + FullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}", DateSendLeave = rawData.CreatedAt, Status = rawData.LeaveStatus, LeaveStartDate = rawData.LeaveStartDate, @@ -1046,7 +1048,7 @@ namespace BMA.EHR.Leave.Service.Controllers foreach (var item in rawData) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(item.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(item.KeycloakUserId, AccessToken); // Get Organization var org = await _userProfileRepository.GetOrganizationById(profile.OcId ?? Guid.Empty); @@ -1063,14 +1065,14 @@ namespace BMA.EHR.Leave.Service.Controllers Id = item.Id, LeaveTypeId = item.Type.Id, LeaveTypeName = item.Type.Name, - FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}", + FullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}", DateSendLeave = item.CreatedAt.Date, Status = item.LeaveStatus, CitizenId = profile.CitizenId ?? "", LeaveStartDate = item.LeaveStartDate, LeaveEndDate = item.LeaveEndDate, - Position = profile.Position == null ? "" : profile.Position.Name, - Level = profile.PositionLevel == null ? "" : profile.PositionLevel.Name, + Position = profile.Position == null ? "" : profile.Position, + Level = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName, Agency = agency == null ? "" : agency.Name, Org = gov_agency == null ? "" : gov_agency.Name, LeaveRange = item.LeaveRange ?? "ALL" @@ -1165,13 +1167,13 @@ namespace BMA.EHR.Leave.Service.Controllers foreach (var item in rawData) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(item.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(item.KeycloakUserId, AccessToken); var res = new GetLeaveCancelRequestResultDto { Id = item.Id, LeaveTypeId = item.Type.Id, LeaveTypeName = item.Type.Name, - FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}", + FullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}", DateSendLeave = item.CreatedAt.Date, Status = item.LeaveCancelStatus }; @@ -1210,7 +1212,7 @@ namespace BMA.EHR.Leave.Service.Controllers return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken); if (profile == null) { @@ -1221,7 +1223,7 @@ namespace BMA.EHR.Leave.Service.Controllers { Id = rawData.Id, LeaveTypeName = rawData.Type.Name, - FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}", + FullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}", Status = rawData.LeaveCancelStatus ?? "", LeaveStartDate = rawData.LeaveStartDate, LeaveEndDate = rawData.LeaveEndDate, @@ -1404,7 +1406,7 @@ namespace BMA.EHR.Leave.Service.Controllers return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken); if (profile == null) { @@ -1444,7 +1446,7 @@ namespace BMA.EHR.Leave.Service.Controllers LeaveTypeName = rawData.Type.Name, LeaveTypeId = rawData.Type.Id, - FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}", + FullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}", DateSendLeave = rawData.CreatedAt, Status = rawData.LeaveStatus, LeaveStartDate = rawData.LeaveStartDate, From b7120551b5537ccafb1d35ac8a79f4142df7e775 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 11 Jun 2024 09:34:06 +0700 Subject: [PATCH 2/3] fix: Change Profile Link to Guid --- .../LeaveRequests/LeaveRequestRepository.cs | 4 +- .../Repositories/UserProfileRepository.cs | 1 - BMA.EHR.Domain/Models/HR/ProfileLeave.cs | 4 +- ...02_Change Profile Link to GUID.Designer.cs | 1116 +++++++++++++++++ ...40604030402_Change Profile Link to GUID.cs | 22 + .../Controllers/LeaveReportController.cs | 113 +- 6 files changed, 1213 insertions(+), 47 deletions(-) create mode 100644 BMA.EHR.Infrastructure/Migrations/LeaveDb/20240604030402_Change Profile Link to GUID.Designer.cs create mode 100644 BMA.EHR.Infrastructure/Migrations/LeaveDb/20240604030402_Change Profile Link to GUID.cs diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index 24b07531..56ed3dbe 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -312,7 +312,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests // insert to profile leave var profileLeave = await _appDbContext.Set() .Where(x => x.TypeLeave.Id == leaveType.Id) - .Where(x => x.Profile.Id == profile.Id) + .Where(x => x.ProfileId == profile.Id) .Where(x => x.DateStartLeave == rawData.LeaveStartDate && x.DateEndLeave == rawData.LeaveEndDate) .FirstOrDefaultAsync(); if (profileLeave != null) @@ -430,7 +430,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests Status = "approve", Reason = rawData.LeaveDetail, - Profile = profile, + ProfileId = profile.Id, // change from profile object to id TypeLeave = leaveType }; _appDbContext.Set().Add(profileLeave); diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index f2aa2ffb..9e52dea5 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -5,7 +5,6 @@ using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.Organizations; using BMA.EHR.Domain.Shared; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; diff --git a/BMA.EHR.Domain/Models/HR/ProfileLeave.cs b/BMA.EHR.Domain/Models/HR/ProfileLeave.cs index 73c92b0e..f229fecc 100644 --- a/BMA.EHR.Domain/Models/HR/ProfileLeave.cs +++ b/BMA.EHR.Domain/Models/HR/ProfileLeave.cs @@ -21,8 +21,10 @@ namespace BMA.EHR.Domain.Models.HR [Comment("เหตุผล")] public string? Reason { get; set; } public virtual List ProfileLeaveHistorys { get; set; } = new List(); - public virtual Profile? Profile { get; set; } + //public virtual Profile? Profile { get; set; } [Comment("ประเภทการลา")] public virtual TypeLeave? TypeLeave { get; set; } + + public Guid ProfileId { get; set; } = Guid.Empty; } } diff --git a/BMA.EHR.Infrastructure/Migrations/LeaveDb/20240604030402_Change Profile Link to GUID.Designer.cs b/BMA.EHR.Infrastructure/Migrations/LeaveDb/20240604030402_Change Profile Link to GUID.Designer.cs new file mode 100644 index 00000000..5a8ca037 --- /dev/null +++ b/BMA.EHR.Infrastructure/Migrations/LeaveDb/20240604030402_Change Profile Link to GUID.Designer.cs @@ -0,0 +1,1116 @@ +// +using System; +using BMA.EHR.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BMA.EHR.Infrastructure.Migrations.LeaveDb +{ + [DbContext(typeof(LeaveDbContext))] + [Migration("20240604030402_Change Profile Link to GUID")] + partial class ChangeProfileLinktoGUID + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Documents.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("CreatedDate") + .HasColumnType("datetime(6)"); + + b.Property("Detail") + .IsRequired() + .HasColumnType("text"); + + b.Property("FileName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("FileSize") + .HasColumnType("int"); + + b.Property("FileType") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("ObjectRefId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.ToTable("Document"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("Code") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รหัสประเภทการลา"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Limit") + .HasColumnType("int") + .HasComment("จำนวนวันลาสูงสุดประจำปี"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ชื่อประเภทการลา"); + + b.HasKey("Id"); + + b.ToTable("LeaveTypes"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("DocumentId") + .HasColumnType("char(36)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("LeaveRequestId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("LeaveRequestId"); + + b.ToTable("LeaveDocuments"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("AbsentDayAt") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("AbsentDayGetIn") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("AbsentDayLocation") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("AbsentDayRegistorDate") + .HasColumnType("datetime(6)"); + + b.Property("AbsentDaySummon") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ApproveStep") + .HasColumnType("longtext") + .HasComment("step การอนุมัติ st1 = จทน.อนุมัตื,st2 = ผู้บังคับบัญชา อนุมัติ "); + + b.Property("CancelLeaveWrote") + .HasColumnType("longtext") + .HasComment("เขียนที่ (ขอยกเลิก)"); + + b.Property("CoupleDayCountryHistory") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CoupleDayEndDateHistory") + .HasColumnType("datetime(6)"); + + b.Property("CoupleDayLevel") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CoupleDayLevelCountry") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CoupleDayName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CoupleDayPosition") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CoupleDayStartDateHistory") + .HasColumnType("datetime(6)"); + + b.Property("CoupleDaySumTotalHistory") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CoupleDayTotalHistory") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("Dear") + .HasColumnType("longtext") + .HasComment("เรียนใคร"); + + b.Property("HajjDayStatus") + .HasColumnType("tinyint(1)"); + + b.Property("KeycloakUserId") + .HasColumnType("char(36)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("LeaveAddress") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สถานที่ติดต่อขณะลา"); + + b.Property("LeaveBirthDate") + .HasColumnType("datetime(6)"); + + b.Property("LeaveCancelComment") + .HasColumnType("longtext") + .HasComment("เหตุผลในการขอยกเลิก"); + + b.Property("LeaveCancelDocumentId") + .HasColumnType("char(36)"); + + b.Property("LeaveCancelStatus") + .HasColumnType("longtext") + .HasComment("สถานะของคำขอยกเลิก"); + + b.Property("LeaveComment") + .HasColumnType("longtext") + .HasComment("ความเห็นของผู้บังคับบัญชา"); + + b.Property("LeaveDetail") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รายละเอียดการลา"); + + b.Property("LeaveDirectorComment") + .HasColumnType("longtext") + .HasComment("ความเห็นของผู้อำนวยการสำนัก"); + + b.Property("LeaveDraftDocumentId") + .HasColumnType("char(36)"); + + b.Property("LeaveEndDate") + .HasColumnType("datetime(6)") + .HasComment("วัน เดือน ปีสิ้นสุดลา"); + + b.Property("LeaveGovernmentDate") + .HasColumnType("datetime(6)"); + + b.Property("LeaveLast") + .HasColumnType("datetime(6)"); + + b.Property("LeaveNumber") + .IsRequired() + .HasColumnType("longtext") + .HasComment("หมายเลขที่ติดต่อขณะลา"); + + b.Property("LeaveRange") + .HasColumnType("longtext") + .HasComment("ช่วงของการลา เช่น ลาทั้งวัน ครึ่งวันเช้า ครึ่งวันบ่าย"); + + b.Property("LeaveSalary") + .HasColumnType("int"); + + b.Property("LeaveSalaryText") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("LeaveStartDate") + .HasColumnType("datetime(6)") + .HasComment("วัน เดือน ปีเริ่มต้นลา"); + + b.Property("LeaveStatus") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สถานะของคำร้อง"); + + b.Property("LeaveTotal") + .HasColumnType("double"); + + b.Property("LeaveTypeCode") + .HasColumnType("longtext") + .HasComment("code ของประเภทการลา"); + + b.Property("LeaveWrote") + .IsRequired() + .HasColumnType("longtext") + .HasComment("เขียนที่"); + + b.Property("OrdainDayBuddhistLentAddress") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OrdainDayBuddhistLentName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OrdainDayLocationAddress") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OrdainDayLocationName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OrdainDayLocationNumber") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("OrdainDayOrdination") + .HasColumnType("datetime(6)"); + + b.Property("OrdainDayStatus") + .HasColumnType("tinyint(1)"); + + b.Property("OrganizationName") + .HasColumnType("longtext") + .HasComment("สังกัดผู้ยื่นขอ"); + + b.Property("PositionLevelName") + .HasColumnType("longtext") + .HasComment("ระดับผู้ยื่นขอ"); + + b.Property("PositionName") + .HasColumnType("longtext") + .HasComment("ตำแหน่งผู้ยื่นขอ"); + + b.Property("RestDayCurrentTotal") + .HasColumnType("double"); + + b.Property("RestDayOldTotal") + .HasColumnType("double"); + + b.Property("StudyDayCountry") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDayDegreeLevel") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDayScholarship") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDaySubject") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDayTrainingName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDayTrainingSubject") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StudyDayUniversityName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("TypeId") + .HasColumnType("char(36)"); + + b.Property("WifeDayDateBorn") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("WifeDayName") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("LeaveCancelDocumentId"); + + b.HasIndex("LeaveDraftDocumentId"); + + b.HasIndex("TypeId"); + + b.ToTable("LeaveRequests"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.AdditionalCheckRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CheckDate") + .HasColumnType("datetime(6)") + .HasComment("*วันที่ลงเวลา"); + + b.Property("CheckInEdit") + .HasColumnType("tinyint(1)") + .HasComment("*ขอลงเวลาช่วงเช้า"); + + b.Property("CheckOutEdit") + .HasColumnType("tinyint(1)") + .HasComment("*ขอลงเวลาช่วงบ่าย"); + + b.Property("Comment") + .HasColumnType("longtext") + .HasComment("หมายเหตุในการการอนุมัติ/ไม่อนุมัติ"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext") + .HasComment("*หมายเหตุขอลงเวลาพิเศษ"); + + b.Property("KeycloakUserId") + .HasColumnType("char(36)") + .HasComment("รหัส User ของ Keycloak ที่ร้องขอ"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("Status") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สถานะการอนุมัติ"); + + b.HasKey("Id"); + + b.ToTable("AdditionalCheckRequests"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.DutyTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext") + .HasComment("คำอธิบาย"); + + b.Property("EndTimeAfternoon") + .IsRequired() + .HasColumnType("longtext") + .HasComment("เวลาออกงานช่วงบ่าย"); + + b.Property("EndTimeMorning") + .IsRequired() + .HasColumnType("longtext") + .HasComment("เวลาออกงานช่วงเช้า"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)") + .HasComment("สถานะการเปิดใช้งาน (เปิด/ปิด)"); + + b.Property("IsDefault") + .HasColumnType("tinyint(1)") + .HasComment("สถานะว่ารอบใดเป็นค่า Default ของข้าราชการ (สำหรับทุกคนที่ยังไม่ได้ทำการเลือกรอบ)"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("StartTimeAfternoon") + .IsRequired() + .HasColumnType("longtext") + .HasComment("เวลาเข้างานช่วงบ่าย"); + + b.Property("StartTimeMorning") + .IsRequired() + .HasColumnType("longtext") + .HasComment("เวลาเข้างานช่วงเช้า"); + + b.HasKey("Id"); + + b.ToTable("DutyTimes"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.ProcessUserTimeStamp", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CheckIn") + .HasColumnType("datetime(6)") + .HasComment("วัน เวลา เข้างาน"); + + b.Property("CheckInImageUrl") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รูปถ่ายสถานที่ Check-In"); + + b.Property("CheckInLat") + .HasColumnType("double") + .HasComment("พิกัดละติจูด Check-In"); + + b.Property("CheckInLocationName") + .HasColumnType("longtext") + .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-In"); + + b.Property("CheckInLon") + .HasColumnType("double") + .HasComment("พิกัดลองจิจูด Check-In"); + + b.Property("CheckInPOI") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-In"); + + b.Property("CheckInRemark") + .HasColumnType("longtext") + .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-In"); + + b.Property("CheckInStatus") + .IsRequired() + .HasColumnType("longtext") + .HasComment("สถานะ Check-In"); + + b.Property("CheckOut") + .HasColumnType("datetime(6)") + .HasComment("วัน เวลา ออกงาน"); + + b.Property("CheckOutImageUrl") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รูปถ่ายสถานที่ Check-Out"); + + b.Property("CheckOutLat") + .HasColumnType("double") + .HasComment("พิกัดละติจูด Check-Out"); + + b.Property("CheckOutLocationName") + .HasColumnType("longtext") + .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-Out"); + + b.Property("CheckOutLon") + .HasColumnType("double") + .HasComment("พิกัดลองจิจูด Check-Out"); + + b.Property("CheckOutPOI") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-Out"); + + b.Property("CheckOutRemark") + .HasColumnType("longtext") + .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-Out"); + + b.Property("CheckOutStatus") + .HasColumnType("longtext") + .HasComment("สถานะ Check-Out"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("EditReason") + .HasColumnType("longtext") + .HasComment("เหตุผลการอนุมัติ/ไม่อนุมัติขอลงเวลาพิเศษ"); + + b.Property("EditStatus") + .HasColumnType("longtext") + .HasComment("สถานะการของลงเวลาพิเศษ"); + + b.Property("IsLocationCheckIn") + .HasColumnType("tinyint(1)") + .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-In"); + + b.Property("IsLocationCheckOut") + .HasColumnType("tinyint(1)") + .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-Out"); + + b.Property("IsProcess") + .HasColumnType("tinyint(1)") + .HasComment("นำไปประมวลผลแล้วหรือยัง"); + + b.Property("KeycloakUserId") + .HasColumnType("char(36)") + .HasComment("รหัส User ของ Keycloak"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.HasKey("Id"); + + b.ToTable("ProcessUserTimeStamps"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserCalendar", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("Calendar") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ปฏิทินการทำงานของ ขรก ปกติ หรือ 6 วันต่อสัปดาห์"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("ProfileId") + .HasColumnType("char(36)") + .HasComment("รหัส Profile ในระบบทะเบียนประวัติ"); + + b.HasKey("Id"); + + b.ToTable("UserCalendars"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserDutyTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("DutyTimeId") + .HasColumnType("char(36)") + .HasComment("รหัสรอบการลงเวลา"); + + b.Property("EffectiveDate") + .HasColumnType("datetime(6)") + .HasComment("วันที่มีผล"); + + b.Property("IsProcess") + .HasColumnType("tinyint(1)") + .HasComment("ทำการประมวลผลแล้วหรือยัง"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.Property("ProfileId") + .HasColumnType("char(36)") + .HasComment("รหัส Profile ในระบบทะเบียนประวัติ"); + + b.Property("Remark") + .HasColumnType("longtext") + .HasComment("หมายเหตุ"); + + b.HasKey("Id"); + + b.HasIndex("DutyTimeId"); + + b.ToTable("UserDutyTimes"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserTimeStamp", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)") + .HasColumnOrder(0) + .HasComment("PrimaryKey") + .HasAnnotation("Relational:JsonPropertyName", "id"); + + b.Property("CheckIn") + .HasColumnType("datetime(6)") + .HasComment("วัน เวลา เข้างาน"); + + b.Property("CheckInImageUrl") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รูปถ่ายสถานที่ Check-In"); + + b.Property("CheckInLat") + .HasColumnType("double") + .HasComment("พิกัดละติจูด Check-In"); + + b.Property("CheckInLocationName") + .HasColumnType("longtext") + .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-In"); + + b.Property("CheckInLon") + .HasColumnType("double") + .HasComment("พิกัดลองจิจูด Check-In"); + + b.Property("CheckInPOI") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-In"); + + b.Property("CheckInRemark") + .HasColumnType("longtext") + .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-In"); + + b.Property("CheckOut") + .HasColumnType("datetime(6)") + .HasComment("วัน เวลา ออกงาน"); + + b.Property("CheckOutImageUrl") + .IsRequired() + .HasColumnType("longtext") + .HasComment("รูปถ่ายสถานที่ Check-Out"); + + b.Property("CheckOutLat") + .HasColumnType("double") + .HasComment("พิกัดละติจูด Check-Out"); + + b.Property("CheckOutLocationName") + .HasColumnType("longtext") + .HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-Out"); + + b.Property("CheckOutLon") + .HasColumnType("double") + .HasComment("พิกัดลองจิจูด Check-Out"); + + b.Property("CheckOutPOI") + .IsRequired() + .HasColumnType("longtext") + .HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-Out"); + + b.Property("CheckOutRemark") + .HasColumnType("longtext") + .HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-Out"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(100) + .HasComment("สร้างข้อมูลเมื่อ"); + + b.Property("CreatedFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(104) + .HasComment("ชื่อ User ที่สร้างข้อมูล"); + + b.Property("CreatedUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(101) + .HasComment("User Id ที่สร้างข้อมูล"); + + b.Property("IsLocationCheckIn") + .HasColumnType("tinyint(1)") + .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-In"); + + b.Property("IsLocationCheckOut") + .HasColumnType("tinyint(1)") + .HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-Out"); + + b.Property("IsProcess") + .HasColumnType("tinyint(1)") + .HasComment("นำไปประมวลผลแล้วหรือยัง"); + + b.Property("KeycloakUserId") + .HasColumnType("char(36)") + .HasComment("รหัส User ของ Keycloak"); + + b.Property("LastUpdateFullName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)") + .HasColumnOrder(105) + .HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdateUserId") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnOrder(103) + .HasComment("User Id ที่แก้ไขข้อมูลล่าสุด"); + + b.Property("LastUpdatedAt") + .HasColumnType("datetime(6)") + .HasColumnOrder(102) + .HasComment("แก้ไขข้อมูลล่าสุดเมื่อ"); + + b.HasKey("Id"); + + b.ToTable("UserTimeStamps"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveDocument", b => + { + b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "Document") + .WithMany() + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", "LeaveRequest") + .WithMany("LeaveDocument") + .HasForeignKey("LeaveRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("LeaveRequest"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b => + { + b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "LeaveCancelDocument") + .WithMany() + .HasForeignKey("LeaveCancelDocumentId"); + + b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "LeaveDraftDocument") + .WithMany() + .HasForeignKey("LeaveDraftDocumentId"); + + b.HasOne("BMA.EHR.Domain.Models.Leave.Commons.LeaveType", "Type") + .WithMany() + .HasForeignKey("TypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LeaveCancelDocument"); + + b.Navigation("LeaveDraftDocument"); + + b.Navigation("Type"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserDutyTime", b => + { + b.HasOne("BMA.EHR.Domain.Models.Leave.TimeAttendants.DutyTime", "DutyTime") + .WithMany() + .HasForeignKey("DutyTimeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DutyTime"); + }); + + modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.Requests.LeaveRequest", b => + { + b.Navigation("LeaveDocument"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BMA.EHR.Infrastructure/Migrations/LeaveDb/20240604030402_Change Profile Link to GUID.cs b/BMA.EHR.Infrastructure/Migrations/LeaveDb/20240604030402_Change Profile Link to GUID.cs new file mode 100644 index 00000000..9da56416 --- /dev/null +++ b/BMA.EHR.Infrastructure/Migrations/LeaveDb/20240604030402_Change Profile Link to GUID.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BMA.EHR.Infrastructure.Migrations.LeaveDb +{ + /// + public partial class ChangeProfileLinktoGUID : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs index f6b7c430..11391d62 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs @@ -1,6 +1,7 @@ using System.Data.Common; using System.Globalization; using System.IO.Pipelines; +using System.Security.Claims; using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.Commands; using BMA.EHR.Application.Repositories.Leaves.LeaveRequests; @@ -40,6 +41,7 @@ namespace BMA.EHR.Leave.Service.Controllers private readonly UserDutyTimeRepository _userDutyTimeRepository; private readonly HolidayRepository _holidayRepository; private readonly UserCalendarRepository _userCalendarRepository; + private readonly IHttpContextAccessor _httpContextAccessor; #endregion @@ -53,7 +55,8 @@ namespace BMA.EHR.Leave.Service.Controllers DutyTimeRepository dutyTimeRepository, UserDutyTimeRepository userDutyTimeRepository, HolidayRepository holidayRepository, - UserCalendarRepository userCalendarRepository) + UserCalendarRepository userCalendarRepository, + IHttpContextAccessor httpContextAccessor) { _leaveRequestRepository = leaveRequestRepository; _userProfileRepository = userProfileRepository; @@ -64,6 +67,30 @@ namespace BMA.EHR.Leave.Service.Controllers _userDutyTimeRepository = userDutyTimeRepository; _holidayRepository = holidayRepository; _userCalendarRepository = userCalendarRepository; + _httpContextAccessor = httpContextAccessor; + } + + #endregion + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); + + private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"]; + + private Guid OcId + { + get + { + if (UserId != null || UserId != "") + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + else + return Guid.Empty; + } } #endregion @@ -74,13 +101,13 @@ namespace BMA.EHR.Leave.Service.Controllers private async Task GetReport01(LeaveRequest data) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}"; + var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var lastLeaveRequest = await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync(data.KeycloakUserId, @@ -108,8 +135,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveTypeName = data.Type.Name, dear = approver, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", leaveDetail = data.LeaveDetail, leaveDateStart = data.LeaveStartDate.Date.ToThaiShortDate(), @@ -129,13 +156,13 @@ namespace BMA.EHR.Leave.Service.Controllers private async Task GetReport02(LeaveRequest data) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}"; + var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); var approver = string.Empty; @@ -157,8 +184,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveTypeName = data.Type.Name, dear = approver, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", wifeDayName = data.WifeDayName ?? "", wifeDayDateBorn = data.WifeDayDateBorn ?? "", @@ -173,13 +200,13 @@ namespace BMA.EHR.Leave.Service.Controllers private async Task GetReport03(LeaveRequest data) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}"; + var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); var approver = string.Empty; @@ -203,8 +230,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveTypeName = data.Type.Name, dear = approver, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", restDayOldTotal = data.RestDayOldTotal, @@ -224,13 +251,13 @@ namespace BMA.EHR.Leave.Service.Controllers private async Task GetReport04(LeaveRequest data, bool isHajj = false) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}"; + var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); var approver = string.Empty; @@ -254,8 +281,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveTypeName = data.Type.Name, dear = approver, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", @@ -282,8 +309,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveTypeName = data.Type.Name, dear = approver, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", leavebirthDate = data.LeaveBirthDate == null ? "" : data.LeaveBirthDate.Value.Date.ToThaiShortDate(), @@ -307,13 +334,13 @@ namespace BMA.EHR.Leave.Service.Controllers private async Task GetReport05(LeaveRequest data) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}"; + var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); var approver = string.Empty; @@ -335,8 +362,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveTypeName = data.Type.Name, dear = approver, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", absentDaySummon = data.AbsentDaySummon, @@ -355,13 +382,13 @@ namespace BMA.EHR.Leave.Service.Controllers private async Task GetReport06(LeaveRequest data) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}"; + var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); var approver = string.Empty; @@ -383,8 +410,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveTypeName = data.Type.Name, dear = approver, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", leavebirthDate = data.LeaveBirthDate == null ? "" : data.LeaveBirthDate.Value.Date.ToThaiShortDate(), @@ -410,13 +437,13 @@ namespace BMA.EHR.Leave.Service.Controllers private async Task GetReport07(LeaveRequest data) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}"; + var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); var approver = string.Empty; @@ -439,8 +466,8 @@ namespace BMA.EHR.Leave.Service.Controllers dear = approver, fullname = fullName, fullnameEng = "", - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", leaveDateStart = data.LeaveStartDate.Date.ToThaiShortDate(), @@ -452,13 +479,13 @@ namespace BMA.EHR.Leave.Service.Controllers private async Task GetReport08(LeaveRequest data) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}"; + var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); var approver = string.Empty; @@ -480,8 +507,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveTypeName = data.Type.Name, dear = approver, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", leaveSalary = data.LeaveSalary, @@ -507,13 +534,13 @@ namespace BMA.EHR.Leave.Service.Controllers private async Task GetReport09(LeaveRequest data) { - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}"; + var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); var approver = string.Empty; @@ -535,8 +562,8 @@ namespace BMA.EHR.Leave.Service.Controllers leaveTypeName = data.Type.Name, dear = approver, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", @@ -657,13 +684,13 @@ namespace BMA.EHR.Leave.Service.Controllers return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); if (profile == null) { return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } - var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}"; + var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); var approver = string.Empty; @@ -684,8 +711,8 @@ namespace BMA.EHR.Leave.Service.Controllers dateSendLeave = data.CreatedAt.Date.ToThaiShortDate(), leaveTypeName = data.Type.Name, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position!.Name, - positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name, + positionName = profile!.Position == null ? "-" : profile!.Position, + positionLeaveName = profile!.Position == null ? "-" : profile!.Position, organizationName = profile!.Oc ?? "", leaveDateStart = data.LeaveStartDate.Date.ToThaiShortDate(), leaveDateEnd = data.LeaveEndDate.Date.ToThaiShortDate(), From 3f5797458f8a710a68bcdedf8d22d926cb7dd95f Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 11 Jun 2024 11:56:28 +0700 Subject: [PATCH 3/3] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B8=94=E0=B9=8C=20Competency.id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BMA.EHR.Application/Responses/ProbationAssignResponse.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BMA.EHR.Application/Responses/ProbationAssignResponse.cs b/BMA.EHR.Application/Responses/ProbationAssignResponse.cs index fa0d928a..cc85de84 100644 --- a/BMA.EHR.Application/Responses/ProbationAssignResponse.cs +++ b/BMA.EHR.Application/Responses/ProbationAssignResponse.cs @@ -74,7 +74,7 @@ public class Competency { - public int id { get; set; } + public string id { get; set; } = string.Empty; public string title { get; set; } = string.Empty; public string description { get; set; } = string.Empty; }