Add API
LV1_026 - รายการลารายบุคคล (ADMIN)
This commit is contained in:
parent
0ed8935b4c
commit
82e97ded24
3 changed files with 95 additions and 1 deletions
|
|
@ -516,6 +516,21 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
public async Task<double> GetSumApproveLeaveByRangeForUser(Guid keycloakUserId,DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||
.Where(x => x.LeaveStatus == "APPROVE")
|
||||
.ToListAsync();
|
||||
|
||||
if (data.Count > 0)
|
||||
return data.Sum(x => x.LeaveTotal);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public async Task<double> GetSumApproveLeaveByTypeAndRangeForUser(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Application.Repositories.Leaves.LeaveRequests;
|
||||
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
|
||||
using BMA.EHR.Application.Responses;
|
||||
using BMA.EHR.Domain.Common;
|
||||
|
|
@ -11,8 +12,10 @@ using BMA.EHR.Leave.Service.DTOs.Calendar;
|
|||
using BMA.EHR.Leave.Service.DTOs.ChangeRound;
|
||||
using BMA.EHR.Leave.Service.DTOs.CheckIn;
|
||||
using BMA.EHR.Leave.Service.DTOs.DutyTime;
|
||||
using BMA.EHR.Leave.Service.DTOs.LeaveRequest;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Org.BouncyCastle.Ocsp;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Security.Claims;
|
||||
|
|
@ -40,6 +43,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
private readonly ProcessUserTimeStampRepository _processUserTimeStampRepository;
|
||||
private readonly UserDutyTimeRepository _userDutyTimeRepository;
|
||||
private readonly AdditionalCheckRequestRepository _additionalCheckRequestRepository;
|
||||
private readonly LeaveRequestRepository _leaveRequestRepository;
|
||||
|
||||
private readonly UserCalendarRepository _userCalendarRepository;
|
||||
|
||||
|
|
@ -63,7 +67,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
UserDutyTimeRepository userDutyTimeRepository,
|
||||
AdditionalCheckRequestRepository additionalCheckRequestRepository,
|
||||
UserCalendarRepository userCalendarRepository,
|
||||
CommandRepository commandRepository)
|
||||
CommandRepository commandRepository,
|
||||
LeaveRequestRepository leaveRequestRepository)
|
||||
{
|
||||
_dutyTimeRepository = dutyTimeRepository;
|
||||
_context = context;
|
||||
|
|
@ -78,6 +83,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
_additionalCheckRequestRepository = additionalCheckRequestRepository;
|
||||
_userCalendarRepository = userCalendarRepository;
|
||||
_commandRepository = commandRepository;
|
||||
_leaveRequestRepository = leaveRequestRepository;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -1640,6 +1647,69 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// LV1_026 - รายการลารายบุคคล (ADMIN)
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// </returns>
|
||||
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("admin/summary/keycloak/{id:guid}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetLeaveSummaryByProfileAsync(Guid id, [FromBody] GetLeaveSummaryDto req)
|
||||
{
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(id);
|
||||
|
||||
var thisYear = DateTime.Now.Year;
|
||||
var startDate = req.StartDate;
|
||||
var endDate = req.EndDate;
|
||||
var leaveDayCount = await _leaveRequestRepository.GetSumApproveLeaveByRangeForUser(id, startDate, endDate);
|
||||
|
||||
var timeStamps = await _processUserTimeStampRepository.GetTimeStampHistoryByRangeForUserAsync(id, startDate, endDate);
|
||||
|
||||
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||
if (defaultRound == null)
|
||||
{
|
||||
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id);
|
||||
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
|
||||
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
|
||||
|
||||
var duty = userRound ?? defaultRound;
|
||||
|
||||
var processTimeStamps = timeStamps
|
||||
.Select(d => new
|
||||
{
|
||||
d.Id,
|
||||
CheckInStatus = DateTime.Parse(d.CheckIn.ToString("yyyy-MM-dd HH:mm")) >
|
||||
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}") ?
|
||||
"LATE" :
|
||||
"NORMAL",
|
||||
CheckOutStatus = d.CheckOut == null ? "" :
|
||||
DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
|
||||
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
|
||||
"LATE" :
|
||||
DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
|
||||
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ?
|
||||
"ABSENT" :
|
||||
"NORMAL",
|
||||
});
|
||||
|
||||
var absentCount = processTimeStamps.Count(x => x.CheckOutStatus == "ABSENT");
|
||||
var lateCount = processTimeStamps.Count(x => x.CheckInStatus == "LATE");
|
||||
|
||||
return Success(new
|
||||
{
|
||||
leave = leaveDayCount,
|
||||
late = lateCount
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
namespace BMA.EHR.Leave.Service.DTOs.LeaveRequest
|
||||
{
|
||||
public class GetLeaveSummaryDto
|
||||
{
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
public DateTime EndDate { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue