issue #1256
Some checks failed
release-dev / release-dev (push) Failing after 11s

This commit is contained in:
Suphonchai Phoonsawat 2025-03-19 16:13:22 +07:00
parent a8a988a372
commit 0cb17540b0

View file

@ -1728,6 +1728,59 @@ namespace BMA.EHR.Leave.Service.Controllers
}
#endregion
#region " Check Checkout Time "
/// <summary>
/// ตรวจสอบว่าเวลาปัจจุบัน ถ้า checkout จะขาดราชการหรือไม่?
/// </summary>
/// <returns>
/// </returns>
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("user/checkout-check")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> CheckoutCheckAsync()
{
var time = DateTime.Now;
var userId = UserId != null ? Guid.Parse(UserId) : Guid.Empty;
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;
var endTime = DateTime.Parse($"{DateTime.Now.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}");
var status = time < endTime ? "ABSENT" : "NORMAL";
return Success(new
{
Status = status,
StatusText = status == "ABSENT" ? "ขาดราชการ" : "ปกติ",
ServerTime = time
});
}
#endregion
#region " ขอลงเวลาเป็นกรณีพิเศษ "