add table duty time
This commit is contained in:
parent
d06e1af217
commit
22d9210416
17 changed files with 2459 additions and 10 deletions
|
|
@ -32,6 +32,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
private readonly UserProfileRepository _userProfileRepository;
|
||||
private readonly UserTimeStampRepository _userTimeStampRepository;
|
||||
private readonly MinIOService _minIOService;
|
||||
private readonly ProcessUserTimeStampRepository _processUserTimeStampRepository;
|
||||
|
||||
private readonly string _bucketName = "check-in";
|
||||
|
||||
|
|
@ -46,7 +47,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
IConfiguration configuration,
|
||||
UserProfileRepository userProfileRepository,
|
||||
UserTimeStampRepository userTimeStampRepository,
|
||||
MinIOService minIOService)
|
||||
MinIOService minIOService,
|
||||
ProcessUserTimeStampRepository processUserTimeStampRepository)
|
||||
{
|
||||
_dutyTimeRepository = dutyTimeRepository;
|
||||
_context = context;
|
||||
|
|
@ -56,6 +58,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
_userProfileRepository = userProfileRepository;
|
||||
_userTimeStampRepository = userTimeStampRepository;
|
||||
_minIOService = minIOService;
|
||||
_processUserTimeStampRepository = processUserTimeStampRepository;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -375,11 +378,16 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
await _minIOService.UploadFileAsync(fileName, ms);
|
||||
}
|
||||
|
||||
var currentCheckInProcess = await _processUserTimeStampRepository.GetTimestampByDateAsync(Guid.Parse(UserId), currentDate);
|
||||
|
||||
// create check in object
|
||||
if (data.CheckInId == null)
|
||||
{
|
||||
// validate duplicate check in
|
||||
var currentCheckIn = await _userTimeStampRepository.GetTimestampByDateAsync(Guid.Parse(UserId), currentDate);
|
||||
|
||||
|
||||
|
||||
if (currentCheckIn != null)
|
||||
{
|
||||
return Error(new Exception("ไม่สามารถลงเวลาได้ เนืองจากมีการลงเวลาในวันนี้แล้ว!"), (int)StatusCodes.Status400BadRequest);
|
||||
|
|
@ -399,11 +407,29 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
CheckIn = currentDate
|
||||
};
|
||||
|
||||
// process - รอทำใน queue
|
||||
var checkin_process = new ProcessUserTimeStamp
|
||||
{
|
||||
KeycloakUserId = UserId != null ? Guid.Parse(UserId) : Guid.Empty,
|
||||
CheckInLat = data.Lat,
|
||||
CheckInLon = data.Lon,
|
||||
IsLocationCheckIn = data.IsLocation,
|
||||
CheckInLocationName = data.LocationName,
|
||||
CheckInPOI = data.POI,
|
||||
CheckInRemark = data.Remark,
|
||||
CheckInImageUrl = fileName,
|
||||
CheckIn = currentDate
|
||||
};
|
||||
|
||||
await _userTimeStampRepository.AddAsync(checkin);
|
||||
await _processUserTimeStampRepository.AddAsync(checkin_process);
|
||||
}
|
||||
else
|
||||
{
|
||||
var checkout = await _userTimeStampRepository.GetByIdAsync(data.CheckInId.Value);
|
||||
var checkout_process = await _processUserTimeStampRepository.GetByIdAsync(currentCheckInProcess.Id);
|
||||
|
||||
|
||||
if (checkout != null)
|
||||
{
|
||||
checkout.CheckOutLat = data.Lat;
|
||||
|
|
@ -421,6 +447,25 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
{
|
||||
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
if (checkout_process != null)
|
||||
{
|
||||
checkout_process.CheckOutLat = data.Lat;
|
||||
checkout_process.CheckOutLon = data.Lon;
|
||||
checkout_process.IsLocationCheckOut = data.IsLocation;
|
||||
checkout_process.CheckOutLocationName = data.LocationName;
|
||||
checkout_process.CheckOutPOI = data.POI;
|
||||
checkout_process.CheckOutRemark = data.Remark;
|
||||
checkout_process.CheckOutImageUrl = fileName;
|
||||
checkout_process.CheckOut = currentDate;
|
||||
|
||||
await _processUserTimeStampRepository.UpdateAsync(checkout_process);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Success(new { date = currentDate });
|
||||
|
|
@ -498,6 +543,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
return Error(new Exception("วันเริ่มต้นต้องมีค่าน้อยกว่าหรือเท่ากับวันสิ้นสุด"), (int)StatusCodes.Status400BadRequest);
|
||||
}
|
||||
|
||||
var count = await _userTimeStampRepository.CountRecordAsync();
|
||||
|
||||
|
||||
var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}";
|
||||
var data = (await _userTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate, page, pageSize, keyword))
|
||||
|
|
@ -522,12 +569,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
})
|
||||
.ToList();
|
||||
|
||||
// if (data == null || data.Count == 0)
|
||||
// {
|
||||
// return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
||||
// }
|
||||
|
||||
return Success(new { data = data, total = data.Count });
|
||||
return Success(new { data = data, total = count });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -576,6 +619,77 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// LV1_009 - รายการลงเวลาปฏิบัติงานที่ประมวลผลแล้ว (ADMIN)
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// </returns>
|
||||
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("time-record")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetTimeRecordAsync([Required] DateTime startDate, [Required] DateTime endDate, int page = 1, int pageSize = 10,string status = "NORMAL", string keyword = "")
|
||||
{
|
||||
if (startDate.Date > endDate.Date)
|
||||
{
|
||||
return Error(new Exception("วันเริ่มต้นต้องมีค่าน้อยกว่าหรือเท่ากับวันสิ้นสุด"), (int)StatusCodes.Status400BadRequest);
|
||||
}
|
||||
|
||||
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
||||
|
||||
// TODO : รอดุึงรอบที่ผูกกับ user
|
||||
var duty = await _dutyTimeRepository.GetDefaultAsync();
|
||||
|
||||
if (duty == null)
|
||||
{
|
||||
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
var checkin_base = DateTime.Parse($"{DateTime.Now.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}");
|
||||
var checkout_base = DateTime.Parse($"{DateTime.Now.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}");
|
||||
|
||||
var count = await _processUserTimeStampRepository.CountRecordAsync();
|
||||
|
||||
var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}";
|
||||
var data = (await _processUserTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate, page, pageSize, keyword))
|
||||
.Select(d => new CheckInProcessHistoryForAdminDto
|
||||
{
|
||||
Id = d.Id,
|
||||
FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId),
|
||||
|
||||
CheckInDate = d.CheckIn.Date,
|
||||
CheckInTime = d.CheckIn.ToString("HH:mm:ss"),
|
||||
CheckInLocation = d.CheckInPOI,
|
||||
CheckInLat = d.CheckInLat,
|
||||
CheckInLon = d.CheckInLon,
|
||||
CheckInStatus = DateTime.Parse(d.CheckIn.ToString("yyyy-MM-dd HH:mm")) >
|
||||
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}") ?
|
||||
"LATE" :
|
||||
"NORMAL",
|
||||
//CheckInImageUrl = $"{imgUrl}/{d.CheckInImageUrl}",
|
||||
|
||||
CheckOutDate = d.CheckOut == null ? null : d.CheckOut.Value.Date,
|
||||
CheckOutTime = d.CheckOut == null ? "" : d.CheckOut.Value.ToString("HH:mm:ss"),
|
||||
CheckOutLocation = d.CheckOut == null ? "" : d.CheckOutPOI,
|
||||
CheckOutLat = d.CheckOut == null ? null : d.CheckOutLat,
|
||||
CheckOutLon = d.CheckOut == null ? null : d.CheckOutLon,
|
||||
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}") ?
|
||||
"LATE" :
|
||||
"NORMAL",
|
||||
//CheckOutImageUrl = d.CheckOut == null ? "" : $"{imgUrl}/{d.CheckOutImageUrl}",
|
||||
})
|
||||
.Where(x => x.CheckInStatus == status || x.CheckOutStatus == status)
|
||||
.ToList();
|
||||
|
||||
|
||||
return Success(new { data = data, total = count });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue