修改定时任务
parent
8a3db78cd0
commit
0006f12151
|
@ -13,6 +13,8 @@ using System.IO;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
using IRaCIS.Core.Infra.EFCore;
|
using IRaCIS.Core.Infra.EFCore;
|
||||||
using IRaCIS.Core.Application.Helper;
|
using IRaCIS.Core.Application.Helper;
|
||||||
|
using IRaCIS.Application.Services.BackGroundJob;
|
||||||
|
using Hangfire;
|
||||||
|
|
||||||
namespace IRaCIS.Core.API
|
namespace IRaCIS.Core.API
|
||||||
{
|
{
|
||||||
|
@ -59,17 +61,10 @@ namespace IRaCIS.Core.API
|
||||||
Log.Logger.Warning($"当前环境:{enviromentName}");
|
Log.Logger.Warning($"当前环境:{enviromentName}");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NewId.SetProcessIdProvider(new CurrentProcessIdProvider());
|
NewId.SetProcessIdProvider(new CurrentProcessIdProvider());
|
||||||
|
|
||||||
|
////缓存项目的状态 匿名化数据
|
||||||
//缓存项目的状态 匿名化数据
|
//await InitCache(host);
|
||||||
await InitCache(host);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
host.Run();
|
host.Run();
|
||||||
|
|
||||||
|
@ -107,15 +102,7 @@ namespace IRaCIS.Core.API
|
||||||
var _repository = host.Services.GetService(typeof(IRepository)) as IRepository;
|
var _repository = host.Services.GetService(typeof(IRepository)) as IRepository;
|
||||||
|
|
||||||
//初始化 国际化数据,并且监测国际化文件变更
|
//初始化 国际化数据,并且监测国际化文件变更
|
||||||
await InternationalizationHelper.InitInternationlizationDataAndWatchJsonFileAsync(_repository);
|
//await InternationalizationHelper.InitInternationlizationDataAndWatchJsonFileAsync(_repository);
|
||||||
|
|
||||||
var _mediator = host.Services.GetService(typeof(IMediator)) as IMediator;
|
|
||||||
|
|
||||||
await _mediator.Send(new AnonymizeCacheRequest());
|
|
||||||
|
|
||||||
await _mediator.Send(new TrialStateCacheRequest());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ using Hangfire.Dashboard;
|
||||||
using Hangfire.Dashboard.BasicAuthorization;
|
using Hangfire.Dashboard.BasicAuthorization;
|
||||||
using IRaCIS.Application.Services.BackGroundJob;
|
using IRaCIS.Application.Services.BackGroundJob;
|
||||||
using IRaCIS.Core.API.Filter;
|
using IRaCIS.Core.API.Filter;
|
||||||
|
using IRaCIS.Core.Application.Helper;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
|
||||||
|
@ -43,6 +44,9 @@ namespace IRaCIS.Core.API
|
||||||
});
|
});
|
||||||
|
|
||||||
#region hangfire
|
#region hangfire
|
||||||
|
|
||||||
|
HangfireJobHelper.ImmediatelyOnceOnlyJob<IIRaCISHangfireJob>( t => t.InitHangfireJobTaskAsync() );
|
||||||
|
|
||||||
|
|
||||||
//// 延迟任务执行 1秒之后执行 有时启动没运行 换成添加到队列中
|
//// 延迟任务执行 1秒之后执行 有时启动没运行 换成添加到队列中
|
||||||
//BackgroundJob.Schedule<ICacheTrialStatusJob>(t => t.MemoryCacheTrialStatus(), TimeSpan.FromSeconds(1));
|
//BackgroundJob.Schedule<ICacheTrialStatusJob>(t => t.MemoryCacheTrialStatus(), TimeSpan.FromSeconds(1));
|
||||||
|
|
|
@ -6,11 +6,10 @@ using Quartz;
|
||||||
|
|
||||||
namespace IRaCIS.Core.API
|
namespace IRaCIS.Core.API
|
||||||
{
|
{
|
||||||
public static class QuartZSetup
|
public static class QuartZSetup
|
||||||
{
|
{
|
||||||
public static void AddQuartZSetup(this IServiceCollection services, IConfiguration configuration)
|
public static void AddQuartZSetup(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
services.AddTransient<CacheTrialStatusQuartZJob>();
|
|
||||||
services.AddTransient<CancelTaskQuartZJob>();
|
services.AddTransient<CancelTaskQuartZJob>();
|
||||||
|
|
||||||
services.AddQuartz(q =>
|
services.AddQuartz(q =>
|
||||||
|
@ -21,16 +20,17 @@ namespace IRaCIS.Core.API
|
||||||
q.UseMicrosoftDependencyInjectionJobFactory();
|
q.UseMicrosoftDependencyInjectionJobFactory();
|
||||||
|
|
||||||
// 基本Quartz调度器、作业和触发器配置
|
// 基本Quartz调度器、作业和触发器配置
|
||||||
var jobKey = new JobKey("RegularTrialWork", "regularWorkGroup");
|
//var jobKey = new JobKey("RegularTrialWork", "regularWorkGroup");
|
||||||
q.AddJob<CacheTrialStatusQuartZJob>(jobKey, j => j
|
//q.AddJob<CacheTrialStatusQuartZJob>(jobKey, j => j
|
||||||
.WithDescription("Trial regular work")
|
// .WithDescription("Trial regular work")
|
||||||
);
|
//);
|
||||||
q.AddTrigger(t => t
|
|
||||||
.WithIdentity("TrialStatusTrigger")
|
//q.AddTrigger(t => t
|
||||||
.ForJob(jobKey)
|
// .WithIdentity("TrialStatusTrigger")
|
||||||
.WithCronSchedule("0 0 * * * ?")
|
// .ForJob(jobKey)
|
||||||
.WithDescription("My regular trial work trigger")
|
// .WithCronSchedule("0 0 * * * ?")
|
||||||
);
|
// .WithDescription("My regular trial work trigger")
|
||||||
|
//);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace IRaCIS.Core.API
|
||||||
//指定存储介质
|
//指定存储介质
|
||||||
hangFireConfig.UseSqlServerStorage(hangFireConnStr, new SqlServerStorageOptions()
|
hangFireConfig.UseSqlServerStorage(hangFireConnStr, new SqlServerStorageOptions()
|
||||||
{
|
{
|
||||||
SchemaName = "hangfire",
|
SchemaName = "dbo",
|
||||||
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||||
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||||
QueuePollInterval = TimeSpan.Zero,
|
QueuePollInterval = TimeSpan.Zero,
|
||||||
|
@ -33,7 +33,11 @@ namespace IRaCIS.Core.API
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddHangfireServer();
|
services.AddHangfireServer(option =>
|
||||||
|
{
|
||||||
|
option.ServerName = "test_study";
|
||||||
|
option.Queues = new[] { "immediately_once","default" };
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@
|
||||||
"LoginMaxFailCount": 5,
|
"LoginMaxFailCount": 5,
|
||||||
|
|
||||||
"LoginFailLockMinutes": 30
|
"LoginFailLockMinutes": 30
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"SystemEmailSendConfig": {
|
"SystemEmailSendConfig": {
|
||||||
|
@ -31,7 +30,9 @@
|
||||||
"Host": "smtp.qiye.aliyun.com",
|
"Host": "smtp.qiye.aliyun.com",
|
||||||
"FromEmail": "test-study@extimaging.com",
|
"FromEmail": "test-study@extimaging.com",
|
||||||
"FromName": "Test_Study",
|
"FromName": "Test_Study",
|
||||||
"AuthorizationCode": "zhanying123"
|
"AuthorizationCode": "zhanying123",
|
||||||
|
|
||||||
|
"SiteUrl": "http://test.study.extimaging.com/login"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,8 @@
|
||||||
"Host": "smtp.qiye.aliyun.com",
|
"Host": "smtp.qiye.aliyun.com",
|
||||||
"FromEmail": "uat-study@extimaging.com",
|
"FromEmail": "uat-study@extimaging.com",
|
||||||
"FromName": "Uat_Study",
|
"FromName": "Uat_Study",
|
||||||
"AuthorizationCode": "zhanying123"
|
"AuthorizationCode": "zhanying123",
|
||||||
|
"SiteUrl": "http://uat.study.extimaging.com/login"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div style='line-height: 24px;font-size: 14px;color:#333;margin-top: 20px;padding-bottom: 40px;'>
|
<div style='line-height: 24px;font-size: 14px;color:#333;margin-top: 20px;padding-bottom: 40px;'>
|
||||||
<div>祝您顺利!/Best Regards</div>
|
<div>祝您顺利!/Best Regards</div>
|
||||||
<div style="font-size: 14px;">展影医疗</div>
|
<div style="font-size: 14px;">展影医疗</div>
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using EasyCaching.Core;
|
|
||||||
using IRaCIS.Core.Domain;
|
|
||||||
using IRaCIS.Core.Infra.EFCore;
|
|
||||||
using IRaCIS.Core.Domain.Models;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Quartz;
|
|
||||||
using IRaCIS.Core.Domain.Share;
|
|
||||||
|
|
||||||
namespace IRaCIS.Application.Services.BackGroundJob
|
|
||||||
{
|
|
||||||
|
|
||||||
public class CacheTrialStatusQuartZJob: IJob
|
|
||||||
{
|
|
||||||
|
|
||||||
private readonly IRepository<Trial> _trialRepository;
|
|
||||||
private readonly IEasyCachingProvider _provider;
|
|
||||||
private readonly ILogger<CacheTrialStatusQuartZJob> _logger;
|
|
||||||
private readonly IRepository<SystemAnonymization> _systemAnonymizationRepository;
|
|
||||||
|
|
||||||
public CacheTrialStatusQuartZJob(IRepository<Trial> trialRepository, IEasyCachingProvider provider,ILogger<CacheTrialStatusQuartZJob> logger, IRepository<SystemAnonymization> systemAnonymizationRepository)
|
|
||||||
{
|
|
||||||
_trialRepository = trialRepository;
|
|
||||||
_provider = provider;
|
|
||||||
_logger = logger;
|
|
||||||
_systemAnonymizationRepository = systemAnonymizationRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Execute(IJobExecutionContext context)
|
|
||||||
|
|
||||||
{
|
|
||||||
_logger.LogInformation($"开始执行QuartZ定时任务作业");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await MemoryCacheTrialStatus();
|
|
||||||
|
|
||||||
await MemoryCacheAnonymizeData();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.LogError($" 查询和缓存过程出现异常"+e.Message);
|
|
||||||
}
|
|
||||||
_logger.LogInformation("QuartZ定时任务作业结束");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task MemoryCacheTrialStatus()
|
|
||||||
{
|
|
||||||
var list = await _trialRepository.Select(t => new { TrialId = t.Id, TrialStatusStr = t.TrialStatusStr })
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
list.ForEach(t => _provider.Set(t.TrialId.ToString(), t.TrialStatusStr, TimeSpan.FromDays(7)));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task MemoryCacheAnonymizeData()
|
|
||||||
{
|
|
||||||
var systemAnonymizationList = await _systemAnonymizationRepository.Where(t => t.IsEnable).ToListAsync();
|
|
||||||
|
|
||||||
_provider.Set(StaticData.Anonymize.Anonymize_AddFixedFiled, systemAnonymizationList.Where(t => t.IsAdd && t.IsFixed).ToList(), TimeSpan.FromDays(7));
|
|
||||||
_provider.Set(StaticData.Anonymize.Anonymize_AddIRCInfoFiled, systemAnonymizationList.Where(t => t.IsAdd && t.IsFixed == false).ToList(), TimeSpan.FromDays(7));
|
|
||||||
_provider.Set(StaticData.Anonymize.Anonymize_FixedField, systemAnonymizationList.Where(t => t.IsAdd == false && t.IsFixed).ToList(), TimeSpan.FromDays(7));
|
|
||||||
_provider.Set(StaticData.Anonymize.Anonymize_IRCInfoField, systemAnonymizationList.Where(t => t.IsAdd == false && t.IsFixed == false).ToList(), TimeSpan.FromDays(7));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,197 @@
|
||||||
|
using EasyCaching.Core;
|
||||||
|
using Hangfire;
|
||||||
|
using IRaCIS.Core.Application.Helper;
|
||||||
|
using IRaCIS.Core.Application.Service;
|
||||||
|
using IRaCIS.Core.Domain.Share;
|
||||||
|
using IRaCIS.Core.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace IRaCIS.Application.Services.BackGroundJob
|
||||||
|
{
|
||||||
|
|
||||||
|
public interface IIRaCISHangfireJob
|
||||||
|
{
|
||||||
|
|
||||||
|
Task MemoryCacheTrialStatusAsync();
|
||||||
|
|
||||||
|
Task InitHangfireJobTaskAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
public class IRaCISCHangfireJob : IIRaCISHangfireJob
|
||||||
|
{
|
||||||
|
public static string JsonFileFolder = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources);
|
||||||
|
|
||||||
|
private readonly IRepository<Trial> _trialRepository;
|
||||||
|
private readonly IEasyCachingProvider _provider;
|
||||||
|
private readonly ILogger<IRaCISCHangfireJob> _logger;
|
||||||
|
|
||||||
|
private readonly IRepository<TrialEmailNoticeConfig> _trialEmailNoticeConfigRepository;
|
||||||
|
private readonly IRepository<Internationalization> _internationalizationRepository;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public IRaCISCHangfireJob(IRepository<Trial> trialRepository, ILogger<IRaCISCHangfireJob> logger, IEasyCachingProvider provider, IRepository<TrialEmailNoticeConfig> trialEmailNoticeConfigRepository, IRepository<Internationalization> internationalizationRepository)
|
||||||
|
{
|
||||||
|
_trialRepository = trialRepository;
|
||||||
|
_provider = provider;
|
||||||
|
_logger = logger;
|
||||||
|
_trialEmailNoticeConfigRepository = trialEmailNoticeConfigRepository;
|
||||||
|
_internationalizationRepository = internationalizationRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task InitHangfireJobTaskAsync()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("项目启动 hangfire 任务初始化 执行开始~");
|
||||||
|
|
||||||
|
|
||||||
|
//项目状态 立即加载到缓存中
|
||||||
|
await MemoryCacheTrialStatusAsync();
|
||||||
|
|
||||||
|
|
||||||
|
//创建项目缓存 定时任务
|
||||||
|
HangfireJobHelper.AddOrUpdateInitCronJob<IIRaCISHangfireJob>("RecurringJob_Cache_TrialState", t => t.MemoryCacheTrialStatusAsync(), Cron.Daily());
|
||||||
|
|
||||||
|
//初始化
|
||||||
|
|
||||||
|
await InitInternationlizationDataAndWatchJsonFileAsync();
|
||||||
|
|
||||||
|
//创建邮件定时任务
|
||||||
|
|
||||||
|
await InitSysAndTrialCronJobAsync();
|
||||||
|
|
||||||
|
|
||||||
|
_logger.LogInformation("项目启动 hangfire 任务初始化 执行结束");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 缓存项目状态
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task MemoryCacheTrialStatusAsync()
|
||||||
|
{
|
||||||
|
|
||||||
|
var list = await _trialRepository.Select(t => new { TrialId = t.Id, TrialStatusStr = t.TrialStatusStr })
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
list.ForEach(t => _provider.Set(t.TrialId.ToString(), t.TrialStatusStr, TimeSpan.FromDays(7)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region 国际化 初始化
|
||||||
|
|
||||||
|
|
||||||
|
public async Task InitInternationlizationDataAndWatchJsonFileAsync()
|
||||||
|
{
|
||||||
|
//查询数据库的数据
|
||||||
|
var toJsonList = await _internationalizationRepository.Where(t => t.InternationalizationType == 1).Select(t => new
|
||||||
|
{
|
||||||
|
t.Code,
|
||||||
|
t.Value,
|
||||||
|
t.ValueCN
|
||||||
|
}).ToListAsync();
|
||||||
|
|
||||||
|
//组织成json 文件
|
||||||
|
|
||||||
|
var usJsonPath = Path.Combine(JsonFileFolder, StaticData.En_US_Json);
|
||||||
|
var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json);
|
||||||
|
|
||||||
|
|
||||||
|
//本地静态文件国际化需要
|
||||||
|
foreach (var tojsonItem in toJsonList)
|
||||||
|
{
|
||||||
|
StaticData.En_US_Dic[tojsonItem.Code] = tojsonItem.Value;
|
||||||
|
StaticData.Zh_CN_Dic[tojsonItem.Code] = tojsonItem.ValueCN;
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(usJsonPath, JsonConvert.SerializeObject(StaticData.En_US_Dic));
|
||||||
|
File.WriteAllText(cnJsonPath, JsonConvert.SerializeObject(StaticData.Zh_CN_Dic));
|
||||||
|
|
||||||
|
|
||||||
|
//监测Json文件变更 实时刷新数据
|
||||||
|
WatchJsonFile(usJsonPath);
|
||||||
|
WatchJsonFile(cnJsonPath);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WatchJsonFile(string filePath)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("国际化Json文件不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSystemWatcher watcher = new FileSystemWatcher(Path.GetDirectoryName(filePath), Path.GetFileName(filePath));
|
||||||
|
watcher.Changed += (sender, e) => LoadJsonFile(filePath);
|
||||||
|
watcher.EnableRaisingEvents = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void LoadJsonFile(string filePath)
|
||||||
|
{
|
||||||
|
|
||||||
|
IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile(filePath);
|
||||||
|
|
||||||
|
IConfigurationRoot enConfiguration = builder.Build();
|
||||||
|
|
||||||
|
foreach (IConfigurationSection section in enConfiguration.GetChildren())
|
||||||
|
{
|
||||||
|
if (filePath.Contains(StaticData.En_US_Json))
|
||||||
|
{
|
||||||
|
StaticData.En_US_Dic[section.Key] = section.Value;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StaticData.Zh_CN_Dic[section.Key] = section.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public async Task InitSysAndTrialCronJobAsync()
|
||||||
|
{
|
||||||
|
var taskInfoList = await _trialEmailNoticeConfigRepository.Where(t => t.Trial.TrialStatusStr == StaticData.TrialState.TrialOngoing && t.EmailCron != string.Empty)
|
||||||
|
.Select(t => new { t.Id, t.Code, t.EmailCron, t.BusinessScenarioEnum, t.TrialId })
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var task in taskInfoList)
|
||||||
|
{
|
||||||
|
//利用主键作为任务Id
|
||||||
|
var jobId = task.Id.ToString();
|
||||||
|
switch (task.BusinessScenarioEnum)
|
||||||
|
{
|
||||||
|
|
||||||
|
case CommonDocumentBusinessScenario.QCTask:
|
||||||
|
HangfireJobHelper.AddOrUpdateCronJob<IEmailSendService>(jobId, t => t.SendTrialImageQCTaskEmailAsync(task.TrialId), task.EmailCron, task.Code);
|
||||||
|
break;
|
||||||
|
case CommonDocumentBusinessScenario.QCQuestion:
|
||||||
|
HangfireJobHelper.AddOrUpdateCronJob<IEmailSendService>(jobId, t => t.SendTrialQCQuestionEmailAsync(task.TrialId), task.EmailCron, task.Code);
|
||||||
|
break;
|
||||||
|
case CommonDocumentBusinessScenario.ImageQuestion:
|
||||||
|
HangfireJobHelper.AddOrUpdateCronJob<IEmailSendService>(jobId, t => t.SendTrialImageQuestionAsync(task.TrialId), task.EmailCron, task.Code);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//case CommonDocumentBusinessScenario.EnrollConfirmed:
|
||||||
|
// AddOrUpdateCronJob<IEmailSendService>(jobId, task.Code, t => t.SendClinicalDataQuestionAsync(), task.EmailCron);
|
||||||
|
// break;
|
||||||
|
//case CommonDocumentBusinessScenario.PDConfirmed:
|
||||||
|
// break;
|
||||||
|
//case CommonDocumentBusinessScenario.ClinicalDataQuestion:
|
||||||
|
// break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,99 +0,0 @@
|
||||||
using EasyCaching.Core;
|
|
||||||
using IRaCIS.Core.Domain.Share;
|
|
||||||
using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace IRaCIS.Application.Services.BackGroundJob
|
|
||||||
{
|
|
||||||
|
|
||||||
public interface IIRaCISCacheHangfireJob
|
|
||||||
{
|
|
||||||
|
|
||||||
Task ProjectStartCache();
|
|
||||||
Task MemoryCacheTrialStatus();
|
|
||||||
|
|
||||||
Task MemoryCacheAnonymizeData();
|
|
||||||
|
|
||||||
Task CacheUserTypePermission(Guid? cacheUserTypeId);
|
|
||||||
}
|
|
||||||
public class IRaCISCacheHangfireJob: IIRaCISCacheHangfireJob
|
|
||||||
{
|
|
||||||
private readonly IRepository<Trial> _trialRepository;
|
|
||||||
private readonly IEasyCachingProvider _provider;
|
|
||||||
private readonly ILogger<IRaCISCacheHangfireJob> _logger;
|
|
||||||
private readonly IRepository<SystemAnonymization> _systemAnonymizationRepository;
|
|
||||||
|
|
||||||
private readonly IRepository<UserTypeMenu> _userTypeMenuRepository;
|
|
||||||
|
|
||||||
public IRaCISCacheHangfireJob(IRepository<Trial> trialRepository,
|
|
||||||
IRepository<SystemAnonymization> systemAnonymizationRepository, IRepository<UserTypeMenu> userTypeMenuRepository,
|
|
||||||
IEasyCachingProvider provider,ILogger<IRaCISCacheHangfireJob> logger)
|
|
||||||
{
|
|
||||||
_trialRepository = trialRepository;
|
|
||||||
_provider = provider;
|
|
||||||
_logger = logger;
|
|
||||||
_systemAnonymizationRepository = systemAnonymizationRepository;
|
|
||||||
_userTypeMenuRepository = userTypeMenuRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task ProjectStartCache()
|
|
||||||
{
|
|
||||||
_logger.LogInformation("hangfire 定时缓存项目状态任务开始~");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await MemoryCacheTrialStatus();
|
|
||||||
|
|
||||||
await MemoryCacheAnonymizeData();
|
|
||||||
|
|
||||||
await CacheUserTypePermission();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.LogError("hangfire 定时任务执行失败" + e.Message);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInformation("hangfire 定时任务执行结束");
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task MemoryCacheTrialStatus()
|
|
||||||
{
|
|
||||||
var list = await _trialRepository.Select(t => new { TrialId = t.Id, TrialStatusStr = t.TrialStatusStr })
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
list.ForEach(t => _provider.Set(t.TrialId.ToString(), t.TrialStatusStr, TimeSpan.FromDays(7)));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task MemoryCacheAnonymizeData()
|
|
||||||
{
|
|
||||||
var systemAnonymizationList = await _systemAnonymizationRepository.Where(t => t.IsEnable).ToListAsync();
|
|
||||||
|
|
||||||
_provider.Set(StaticData.Anonymize.Anonymize_AddFixedFiled, systemAnonymizationList.Where(t => t.IsAdd && t.IsFixed).ToList(), TimeSpan.FromDays(7));
|
|
||||||
_provider.Set(StaticData.Anonymize.Anonymize_AddIRCInfoFiled, systemAnonymizationList.Where(t => t.IsAdd && t.IsFixed == false).ToList(), TimeSpan.FromDays(7));
|
|
||||||
_provider.Set(StaticData.Anonymize.Anonymize_FixedField, systemAnonymizationList.Where(t => t.IsAdd == false && t.IsFixed).ToList(), TimeSpan.FromDays(7));
|
|
||||||
_provider.Set(StaticData.Anonymize.Anonymize_IRCInfoField, systemAnonymizationList.Where(t => t.IsAdd == false && t.IsFixed == false).ToList(), TimeSpan.FromDays(7));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task CacheUserTypePermission(Guid? cacheUserTypeId=null)
|
|
||||||
{
|
|
||||||
|
|
||||||
var permissionList = await _userTypeMenuRepository.Where(t => t.Menu.MenuType == "F")
|
|
||||||
.WhereIf(cacheUserTypeId != null, t => t.UserTypeId == cacheUserTypeId.Value).Select(t => new { t.UserTypeId, t.Menu.PermissionStr }).ToListAsync();
|
|
||||||
|
|
||||||
foreach (var userTypeGroup in permissionList.GroupBy(t => t.UserTypeId))
|
|
||||||
{
|
|
||||||
_provider.Set($"{StaticData.CacheKey.UserTypeId}_{userTypeGroup.Key}", userTypeGroup.Select(t => t.PermissionStr).ToList(), TimeSpan.FromDays(7));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11000,6 +11000,12 @@
|
||||||
构造函数注入
|
构造函数注入
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:IRaCIS.Application.Services.BackGroundJob.IRaCISCHangfireJob.MemoryCacheTrialStatusAsync">
|
||||||
|
<summary>
|
||||||
|
缓存项目状态
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="T:IRaCIS.Application.Services.BusinessFilter.UnifiedApiResultFilter">
|
<member name="T:IRaCIS.Application.Services.BusinessFilter.UnifiedApiResultFilter">
|
||||||
<summary>
|
<summary>
|
||||||
统一返回前端数据包装,之前在控制器包装,现在修改为动态Api 在ResultFilter这里包装,减少重复冗余代码
|
统一返回前端数据包装,之前在控制器包装,现在修改为动态Api 在ResultFilter这里包装,减少重复冗余代码
|
||||||
|
|
Loading…
Reference in New Issue