Compare commits

...

2 commits

Author SHA1 Message Date
Suphonchai Phoonsawat
76697c4f63 แก้ไขข้อความ Notofication
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m55s
2026-05-15 16:14:50 +07:00
Suphonchai Phoonsawat
e5f6a44f5f เพิ่ม Call API GetProfileByCheckInAsync ใช้แทนของเดิม 2026-05-15 16:04:39 +07:00
2 changed files with 36 additions and 13 deletions

View file

@ -233,6 +233,29 @@ namespace BMA.EHR.Application.Repositories
throw;
}
}
public async Task<GetProfileByKeycloakIdDto?> GetProfileByCheckInAsync(Guid keycloakId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/check-keycloak/{keycloakId}";
var apiKey = _configuration["API_KEY"];
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByKeycloakIdResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<GetProfileLeaveByKeycloakDto?> GetProfileLeaveByKeycloakIdAsync(Guid keycloakId, string? accessToken)

View file

@ -945,13 +945,13 @@ namespace BMA.EHR.Leave.Service.Controllers
await _checkInJobStatusRepository.UpdateToProcessingAsync(taskId);
}
var profile = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(userId, data.Token);
var profile = await _userProfileRepository.GetProfileByCheckInAsync(userId, data.Token);
if (profile == null)
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "เกิดข้อผิดพลาดจากการเรียก API [GetProfileByKeycloakIdNew2Async] : ไม่พบข้อมูลผู้ใช้");
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "เกิดข้อผิดพลาดจากการเรียก API [GetProfileByCheckInAsync] : ไม่พบข้อมูลผู้ใช้");
await _notificationService.SendNotificationAsync(data.Token, true,
"เกิดข้อผิดพลาดจากการเรียก API [GetProfileByKeycloakIdNew2Async] : ไม่พบข้อมูลผู้ใช้");
$"ลงเวลาไม่สำเร็จ \r\nเนื่องจาก ไม่พบข้อมูลผู้ใช้ \r\nกรุณาลองใหม่อีกครั้ง");
//var staffList = await _userProfileRepository.GetOCStaffAsync(profile)
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
@ -962,7 +962,7 @@ namespace BMA.EHR.Leave.Service.Controllers
{
//throw new Exception(GlobalMessages.NoFileToUpload);
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, GlobalMessages.NoFileToUpload);
await _notificationService.SendNotificationAsync(data.Token, true, $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจาก {GlobalMessages.NoFileToUpload}");
await _notificationService.SendNotificationAsync(data.Token, true, $"ลงเวลาไม่สำเร็จ \r\nเนื่องจาก {GlobalMessages.NoFileToUpload}\r\nกรุณาลองใหม่อีกครั้ง");
// send notification to user
var noti1 = new Notification
@ -1000,7 +1000,7 @@ namespace BMA.EHR.Leave.Service.Controllers
catch (Exception ex)
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, $"ไม่สามารถอัปโหลดรูปภาพได้: {ex.Message}");
await _notificationService.SendNotificationAsync(data.Token, true, $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่สามารถอัปโหลดรูปภาพได้ {ex.Message}");
await _notificationService.SendNotificationAsync(data.Token, true, $"ลงเวลาไม่สำเร็จ \r\nเนื่องจากไม่สามารถอัปโหลดรูปภาพได้ {ex.Message}\r\nกรุณาลองใหม่อีกครั้ง");
// send notification to user
var noti1 = new Notification
@ -1035,7 +1035,7 @@ namespace BMA.EHR.Leave.Service.Controllers
catch (Exception ex)
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, $"ไม่สามารถอัปโหลดรูปภาพได้: {ex.Message}");
await _notificationService.SendNotificationAsync(data.Token, true, $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่สามารถอัปโหลดรูปภาพได้ {ex.Message}");
await _notificationService.SendNotificationAsync(data.Token, true, $"ลงเวลาไม่สำเร็จ \r\nเนื่องจากไม่สามารถอัปโหลดรูปภาพได้ {ex.Message}\r\nกรุณาลองใหม่อีกครั้ง");
// send notification to user
var noti1 = new Notification
@ -1061,7 +1061,7 @@ namespace BMA.EHR.Leave.Service.Controllers
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบรอบการลงเวลาทำงาน Default");
await _notificationService.SendNotificationAsync(data.Token, true,
$"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่พบรอบการลงเวลาทำงาน Default");
$"ลงเวลาไม่สำเร็จ \r\nเนื่องจากไม่พบรอบการลงเวลาทำงาน Default\r\nกรุณาลองใหม่อีกครั้ง");
// send notification to user
var noti1 = new Notification
{
@ -1215,12 +1215,12 @@ namespace BMA.EHR.Leave.Service.Controllers
if (currentCheckIn != null)
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่สามารถลงเวลาได้ เนื่องจากมีการลงเวลาในวันนี้แล้ว");
await _notificationService.SendNotificationAsync(data.Token, true,$"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากมีการลงเวลาในวันนี้แล้ว");
await _notificationService.SendNotificationAsync(data.Token, true,$"ลงเวลาไม่สำเร็จ \r\nเนื่องจากมีการลงเวลาในวันนี้แล้ว\r\nกรุณาลองใหม่อีกครั้ง");
// send notification to user
var noti1 = new Notification
{
Body = $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากมีการลงเวลาในวันนี้แล้ว",
Body = $"ลงเวลาไม่สำเร็จ \r\nเนื่องจากมีการลงเวลาในวันนี้แล้ว",
ReceiverUserId = profile.Id,
Type = "",
Payload = "",
@ -1373,7 +1373,7 @@ namespace BMA.EHR.Leave.Service.Controllers
if (checkout == null)
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบข้อมูลการลงเวลาทำงาน");
await _notificationService.SendNotificationAsync(data.Token,true, $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่พบข้อมูลการลงเวลาทำงาน");
await _notificationService.SendNotificationAsync(data.Token,true, $"ลงเวลาไม่สำเร็จ \r\nเนื่องจากไม่พบข้อมูลการลงเวลาทำงาน\r\nกรุณาลองใหม่อีกครั้ง");
// send notification to user
var noti1 = new Notification
@ -1394,7 +1394,7 @@ namespace BMA.EHR.Leave.Service.Controllers
if (currentCheckInProcess == null)
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบข้อมูลการประมวลผลเวลาทำงาน (CheckIn)");
await _notificationService.SendNotificationAsync(data.Token, true, $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่พบข้อมูลการประมวลผลเวลาทำงาน (CheckIn)");
await _notificationService.SendNotificationAsync(data.Token, true, $"ลงเวลาไม่สำเร็จ \r\nเนื่องจากไม่พบข้อมูลการประมวลผลเวลาทำงาน (CheckIn)\r\nกรุณาลองใหม่อีกครั้ง");
// send notification to user
var noti1 = new Notification
@ -1572,7 +1572,7 @@ namespace BMA.EHR.Leave.Service.Controllers
else
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบข้อมูลการประมวลผลเวลาทำงาน");
await _notificationService.SendNotificationAsync(data.Token,true, $"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่พบข้อมูลการประมวลผลเวลาทำงาน");
await _notificationService.SendNotificationAsync(data.Token,true, $"ลงเวลาไม่สำเร็จ \r\nเนื่องจากไม่พบข้อมูลการประมวลผลเวลาทำงาน\r\nกรุณาลองใหม่อีกครั้ง");
// send notification to user
var noti1 = new Notification
{
@ -1597,7 +1597,7 @@ namespace BMA.EHR.Leave.Service.Controllers
});
await _checkInJobStatusRepository.UpdateToCompletedAsync(taskId, additionalData);
await _notificationService.SendNotificationAsync(data.Token, false,
$"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} สำเร็จ");
$"ลงเวลาสำเร็จ");
}
var checkInType = data.CheckInId == null ? "check-in" : "check-out";