เพิ่มเงื่อนไข api
This commit is contained in:
parent
247071b246
commit
4d5170d9f6
2 changed files with 25 additions and 6 deletions
|
|
@ -57,6 +57,16 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
|
|
||||||
#region " Methods "
|
#region " Methods "
|
||||||
|
|
||||||
|
public async Task<UserTimeStamp?> GetTimestampByDateAsync(Guid keycloakId,DateTime date)
|
||||||
|
{
|
||||||
|
var data = await _dbContext.Set<UserTimeStamp>()
|
||||||
|
.Where(u => u.KeycloakUserId == keycloakId)
|
||||||
|
.Where(u => u.CheckIn.Date == date.Date)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<UserTimeStamp?> GetLastRecord(Guid keycloakId)
|
public async Task<UserTimeStamp?> GetLastRecord(Guid keycloakId)
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<UserTimeStamp>()
|
var data = await _dbContext.Set<UserTimeStamp>()
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using BMA.EHR.Infrastructure.Persistence;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Swashbuckle.AspNetCore.Annotations;
|
using Swashbuckle.AspNetCore.Annotations;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
|
||||||
namespace BMA.EHR.Command.Service.Controllers
|
namespace BMA.EHR.Command.Service.Controllers
|
||||||
|
|
@ -377,6 +378,14 @@ namespace BMA.EHR.Command.Service.Controllers
|
||||||
// create check in object
|
// create check in object
|
||||||
if (data.CheckInId == null)
|
if (data.CheckInId == null)
|
||||||
{
|
{
|
||||||
|
// validate duplicate check in
|
||||||
|
var currentCheckIn = await _userTimeStampRepository.GetTimestampByDateAsync(Guid.Parse(UserId), currentDate);
|
||||||
|
if (currentCheckIn != null)
|
||||||
|
{
|
||||||
|
throw new Exception("ไม่สามารถลงเวลาได้ เนืองจากมีการลงเวลาในวันนี้แล้ว!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var checkin = new UserTimeStamp
|
var checkin = new UserTimeStamp
|
||||||
{
|
{
|
||||||
KeycloakUserId = UserId != null ? Guid.Parse(UserId) : Guid.Empty,
|
KeycloakUserId = UserId != null ? Guid.Parse(UserId) : Guid.Empty,
|
||||||
|
|
@ -436,7 +445,7 @@ namespace BMA.EHR.Command.Service.Controllers
|
||||||
// TODO : รอดุึงรอบที่ผูกกับ user
|
// TODO : รอดุึงรอบที่ผูกกับ user
|
||||||
var duty = await _dutyTimeRepository.GetDefaultAsync();
|
var duty = await _dutyTimeRepository.GetDefaultAsync();
|
||||||
|
|
||||||
if(duty == null)
|
if (duty == null)
|
||||||
{
|
{
|
||||||
throw new Exception(GlobalMessages.DataNotFound);
|
throw new Exception(GlobalMessages.DataNotFound);
|
||||||
}
|
}
|
||||||
|
|
@ -452,16 +461,16 @@ namespace BMA.EHR.Command.Service.Controllers
|
||||||
CheckInDate = d.CheckIn.Date,
|
CheckInDate = d.CheckIn.Date,
|
||||||
CheckInTime = d.CheckIn.ToString("HH:mm"),
|
CheckInTime = d.CheckIn.ToString("HH:mm"),
|
||||||
CheckInLocation = d.CheckInPOI,
|
CheckInLocation = d.CheckInPOI,
|
||||||
CheckInStatus = DateTime.Parse(d.CheckIn.ToString("yyyy-MM-dd HH:mm")) >
|
CheckInStatus = DateTime.Parse(d.CheckIn.ToString("yyyy-MM-dd HH:mm")) >
|
||||||
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}") ?
|
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}") ?
|
||||||
"LATE" :
|
"LATE" :
|
||||||
"NORMAL",
|
"NORMAL",
|
||||||
CheckOutDate = d.CheckOut == null ? null : d.CheckOut.Value.Date,
|
CheckOutDate = d.CheckOut == null ? null : d.CheckOut.Value.Date,
|
||||||
CheckOutTime = d.CheckOut == null ? "" : d.CheckOut.Value.ToString("HH:mm"),
|
CheckOutTime = d.CheckOut == null ? "" : d.CheckOut.Value.ToString("HH:mm"),
|
||||||
CheckOutLocation = d.CheckOutPOI ?? "",
|
CheckOutLocation = d.CheckOutPOI ?? "",
|
||||||
CheckOutStatus = d.CheckOut == null ? null : DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
|
CheckOutStatus = d.CheckOut == null ? null : DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
|
||||||
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
|
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
|
||||||
"LATE" :
|
"LATE" :
|
||||||
"NORMAL",
|
"NORMAL",
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
@ -482,7 +491,7 @@ namespace BMA.EHR.Command.Service.Controllers
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
public async Task<ActionResult<ResponseObject>> LogRecordAsync(DateTime startDate, DateTime endDate, int page = 1, int pageSize = 10, string keyword = "")
|
public async Task<ActionResult<ResponseObject>> LogRecordAsync([Required] DateTime startDate, [Required] DateTime endDate, int page = 1, int pageSize = 10, string keyword = "")
|
||||||
{
|
{
|
||||||
var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}";
|
var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}";
|
||||||
var data = (await _userTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate, page, pageSize, keyword))
|
var data = (await _userTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate, page, pageSize, keyword))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue