From e023ed65f79dbd47a1ded7e82202a6cbf2859f3d Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 15 Dec 2025 09:48:08 +0700 Subject: [PATCH 1/3] fix: update leave remark formatting for better clarity --- .../Controllers/LeaveReportController.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 8849f4da..2b1c90be 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -2079,11 +2079,20 @@ namespace BMA.EHR.Leave.Service.Controllers remarkStr += "ครึ่งวันบ่าย"; + // var leaveRangeEnd = leaveReq.LeaveRangeEnd == null ? "" : leaveReq.LeaveRangeEnd.ToUpper(); + // if (leaveRangeEnd == "MORNING") + // remarkStr += "ครึ่งวันเช้า"; + // else if (leaveRangeEnd == "AFTERNOON") + // remarkStr += "ครึ่งวันบ่าย"; + var leaveRangeEnd = leaveReq.LeaveRangeEnd == null ? "" : leaveReq.LeaveRangeEnd.ToUpper(); - if (leaveRangeEnd == "MORNING") - remarkStr += "ครึ่งวันเช้า"; - else if (leaveRangeEnd == "AFTERNOON") - remarkStr += "ครึ่งวันบ่าย"; + if(leaveRange != leaveRangeEnd) + { + if (leaveRangeEnd == "MORNING") + remarkStr += " - ครึ่งวันเช้า"; + else if (leaveRangeEnd == "AFTERNOON") + remarkStr += " - ครึ่งวันบ่าย"; + } break; default: remarkStr += leaveReq.Type.Name; From ff66aebdfa08665afe9257efa1924148292cb500 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 15 Dec 2025 10:29:23 +0700 Subject: [PATCH 2/3] fix: update end time parsing and improve attendance status logic --- BMA.EHR.Leave/Controllers/LeaveController.cs | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index b751b322..6ae9f015 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -2373,9 +2373,30 @@ namespace BMA.EHR.Leave.Service.Controllers //var endTime = DateTimeOffset.Parse($"{DateTime.Now.Date.ToString("yyyy-MM-dd")}T{duty.EndTimeAfternoon}:00.0000000+07:00").ToLocalTime().DateTime; - var endTime = DateTime.Parse($"{DateTime.Now.Date.ToString("yyyy-MM-dd")}T{duty.EndTimeAfternoon}:00.0000000+07:00"); +  //var endTime = DateTime.Parse($"{DateTime.Now.Date.ToString("yyyy-MM-dd")}T{duty.EndTimeAfternoon}:00.0000000+07:00"); + var endTime = DateTime.Parse($"{DateTime.Now.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}"); + var status = string.Empty; + if(lastCheckIn == null) + { + status = "ABSENT"; + } + else if (lastCheckIn.CheckIn.Date < DateTime.Now.Date) + { + status = "NORMAL"; + } + else + { + if (time < endTime) + { + status = "ABSENT"; + } + else + { + status = "NORMAL"; + } + } - var status = lastCheckIn == null ? "ABSENT" : lastCheckIn.CheckIn.Date < DateTime.Now.Date ? "NORMAL" : time < endTime ? "ABSENT" : "NORMAL"; + //var status = lastCheckIn == null ? "ABSENT" : lastCheckIn.CheckIn.Date < DateTime.Now.Date ? "NORMAL" : time < endTime ? "ABSENT" : "NORMAL"; return Success(new { From 18ab28e335ecbc88eac5648ac61cf33dadaa4b5b Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 15 Dec 2025 11:12:29 +0700 Subject: [PATCH 3/3] fix: enhance database context configuration with retry logic for resilience --- .../InfrastructureServiceRegistration.cs | 24 +++++++++++++------ .../Controllers/LeaveReportController.cs | 7 +++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/BMA.EHR.Infrastructure/InfrastructureServiceRegistration.cs b/BMA.EHR.Infrastructure/InfrastructureServiceRegistration.cs index 36ba47ef..deee6910 100644 --- a/BMA.EHR.Infrastructure/InfrastructureServiceRegistration.cs +++ b/BMA.EHR.Infrastructure/InfrastructureServiceRegistration.cs @@ -20,8 +20,6 @@ namespace BMA.EHR.Infrastructure public static IServiceCollection AddLeavePersistence(this IServiceCollection services, IConfiguration configuration) { - - // leave db context var connectionStringLeave = configuration.GetConnectionString("LeaveConnection"); @@ -31,6 +29,10 @@ namespace BMA.EHR.Infrastructure { b.MigrationsAssembly(typeof(LeaveDbContext).Assembly.FullName); b.MigrationsHistoryTable("__LeaveMigrationsHistory"); + b.EnableRetryOnFailure( + maxRetryCount: 5, + maxRetryDelay: System.TimeSpan.FromSeconds(30), + errorNumbersToAdd: null); }), ServiceLifetime.Transient); @@ -43,8 +45,6 @@ namespace BMA.EHR.Infrastructure public static IServiceCollection AddDisciplinePersistence(this IServiceCollection services, IConfiguration configuration) { - - // discipline db context var connectionStringDiscipline = configuration.GetConnectionString("DisciplineConnection"); @@ -54,7 +54,10 @@ namespace BMA.EHR.Infrastructure { b.MigrationsAssembly(typeof(DisciplineDbContext).Assembly.FullName); b.MigrationsHistoryTable("__DisciplineMigrationsHistory"); - + b.EnableRetryOnFailure( + maxRetryCount: 5, + maxRetryDelay: System.TimeSpan.FromSeconds(30), + errorNumbersToAdd: null); }), ServiceLifetime.Transient); @@ -67,8 +70,6 @@ namespace BMA.EHR.Infrastructure IConfiguration configuration) { services.AddTransient(); - - var connectionString = configuration.GetConnectionString("DefaultConnection"); services.AddDbContext(options => @@ -77,9 +78,14 @@ namespace BMA.EHR.Infrastructure { b.MigrationsAssembly(typeof(ApplicationDBContext).Assembly.FullName); b.MigrationsHistoryTable("__EHRMigrationsHistory"); + b.EnableRetryOnFailure( + maxRetryCount: 5, + maxRetryDelay: System.TimeSpan.FromSeconds(30), + errorNumbersToAdd: null); }), ServiceLifetime.Transient); + services.AddTransient(provider => provider.GetService()); @@ -91,6 +97,10 @@ namespace BMA.EHR.Infrastructure { b.MigrationsAssembly(typeof(ApplicationDBExamContext).Assembly.FullName); b.MigrationsHistoryTable("__EHRMigrationsHistory"); + b.EnableRetryOnFailure( + maxRetryCount: 5, + maxRetryDelay: System.TimeSpan.FromSeconds(30), + errorNumbersToAdd: null); }), ServiceLifetime.Transient); diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 2b1c90be..ea798ed9 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -2167,8 +2167,8 @@ namespace BMA.EHR.Leave.Service.Controllers timeStamps.CheckOut != null ? timeStamps.CheckOut.Value.ToThaiFullDate2() : "", - checkInTimeRaw = timeStamps?.CheckIn, - checkOutTimeRaw = timeStamps?.CheckOut, + checkInTimeRaw = timeStamps == null ? dd.date.Date : timeStamps?.CheckIn, + checkOutTimeRaw = timeStamps == null ? dd.date.Date : timeStamps?.CheckOut != null ? timeStamps?.CheckOut : null, }; if (timeStamps != null) @@ -2204,7 +2204,8 @@ namespace BMA.EHR.Leave.Service.Controllers count++; } } - employees = employees.OrderBy(x => x.checkInDate).ThenBy(x => x.checkInTimeRaw ?? DateTime.MaxValue).ThenBy(x => x.checkOutTimeRaw ?? DateTime.MaxValue).ToList(); + //employees = employees.OrderBy(x => x.checkInDate).ThenBy(x => x.checkInTimeRaw ?? DateTime.MaxValue).ThenBy(x => x.checkOutTimeRaw ?? DateTime.MaxValue).ToList(); + employees = employees.OrderBy(x => x.checkInTimeRaw ?? DateTime.MaxValue).ThenBy(x => x.checkOutTimeRaw ?? DateTime.MaxValue).ToList(); for (int i = 0; i < employees.Count; i++) { employees[i].no = i + 1;