หลังอนุมัติลา แก้สถานะการลงเวลาเป็น ปกติ
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m47s

This commit is contained in:
Suphonchai Phoonsawat 2026-05-11 10:11:40 +07:00
parent 1739aa8057
commit f02413f2b2

View file

@ -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<ProcessUserTimeStamp>()
.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<ProcessUserTimeStamp>()
.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
{