Add CreateChangeRoundMultipleAsync method for batch processing of duty time changes #1555
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m51s
Build & Deploy Placement Service / build (push) Successful in 1m54s
Build & Deploy Insignia Service / build (push) Successful in 1m51s
Build & Deploy Discipline Service / build (push) Successful in 1m51s

This commit is contained in:
Suphonchai Phoonsawat 2026-03-23 09:49:17 +07:00
parent 7e0f0485fd
commit 23bbd9791e

View file

@ -2554,6 +2554,59 @@ namespace BMA.EHR.Leave.Service.Controllers
}
[HttpPost("round/multiple")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> CreateChangeRoundMultipleAsync([FromBody] List<CreateChangeRoundDto> reqs)
{
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_WORK_ROUND_EDIT");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
var currentDate = DateTime.Now.Date;
foreach(var req in reqs)
{
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);
}
var old = await _userDutyTimeRepository.GetExist(req.ProfileId, req.EffectiveDate);
if (old != null)
{
return Error(new Exception($"กำหนดรอบลงเวลาของ {profile.FirstName} {profile.LastName} ผิดพลาด เนื่องจากมีการกำหนดรอบการทำงานในวันที่นี้ไว้แล้ว"), StatusCodes.Status400BadRequest);
}
var data = new UserDutyTime
{
ProfileId = req.ProfileId,
DutyTimeId = req.RoundId,
EffectiveDate = req.EffectiveDate,
Remark = req.Remark,
RootDnaId = profile.RootDnaId,
Child1DnaId = profile.Child1DnaId,
Child2DnaId = profile.Child2DnaId,
Child3DnaId = profile.Child3DnaId,
Child4DnaId = profile.Child4DnaId,
};
await _userDutyTimeRepository.AddAsync(data);
}
return Success();
}
/// <summary>
/// LV1_015 - ประวัติการเปลี่ยนรอบการลงเวลา (ADMIN)
/// </summary>