Add admin endpoints for processing leave tasks, including retrieval, deletion, and updates
This commit is contained in:
parent
759a51ab58
commit
2cd7798dd9
2 changed files with 189 additions and 28 deletions
|
|
@ -80,6 +80,19 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ดึงข้อมูล Job Status จาก UserId
|
||||||
|
/// </summary>
|
||||||
|
public async Task<List<LeaveProcessJobStatus>> GetByUserIdAsync(Guid userId)
|
||||||
|
{
|
||||||
|
var data = await _dbContext.Set<LeaveProcessJobStatus>()
|
||||||
|
.Where(x => x.CreatedUserId == userId.ToString("D"))
|
||||||
|
.OrderByDescending(x => x.CreatedDate)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ดึงข้อมูล Job Status ที่ยัง pending หรือ processing
|
/// ดึงข้อมูล Job Status ที่ยัง pending หรือ processing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -225,6 +238,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
// check วันลาของแต่ละคน
|
// check วันลาของแต่ละคน
|
||||||
var leaveReq = await _leaveRequestRepository.GetLeavePeriodAsync(keycloakUserId, dd.date);
|
var leaveReq = await _leaveRequestRepository.GetLeavePeriodAsync(keycloakUserId, dd.date);
|
||||||
var remarkStr = string.Empty;
|
var remarkStr = string.Empty;
|
||||||
|
var status = string.Empty;
|
||||||
|
var stampType = string.Empty;
|
||||||
|
var stampAmount = 0.0;
|
||||||
|
|
||||||
if (leaveReq != null)
|
if (leaveReq != null)
|
||||||
{
|
{
|
||||||
|
|
@ -260,6 +276,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
remarkStr += leaveReq.Type.Name;
|
remarkStr += leaveReq.Type.Name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
status = "LEAVE";
|
||||||
|
stampType = leaveReq.LeaveRange ?? "";
|
||||||
|
stampAmount = leaveReq.LeaveRange == "MORNING" || leaveReq.LeaveRangeEnd == "MORNING" ? 0.5 : 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -268,13 +287,18 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
if (dd.date <= DateTime.Now.Date)
|
if (dd.date <= DateTime.Now.Date)
|
||||||
{
|
{
|
||||||
remarkStr = "ขาดราชการ";
|
remarkStr = "ขาดราชการ";
|
||||||
|
status = "ABSENT";
|
||||||
|
stampType = "FULL_DAY";
|
||||||
|
stampAmount = 1;
|
||||||
if (dd.isHoliday == true)
|
if (dd.isHoliday == true)
|
||||||
{
|
{
|
||||||
remarkStr = $"วันหยุด ({dd.dateRemark})";
|
remarkStr = $"วันหยุด ({dd.dateRemark})";
|
||||||
|
status = "HOLIDAY";
|
||||||
}
|
}
|
||||||
else if (dd.isWeekEnd)
|
else if (dd.isWeekEnd)
|
||||||
{
|
{
|
||||||
remarkStr = dd.dateRemark;
|
remarkStr = dd.dateRemark;
|
||||||
|
status = "WEEKEND";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else remarkStr = "";
|
else remarkStr = "";
|
||||||
|
|
@ -285,12 +309,25 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
if (timeStamps.CheckOut != null)
|
if (timeStamps.CheckOut != null)
|
||||||
{
|
{
|
||||||
if (timeStamps.CheckOutStatus == "ABSENT")
|
if (timeStamps.CheckOutStatus == "ABSENT")
|
||||||
|
{
|
||||||
remarkStr = "ขาดราชการ" + (!timeStamps.IsLocationCheckOut ? $" (นอกสถานที่:{timeStamps.CheckOutLocationName})".Trim() : "");
|
remarkStr = "ขาดราชการ" + (!timeStamps.IsLocationCheckOut ? $" (นอกสถานที่:{timeStamps.CheckOutLocationName})".Trim() : "");
|
||||||
|
status = "ABSENT";
|
||||||
|
stampType = "FULL_DAY";
|
||||||
|
stampAmount = 1;
|
||||||
|
}
|
||||||
else if (timeStamps.CheckInStatus == "ABSENT")
|
else if (timeStamps.CheckInStatus == "ABSENT")
|
||||||
|
{
|
||||||
remarkStr = "ขาดราชการ" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
|
remarkStr = "ขาดราชการ" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
|
||||||
|
status = "ABSENT";
|
||||||
|
stampType = "FULL_DAY";
|
||||||
|
stampAmount = 1;
|
||||||
|
}
|
||||||
else if (timeStamps.CheckInStatus == "LATE")
|
else if (timeStamps.CheckInStatus == "LATE")
|
||||||
{
|
{
|
||||||
remarkStr = "สาย" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
|
remarkStr = "สาย" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
|
||||||
|
status = "LATE";
|
||||||
|
stampType = "FULL_DAY";
|
||||||
|
stampAmount = 1;
|
||||||
//lateTotal += 1;
|
//lateTotal += 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -299,9 +336,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (timeStamps.CheckInStatus == "ABSENT")
|
if (timeStamps.CheckInStatus == "ABSENT")
|
||||||
|
{
|
||||||
|
status = "ABSENT";
|
||||||
|
stampType = "FULL_DAY";
|
||||||
|
stampAmount = 1;
|
||||||
remarkStr = "ขาดราชการ" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
|
remarkStr = "ขาดราชการ" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
|
||||||
|
}
|
||||||
else if (timeStamps.CheckInStatus == "LATE")
|
else if (timeStamps.CheckInStatus == "LATE")
|
||||||
{
|
{
|
||||||
|
status = "LATE";
|
||||||
|
stampType = "FULL_DAY";
|
||||||
|
stampAmount = 1;
|
||||||
remarkStr = "สาย" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
|
remarkStr = "สาย" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
|
||||||
//lateTotal += 1;
|
//lateTotal += 1;
|
||||||
}
|
}
|
||||||
|
|
@ -313,24 +358,13 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
|
|
||||||
var emp = new DateResultReport
|
var emp = new DateResultReport
|
||||||
{
|
{
|
||||||
no = count,
|
profileId = p.Id.ToString(),
|
||||||
fullName = fullName,
|
stampDate = dd.date,
|
||||||
dutyTimeName = $"{duty.StartTimeMorning} - {duty.EndTimeAfternoon} น.",
|
stampType = stampType,
|
||||||
checkInLocation = timeStamps == null ? "" : timeStamps.CheckInPOI,
|
stampAmount = stampAmount,
|
||||||
checkInTime = timeStamps == null ? "" : $"{timeStamps.CheckIn.ToString("HH:mm")} น.",
|
|
||||||
checkOutLocation = timeStamps == null ? "" : timeStamps.CheckOutPOI ?? "",
|
|
||||||
checkOutTime = timeStamps == null ? "" :
|
|
||||||
timeStamps.CheckOut != null ?
|
|
||||||
$"{timeStamps.CheckOut.Value.ToString("HH:mm")} น." :
|
|
||||||
"",
|
|
||||||
remark = remarkStr,
|
remark = remarkStr,
|
||||||
checkInDate = timeStamps == null ? dd.date.Date.ToThaiFullDate2() : timeStamps.CheckIn.Date.ToThaiFullDate2(),
|
status = status
|
||||||
checkedOutDate = timeStamps == null ? dd.date.Date.ToThaiFullDate2() :
|
|
||||||
timeStamps.CheckOut != null ?
|
|
||||||
timeStamps.CheckOut.Value.ToThaiFullDate2() :
|
|
||||||
"",
|
|
||||||
checkInTimeRaw = timeStamps == null ? dd.date.Date : timeStamps?.CheckIn,
|
|
||||||
checkOutTimeRaw = timeStamps == null ? dd.date.Date : timeStamps?.CheckOut != null ? timeStamps?.CheckOut : null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
employees.Add(emp);
|
employees.Add(emp);
|
||||||
|
|
@ -403,18 +437,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
|
|
||||||
class DateResultReport
|
class DateResultReport
|
||||||
{
|
{
|
||||||
public int no { get; set; }
|
public string? profileId { get; set; }
|
||||||
public string fullName { get; set; }
|
public DateTime stampDate { get; set; }
|
||||||
public string dutyTimeName { get; set; }
|
public string stampType { get; set; }
|
||||||
public string checkInLocation { get; set; }
|
public double stampAmount { get; set; }
|
||||||
public string checkInTime { get; set; }
|
|
||||||
public string checkOutLocation { get; set; }
|
|
||||||
public string checkOutTime { get; set; }
|
|
||||||
public string remark { get; set; }
|
public string remark { get; set; }
|
||||||
public string checkInDate { get; set; }
|
public string status { get; set; }
|
||||||
public string checkedOutDate { get; set; }
|
|
||||||
public DateTime? checkInTimeRaw { get; set; }
|
|
||||||
public DateTime? checkOutTimeRaw { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4200,6 +4200,139 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// แสดงรายการ Task สำหรับ Process ข้อมูลวันลาและขาดราชการ (ADMIN)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// </returns>
|
||||||
|
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpGet("admin/leave-task/process")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> GetProcessTaskAsync()
|
||||||
|
{
|
||||||
|
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
||||||
|
|
||||||
|
var tasks = await _leaveProcessJobStatusRepository.GetByUserIdAsync(userId);
|
||||||
|
|
||||||
|
var result = tasks.Select(t => new
|
||||||
|
{
|
||||||
|
t.Id,
|
||||||
|
t.CreatedFullName,
|
||||||
|
t.CreatedAt,
|
||||||
|
t.Status,
|
||||||
|
t.StartDate,
|
||||||
|
t.EndDate,
|
||||||
|
t.ProcessingDate,
|
||||||
|
t.CompletedDate,
|
||||||
|
t.ErrorMessage
|
||||||
|
});
|
||||||
|
|
||||||
|
return Success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// แสดงรายการ Task สำหรับ Process ข้อมูลวันลาและขาดราชการ (ADMIN)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// </returns>
|
||||||
|
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpGet("admin/leave-task/process/{id:guid}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> GetProcessTaskByIdAsync(Guid id)
|
||||||
|
{
|
||||||
|
var task = await _leaveProcessJobStatusRepository.GetByTaskIdAsync(id);
|
||||||
|
|
||||||
|
if (task == null)
|
||||||
|
{
|
||||||
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = new
|
||||||
|
{
|
||||||
|
task.Id,
|
||||||
|
task.CreatedFullName,
|
||||||
|
task.CreatedAt,
|
||||||
|
task.Status,
|
||||||
|
task.StartDate,
|
||||||
|
task.EndDate,
|
||||||
|
task.ProcessingDate,
|
||||||
|
task.CompletedDate,
|
||||||
|
task.ErrorMessage
|
||||||
|
};
|
||||||
|
|
||||||
|
return Success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ลบ Task สำหรับ Process ข้อมูลวันลาและขาดราชการ (ADMIN)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// </returns>
|
||||||
|
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpDelete("admin/leave-task/process/{id:guid}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> DeleteProcessTaskByIdAsync(Guid id)
|
||||||
|
{
|
||||||
|
var task = await _leaveProcessJobStatusRepository.GetByTaskIdAsync(id);
|
||||||
|
|
||||||
|
if (task == null)
|
||||||
|
{
|
||||||
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
await _leaveProcessJobStatusRepository.DeleteAsync(task);
|
||||||
|
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// อัปเดต Task สำหรับ Process ข้อมูลวันลาและขาดราชการ (ADMIN)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// </returns>
|
||||||
|
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPut("admin/leave-task/process/{id:guid}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> UpdateProcessTaskByIdAsync(Guid id,[FromBody] CreateLeaveProcessJobDto req)
|
||||||
|
{
|
||||||
|
var task = await _leaveProcessJobStatusRepository.GetByTaskIdAsync(id);
|
||||||
|
|
||||||
|
if (task == null)
|
||||||
|
{
|
||||||
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(task.Status != "PENDING")
|
||||||
|
{
|
||||||
|
return Error("ไม่สามารถแก้ไขได้เนื่องจาก Task อยู่ในสถานะกำลังดำเนินการหรือดำเนินการเสร็จสิ้นแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
task.StartDate = req.StartDate;
|
||||||
|
task.EndDate = req.EndDate;
|
||||||
|
|
||||||
|
await _leaveProcessJobStatusRepository.UpdateAsync(task);
|
||||||
|
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue