fix CheckTime ให้ใช้ Round ของ user และการฌช็คเวลาเป็น UTC+7

This commit is contained in:
Suphonchai Phoonsawat 2025-03-21 21:34:39 +07:00
parent 0af37b0ecc
commit 0ec841f826
2 changed files with 28 additions and 6 deletions

View file

@ -419,8 +419,26 @@ namespace BMA.EHR.Leave.Service.Controllers
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
var data = await _userTimeStampRepository.GetLastRecord(userId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken);
if (profile == null)
{
throw new Exception(GlobalMessages.DataNotFound);
}
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
if (getDefaultRound == null)
{
return Error("ไม่พบรอบลงเวลา Default", StatusCodes.Status404NotFound);
}
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
var duty = userRound ?? getDefaultRound;
// TODO : รอดุึงรอบที่ผูกกับ user
var duty = await _dutyTimeRepository.GetDefaultAsync();
//var duty = await _dutyTimeRepository.GetDefaultAsync();
CheckInResultDto ret;
if (data == null)
@ -1776,7 +1794,9 @@ namespace BMA.EHR.Leave.Service.Controllers
.FirstOrDefaultAsync();
var endTime = DateTime.Parse($"{DateTime.Now.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}");
//var endTime = DateTimeOffset.Parse($"{DateTime.Now.Date.ToString("yyyy-MM-dd")}T{duty.EndTimeAfternoon}:00.0000000+07:00").ToLocalTime().DateTime;
var endTime = DateTime.Parse($"{DateTime.Now.Date.ToString("yyyy-MM-dd")}T{duty.EndTimeAfternoon}:00.0000000+07:00");
var status = lastCheckIn == null ? "ABSENT" : lastCheckIn.CheckIn.Date < DateTime.Now.Date ? "NORMAL" : time < endTime ? "ABSENT" : "NORMAL";
@ -1784,7 +1804,8 @@ namespace BMA.EHR.Leave.Service.Controllers
{
Status = status,
StatusText = status == "ABSENT" ? "ขาดราชการ" : "ปกติ",
ServerTime = time
ServerTime = time,
EndTime = endTime
});
}

View file

@ -74,8 +74,8 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJw
builder.Services.AddAuthorization();
// use serilog
ConfigureLogs();
builder.Host.UseSerilog();
//ConfigureLogs();
//builder.Host.UseSerilog();
// Add config CORS
builder.Services.AddCors(options => options.AddDefaultPolicy(builder =>
@ -161,7 +161,8 @@ app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
app.UseMiddleware<ErrorHandlerMiddleware>();
app.UseMiddleware<RequestLoggingMiddleware>();
// Disable ก่อน เพื่อแก้ไขให้เรีบร้อยก่อนการใช้งาน
// app.UseMiddleware<RequestLoggingMiddleware>();
app.UseHangfireDashboard("/hangfire", new DashboardOptions()