This commit is contained in:
Suphonchai Phoonsawat 2025-07-11 10:03:38 +07:00
parent e58bda8e9e
commit 53e547f168
2 changed files with 268 additions and 2 deletions

View file

@ -740,7 +740,7 @@ namespace BMA.EHR.Application.Repositories
}
}
public async Task<List<SearchProfileDto>> SearchProfileEmployee(string? citizenId, string? firstName, string? lastName, string accessToken)
public async Task<List<SearchProfileDto>> SearchProfileEmployee(string? citizenId, string? firstName, string? lastName, string accessToken, string? role, string? nodeId, int? node)
{
try
{
@ -750,7 +750,10 @@ namespace BMA.EHR.Application.Repositories
{
citizenId = citizenId,
firstName = firstName,
lastName = lastName
lastName = lastName,
role = role,
nodeId = nodeId,
node = node,
};
var profiles = new List<SearchProfileDto>();

View file

@ -1851,6 +1851,193 @@ namespace BMA.EHR.Leave.Service.Controllers
}
#endregion
#region " เปลี่ยนรอบการทำงาน ลจ. "
/// <summary>
/// LV1_006 - เช็คเวลาต้องลงเวลาเข้าหรือออกงาน (USER) ลจ.
/// </summary>
/// <returns>
/// </returns>
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("emp/search")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> SearchEmpProfileAsync([FromBody] DTOs.ChangeRound.SearchProfileDto req)
{
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_WORK_ROUND_EDIT");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
string role = jsonData["result"]?.ToString();
var nodeId = string.Empty;
var profileAdmin = new GetUserOCAllDto();
profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken);
if (role == "NORMAL" || role == "CHILD")
{
nodeId = profileAdmin?.Node == 4
? profileAdmin?.Child4DnaId
: profileAdmin?.Node == 3
? profileAdmin?.Child3DnaId
: profileAdmin?.Node == 2
? profileAdmin?.Child2DnaId
: profileAdmin?.Node == 1
? profileAdmin?.Child1DnaId
: profileAdmin?.Node == 0
? profileAdmin?.RootDnaId
: "";
}
else if (role == "ROOT")
{
nodeId = profileAdmin?.RootDnaId;
}
var profile = await _userProfileRepository.SearchProfileEmployee(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", role, nodeId, profileAdmin?.Node);
var pagedProfile = profile.Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList();
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
var resultSet = new List<SearchProfileResultDto>();
foreach (var p in pagedProfile)
{
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
var duty = userRound ?? getDefaultRound;
var res = new SearchProfileResultDto
{
ProfileId = p.Id,
CitizenId = p.CitizenId ?? "",
FullName = $"{p.Prefix ?? ""}{p.FirstName ?? ""} {p.LastName ?? ""}",
StartTimeMorning = duty.StartTimeMorning,
LeaveTimeAfterNoon = duty.EndTimeAfternoon,
EffectiveDate = effectiveDate == null ? null : effectiveDate.EffectiveDate.Value.Date
};
resultSet.Add(res);
}
return Success(new { data = resultSet, total = profile.Count });
}
/// <summary>
/// LV1_014 - เปลี่ยนรอบการลงเวลา (ADMIN) Employee
/// </summary>
/// <returns>
/// </returns>
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("emp/round")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> CreateChangeEmpRoundAsync([FromBody] CreateChangeRoundDto req)
{
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;
if (req.EffectiveDate.Date < currentDate)
{
return Error(new Exception($"วันที่มีผลต้องมากกว่าหรือเท่ากับวันที่ปัจจุบัน({currentDate.ToString("yyyy-MM-dd")})"), StatusCodes.Status400BadRequest);
}
var old = await _userDutyTimeRepository.GetExist(req.ProfileId, req.EffectiveDate);
var profile = await _userProfileRepository.GetProfileByProfileIdAsync(req.ProfileId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
if (old != null)
{
return Error(new Exception("ไม่สามารถทำรายการได้ เนื่องจากมีการกำหนดรอบการทำงานในวันที่นี้ไว้แล้ว"), 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) Employee
/// </summary>
/// <returns>
/// </returns>
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("emp/round/{id:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetChangeEmpRoundHistoryByProfileIdAsync(Guid id, int page = 1, int pageSize = 10, string keyword = "")
{
var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_WORK_ROUND_EDIT");
if (getWorkflow == false)
{
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_WORK_ROUND_EDIT");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
}
var data = await _userDutyTimeRepository.GetListByProfileIdAsync(id);
var resultSet = new List<ChangeRoundHistoryDto>();
if (data != null)
{
resultSet = data
.GroupBy(item => item.ProfileId)
.SelectMany(group => group
.OrderBy(item => item.EffectiveDate) // เรียงลำดับตาม property ที่คุณต้องการ
.Select((item, index) => new ChangeRoundHistoryDto
{
Round = index + 1,
StartTimeMorning = item.DutyTime.StartTimeMorning,
LeaveTimeAfternoon = item.DutyTime.EndTimeAfternoon,
EffectiveDate = item.EffectiveDate.Value,
Remark = item.Remark
}))
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
}
return Success(new { data = resultSet, total = data.Count });
}
#endregion
#region " Check Checkout Time "
@ -2631,6 +2818,82 @@ namespace BMA.EHR.Leave.Service.Controllers
#endregion
#region " ปฏิทินการทำงานของ ลจ. "
/// <summary>
/// LV1_023 - แสดงปฏิทินวันทำงานรายคน (ADMIN) Employee
/// </summary>
/// <returns>
/// </returns>
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("admin/emp/work/{id:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetCalendarEmpByProfileAsync(Guid id)
{
var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_WORK_ROUND_EDIT");
if (getWorkflow == false)
{
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_WORK_ROUND_EDIT");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
if (jsonData["status"]?.ToString() != "200")
{
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
}
}
var data = await _userCalendarRepository.GetExist(id);
if (data == null)
return Success(new { Work = "NORMAL" });
else
return Success(new { Work = data.Calendar });
}
/// <summary>
/// LV1_024 - บันทึกแก้ไขปฏิทินวันทำงาน (ADMIN)
/// </summary>
/// <returns>
/// </returns>
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("admin/emp/work/{id:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> UpdateEmpCalendarByProfileAsync(Guid id, [FromBody] UpdateCalendarDto req)
{
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 data = await _userCalendarRepository.GetExist(id);
if (data != null)
{
data.Calendar = req.Work;
await _userCalendarRepository.UpdateAsync(data);
return Success();
}
else
{
data = new UserCalendar
{
ProfileId = id,
Calendar = req.Work
};
await _userCalendarRepository.AddAsync(data);
return Success();
}
}
#endregion
#region " แก้ไขสถานะการลงเวลา "
/// <summary>