定时任务修改迁移
parent
746f2ba7e0
commit
ed89bc652e
|
@ -1,106 +0,0 @@
|
||||||
{
|
|
||||||
"needAnonymizeTag": [
|
|
||||||
{ //PatientsName
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "0010",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{ // PatientID
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "0020",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{ // IssuerOfPatientID
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "0021",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{ // PatientsBirthDate
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "0030",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{ // PatientsBirthTime
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "0032",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": false
|
|
||||||
},
|
|
||||||
{ // PatientsSex
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "0040",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": false
|
|
||||||
},
|
|
||||||
{ // OtherPatientIDs
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "1000",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": false
|
|
||||||
},
|
|
||||||
{ // OtherPatientNames
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "1001",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": false
|
|
||||||
},
|
|
||||||
{ // OtherPatientNames
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "1005",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{ // PatientBirthName
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "1005",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{ // PatientsAge
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "1010",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{ // PatientsAddress
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "1040",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{ // PatientsMothersBirthName
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "1060",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "2150",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "2152",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Group": "0010",
|
|
||||||
"Element": "2154",
|
|
||||||
"ReplaceValue": "",
|
|
||||||
"Enable": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Group": "0012",
|
|
||||||
"Element": "0040",
|
|
||||||
"ReplaceValue": "XXX",
|
|
||||||
"Enable": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -108,9 +108,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Update="NLog.config">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Update="wwwroot\EmailTemplate\AdminAddUser_US.html">
|
<Content Update="wwwroot\EmailTemplate\AdminAddUser_US.html">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
|
|
@ -429,6 +429,12 @@
|
||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:IRaCIS.Core.API.Controllers.UploadDownLoadController.Upload(IRaCIS.Core.API.Controllers.UploadDownLoadController.UploadFileType)">
|
||||||
|
<summary>
|
||||||
|
1:数据上传 2:导出、 3:邮件附件 4:邮件Html 通过 ----new
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="T:IRaCIS.Core.API.IpPolicyRateLimitSetup">
|
<member name="T:IRaCIS.Core.API.IpPolicyRateLimitSetup">
|
||||||
<summary>
|
<summary>
|
||||||
IPLimit限流 启动服务
|
IPLimit限流 启动服务
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
autoReload="true"
|
|
||||||
throwExceptions="false"
|
|
||||||
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
|
|
||||||
<variable name="myvar" value="myvalue"/>
|
|
||||||
|
|
||||||
<targets>
|
|
||||||
|
|
||||||
<target xsi:type="file" name="File" fileName="${basedir}/logs/${shortdate}/${level}.log"
|
|
||||||
layout="${longdate}||${level}||${logger}||${message}||${exception:format=ToString:innerFormat=ToString:maxInnerExceptionLevel=10:separator=\r\n}||end" />
|
|
||||||
</targets>
|
|
||||||
|
|
||||||
<rules>
|
|
||||||
<logger name="*" minlevel="Debug" writeTo="file" />
|
|
||||||
</rules>
|
|
||||||
</nlog>
|
|
|
@ -53,24 +53,12 @@ namespace IRaCIS.Core.API
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
||||||
//// Serilog
|
//// Serilog
|
||||||
SerilogExtension.AddSerilogSetup(enviromentName, host.Services);
|
SerilogExtension.AddSerilogSetup(enviromentName, host.Services);
|
||||||
Log.Logger.Warning($"µ±Ç°»·¾³£º{enviromentName}");
|
Log.Logger.Warning($"µ±Ç°»·¾³£º{enviromentName}");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NewId.SetProcessIdProvider(new CurrentProcessIdProvider());
|
NewId.SetProcessIdProvider(new CurrentProcessIdProvider());
|
||||||
|
|
||||||
|
|
||||||
//缓存项目的状态 匿名化数据
|
|
||||||
await InitCache(host);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
host.Run();
|
host.Run();
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,28 +88,7 @@ namespace IRaCIS.Core.API
|
||||||
webBuilder.UseStartup<Startup>();
|
webBuilder.UseStartup<Startup>();
|
||||||
}).UseSerilog()
|
}).UseSerilog()
|
||||||
.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||||
|
|
||||||
|
|
||||||
private static async Task InitCache(IHost host)
|
|
||||||
{
|
|
||||||
var _repository = host.Services.GetService(typeof(IRepository)) as IRepository;
|
|
||||||
|
|
||||||
//初始化 国际化数据,并且监测国际化文件变更
|
|
||||||
await InternationalizationHelper.InitInternationlizationDataAndWatchJsonFileAsync(_repository);
|
|
||||||
|
|
||||||
var _mediator = host.Services.GetService(typeof(IMediator)) as IMediator;
|
|
||||||
|
|
||||||
await _mediator.Send(new AnonymizeCacheRequest());
|
|
||||||
|
|
||||||
await _mediator.Send(new TrialStateCacheRequest());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ using Microsoft.AspNetCore.SignalR;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
using Microsoft.AspNetCore.StaticFiles;
|
using Microsoft.AspNetCore.StaticFiles;
|
||||||
using IRaCIS.Core.Application.Helper;
|
using IRaCIS.Core.Application.Helper;
|
||||||
|
using IRaCIS.Application.Services.BackGroundJob;
|
||||||
|
|
||||||
namespace IRaCIS.Core.API
|
namespace IRaCIS.Core.API
|
||||||
{
|
{
|
||||||
|
@ -162,7 +163,7 @@ namespace IRaCIS.Core.API
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
//±¾µØ»¯
|
//±¾µØ»¯
|
||||||
app.UseLocalization();
|
app.UseLocalization();
|
||||||
|
@ -236,6 +237,10 @@ namespace IRaCIS.Core.API
|
||||||
endpoints.MapHub<UploadHub>("/UploadHub");
|
endpoints.MapHub<UploadHub>("/UploadHub");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var hangfireJobService = app.ApplicationServices.GetRequiredService<IIRaCISHangfireJob>();
|
||||||
|
|
||||||
|
await hangfireJobService.InitHangfireJobTaskAsync();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,213 @@
|
||||||
|
using EasyCaching.Core;
|
||||||
|
using Hangfire;
|
||||||
|
using Hangfire.Storage;
|
||||||
|
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<SystemAnonymization> _systemAnonymizationRepository;
|
||||||
|
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, IRepository<SystemAnonymization> systemAnonymizationRepository)
|
||||||
|
{
|
||||||
|
_trialRepository = trialRepository;
|
||||||
|
_provider = provider;
|
||||||
|
_logger = logger;
|
||||||
|
_trialEmailNoticeConfigRepository = trialEmailNoticeConfigRepository;
|
||||||
|
_internationalizationRepository = internationalizationRepository;
|
||||||
|
_systemAnonymizationRepository = systemAnonymizationRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task InitHangfireJobTaskAsync()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("项目启动 hangfire 任务初始化 执行开始~");
|
||||||
|
|
||||||
|
|
||||||
|
//项目状态 立即加载到缓存中
|
||||||
|
await MemoryCacheTrialStatusAsync();
|
||||||
|
|
||||||
|
await MemoryCacheAnonymizeData();
|
||||||
|
|
||||||
|
|
||||||
|
//创建项目缓存 定时任务
|
||||||
|
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)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#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(StaticData.International("IRaCISCHangfireJob_FileNotFound"));
|
||||||
|
}
|
||||||
|
|
||||||
|
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 deleteJobIdList = await _trialEmailNoticeConfigRepository.Where(t => t.Trial.TrialStatusStr != StaticData.TrialState.TrialOngoing && t.EmailCron != string.Empty && t.IsAutoSend)
|
||||||
|
// .Select(t => t.TrialId + "_" + t.Id)
|
||||||
|
// .ToListAsync();
|
||||||
|
|
||||||
|
//foreach (var jobId in deleteJobIdList)
|
||||||
|
//{
|
||||||
|
// HangfireJobHelper.RemoveCronJob(jobId);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
var taskInfoList = await _trialEmailNoticeConfigRepository.Where(t => t.Trial.TrialStatusStr == StaticData.TrialState.TrialOngoing && t.EmailCron != string.Empty && t.IsAutoSend)
|
||||||
|
.Select(t => new { t.Id, t.Code, t.EmailCron, t.BusinessScenarioEnum, t.TrialId })
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
foreach (var task in taskInfoList)
|
||||||
|
{
|
||||||
|
//利用主键作为任务Id
|
||||||
|
var jobId = $"{task.TrialId}_{task.Id}";
|
||||||
|
|
||||||
|
HangfireJobHelper.AddOrUpdateTrialCronJob(jobId, task.TrialId, task.BusinessScenarioEnum, task.EmailCron);
|
||||||
|
}
|
||||||
|
|
||||||
|
var addOrUpdateJobIdList = taskInfoList.Select(t => $"{t.TrialId}_{t.Id}").ToList();
|
||||||
|
|
||||||
|
var list = JobStorage.Current.GetConnection().GetRecurringJobs().ToList();
|
||||||
|
|
||||||
|
//项目定时任务都在default 队列
|
||||||
|
//var dbJobIdList = JobStorage.Current.GetConnection().GetRecurringJobs().Where(t => t.Queue == "default").Select(t => t.Id).ToList();
|
||||||
|
|
||||||
|
//var deleteList= dbJobIdList.Except(addOrUpdateJobIdList).ToList();
|
||||||
|
|
||||||
|
// foreach (var jobId in deleteList)
|
||||||
|
// {
|
||||||
|
// HangfireJobHelper.RemoveCronJob(jobId);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11927,6 +11927,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这里包装,减少重复冗余代码
|
||||||
|
|
|
@ -78,7 +78,7 @@ public static class StaticData
|
||||||
|
|
||||||
public static readonly string Resources = "Resources";
|
public static readonly string Resources = "Resources";
|
||||||
public static readonly string IRaCISDataFolder = "IRaCISData";
|
public static readonly string IRaCISDataFolder = "IRaCISData";
|
||||||
|
public static readonly string OtherDataFolder = "OtherData";
|
||||||
public static readonly string TrialDataFolder = "TrialData";
|
public static readonly string TrialDataFolder = "TrialData";
|
||||||
|
|
||||||
public static readonly string SystemDataFolder = "SystemData";
|
public static readonly string SystemDataFolder = "SystemData";
|
||||||
|
|
Loading…
Reference in New Issue