diff --git a/IRaCIS.Core.API/Progranm.cs b/IRaCIS.Core.API/Progranm.cs index 6c9da888d..fab8c9ecb 100644 --- a/IRaCIS.Core.API/Progranm.cs +++ b/IRaCIS.Core.API/Progranm.cs @@ -36,6 +36,7 @@ using IRaCIS.Core.Application.MassTransit.Consumer; using DocumentFormat.OpenXml.InkML; using IRaCIS.Core.Domain; using MassTransit.Internals; +using IRaCIS.Core.Domain.BaseModel; AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); @@ -184,7 +185,7 @@ builder.Services.AddMassTransit(cfg => cfg.UseHangfireScheduler(); cfg.UseConsumeFilter(typeof(CultureInfoFilter<>), context, - x => x.Include(type => type.HasInterface(typeof(IConsumer<>)))); + x => x.Include(type => type.IsAssignableTo(typeof(DomainEvent)))); // 这里可以进行额外的配置 diff --git a/IRaCIS.Core.Application/MassTransit/Consumer/SiteSurverEmailConsumer.cs b/IRaCIS.Core.Application/MassTransit/Consumer/SiteSurverEmailConsumer.cs index d5f8d3453..e56649c17 100644 --- a/IRaCIS.Core.Application/MassTransit/Consumer/SiteSurverEmailConsumer.cs +++ b/IRaCIS.Core.Application/MassTransit/Consumer/SiteSurverEmailConsumer.cs @@ -41,6 +41,8 @@ public class UserSiteSurveySubmitedEventConsumer( var trialSiteSurveyId = context.Message.TrialSiteSurveyId; + return; + var siteSurveyInfo = _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId).FirstOrDefault().IfNullThrowException(); var trialId = siteSurveyInfo.TrialId; diff --git a/IRaCIS.Core.Application/MassTransit/CultureInfoMiddleware.cs b/IRaCIS.Core.Application/MassTransit/CultureInfoMiddleware.cs deleted file mode 100644 index b0f621855..000000000 --- a/IRaCIS.Core.Application/MassTransit/CultureInfoMiddleware.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Globalization; -using System.Threading; -using System.Threading.Tasks; -using IRaCIS.Core.Domain.BaseModel; -using MassTransit; - -public class CultureInfoFilter : IFilter> where T : DomainEvent -{ - public async Task Send(ConsumeContext context, IPipe> next) - { - var cultureInfoName = context.Message.CultureInfoName; - - if (!string.IsNullOrEmpty(cultureInfoName)) - { - // 设置线程的文化信息 - Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureInfoName); - Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureInfoName); - } - - try - { - // 继续处理消息 - await next.Send(context); - } - finally - { - // 还原文化信息(可选) - // Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; // 或者之前的文化 - // Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - } - } - - public void Probe(ProbeContext context) { } -} diff --git a/IRaCIS.Core.Application/MassTransit/Extension/CultureInfoFilter.cs b/IRaCIS.Core.Application/MassTransit/Extension/CultureInfoFilter.cs new file mode 100644 index 000000000..1079e3d78 --- /dev/null +++ b/IRaCIS.Core.Application/MassTransit/Extension/CultureInfoFilter.cs @@ -0,0 +1,34 @@ +using System.Globalization; +using System.Threading; +using System.Threading.Tasks; +using IRaCIS.Core.Domain.BaseModel; +using IRaCIS.Core.Domain.Share; +using MassTransit; +using NPOI.SS.Formula.Functions; + +public class CultureInfoFilter (IRepository _eventStoreRecordRepository) : IFilter> where T : DomainEvent +{ + + public async Task Send(ConsumeContext context, IPipe> next) + { + var cultureInfoName = context.Message.CultureInfoName; + + var eventId = context.Message.EventId; + + if (!string.IsNullOrEmpty(cultureInfoName)) + { + CultureInfo.CurrentCulture = new CultureInfo(cultureInfoName); + CultureInfo.CurrentUICulture = new CultureInfo(cultureInfoName); + } + + + await next.Send(context); + + await _eventStoreRecordRepository.BatchUpdateNoTrackingAsync(t => t.Id == eventId, u => new EventStoreRecord() { EventState= EventStateEnum.ConsumeSuccessed } ); + } + + public void Probe(ProbeContext context) + { + context.CreateFilterScope("CultureInfoFilter"); + } +} diff --git a/IRaCIS.Core.Application/Service/Common/EventStoreRecordService.cs b/IRaCIS.Core.Application/Service/Common/EventStoreRecordService.cs index 53926043e..1b05b453d 100644 --- a/IRaCIS.Core.Application/Service/Common/EventStoreRecordService.cs +++ b/IRaCIS.Core.Application/Service/Common/EventStoreRecordService.cs @@ -46,15 +46,9 @@ public class EventStoreRecordService(IRepository _eventStoreRe var domainEvent = storedEvent.EventData.JsonStrToObject(Type.GetType(storedEvent.EventType)); - CultureInfo.CurrentCulture = new CultureInfo(StaticData.CultureInfo.en_US); - - var tt = (UserSiteSurveySubmitedEvent)domainEvent; - - tt.CultureInfoName = CultureInfo.CurrentCulture.Name; - //IMediator 发布的时候,设置当前线程的CultureInfo 消费者会与发布线程CultureInfo 一致 分布式的话 _publishEndpoint 会不一致,需要手动设置 - await _publishEndpoint.Publish(domainEvent.GetType(), tt); + await _publishEndpoint.Publish(domainEvent.GetType(), domainEvent); return ResponseOutput.Ok();