From f02413f2b213f197b2fb1f0d0b6102bd0661a99d Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 11 May 2026 10:11:40 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AB=E0=B8=A5=E0=B8=B1=E0=B8=87=E0=B8=AD?= =?UTF-8?q?=E0=B8=99=E0=B8=B8=E0=B8=A1=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=A5?= =?UTF-8?q?=E0=B8=B2=20=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=AA=E0=B8=96?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=E0=B8=B0=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=A5?= =?UTF-8?q?=E0=B8=87=E0=B9=80=E0=B8=A7=E0=B8=A5=E0=B8=B2=E0=B9=80=E0=B8=9B?= =?UTF-8?q?=E0=B9=87=E0=B8=99=20=E0=B8=9B=E0=B8=81=E0=B8=95=E0=B8=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LeaveRequests/LeaveRequestRepository.cs | 72 +++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index 8cb9b715..dee940fe 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -11,6 +11,8 @@ using Microsoft.Extensions.Configuration; using System.IO.Compression; using System.Net.Http.Headers; using System.Net.Http.Json; +using BMA.EHR.Application.Repositories.Leaves.TimeAttendants; +using BMA.EHR.Domain.Models.Leave.TimeAttendants; namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests { @@ -29,6 +31,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests private readonly MinIOLeaveService _minIOService; private readonly LeaveBeginningRepository _leaveBeginningRepository; + private readonly ProcessUserTimeStampRepository _processUserTimeStampRepository; private readonly string URL = string.Empty; @@ -44,7 +47,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests EmailSenderService emailSenderService, IApplicationDBContext appDbContext, MinIOLeaveService minIOService, - LeaveBeginningRepository leaveBeginningRepository) : base(dbContext, httpContextAccessor) + LeaveBeginningRepository leaveBeginningRepository, + ProcessUserTimeStampRepository processUserTimeStampRepository) : base(dbContext, httpContextAccessor) { _dbContext = dbContext; _httpContextAccessor = httpContextAccessor; @@ -58,6 +62,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests Console.WriteLine($"URL : {URL}"); _minIOService = minIOService; _leaveBeginningRepository = leaveBeginningRepository; + _processUserTimeStampRepository = processUserTimeStampRepository; } #endregion @@ -1325,9 +1330,68 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests } await _appDbContext.SaveChangesAsync(); - // insert to process timestamp - - + // ปรับสถานะการลงเวลา + if (rawData.LeaveStartDate.Date == rawData.LeaveEndDate.Date) + { + var processCheckIn = await _dbContext.Set() + .Where(x => x.KeycloakUserId == rawData.KeycloakUserId) + .Where(x => x.CheckIn.Date == rawData.LeaveStartDate.Date) + .FirstOrDefaultAsync(); + + + if (processCheckIn is not null) + { + switch (rawData.LeaveRange.Trim().ToUpper()) + { + case "MORNING": + processCheckIn.CheckInStatus = "NORMAL"; + break; + case "AFTERNOON": + processCheckIn.CheckOutStatus = "NORMAL"; + break; + case "ALL": + processCheckIn.CheckInStatus = "NORMAL"; + processCheckIn.CheckOutStatus = "NORMAL"; + break; + default: + break; + } + } + await _dbContext.SaveChangesAsync(); + } + else + { + var from = rawData.LeaveStartDate.Date; + var to = rawData.LeaveEndDate.Date; + for (var day = from.Date; day <= to.Date; day = day.AddDays(1)) + { + var processCheckIn = await _dbContext.Set() + .Where(x => x.KeycloakUserId == rawData.KeycloakUserId) + .Where(x => x.CheckIn.Date == day.Date) + .FirstOrDefaultAsync(); + + if (processCheckIn is not null) + { + switch (rawData.LeaveRange.Trim().ToUpper()) + { + case "MORNING": + processCheckIn.CheckInStatus = "NORMAL"; + break; + case "AFTERNOON": + processCheckIn.CheckOutStatus = "NORMAL"; + break; + case "ALL": + processCheckIn.CheckInStatus = "NORMAL"; + processCheckIn.CheckOutStatus = "NORMAL"; + break; + default: + break; + } + } + } + await _dbContext.SaveChangesAsync(); + } + // Send Noti var noti = new Notification {