Add support for multiple child DNA IDs in leave processing and enhance batch creation of duty time changes
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m45s

This commit is contained in:
Suphonchai Phoonsawat 2026-03-25 15:17:54 +07:00
parent 6427cb4344
commit aef81e9f4e
5 changed files with 81 additions and 16 deletions

View file

@ -68,6 +68,24 @@ namespace BMA.EHR.Application.Repositories.Leaves
return entity;
}
public virtual async Task<IReadOnlyList<T>> AddRangeAsync(List<T> 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<T> UpdateAsync(T entity)
{
if (entity is EntityBase)

View file

@ -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

View file

@ -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<ActionResult<ResponseObject>> CreateChangeRoundMultipleAsync([FromBody] List<CreateChangeRoundDto> reqs)
public async Task<ActionResult<ResponseObject>> CreateChangeRoundMultipleAsync([FromBody] List<CreateChangeRoundMultipleDto> reqs)
{
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_WORK_ROUND_EDIT");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
@ -2568,24 +2577,28 @@ namespace BMA.EHR.Leave.Service.Controllers
}
var currentDate = DateTime.Now.Date;
List<UserDutyTime> dataList = new List<UserDutyTime>();
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();
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}