Refactor file upload logic in LeaveController to handle check-in scenarios more effectively

#2328
This commit is contained in:
Suphonchai Phoonsawat 2026-02-20 16:32:57 +07:00
parent 7e613ab2e6
commit 3e34aaa178

View file

@ -970,11 +970,11 @@ namespace BMA.EHR.Leave.Service.Controllers
try
{
await _minIOService.UploadFileAsync(fileName, ms);
if (lastCheckIn != null && lastCheckIn.CheckOut == null)
{
// ยังไม่เคย check-out มาก่อน หรือ check-out เป็น null ให้ใช้ชื่อไฟล์แบบ check-out
await _minIOService.UploadFileAsync(fileNameCheckOut, ms);
}
// if (lastCheckIn != null && lastCheckIn.CheckOut == null)
// {
// // ยังไม่เคย check-out มาก่อน หรือ check-out เป็น null ให้ใช้ชื่อไฟล์แบบ check-out
// await _minIOService.UploadFileAsync(fileNameCheckOut, ms);
// }
}
catch (Exception ex)
{
@ -997,6 +997,42 @@ namespace BMA.EHR.Leave.Service.Controllers
}
if (lastCheckIn != null && lastCheckIn.CheckOut == null)
{
using (var ms2 = new MemoryStream(data.CheckInFileBytes ?? new byte[0]))
{
try
{
await _minIOService.UploadFileAsync(fileNameCheckOut, ms2);
// if (lastCheckIn != null && lastCheckIn.CheckOut == null)
// {
// // ยังไม่เคย check-out มาก่อน หรือ check-out เป็น null ให้ใช้ชื่อไฟล์แบบ check-out
// await _minIOService.UploadFileAsync(fileNameCheckOut, ms);
// }
}
catch (Exception ex)
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, $"ไม่สามารถอัปโหลดรูปภาพได้: {ex.Message}");
// send notification to user
var noti1 = new Notification
{
Body = $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่สามารถอัปโหลดรูปภาพได้ {ex.Message}",
ReceiverUserId = profile.Id,
Type = "",
Payload = "",
};
_appDbContext.Set<Notification>().Add(noti1);
await _appDbContext.SaveChangesAsync();
return Error($"ไม่สามารถอัปโหลดรูปภาพได้: {ex.Message}", StatusCodes.Status500InternalServerError);
}
}
}
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
if (defaultRound == null)
{