From aef81e9f4e7b8de198e30095c318b1aa2dac0f2c Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Wed, 25 Mar 2026 15:17:54 +0700 Subject: [PATCH] Add support for multiple child DNA IDs in leave processing and enhance batch creation of duty time changes --- .../Leaves/GenericLeaveRepository.cs | 18 ++++++++ .../Profiles/GetProfileByKeycloakIdRootDto.cs | 6 +++ BMA.EHR.Leave/Controllers/LeaveController.cs | 46 ++++++++++++------- .../DTOs/ChangeRound/CreateChangeRoundDto.cs | 21 +++++++++ .../ChangeRound/SearchProfileResultDto.cs | 6 +++ 5 files changed, 81 insertions(+), 16 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/GenericLeaveRepository.cs b/BMA.EHR.Application/Repositories/Leaves/GenericLeaveRepository.cs index 5fbbb8a1..93ae9cec 100644 --- a/BMA.EHR.Application/Repositories/Leaves/GenericLeaveRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/GenericLeaveRepository.cs @@ -68,6 +68,24 @@ namespace BMA.EHR.Application.Repositories.Leaves return entity; } + public virtual async Task> AddRangeAsync(List entities) + { + foreach (var entity in entities) + { + if (entity is EntityBase) + { + (entity as EntityBase).CreatedUserId = UserId ?? ""; + (entity as EntityBase).CreatedFullName = FullName ?? "System Administrator"; + (entity as EntityBase).CreatedAt = DateTime.Now; + } + } + + await _dbSet.AddRangeAsync(entities); + await _dbContext.SaveChangesAsync(); + + return entities; + } + public virtual async Task UpdateAsync(T entity) { if (entity is EntityBase) diff --git a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdRootDto.cs b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdRootDto.cs index 1110ca9e..2eff51dd 100644 --- a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdRootDto.cs +++ b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdRootDto.cs @@ -25,6 +25,12 @@ namespace BMA.EHR.Application.Responses.Profiles public DateTime? DateStart { get; set; } public DateTime? DateAppoint { get; set; } + + public string? RootDnaId { get; set; } + public string? Child1DnaId { get; set; } + public string? Child2DnaId { get; set; } + public string? Child3DnaId { get; set; } + public string? Child4DnaId { get; set; } } public class GetProfileByKeycloakIdRootAddTotalDto diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index 23d38e3a..0adb3a3a 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -2487,7 +2487,16 @@ namespace BMA.EHR.Leave.Service.Controllers FullName = $"{p.Prefix ?? ""}{p.FirstName ?? ""} {p.LastName ?? ""}", StartTimeMorning = duty.StartTimeMorning, LeaveTimeAfterNoon = duty.EndTimeAfternoon, - EffectiveDate = effectiveDate?.EffectiveDate?.Date + EffectiveDate = effectiveDate?.EffectiveDate?.Date, + Prefix = p.Prefix ?? "", + FirstName = p.FirstName ?? "", + LastName = p.LastName ?? "", + RootDnaId = p.RootDnaId, + Child1DnaId = p.Child1DnaId, + Child2DnaId = p.Child2DnaId, + Child3DnaId = p.Child3DnaId, + Child4DnaId = p.Child4DnaId + }; resultSet.Add(res); } @@ -2558,7 +2567,7 @@ namespace BMA.EHR.Leave.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task> CreateChangeRoundMultipleAsync([FromBody] List reqs) + public async Task> CreateChangeRoundMultipleAsync([FromBody] List reqs) { var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_WORK_ROUND_EDIT"); var jsonData = JsonConvert.DeserializeObject(getPermission); @@ -2568,24 +2577,28 @@ namespace BMA.EHR.Leave.Service.Controllers } var currentDate = DateTime.Now.Date; + List dataList = new List(); + foreach(var req in reqs) { - var profile = await _userProfileRepository.GetProfileByProfileIdAsync(req.ProfileId, AccessToken); - if (profile == null) - { - return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - } + // var profile = await _userProfileRepository.GetProfileByProfileIdAsync(req.ProfileId, AccessToken); + // if (profile == null) + // { + // return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); + // } if (req.EffectiveDate.Date < currentDate) { - return Error(new Exception($"กำหนดรอบลงเวลาของ {profile.FirstName} {profile.LastName} ผิดพลาด เนื่องจากวันที่มีผลต้องมากกว่าหรือเท่ากับวันที่ปัจจุบัน({currentDate.ToString("yyyy-MM-dd")})"), StatusCodes.Status400BadRequest); + continue; // move to next item if effective date is in the past, not return error + // return Error(new Exception($"กำหนดรอบลงเวลาของ {req.FirstName} {req.LastName} ผิดพลาด เนื่องจากวันที่มีผลต้องมากกว่าหรือเท่ากับวันที่ปัจจุบัน({currentDate.ToString("yyyy-MM-dd")})"), StatusCodes.Status400BadRequest); } var old = await _userDutyTimeRepository.GetExist(req.ProfileId, req.EffectiveDate); if (old != null) { - return Error(new Exception($"กำหนดรอบลงเวลาของ {profile.FirstName} {profile.LastName} ผิดพลาด เนื่องจากมีการกำหนดรอบการทำงานในวันที่นี้ไว้แล้ว"), StatusCodes.Status400BadRequest); + continue; // move to next item if already exist, not return error + //return Error(new Exception($"กำหนดรอบลงเวลาของ {req.FirstName} {req.LastName} ผิดพลาด เนื่องจากมีการกำหนดรอบการทำงานในวันที่นี้ไว้แล้ว"), StatusCodes.Status400BadRequest); } var data = new UserDutyTime @@ -2595,15 +2608,16 @@ namespace BMA.EHR.Leave.Service.Controllers EffectiveDate = req.EffectiveDate, Remark = req.Remark, - RootDnaId = profile.RootDnaId, - Child1DnaId = profile.Child1DnaId, - Child2DnaId = profile.Child2DnaId, - Child3DnaId = profile.Child3DnaId, - Child4DnaId = profile.Child4DnaId, + RootDnaId = req.RootDnaId, + Child1DnaId = req.Child1DnaId, + Child2DnaId = req.Child2DnaId, + Child3DnaId = req.Child3DnaId, + Child4DnaId = req.Child4DnaId, }; - - await _userDutyTimeRepository.AddAsync(data); + dataList.Add(data); } + + await _userDutyTimeRepository.AddRangeAsync(dataList); return Success(); } diff --git a/BMA.EHR.Leave/DTOs/ChangeRound/CreateChangeRoundDto.cs b/BMA.EHR.Leave/DTOs/ChangeRound/CreateChangeRoundDto.cs index 6ad96fcd..5379abda 100644 --- a/BMA.EHR.Leave/DTOs/ChangeRound/CreateChangeRoundDto.cs +++ b/BMA.EHR.Leave/DTOs/ChangeRound/CreateChangeRoundDto.cs @@ -12,4 +12,25 @@ namespace BMA.EHR.Leave.Service.DTOs.ChangeRound public string Remark { get; set; } } + + public class CreateChangeRoundMultipleDto + { + public Guid ProfileId { get; set; } + + public Guid RoundId { get; set; } + + public DateTime EffectiveDate { get; set; } + + public string Remark { get; set; } + + public Guid? RootDnaId { get; set; } + public Guid? Child1DnaId { get; set; } + public Guid? Child2DnaId { get; set; } + public Guid? Child3DnaId { get; set; } + public Guid? Child4DnaId { get; set; } + + public string? Prefix { get; set; } + public string? FirstName { get; set; } + public string? LastName { get; set; } + } } diff --git a/BMA.EHR.Leave/DTOs/ChangeRound/SearchProfileResultDto.cs b/BMA.EHR.Leave/DTOs/ChangeRound/SearchProfileResultDto.cs index 83b4d7b9..00df91a9 100644 --- a/BMA.EHR.Leave/DTOs/ChangeRound/SearchProfileResultDto.cs +++ b/BMA.EHR.Leave/DTOs/ChangeRound/SearchProfileResultDto.cs @@ -17,5 +17,11 @@ public string LeaveTimeAfterNoon { get;set; } public DateTime? EffectiveDate { get; set; } + + public string? RootDnaId { get; set; } + public string? Child1DnaId { get; set; } + public string? Child2DnaId { get; set; } + public string? Child3DnaId { get; set; } + public string? Child4DnaId { get; set; } } }