From 971c4dcf9ee81570e3a2b07baf903d73a9b9e504 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 11 Oct 2024 16:25:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=91=E5=B8=83=E7=9A=84?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E8=AE=B0=E5=BD=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.API/Progranm.cs | 17 +- .../IRaCIS.Core.Application.xml | 15 ++ .../MassTransit/Consumer/CommonEmailHelper.cs | 61 +++++ .../Consumer/SiteSurverEmailConsumer.cs | 240 +++++++++++++++++- .../Service/Common/EventStoreRecordService.cs | 23 +- .../SiteSurvey/TrialSiteSurveyService.cs | 23 +- .../Interceptor/AddDomainExt.cs | 14 +- .../Interceptor/AuditEntityInterceptor.cs | 10 - .../_IRaCIS/ObjectExtension.cs | 18 +- 9 files changed, 367 insertions(+), 54 deletions(-) create mode 100644 IRaCIS.Core.Application/MassTransit/Consumer/CommonEmailHelper.cs diff --git a/IRaCIS.Core.API/Progranm.cs b/IRaCIS.Core.API/Progranm.cs index 0d9bcef7b..c5bcdb419 100644 --- a/IRaCIS.Core.API/Progranm.cs +++ b/IRaCIS.Core.API/Progranm.cs @@ -150,18 +150,23 @@ builder.Services.AddJWTAuthSetup(_configuration); //参考链接:https://masstransit.io/documentation/concepts/mediator#scoped-mediator builder.Services.AddMediator(cfg => { - cfg.AddConsumer(); - cfg.AddConsumer(); - cfg.AddConsumer(); + cfg.AddConsumers(typeof(UserSiteSurveySubmitedEventConsumer).Assembly); + + //cfg.AddConsumer(); + //cfg.AddConsumer(); + //cfg.AddConsumer(); //cfg.ConfigureMediator((context, cfg) => cfg.UseHttpContextScopeFilter(context)); }); //添加 MassTransit 和 InMemory 传输 builder.Services.AddMassTransit(cfg => { - // 注册消费者 - cfg.AddConsumer(); // 替换为你的消费者类 - cfg.AddConsumer(); + // 自动扫描程序集中的消费者并进行注册 + cfg.AddConsumers(typeof(UserSiteSurveySubmitedEventConsumer).Assembly); + + //// 注册消费者 + //cfg.AddConsumer(); // 替换为你的消费者类 + //cfg.AddConsumer(); cfg.AddPublishMessageScheduler(); //cfg.AddHangfireConsumers(); diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index f01d2d437..a674db29d 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -12747,16 +12747,31 @@ 用户提交 发送邮件 通知SPM 或者PM + + + 用户提交 发送邮件 通知SPM 或者PM + + 调研表初审通过,进行复审发送邮件 + + + 调研表初审通过,进行复审发送邮件 + + 调研表驳回发送邮件 之前已有,需要迁移过来 + + + 调研表驳回发送邮件 之前已有,需要迁移过来 + + CRC 提交了 通知QC进行质控 diff --git a/IRaCIS.Core.Application/MassTransit/Consumer/CommonEmailHelper.cs b/IRaCIS.Core.Application/MassTransit/Consumer/CommonEmailHelper.cs new file mode 100644 index 000000000..cbb6444e8 --- /dev/null +++ b/IRaCIS.Core.Application/MassTransit/Consumer/CommonEmailHelper.cs @@ -0,0 +1,61 @@ +using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Infrastructure; +using MimeKit; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IRaCIS.Core.Application.MassTransit.Consumer; + +public static class CommonEmailHelper +{ + public static async Task GetEmailSubejctAndHtmlInfoAndBuildAsync(IRepository _emailNoticeConfigrepository, EmailBusinessScenario scenario, MimeMessage messageToSend, + Func<(string topicStr, string htmlBodyStr), (string topicStr, string htmlBodyStr)> emailFunc) + { + var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US; + + var configInfo = await _emailNoticeConfigrepository.Where(t => t.BusinessScenarioEnum == scenario).FirstOrDefaultAsync(); + + if (configInfo == null) + { + throw new BusinessValidationFailedException("系统未找到当前场景邮件配置信息,请联系运维人员核查"); + } + + + var (topicStr, htmlBodyStr) = isEn_US ? (configInfo.EmailTopic, configInfo.EmailHtmlContent) : (configInfo.EmailTopicCN, configInfo.EmailHtmlContentCN); + + try + { + //每个场景修改主题 和body的逻辑不一样 + (topicStr, htmlBodyStr) = emailFunc((topicStr, htmlBodyStr)); + } + catch (Exception ex) + { + + throw new BusinessValidationFailedException("邮件模板内容有误,填充内容出现问题,请联系运维人员核查"); + } + + + messageToSend.Subject = topicStr; + + var builder = new BodyBuilder(); + + builder.HtmlBody = htmlBodyStr; + + messageToSend.Body = builder.ToMessageBody(); + + return configInfo; + } + + public static string ReplaceCompanyName(SystemEmailSendConfig _systemEmailConfig, string needDealtxt) + { + var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US; + + var str = needDealtxt.Replace("{company}", isEn_US ? _systemEmailConfig.CompanyName : _systemEmailConfig.CompanyNameCN) + .Replace("{company abbreviation}", isEn_US ? _systemEmailConfig.CompanyShortName : _systemEmailConfig.CompanyShortNameCN); + return str; + } +} diff --git a/IRaCIS.Core.Application/MassTransit/Consumer/SiteSurverEmailConsumer.cs b/IRaCIS.Core.Application/MassTransit/Consumer/SiteSurverEmailConsumer.cs index 3b9ad510e..d5f8d3453 100644 --- a/IRaCIS.Core.Application/MassTransit/Consumer/SiteSurverEmailConsumer.cs +++ b/IRaCIS.Core.Application/MassTransit/Consumer/SiteSurverEmailConsumer.cs @@ -1,9 +1,21 @@ -using IRaCIS.Core.Application.MassTransit.Command; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Vml; +using DocumentFormat.OpenXml.Wordprocessing; +using IRaCIS.Core.Application.Contracts; +using IRaCIS.Core.Application.Helper; +using IRaCIS.Core.Application.MassTransit.Command; using IRaCIS.Core.Domain; using IRaCIS.Core.Domain.BaseModel; +using IRaCIS.Core.Domain.Models; +using IRaCIS.Core.Domain.Share; using MassTransit; +using Microsoft.AspNetCore.Components.Routing; +using Microsoft.Extensions.Options; +using MimeKit; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -13,22 +25,148 @@ namespace IRaCIS.Core.Application.MassTransit.Consumer; /// /// 用户提交 发送邮件 通知SPM 或者PM /// -public class UserSiteSurveySubmitedEventConsumer : IConsumer +public class UserSiteSurveySubmitedEventConsumer( + IRepository _userRepository, + IRepository _trialRepository, + IRepository _trialSiteRepository, + IRepository _trialSiteSurveyRepository, + IRepository _emailNoticeConfigrepository, + IOptionsMonitor systemEmailConfig + ) : IConsumer { - public Task Consume(ConsumeContext context) + private readonly SystemEmailSendConfig _systemEmailConfig = systemEmailConfig.CurrentValue; + public async Task Consume(ConsumeContext context) { - throw new NotImplementedException(); + var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US; + + var trialSiteSurveyId = context.Message.TrialSiteSurveyId; + + var siteSurveyInfo = _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId).FirstOrDefault().IfNullThrowException(); + + var trialId = siteSurveyInfo.TrialId; + + var hasSPMOrCPM = await _trialSiteSurveyRepository.AnyAsync(t => t.TrialId == siteSurveyInfo.TrialId && t.Trial.TrialUserList.Any(u => u.User.UserTypeEnum == UserTypeEnum.SPM || u.User.UserTypeEnum == UserTypeEnum.CPM)); + + + var messageToSend = new MimeMessage(); + + + var userName = siteSurveyInfo.UserName; + var email = siteSurveyInfo.Email; + var phone = siteSurveyInfo.Phone; + + if (hasSPMOrCPM) + { + var user = await _userRepository.FirstOrDefaultAsync(t => t.Id == siteSurveyInfo.PreliminaryUserId); + + userName = user.FullName; + email = user.EMail; + phone = user.Phone; + + messageToSend.To.Add(new MailboxAddress(String.Empty, user.EMail)); + } + else + { + messageToSend.To.Add(new MailboxAddress(String.Empty, siteSurveyInfo.Email)); + } + + var trialInfo = await _trialRepository.FirstOrDefaultAsync(t => t.Id == trialId); + + var siteInfo = await _trialSiteRepository.FirstOrDefaultAsync(t => t.TrialId == trialId && t.Id == siteSurveyInfo.TrialSiteId, true); + + + var companyName = isEn_US ? _systemEmailConfig.CompanyShortName : _systemEmailConfig.CompanyShortNameCN; + + + Func<(string topicStr, string htmlBodyStr), (string topicStr, string htmlBodyStr)> emailConfigFunc = input => + { + var topicStr = string.Format(input.topicStr, companyName, trialInfo.ResearchProgramNo); + var htmlBodyStr = string.Format(CommonEmailHelper.ReplaceCompanyName(_systemEmailConfig, input.htmlBodyStr), + + siteInfo.TrialSiteCode, + siteInfo.TrialSiteAliasName, + userName, + email, + phone, + _systemEmailConfig.SiteUrl + ); + + return (topicStr, htmlBodyStr); + }; + + await CommonEmailHelper.GetEmailSubejctAndHtmlInfoAndBuildAsync(_emailNoticeConfigrepository, EmailBusinessScenario.SiteSurveyReject, messageToSend, emailConfigFunc); + + await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig); + } } /// /// 调研表初审通过,进行复审发送邮件 /// -public class SiteSurveySPMSubmitedEventConsumer : IConsumer +public class SiteSurveySPMSubmitedEventConsumer( + IRepository _userRepository, + IRepository _trialRepository, + IRepository _trialSiteRepository, + IRepository _trialSiteSurveyRepository, + IRepository _emailNoticeConfigrepository, + IOptionsMonitor systemEmailConfig) : IConsumer { - public Task Consume(ConsumeContext context) + private readonly SystemEmailSendConfig _systemEmailConfig = systemEmailConfig.CurrentValue; + public async Task Consume(ConsumeContext context) { - throw new NotImplementedException(); + + var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US; + + var trialSiteSurveyId = context.Message.TrialSiteSurveyId; + + var siteSurveyInfo = _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId).FirstOrDefault().IfNullThrowException(); + + var trialId = siteSurveyInfo.TrialId; + + var messageToSend = new MimeMessage(); + + var pmAndAPMList = _trialRepository.Where(t => t.Id == trialId).SelectMany(t => t.TrialUserList.Where(t => t.User.UserTypeEnum == UserTypeEnum.APM || t.User.UserTypeEnum == UserTypeEnum.ProjectManager)) + .Select(t => new { t.User.EMail/*,t.User.FullName,t.User.UserName*/ }).ToList(); + + + foreach (var item in pmAndAPMList) + { + messageToSend.To.Add(new MailboxAddress(String.Empty, item.EMail)); + } + + var user = await _userRepository.FirstOrDefaultAsync(t => t.Id == siteSurveyInfo.PreliminaryUserId); + var userName = user.FullName; + var email = user.EMail; + var phone = user.Phone; + + var trialInfo = await _trialRepository.FirstOrDefaultAsync(t => t.Id == trialId); + + var siteInfo = await _trialSiteRepository.FirstOrDefaultAsync(t => t.TrialId == trialId && t.Id == siteSurveyInfo.TrialSiteId, true); + + + var companyName = isEn_US ? _systemEmailConfig.CompanyShortName : _systemEmailConfig.CompanyShortNameCN; + + + Func<(string topicStr, string htmlBodyStr), (string topicStr, string htmlBodyStr)> emailConfigFunc = input => + { + var topicStr = string.Format(input.topicStr, companyName, trialInfo.ResearchProgramNo); + var htmlBodyStr = string.Format(CommonEmailHelper.ReplaceCompanyName(_systemEmailConfig, input.htmlBodyStr), + + siteInfo.TrialSiteCode, + siteInfo.TrialSiteAliasName, + userName, + email, + phone, + _systemEmailConfig.SiteUrl + ); + + return (topicStr, htmlBodyStr); + }; + + await CommonEmailHelper.GetEmailSubejctAndHtmlInfoAndBuildAsync(_emailNoticeConfigrepository, EmailBusinessScenario.SiteSurveyReject, messageToSend, emailConfigFunc); + + await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig); } } @@ -36,10 +174,92 @@ public class SiteSurveySPMSubmitedEventConsumer : IConsumer /// 调研表驳回发送邮件 之前已有,需要迁移过来 /// -public class SiteSurverRejectedEventConsumer : IConsumer +public class SiteSurverRejectedEventConsumer( + IRepository _userRepository, + IRepository _trialRepository, + IRepository _trialSiteRepository, + IRepository _trialSiteSurveyRepository, + IRepository _emailNoticeConfigrepository, + IOptionsMonitor systemEmailConfig + ) : IConsumer { - public Task Consume(ConsumeContext context) + private readonly SystemEmailSendConfig _systemEmailConfig = systemEmailConfig.CurrentValue; + + public async Task Consume(ConsumeContext context) { - throw new NotImplementedException(); + var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US; + + var trialSiteSurveyId = context.Message.TrialSiteSurveyId; + + var siteSurveyInfo = _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId).FirstOrDefault().IfNullThrowException(); + + var trialId = siteSurveyInfo.TrialId; + + var hasSPMOrCPM = await _trialSiteSurveyRepository.AnyAsync(t => t.TrialId == siteSurveyInfo.TrialId && t.Trial.TrialUserList.Any(u => u.User.UserTypeEnum == UserTypeEnum.SPM || u.User.UserTypeEnum == UserTypeEnum.CPM)); + + + var messageToSend = new MimeMessage(); + + var name = siteSurveyInfo.UserName; + + if (hasSPMOrCPM) + { + //PM 驳回 + if (siteSurveyInfo.State == TrialSiteSurveyEnum.CRCSubmitted) + { + var user = await _userRepository.FirstOrDefaultAsync(t => t.Id == siteSurveyInfo.PreliminaryUserId); + + name = user.FullName; + + messageToSend.To.Add(new MailboxAddress(String.Empty, user.EMail)); + } + //SPM 驳回 + else if (siteSurveyInfo.State == TrialSiteSurveyEnum.ToSubmit) + { + messageToSend.To.Add(new MailboxAddress(String.Empty, siteSurveyInfo.Email)); + } + } + else + { + //没有SPM 给填表人发 + + messageToSend.To.Add(new MailboxAddress(String.Empty, siteSurveyInfo.Email)); + } + + //发件地址 + messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail)); + + + var trialInfo = await _trialRepository.FirstOrDefaultAsync(t => t.Id == trialId); + + var siteInfo = await _trialSiteRepository.FirstOrDefaultAsync(t => t.TrialId == trialId && t.Id == siteSurveyInfo.TrialSiteId, true); + + + var companyName = isEn_US ? _systemEmailConfig.CompanyShortName : _systemEmailConfig.CompanyShortNameCN; + + + Func<(string topicStr, string htmlBodyStr), (string topicStr, string htmlBodyStr)> emailConfigFunc = input => + { + var topicStr = string.Format(input.topicStr, companyName, trialInfo.ResearchProgramNo); + var htmlBodyStr = string.Format(CommonEmailHelper.ReplaceCompanyName(_systemEmailConfig, input.htmlBodyStr), + name, + trialInfo.TrialCode, + trialInfo.ResearchProgramNo, + trialInfo.ExperimentName, + siteInfo.TrialSiteCode, + siteInfo.TrialSiteAliasName, + siteSurveyInfo.LatestBackReason, + _systemEmailConfig.SiteUrl, + (siteSurveyInfo.State == TrialSiteSurveyEnum.ToSubmit ? "inline - block" : "none") + ); + + return (topicStr, htmlBodyStr); + }; + + await CommonEmailHelper.GetEmailSubejctAndHtmlInfoAndBuildAsync(_emailNoticeConfigrepository, EmailBusinessScenario.SiteSurveyReject, messageToSend, emailConfigFunc); + + await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig); + + } } diff --git a/IRaCIS.Core.Application/Service/Common/EventStoreRecordService.cs b/IRaCIS.Core.Application/Service/Common/EventStoreRecordService.cs index 05f06898f..67b9b5cdd 100644 --- a/IRaCIS.Core.Application/Service/Common/EventStoreRecordService.cs +++ b/IRaCIS.Core.Application/Service/Common/EventStoreRecordService.cs @@ -11,13 +11,16 @@ using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Infrastructure.Extention; using System.Threading.Tasks; using IRaCIS.Core.Infra.EFCore; +using MassTransit.Mediator; +using Newtonsoft.Json; +using MassTransit; +using IRaCIS.Core.Domain; namespace IRaCIS.Core.Application.Service; [ApiExplorerSettings(GroupName = "Common")] -public class EventStoreRecordService(IRepository _eventStoreRecordRepository) : BaseService +public class EventStoreRecordService(IRepository _eventStoreRecordRepository, IMediator _mediator) : BaseService { - [HttpPost] public async Task> GetEventStoreRecordList(EventStoreRecordQuery inQuery) { @@ -31,7 +34,23 @@ public class EventStoreRecordService(IRepository _eventStoreRe } + public async Task RePublishEvent(Guid eventId) + { + var storedEvent = await _eventStoreRecordRepository.FirstOrDefaultAsync(t => t.Id == eventId); + var domainEvent = storedEvent.EventData.JsonStrToObject(Type.GetType(storedEvent.EventType)); + + Console.WriteLine(Type.GetType(storedEvent.EventType)); + + Console.WriteLine(domainEvent.GetType()); + + Console.WriteLine(new UserSiteSurveySubmitedEvent().GetType().AssemblyQualifiedName); + + await _mediator.Publish(domainEvent.GetType(), domainEvent); + + return ResponseOutput.Ok(); + + } } diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index 5a92b82ad..3ba057439 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -545,9 +545,9 @@ namespace IRaCIS.Core.Application.Contracts survey.LatestBackReason = trialSiteSubmitBackCommand.LatestBackReason; - User? user = null; + //User? user = null; - var messageToSend = new MimeMessage(); + //var messageToSend = new MimeMessage(); if (await _trialSiteSurveyRepository.AnyAsync(t => t.State == TrialSiteSurveyEnum.PMCreatedAndLock && t.Id == trialSiteSurveyId)) @@ -558,8 +558,8 @@ namespace IRaCIS.Core.Application.Contracts if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM) { - //SPM 给填表人发 - messageToSend.To.Add(new MailboxAddress(String.Empty, survey.Email)); + ////SPM 给填表人发 + //messageToSend.To.Add(new MailboxAddress(String.Empty, survey.Email)); survey.State = TrialSiteSurveyEnum.ToSubmit; } @@ -570,10 +570,10 @@ namespace IRaCIS.Core.Application.Contracts if (hasSPMOrCPM) { - //PM 给SPM发 (初审人) - user = await _userRepository.FirstOrDefaultAsync(t => t.Id == survey.PreliminaryUserId); + ////PM 给SPM发 (初审人) + //user = await _userRepository.FirstOrDefaultAsync(t => t.Id == survey.PreliminaryUserId); - messageToSend.To.Add(new MailboxAddress(String.Empty, survey.PreliminaryUserId == null ? survey.Email : user.EMail)); + //messageToSend.To.Add(new MailboxAddress(String.Empty, survey.PreliminaryUserId == null ? survey.Email : user.EMail)); survey.State = TrialSiteSurveyEnum.CRCSubmitted; @@ -583,8 +583,8 @@ namespace IRaCIS.Core.Application.Contracts else { - //没有SPM 给填表人发 - messageToSend.To.Add(new MailboxAddress(String.Empty, survey.Email)); + ////没有SPM 给填表人发 + //messageToSend.To.Add(new MailboxAddress(String.Empty, survey.Email)); survey.State = TrialSiteSurveyEnum.ToSubmit; @@ -597,10 +597,7 @@ namespace IRaCIS.Core.Application.Contracts } } - - - await _IMailVerificationService.SiteSurveyRejectEmail(messageToSend, survey, trialSiteSubmitBackCommand.RouteUrl, user); - + //await _IMailVerificationService.SiteSurveyRejectEmail(messageToSend, survey, trialSiteSubmitBackCommand.RouteUrl, user); await _trialSiteSurveyRepository.SaveChangesAsync(); diff --git a/IRaCIS.Core.Infra.EFCore/Interceptor/AddDomainExt.cs b/IRaCIS.Core.Infra.EFCore/Interceptor/AddDomainExt.cs index 45d8f4467..85e70c383 100644 --- a/IRaCIS.Core.Infra.EFCore/Interceptor/AddDomainExt.cs +++ b/IRaCIS.Core.Infra.EFCore/Interceptor/AddDomainExt.cs @@ -50,7 +50,7 @@ public static class DBContext_Ext } //添加进记录 - eventStoreList.AddRange(trialSiteSurvey.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().Name, EventData = t.ToJsonStr() })); + eventStoreList.AddRange(trialSiteSurvey.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().AssemblyQualifiedName, EventData = t.ToJsonStr() })); } @@ -89,7 +89,7 @@ public static class DBContext_Ext //添加进记录 - eventStoreList.AddRange(subjectVisit.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().Name, EventData = t.ToJsonStr() })); + eventStoreList.AddRange(subjectVisit.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().AssemblyQualifiedName, EventData = t.ToJsonStr() })); } } @@ -117,7 +117,7 @@ public static class DBContext_Ext } //添加进记录 - eventStoreList.AddRange(qCChallengeDialog.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().Name, EventData = t.ToJsonStr() })); + eventStoreList.AddRange(qCChallengeDialog.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().AssemblyQualifiedName, EventData = t.ToJsonStr() })); } } @@ -143,7 +143,7 @@ public static class DBContext_Ext } //添加进记录 - eventStoreList.AddRange(checkChallengeDialog.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().Name, EventData = t.ToJsonStr() })); + eventStoreList.AddRange(checkChallengeDialog.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().AssemblyQualifiedName, EventData = t.ToJsonStr() })); } } @@ -180,7 +180,7 @@ public static class DBContext_Ext taskMedicalReview.AddDomainEvent(new UrgentMedicalReviewAddedEvent() { MedicalReviewId = taskMedicalReview.Id, VisitTaskId = taskMedicalReview.VisitTaskId }); //添加进记录 - eventStoreList.AddRange(taskMedicalReview.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().Name, EventData = t.ToJsonStr() })); + eventStoreList.AddRange(taskMedicalReview.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().AssemblyQualifiedName, EventData = t.ToJsonStr() })); } } } @@ -221,7 +221,7 @@ public static class DBContext_Ext } //添加进记录 - eventStoreList.AddRange(readingMedicalReviewDialog.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().Name, EventData = t.ToJsonStr() })); + eventStoreList.AddRange(readingMedicalReviewDialog.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().AssemblyQualifiedName, EventData = t.ToJsonStr() })); } } @@ -259,7 +259,7 @@ public static class DBContext_Ext visitTask.AddDomainEvent(new UrgentIRApplyedReReading() { VisitTaskId = visitTask.Id }); //添加进记录 - eventStoreList.AddRange(visitTask.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().Name, EventData = t.ToJsonStr() })); + eventStoreList.AddRange(visitTask.DomainEvents.Select(t => new EventStoreRecord() { Id = t.EventId, EventType = t.GetType().AssemblyQualifiedName, EventData = t.ToJsonStr() })); } } diff --git a/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs b/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs index bb37a9a52..c301521d0 100644 --- a/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs +++ b/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs @@ -36,16 +36,6 @@ public class AuditEntityInterceptor(IUserInfo _userInfo, { //////领域命令 (同一个事务提交的一些逻辑,类似Trigger 保存事务之前执行的一些逻辑) IMediator 和autofac 有冲突,不在一个事务,废弃。 //eventData.Context.AddDomainCommands(); - //await DispatchDomainCommands(eventData.Context); - // var domainEvent = JsonSerializer.Deserialize(storedEvent.EventData, Type.GetType(storedEvent.EventType)); - //// 序列化事件 - //var eventData = JsonSerializer.Serialize(domainEvent); - - //var storedEvent = new StoredEvent - //{ - // EventType = domainEvent.GetType().Name, - // EventData = eventData - //}; //领域事件 eventData.Context.AddDomainEvents(); diff --git a/IRaCIS.Core.Infrastructure/_IRaCIS/ObjectExtension.cs b/IRaCIS.Core.Infrastructure/_IRaCIS/ObjectExtension.cs index c51693fe3..656b6ced8 100644 --- a/IRaCIS.Core.Infrastructure/_IRaCIS/ObjectExtension.cs +++ b/IRaCIS.Core.Infrastructure/_IRaCIS/ObjectExtension.cs @@ -32,12 +32,18 @@ namespace IRaCIS.Core.Infrastructure.Extention return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss", ReferenceLoopHandling = ReferenceLoopHandling.Ignore, NullValueHandling = NullValueHandling.Ignore }); } - /// - /// 将对象序列化成稽查需要的Json字符串 - /// - /// - /// - public static string ToJsonNotIgnoreNull(this object obj) + // 通过类型参数反序列化 JSON 字符串为指定类型的对象 + public static object JsonStrToObject(this string jsonStr, Type type) + { + return JsonConvert.DeserializeObject(jsonStr, type); + } + + /// + /// 将对象序列化成稽查需要的Json字符串 + /// + /// + /// + public static string ToJsonNotIgnoreNull(this object obj) { return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss", Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, NullValueHandling = NullValueHandling.Include });