API การลา 01-03

This commit is contained in:
Suphonchai Phoonsawat 2023-11-29 17:28:15 +07:00
parent 32686c3e0b
commit cffb53c1f5
29 changed files with 6391 additions and 4 deletions

View file

@ -4,6 +4,7 @@ using BMA.EHR.Application.Repositories.Commands;
using BMA.EHR.Application.Repositories.Leaves.LeaveRequests;
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Application.Repositories.MetaData;
using BMA.EHR.Application.Repositories.Reports;
using Microsoft.Extensions.DependencyInjection;
@ -36,8 +37,7 @@ namespace BMA.EHR.Application
services.AddTransient<CandidateReportRepository>();
services.AddTransient<MinIOExamService>();
//services.AddTransient<DutyTimeRepository>();
//services.AddTransient<UserTimeStampRepository>();
services.AddTransient<HolidayRepository>();
return services;
}
@ -51,6 +51,7 @@ namespace BMA.EHR.Application
services.AddTransient<AdditionalCheckRequestRepository>();
services.AddTransient<LeaveTypeRepository>();
services.AddTransient<LeaveRequestRepository>();
return services;
}

View file

@ -0,0 +1,107 @@
using Amazon.S3.Model.Internal.MarshallTransformations;
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging;
using BMA.EHR.Domain.Models.Leave.Commons;
using BMA.EHR.Domain.Models.Leave.Requests;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
{
public class LeaveRequestRepository : GenericLeaveRepository<Guid, LeaveRequest>
{
#region " Fields "
private readonly ILeaveDbContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly OrganizationCommonRepository _organizationCommonRepository;
private readonly UserProfileRepository _userProfileRepository;
private readonly IConfiguration _configuration;
private readonly EmailSenderService _emailSenderService;
#endregion
#region " Constructor and Destuctor "
public LeaveRequestRepository(ILeaveDbContext dbContext,
IHttpContextAccessor httpContextAccessor,
OrganizationCommonRepository organizationCommonRepository,
UserProfileRepository userProfileRepository,
IConfiguration configuration,
EmailSenderService emailSenderService) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
_organizationCommonRepository = organizationCommonRepository;
_userProfileRepository = userProfileRepository;
_configuration = configuration;
_emailSenderService = emailSenderService;
}
#endregion
#region " Properties "
protected Guid UserOrganizationId
{
get
{
if (UserId != null || UserId != "")
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
else
return Guid.Empty;
}
}
#endregion
#region " Methods "
public async Task<int> GetRestDayTotalByYearForUserAsync(Guid keycloakUserId, int year)
{
var leaveType = await _dbContext.Set<LeaveType>().AsQueryable().FirstOrDefaultAsync(l => l.Code.Trim().ToUpper() == "LV-005");
if (leaveType == null)
{
throw new Exception("ไม่พบข้อมูลประเภทการลาพักผ่อน โปรดติดต่อผู้ดูและระบบ");
}
var data = _dbContext.Set<LeaveRequest>().AsQueryable()
.Include(x => x.Type)
.Where(x => x.KeycloakUserId == keycloakUserId)
.Where(x => x.Type.Id == leaveType.Id)
.Where(x => x.LeaveStartDate.Year == year)
.Sum(x => x.LeaveTotal);
return data;
}
public async Task<int> GetSumLeaveByTypeForUserAsync(Guid keycloakUserId, Guid leaveTypeId, int year)
{
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
.Include(x => x.Type)
.Where(x => x.KeycloakUserId == keycloakUserId)
.Where(x => x.Type.Id == leaveTypeId)
.Where(x => x.LeaveStartDate.Year == year)
.ToListAsync();
return data.Sum(x => x.LeaveTotal);
}
public async Task<DateTime?> GetLeaveLastByTypeForUserAsync(Guid keycloakUserId, Guid leaveTypeId)
{
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
.Include(x => x.Type)
.Where(x => x.KeycloakUserId == keycloakUserId)
.Where(x => x.Type.Id == leaveTypeId)
.OrderByDescending(x => x.LeaveStartDate.Date)
.Select(x => x.LeaveStartDate.Date)
.FirstOrDefaultAsync();
return data;
}
#endregion
}
}

View file

@ -0,0 +1,40 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Models.MetaData;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Application.Repositories.MetaData
{
public class HolidayRepository : GenericRepository<Guid, Holiday>
{
#region " Fields "
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Costructor and Destructor "
public HolidayRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Methods "
public async Task<int> GetHolidayCountAsync(DateTime startDate,DateTime endDate, string category = "NORMAL")
{
var data = await _dbContext.Set<Holiday>().AsQueryable()
.Where(x => x.HolidayDate.Date >= startDate && x.HolidayDate.Date <= endDate)
.CountAsync();
return data;
}
#endregion
}
}

View file

@ -34,6 +34,9 @@ namespace BMA.EHR.Application.Repositories
{
var data = await _dbContext.Set<Profile>().AsQueryable()
.Include(p => p.Prefix)
.Include(p => p.Position)
.Include(p => p.PositionLevel)
.Include(p => p.Salaries)
.FirstOrDefaultAsync(p => p.KeycloakId == keycloakId);
return data;