LV1_018 - รายการลงเวลากรณีพิเศษ (ADMIN)
This commit is contained in:
parent
e76d994098
commit
a8379303f9
8 changed files with 761 additions and 5 deletions
|
|
@ -866,6 +866,97 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LV1_018 - รายการลงเวลากรณีพิเศษ (ADMIN)
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// </returns>
|
||||
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("admin/edit")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetAdditionalCheckRequestAsync([Required] int year, [Required] int month, [Required] int page = 1, [Required] int pageSize = 10, string keyword = "")
|
||||
{
|
||||
var rawData = await _additionalCheckRequestRepository.GetAdditionalCheckRequests(year, month);
|
||||
|
||||
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||
if (getDefaultRound == null)
|
||||
{
|
||||
return Error("ไม่พบรอบลงเวลา Default", (int)StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
var result = new List<GetAdditionalCheckRequestDto>();
|
||||
|
||||
foreach (var data in rawData)
|
||||
{
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
|
||||
if (profile == null)
|
||||
{
|
||||
return Error(GlobalMessages.DataNotFound, (int)StatusCodes.Status404NotFound);
|
||||
}
|
||||
var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
|
||||
var checkInData = await _userTimeStampRepository.GetTimestampByDateAsync(data.KeycloakUserId, data.CheckDate);
|
||||
|
||||
var duty = userRound ?? getDefaultRound;
|
||||
|
||||
// create result object to return
|
||||
var resObj = new GetAdditionalCheckRequestDto
|
||||
{
|
||||
Id = data.Id,
|
||||
FullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}",
|
||||
CreatedAt = data.CreatedAt,
|
||||
CheckDate = data.CheckDate,
|
||||
CheckInEdit = data.CheckInEdit,
|
||||
CheckOutEdit = data.CheckOutEdit,
|
||||
|
||||
CheckInTime = checkInData == null ? "00:00" : checkInData.CheckIn.ToString("HH:mm"),
|
||||
CheckOutTime = checkInData == null ? "00:00" : checkInData.CheckOut == null ? "00:00" : checkInData.CheckOut.Value.ToString("HH:mm"),
|
||||
|
||||
CheckInStatus = checkInData == null ? null :
|
||||
DateTime.Parse(checkInData.CheckIn.ToString("yyyy-MM-dd HH:mm")) >
|
||||
DateTime.Parse($"{checkInData.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}") ?
|
||||
"LATE" :
|
||||
"NORMAL",
|
||||
|
||||
CheckOutStatus = checkInData == null ? null :
|
||||
checkInData.CheckOut == null ? null :
|
||||
DateTime.Parse(checkInData.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
|
||||
DateTime.Parse($"{checkInData.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
|
||||
"LATE" :
|
||||
"NORMAL",
|
||||
|
||||
StartTimeMorning = duty.StartTimeMorning,
|
||||
EndTimeMorning = duty.EndTimeMorning,
|
||||
StartTimeAfternoon = duty.StartTimeAfternoon,
|
||||
EndTimeAfternoon = duty.EndTimeAfternoon,
|
||||
|
||||
Reason = data.Comment ?? "",
|
||||
Status = data.Status,
|
||||
Description = data.Description,
|
||||
|
||||
StatusSort = data.Status.Trim().ToLower() == "pending" ? 1 :
|
||||
data.Status.Trim().ToLower() == "approve" ? 2 : 3,
|
||||
|
||||
};
|
||||
|
||||
result.Add(resObj);
|
||||
}
|
||||
|
||||
if (keyword != "")
|
||||
{
|
||||
result = result.Where(x => x.FullName.Contains(keyword)).ToList();
|
||||
}
|
||||
|
||||
var pageResult = result.Skip((page - 1) * pageSize).Take(pageSize)
|
||||
.OrderBy(x => x.StatusSort)
|
||||
.ToList();
|
||||
|
||||
return Success(new { data = pageResult, total = result.Count });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue