cronjob retirement (test)
This commit is contained in:
parent
e42dd1926b
commit
01f16eaef4
3 changed files with 81 additions and 7 deletions
|
|
@ -3,6 +3,7 @@ using BMA.EHR.Application.Repositories.MessageQueue;
|
|||
using BMA.EHR.Domain.Models.Retirement;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories
|
||||
{
|
||||
|
|
@ -11,13 +12,16 @@ namespace BMA.EHR.Application.Repositories
|
|||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
private readonly IConfiguration _configuration;
|
||||
public RetirementRepository(IApplicationDBContext dbContext,
|
||||
NotificationRepository repositoryNoti,
|
||||
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IConfiguration configuration) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
//ปลดออก
|
||||
|
|
@ -92,11 +96,40 @@ namespace BMA.EHR.Application.Repositories
|
|||
//เกษียณอายุราชการ
|
||||
public async Task ExecuteRetirement()
|
||||
{
|
||||
//var retirePeriodOfficer = await _dbContext.Set<RetirementPeriod>()
|
||||
// .Include(x => x.RetirementRawProfiles.Where(y => y.Remove != "REMOVE"))
|
||||
// .Where(x => x.Year == DateTime.Now.Year)
|
||||
// .Where(x => x.Type.Trim().ToUpper().Contains("OFFICER"))
|
||||
// .FirstOrDefaultAsync();
|
||||
var retirePeriodOfficer = await _dbContext.Set<RetirementPeriod>()
|
||||
.Include(x => x.RetirementRawProfiles.Where(y => y.Remove != "REMOVE"))
|
||||
.Where(x => x.Year == /*DateTime.Now.Year*/2026)
|
||||
.Where(x => x.Type.Trim().ToUpper().Contains("OFFICER"))
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
var body = retirePeriodOfficer.RetirementProfiles
|
||||
.Select(x => new {
|
||||
profileId = x.profileId,
|
||||
//lastUpdateUserId = UserId,
|
||||
//lastUpdateFullName = FullName,
|
||||
})
|
||||
.ToList();
|
||||
|
||||
//ข้าราชการ
|
||||
var apiUrl = $"{_configuration["API"]}/org/unauthorize/retirement";
|
||||
//var apiUrl = $"http://localhost:13001/api/v1/org/unauthorize/retirement";
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
var jsonBody = JsonConvert.SerializeObject(body);
|
||||
var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
|
||||
var _req = new HttpRequestMessage(HttpMethod.Patch, apiUrl)
|
||||
{
|
||||
Content = content
|
||||
};
|
||||
var response = await client.SendAsync(_req);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1997,5 +1997,44 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
};
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
//เกษียณอายุราชการ
|
||||
//public async Task ExecuteRetirement()
|
||||
//{
|
||||
// var retirePeriodOfficer = await _context.RetirementPeriods
|
||||
// .Include(x => x.RetirementRawProfiles.Where(y => y.Remove != "REMOVE"))
|
||||
// .Where(x => x.Year == /*DateTime.Now.Year*/2026)
|
||||
// .Where(x => x.Type.Trim().ToUpper().Contains("OFFICER"))
|
||||
// .FirstOrDefaultAsync();
|
||||
|
||||
// var body = retirePeriodOfficer.RetirementProfiles
|
||||
// .Select(x => new {
|
||||
// profileId = x.profileId,
|
||||
// //lastUpdateUserId = UserId,
|
||||
// //lastUpdateFullName = FullName,
|
||||
// })
|
||||
// .ToList();
|
||||
|
||||
// //ข้าราชการ
|
||||
// //var apiUrl = $"{_configuration["API"]}/org/unauthorize/retirement";
|
||||
// var apiUrl = $"http://localhost:13001/api/v1/org/unauthorize/retirement";
|
||||
// using (var client = new HttpClient())
|
||||
// {
|
||||
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||
// client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
// var jsonBody = JsonConvert.SerializeObject(body);
|
||||
// var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
|
||||
// var _req = new HttpRequestMessage(HttpMethod.Patch, apiUrl)
|
||||
// {
|
||||
// Content = content
|
||||
// };
|
||||
// var response = await client.SendAsync(_req);
|
||||
// var responseContent = await response.Content.ReadAsStringAsync();
|
||||
// if (!response.IsSuccessStatusCode)
|
||||
// {
|
||||
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ using System.Text;
|
|||
using System.Transactions;
|
||||
using BMA.EHR.Retirement.Service.Filters;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Retirement.Service.Controllers;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
{
|
||||
|
|
@ -168,7 +169,8 @@ var app = builder.Build();
|
|||
//manager.AddOrUpdate("แจ้งเตือนระบบปลดออก", Job.FromExpression<RetirementRepository>(x => x.NotifyDischarge()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||
//manager.AddOrUpdate("แจ้งเตือนระบบไล่ออก", Job.FromExpression<RetirementRepository>(x => x.NotifyExpulsion()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||
//manager.AddOrUpdate("แจ้งเตือนระบบให้ออก", Job.FromExpression<RetirementRepository>(x => x.NotifyOut()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||
manager.AddOrUpdate("อัพเดทสถานะเกษียณอายุราชการ", Job.FromExpression<RetirementRepository>(x => x.ExecuteRetirement()), "*/2 * * * *", TimeZoneInfo.Local);
|
||||
manager.AddOrUpdate("อัพเดทสถานะเกษียณอายุราชการ", Job.FromExpression<RetirementRepository>(x => x.ExecuteRetirement()), Cron.Yearly(10, 1, 0, 0), TimeZoneInfo.Local);
|
||||
//manager.AddOrUpdate("Test อัพเดทสถานะเกษียณอายุราชการ", Job.FromExpression<RetirementController>(x => x.ExecuteRetirement()), Cron.Yearly(10, 1, 0, 0), TimeZoneInfo.Local);
|
||||
}
|
||||
|
||||
// apply migrations
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue