This commit is contained in:
parent
a8a988a372
commit
0cb17540b0
1 changed files with 53 additions and 0 deletions
|
|
@ -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 " ขอลงเวลาเป็นกรณีพิเศษ "
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue