Add admin endpoints for processing leave tasks, including retrieval, deletion, and updates

This commit is contained in:
Suphonchai Phoonsawat 2026-03-31 09:46:44 +07:00
parent 759a51ab58
commit 2cd7798dd9
2 changed files with 189 additions and 28 deletions

View file

@ -80,6 +80,19 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
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>
/// ดึงข้อมูล Job Status ที่ยัง pending หรือ processing
/// </summary>
@ -225,6 +238,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
// check วันลาของแต่ละคน
var leaveReq = await _leaveRequestRepository.GetLeavePeriodAsync(keycloakUserId, dd.date);
var remarkStr = string.Empty;
var status = string.Empty;
var stampType = string.Empty;
var stampAmount = 0.0;
if (leaveReq != null)
{
@ -260,6 +276,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
remarkStr += leaveReq.Type.Name;
break;
}
status = "LEAVE";
stampType = leaveReq.LeaveRange ?? "";
stampAmount = leaveReq.LeaveRange == "MORNING" || leaveReq.LeaveRangeEnd == "MORNING" ? 0.5 : 1;
}
else
{
@ -268,13 +287,18 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
if (dd.date <= DateTime.Now.Date)
{
remarkStr = "ขาดราชการ";
status = "ABSENT";
stampType = "FULL_DAY";
stampAmount = 1;
if (dd.isHoliday == true)
{
remarkStr = $"วันหยุด ({dd.dateRemark})";
status = "HOLIDAY";
}
else if (dd.isWeekEnd)
{
remarkStr = dd.dateRemark;
status = "WEEKEND";
}
}
else remarkStr = "";
@ -285,12 +309,25 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
if (timeStamps.CheckOut != null)
{
if (timeStamps.CheckOutStatus == "ABSENT")
{
remarkStr = "ขาดราชการ" + (!timeStamps.IsLocationCheckOut ? $" (นอกสถานที่:{timeStamps.CheckOutLocationName})".Trim() : "");
status = "ABSENT";
stampType = "FULL_DAY";
stampAmount = 1;
}
else if (timeStamps.CheckInStatus == "ABSENT")
{
remarkStr = "ขาดราชการ" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
status = "ABSENT";
stampType = "FULL_DAY";
stampAmount = 1;
}
else if (timeStamps.CheckInStatus == "LATE")
{
remarkStr = "สาย" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
status = "LATE";
stampType = "FULL_DAY";
stampAmount = 1;
//lateTotal += 1;
}
else
@ -299,9 +336,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
else
{
if (timeStamps.CheckInStatus == "ABSENT")
{
status = "ABSENT";
stampType = "FULL_DAY";
stampAmount = 1;
remarkStr = "ขาดราชการ" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
}
else if (timeStamps.CheckInStatus == "LATE")
{
status = "LATE";
stampType = "FULL_DAY";
stampAmount = 1;
remarkStr = "สาย" + (!timeStamps.IsLocationCheckIn ? $" (นอกสถานที่:{timeStamps.CheckInLocationName})".Trim() : "");
//lateTotal += 1;
}
@ -313,24 +358,13 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
var emp = new DateResultReport
{
no = count,
fullName = fullName,
dutyTimeName = $"{duty.StartTimeMorning} - {duty.EndTimeAfternoon} น.",
checkInLocation = timeStamps == null ? "" : timeStamps.CheckInPOI,
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")} น." :
"",
profileId = p.Id.ToString(),
stampDate = dd.date,
stampType = stampType,
stampAmount = stampAmount,
remark = remarkStr,
checkInDate = timeStamps == null ? dd.date.Date.ToThaiFullDate2() : timeStamps.CheckIn.Date.ToThaiFullDate2(),
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,
status = status
};
employees.Add(emp);
@ -403,18 +437,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
class DateResultReport
{
public int no { get; set; }
public string fullName { get; set; }
public string dutyTimeName { get; set; }
public string checkInLocation { get; set; }
public string checkInTime { get; set; }
public string checkOutLocation { get; set; }
public string checkOutTime { get; set; }
public string? profileId { get; set; }
public DateTime stampDate { get; set; }
public string stampType { get; set; }
public double stampAmount { get; set; }
public string remark { get; set; }
public string checkInDate { get; set; }
public string checkedOutDate { get; set; }
public DateTime? checkInTimeRaw { get; set; }
public DateTime? checkOutTimeRaw { get; set; }
public string status { get; set; }
}
}