send noti process-checkin

This commit is contained in:
Suphonchai Phoonsawat 2026-05-15 11:41:59 +07:00
parent 20e8dfddd6
commit ecf660e4cf
2 changed files with 78 additions and 2 deletions

View file

@ -33,6 +33,7 @@ using System.Diagnostics;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using BMA.EHR.Leave.Services;
using SearchProfileResultDto = BMA.EHR.Leave.Service.DTOs.ChangeRound.SearchProfileResultDto;
namespace BMA.EHR.Leave.Service.Controllers
@ -63,6 +64,7 @@ namespace BMA.EHR.Leave.Service.Controllers
private readonly UserCalendarRepository _userCalendarRepository;
private readonly PermissionRepository _permission;
private readonly CheckInJobStatusRepository _checkInJobStatusRepository;
private readonly NotificationService _notificationService;
private readonly CommandRepository _commandRepository;
@ -102,7 +104,8 @@ namespace BMA.EHR.Leave.Service.Controllers
CheckInJobStatusRepository checkInJobStatusRepository,
HttpClient httpClient,
ApplicationDBContext appDbContext,
LeaveProcessJobStatusRepository leaveProcessJobStatusRepository)
LeaveProcessJobStatusRepository leaveProcessJobStatusRepository,
NotificationService notificationService)
{
_dutyTimeRepository = dutyTimeRepository;
_context = context;
@ -122,6 +125,7 @@ namespace BMA.EHR.Leave.Service.Controllers
_notificationRepository = notificationRepository;
_checkInJobStatusRepository = checkInJobStatusRepository;
_leaveProcessJobStatusRepository = leaveProcessJobStatusRepository;
_notificationService = notificationService;
_objectPool = objectPool;
_permission = permission;
@ -943,7 +947,9 @@ namespace BMA.EHR.Leave.Service.Controllers
if (profile == null)
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบข้อมูลผู้ใช้");
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "เกิดข้อผิดพลาดจากการเรียก API [GetProfileByKeycloakIdNew2Async] : ไม่พบข้อมูลผู้ใช้");
await _notificationService.SendNotificationAsync(data.Token, true,
"เกิดข้อผิดพลาดจากการเรียก API [GetProfileByKeycloakIdNew2Async] : ไม่พบข้อมูลผู้ใช้");
//var staffList = await _userProfileRepository.GetOCStaffAsync(profile)
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
@ -954,6 +960,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}");
// send notification to user
var noti1 = new Notification
@ -991,6 +998,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}");
// send notification to user
var noti1 = new Notification
@ -1025,6 +1033,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}");
// send notification to user
var noti1 = new Notification
@ -1049,6 +1058,8 @@ namespace BMA.EHR.Leave.Service.Controllers
if (defaultRound == null)
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, "ไม่พบรอบการลงเวลาทำงาน Default");
await _notificationService.SendNotificationAsync(data.Token, true,
$"ประมวลผลการลงเวลาวันที่ {currentDate.ToString("dd-MM-yyyy")} ไม่สำเร็จ \r\nเนื่องจากไม่พบรอบการลงเวลาทำงาน Default");
// send notification to user
var noti1 = new Notification
{
@ -1202,6 +1213,7 @@ 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เนื่องจากมีการลงเวลาในวันนี้แล้ว");
// send notification to user
var noti1 = new Notification
@ -1359,6 +1371,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เนื่องจากไม่พบข้อมูลการลงเวลาทำงาน");
// send notification to user
var noti1 = new Notification
@ -1379,6 +1392,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)");
// send notification to user
var noti1 = new Notification
@ -1556,6 +1570,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เนื่องจากไม่พบข้อมูลการประมวลผลเวลาทำงาน");
// send notification to user
var noti1 = new Notification
{
@ -1579,6 +1594,8 @@ namespace BMA.EHR.Leave.Service.Controllers
ProcessedDate = currentDate
});
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";
@ -1590,6 +1607,7 @@ namespace BMA.EHR.Leave.Service.Controllers
if (taskId != Guid.Empty)
{
await _checkInJobStatusRepository.UpdateToFailedAsync(taskId, ex.Message);
await _notificationService.SendNotificationAsync(data.Token, true, ex.Message);
}
return Error(ex);
}