fix: Leave Performance

This commit is contained in:
Suphonchai Phoonsawat 2024-07-08 10:50:11 +07:00
parent aaa180e217
commit 9c696be46e
4 changed files with 132 additions and 140 deletions

View file

@ -3,6 +3,7 @@ using System.Net.Http.Headers;
using System.Net.Http.Json;
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging;
using BMA.EHR.Application.Responses.Leaves;
using BMA.EHR.Domain.Models.HR;
using BMA.EHR.Domain.Models.Leave.Commons;
using BMA.EHR.Domain.Models.Leave.Requests;
@ -552,6 +553,48 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
return 0;
}
public async Task<List<GetSumApproveLeaveByTypeDto>> GetSumApproveLeaveByTypeAndRange(DateTime startDate, DateTime endDate)
{
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
.Include(x => x.Type)
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
.Where(x => x.LeaveStatus == "APPROVE").ToListAsync();
var res = (from d in data
group d by new { d.KeycloakUserId, LeaveTypeId = d.Type.Id, LeaveTypeCode = d.Type.Code } into grp
select new GetSumApproveLeaveByTypeDto
{
KeycloakUserId = grp.Key.KeycloakUserId,
LeaveTypeId = grp.Key.LeaveTypeId,
LeaveTypeCode = grp.Key.LeaveTypeCode,
SumLeaveDay = grp.Sum(x => x.LeaveTotal)
})
.ToList();
return res;
}
public async Task<List<GetCountApproveLeaveByTypeDto>> GetCountApproveLeaveByTypeAndRange(DateTime startDate, DateTime endDate)
{
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
.Include(x => x.Type)
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
.Where(x => x.LeaveStatus == "APPROVE").ToListAsync();
var res = (from d in data
group d by new { d.KeycloakUserId, LeaveTypeId = d.Type.Id, LeaveTypeCode = d.Type.Code } into grp
select new GetCountApproveLeaveByTypeDto
{
KeycloakUserId = grp.Key.KeycloakUserId,
LeaveTypeId = grp.Key.LeaveTypeId,
LeaveTypeCode = grp.Key.LeaveTypeCode,
CountLeave = grp.Count()
})
.ToList();
return res;
}
public async Task<double> GetSumApproveLeaveByTypeAndRangeForUser(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
{
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()

View file

@ -0,0 +1,13 @@
namespace BMA.EHR.Application.Responses.Leaves
{
public class GetCountApproveLeaveByTypeDto
{
public Guid KeycloakUserId { get; set; }
public Guid LeaveTypeId { get; set; }
public string LeaveTypeCode { get; set; } = string.Empty;
public int CountLeave { get; set; }
}
}

View file

@ -0,0 +1,13 @@
namespace BMA.EHR.Application.Responses.Leaves
{
public class GetSumApproveLeaveByTypeDto
{
public Guid KeycloakUserId { get; set; }
public Guid LeaveTypeId { get; set; }
public string LeaveTypeCode { get; set; } = string.Empty;
public double SumLeaveDay { get; set; }
}
}