add conjob insignia
This commit is contained in:
parent
42b1ae87fa
commit
ffac27ef76
4 changed files with 70 additions and 18 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
using BMA.EHR.Application.Common.Interfaces;
|
using BMA.EHR.Application.Common.Interfaces;
|
||||||
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
||||||
using BMA.EHR.Application.Responses;
|
using BMA.EHR.Application.Responses;
|
||||||
using BMA.EHR.Domain.Extensions;
|
using BMA.EHR.Domain.Extensions;
|
||||||
using BMA.EHR.Domain.Models.HR;
|
using BMA.EHR.Domain.Models.HR;
|
||||||
|
|
@ -19,6 +20,7 @@ namespace BMA.EHR.Application.Repositories.Reports
|
||||||
private readonly IApplicationDBContext _dbContext;
|
private readonly IApplicationDBContext _dbContext;
|
||||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||||
private readonly OrganizationCommonRepository _organizationCommonRepository;
|
private readonly OrganizationCommonRepository _organizationCommonRepository;
|
||||||
|
private readonly NotificationRepository _repositoryNoti;
|
||||||
private readonly string CRLF = "\r\n";
|
private readonly string CRLF = "\r\n";
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -27,10 +29,12 @@ namespace BMA.EHR.Application.Repositories.Reports
|
||||||
|
|
||||||
public InsigniaReportRepository(IApplicationDBContext dbContext,
|
public InsigniaReportRepository(IApplicationDBContext dbContext,
|
||||||
OrganizationCommonRepository organizationCommonRepository,
|
OrganizationCommonRepository organizationCommonRepository,
|
||||||
|
NotificationRepository repositoryNoti,
|
||||||
IWebHostEnvironment hostEnvironment)
|
IWebHostEnvironment hostEnvironment)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_hostingEnvironment = hostEnvironment;
|
_hostingEnvironment = hostEnvironment;
|
||||||
|
_repositoryNoti = repositoryNoti;
|
||||||
_organizationCommonRepository = organizationCommonRepository;
|
_organizationCommonRepository = organizationCommonRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -740,6 +744,23 @@ namespace BMA.EHR.Application.Repositories.Reports
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
public async Task NotifyInsignia()
|
||||||
|
{
|
||||||
|
var insigniaPeriods = await _dbContext.Set<InsigniaPeriod>()
|
||||||
|
.AsQueryable()
|
||||||
|
.ToListAsync();
|
||||||
|
foreach (var insigniaPeriod in insigniaPeriods)
|
||||||
|
{
|
||||||
|
if (insigniaPeriod.StartDate.AddDays(-insigniaPeriod.Amount).Date == DateTime.Now.Date)
|
||||||
|
{
|
||||||
|
await _repositoryNoti.PushNotificationAsync(
|
||||||
|
Guid.Parse("08db721d-ade4-480e-8d84-0853946a0ea5"),
|
||||||
|
$"แจ้งเตือนรอบการเสนอขอ {insigniaPeriod.Name} รอบที่{insigniaPeriod.Round}",
|
||||||
|
$"แจ้งเตือนรอบการเสนอขอ {insigniaPeriod.Name} รอบที่{insigniaPeriod.Round}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -290,22 +290,5 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
||||||
|
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task NotifyInsignia()
|
|
||||||
{
|
|
||||||
var insigniaPeriods = await _context.InsigniaPeriods.AsQueryable()
|
|
||||||
.ToListAsync();
|
|
||||||
foreach (var insigniaPeriod in insigniaPeriods)
|
|
||||||
{
|
|
||||||
if (insigniaPeriod.StartDate.AddDays(-insigniaPeriod.Amount).Date == DateTime.Now.Date)
|
|
||||||
{
|
|
||||||
await _repositoryNoti.PushNotificationAsync(
|
|
||||||
Guid.Parse("08db721d-ae67-4ed1-8b3c-490f44a73e65"),
|
|
||||||
$"แจ้งเตือนรอบการเสนอขอ {insigniaPeriod.Name} รอบที่{insigniaPeriod.Round}",
|
|
||||||
$"แจ้งเตือนรอบการเสนอขอ {insigniaPeriod.Name} รอบที่{insigniaPeriod.Round}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
16
BMA.EHR.Insignia.Service/Filters/CustomAuthorizeFilter.cs
Normal file
16
BMA.EHR.Insignia.Service/Filters/CustomAuthorizeFilter.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Hangfire.Dashboard;
|
||||||
|
|
||||||
|
namespace BMA.EHR.Insignia.Service.Filters
|
||||||
|
{
|
||||||
|
public class CustomAuthorizeFilter : IDashboardAuthorizationFilter
|
||||||
|
{
|
||||||
|
public bool Authorize([NotNull] DashboardContext context)
|
||||||
|
{
|
||||||
|
//var httpcontext = context.GetHttpContext();
|
||||||
|
//return httpcontext.User.Identity.IsAuthenticated;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
using BMA.EHR.Application;
|
using BMA.EHR.Application;
|
||||||
|
using BMA.EHR.Application.Repositories.Reports;
|
||||||
using BMA.EHR.Domain.Middlewares;
|
using BMA.EHR.Domain.Middlewares;
|
||||||
using BMA.EHR.Infrastructure;
|
using BMA.EHR.Infrastructure;
|
||||||
using BMA.EHR.Infrastructure.Persistence;
|
using BMA.EHR.Infrastructure.Persistence;
|
||||||
using BMA.EHR.Insignia.Service;
|
using BMA.EHR.Insignia.Service;
|
||||||
using BMA.EHR.Insignia.Service.Controllers;
|
using BMA.EHR.Insignia.Service.Controllers;
|
||||||
|
using BMA.EHR.Insignia.Service.Filters;
|
||||||
using Hangfire;
|
using Hangfire;
|
||||||
using Hangfire.Common;
|
using Hangfire.Common;
|
||||||
|
using Hangfire.MySql;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||||
|
|
@ -18,6 +21,7 @@ using Serilog.Exceptions;
|
||||||
using Serilog.Sinks.Elasticsearch;
|
using Serilog.Sinks.Elasticsearch;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Transactions;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
{
|
{
|
||||||
|
|
@ -92,7 +96,31 @@ var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
builder.Services.ConfigureOptions<ConfigureSwaggerOptions>();
|
builder.Services.ConfigureOptions<ConfigureSwaggerOptions>();
|
||||||
|
|
||||||
|
// Register DbContext
|
||||||
|
var defaultConnection = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||||
|
builder.Services.AddDbContext<ApplicationDBContext>(options =>
|
||||||
|
options.UseMySql(defaultConnection, ServerVersion.AutoDetect(defaultConnection)));
|
||||||
builder.Services.AddHealthChecks();
|
builder.Services.AddHealthChecks();
|
||||||
|
// Add Hangfire services.
|
||||||
|
builder.Services.AddHangfire(configuration => configuration
|
||||||
|
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||||
|
.UseSimpleAssemblyNameTypeSerializer()
|
||||||
|
.UseRecommendedSerializerSettings()
|
||||||
|
.UseStorage(
|
||||||
|
new MySqlStorage(
|
||||||
|
defaultConnection,
|
||||||
|
new MySqlStorageOptions
|
||||||
|
{
|
||||||
|
TransactionIsolationLevel = IsolationLevel.ReadCommitted,
|
||||||
|
QueuePollInterval = TimeSpan.FromSeconds(15),
|
||||||
|
JobExpirationCheckInterval = TimeSpan.FromHours(1),
|
||||||
|
CountersAggregateInterval = TimeSpan.FromMinutes(5),
|
||||||
|
PrepareSchemaIfNecessary = true,
|
||||||
|
DashboardJobListLimit = 50000,
|
||||||
|
TransactionTimeout = TimeSpan.FromMinutes(1),
|
||||||
|
TablesPrefix = "Hangfire"
|
||||||
|
})));
|
||||||
|
builder.Services.AddHangfireServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
@ -123,10 +151,14 @@ var app = builder.Build();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.UseMiddleware<ErrorHandlerMiddleware>();
|
app.UseMiddleware<ErrorHandlerMiddleware>();
|
||||||
|
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
|
||||||
|
{
|
||||||
|
Authorization = new[] { new CustomAuthorizeFilter() }
|
||||||
|
});
|
||||||
var manager = new RecurringJobManager();
|
var manager = new RecurringJobManager();
|
||||||
if (manager != null)
|
if (manager != null)
|
||||||
{
|
{
|
||||||
manager.AddOrUpdate("SendNotifyFirstRound", Job.FromExpression<InsigniaPeriodController>(x => x.NotifyInsignia()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
manager.AddOrUpdate("SendNotifyFirstRound", Job.FromExpression<InsigniaReportRepository>(x => x.NotifyInsignia()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply migrations
|
// apply migrations
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue