cronjob พ้นราชการ
This commit is contained in:
parent
dd6471ddf1
commit
cfaf90cb01
6 changed files with 171 additions and 20 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Repositories.MessageQueue;
|
||||
using BMA.EHR.Domain.Models.Retirement;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
|
@ -9,17 +10,83 @@ namespace BMA.EHR.Application.Repositories
|
|||
{
|
||||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
public RetirementRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
public RetirementRepository(IApplicationDBContext dbContext,
|
||||
NotificationRepository repositoryNoti,
|
||||
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
}
|
||||
|
||||
// public async Task<IEnumerable<Retirement>> FindByNameAsync(string name)
|
||||
// {
|
||||
// var data = await _dbContext.Set<Retirement>().Where(x => x.Name == name).ToListAsync();
|
||||
//ปลดออก
|
||||
public async Task NotifyDischarge()
|
||||
{
|
||||
var cronjobNotis = await _dbContext.Set<RetirementDischarge>()
|
||||
.Include(x => x.Profile)
|
||||
.ThenInclude(x => x.Prefix)
|
||||
.Where(x => x.Date != null && x.Date.Value.Date == DateTime.Now.Date)
|
||||
.AsQueryable()
|
||||
.ToListAsync();
|
||||
foreach (var cronjobNoti in cronjobNotis)
|
||||
{
|
||||
cronjobNoti.Profile.IsLeave = true;
|
||||
cronjobNoti.Profile.LeaveReason = "DISCHARGE";
|
||||
cronjobNoti.Profile.LeaveDate = DateTime.Now;
|
||||
// await _repositoryNoti.PushNotificationAsync(
|
||||
// Guid.Parse("08db721d-ada0-4e64-89d3-7584a893d8b8"),
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}",
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}"
|
||||
// );
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// return data;
|
||||
// }
|
||||
//ไล่ออก
|
||||
public async Task NotifyExpulsion()
|
||||
{
|
||||
var cronjobNotis = await _dbContext.Set<RetirementExpulsion>()
|
||||
.Include(x => x.Profile)
|
||||
.ThenInclude(x => x.Prefix)
|
||||
.Where(x => x.Date != null && x.Date.Value.Date == DateTime.Now.Date)
|
||||
.AsQueryable()
|
||||
.ToListAsync();
|
||||
foreach (var cronjobNoti in cronjobNotis)
|
||||
{
|
||||
cronjobNoti.Profile.IsLeave = true;
|
||||
cronjobNoti.Profile.LeaveReason = "DISMISS";
|
||||
cronjobNoti.Profile.LeaveDate = DateTime.Now;
|
||||
// await _repositoryNoti.PushNotificationAsync(
|
||||
// Guid.Parse("08db721d-ada0-4e64-89d3-7584a893d8b8"),
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}",
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}"
|
||||
// );
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
//ให้ออก
|
||||
public async Task NotifyOut()
|
||||
{
|
||||
var cronjobNotis = await _dbContext.Set<RetirementOut>()
|
||||
.Include(x => x.Profile)
|
||||
.ThenInclude(x => x.Prefix)
|
||||
.Where(x => x.Date != null && x.Date.Value.Date == DateTime.Now.Date)
|
||||
.AsQueryable()
|
||||
.ToListAsync();
|
||||
foreach (var cronjobNoti in cronjobNotis)
|
||||
{
|
||||
cronjobNoti.Profile.IsLeave = true;
|
||||
cronjobNoti.Profile.LeaveReason = "LAYOFF";
|
||||
cronjobNoti.Profile.LeaveDate = DateTime.Now;
|
||||
// await _repositoryNoti.PushNotificationAsync(
|
||||
// Guid.Parse("08db721d-ada0-4e64-89d3-7584a893d8b8"),
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}",
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}"
|
||||
// );
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue