From a4d0a5a57a2fa56f5d1ba0bda4c5bf0fada2edc3 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 21 Oct 2022 10:52:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=97=E5=85=B8=E8=A1=A8bu?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.API/IRaCIS.Core.API.csproj | 3 + .../SubjectEnrollConfirmOrPDProgress.html | 27 ++++++ .../Helper/SendEmailHelper.cs | 85 ++++++++++++++++-- .../IRaCIS.Core.Application.csproj | 1 + .../IRaCIS.Core.Application.xml | 8 ++ .../Service/Common/DictionaryService.cs | 4 +- .../Service/Common/MailService.cs | 5 +- .../Document/TrialEmailNoticeConfigService.cs | 88 +++++++++++++++++++ 8 files changed, 212 insertions(+), 9 deletions(-) create mode 100644 IRaCIS.Core.API/wwwroot/EmailTemplate/SubjectEnrollConfirmOrPDProgress.html diff --git a/IRaCIS.Core.API/IRaCIS.Core.API.csproj b/IRaCIS.Core.API/IRaCIS.Core.API.csproj index 145bf7282..e4fd66a8d 100644 --- a/IRaCIS.Core.API/IRaCIS.Core.API.csproj +++ b/IRaCIS.Core.API/IRaCIS.Core.API.csproj @@ -123,6 +123,9 @@ Always + + Always + Always diff --git a/IRaCIS.Core.API/wwwroot/EmailTemplate/SubjectEnrollConfirmOrPDProgress.html b/IRaCIS.Core.API/wwwroot/EmailTemplate/SubjectEnrollConfirmOrPDProgress.html new file mode 100644 index 000000000..0d184d0a3 --- /dev/null +++ b/IRaCIS.Core.API/wwwroot/EmailTemplate/SubjectEnrollConfirmOrPDProgress.html @@ -0,0 +1,27 @@ + + + + + Title + + +
+
+
+ 您好: +
+
+ 感谢您使用展影云平台。 +
+
+ {0}。 +
+ +
+
祝您顺利!/Best Regards
+
上海展影医疗科技有限公司
+
+
+
+ + diff --git a/IRaCIS.Core.Application/Helper/SendEmailHelper.cs b/IRaCIS.Core.Application/Helper/SendEmailHelper.cs index a6ee6f237..053d18487 100644 --- a/IRaCIS.Core.Application/Helper/SendEmailHelper.cs +++ b/IRaCIS.Core.Application/Helper/SendEmailHelper.cs @@ -31,8 +31,53 @@ public static class SendEmailHelper } } - public static async Task SendEmailAsync(MimeMessage messageToSend, SMTPEmailConfig sMTPEmailConfig, EventHandler? messageSentSuccess = null) + public static async Task SendEmailAsync(SMTPEmailConfig sMTPEmailConfig, EventHandler? messageSentSuccess = null) { + var messageToSend = new MimeMessage(); + + //主题 + messageToSend.Subject = sMTPEmailConfig.TopicDescription; + + //发件地址 + messageToSend.From.Add(sMTPEmailConfig.FromEmailAddress); + + //收件地址 + + if (sMTPEmailConfig.ToMailAddressList.Count == 0) + { + throw new ArgumentException("没有收件人"); + } + else + { + foreach (var item in sMTPEmailConfig.ToMailAddressList) + { + messageToSend.To.Add(item); + } + + //抄送 + foreach (var copyToMailAddress in sMTPEmailConfig.CopyToMailAddressList) + { + messageToSend.Cc.Add(copyToMailAddress); + } + } + + var builder = new BodyBuilder(); + + //html body + + builder.HtmlBody = sMTPEmailConfig.HtmlBodyStr; + + + //附件 + + foreach (var item in sMTPEmailConfig.EmailAttachMentConfigList) + { + await builder.Attachments.AddAsync(item.FileName, item.FileStream); + } + + + messageToSend.Body = builder.ToMessageBody(); + using (var smtp = new MailKit.Net.Smtp.SmtpClient()) { if (messageSentSuccess != null) @@ -61,12 +106,42 @@ public static class SendEmailHelper public class SMTPEmailConfig { - public int Port { get; set; } + public int Port { get; set; } = 465; - public string Host { get; set; } + public string Host { get; set; } = "smtp.163.com"; - public string UserName { get; set; } + public string UserName { get; set; } = "iracis_grr@163.com"; + + public string AuthorizationCode { get; set; } = "XLWVQKZAEKLDWOAH"; + + + //邮件HtmlBody + + public string HtmlBodyStr { get; set; } = string.Empty; + + + //发 + public MailboxAddress FromEmailAddress { get; set; } = new MailboxAddress("GRR", "iracis_grr@163.com"); + + //收 + public List ToMailAddressList { get; set; } = new List(); + + //抄送 + public List CopyToMailAddressList { get; set; } = new List(); + + //邮件主题 + public string TopicDescription { get; set; } = string.Empty; + + //邮件附件 + public List EmailAttachMentConfigList { get; set; } = new List() { }; - public string AuthorizationCode { get; set; } +} + + +public class EmailAttachMentConfig +{ + public string FileName { get; set; } + + public Stream FileStream { get; set; } } diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj index cc2629723..61cb98686 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj @@ -92,6 +92,7 @@ + true diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index a014ab851..af767e115 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -398,6 +398,7 @@ 同步系统配置的文档到想项目中 + @@ -7059,6 +7060,13 @@ + + + 同步项目标准字典信息 + + + + 修改全局阅片配置信息 diff --git a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs index f42845ee9..45fa9bd85 100644 --- a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs +++ b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs @@ -123,9 +123,11 @@ namespace IRaCIS.Application.Services //} - if (addOrEditBasic.Id != null && addOrEditBasic.ParentId!=null) + if (addOrEditBasic.Id != null && addOrEditBasic.ParentId==null) { await _dicRepository.UpdatePartialFromQueryAsync(t => t.ParentId == addOrEditBasic.Id, c => new Dictionary() { DataTypeEnum = addOrEditBasic.DataTypeEnum }); + + //await _dicRepository.BatchUpdateNoTrackingAsync(t => t.ParentId == addOrEditBasic.Id, c => new Dictionary() { DataTypeEnum = addOrEditBasic.DataTypeEnum }); } var entity = await _dicRepository.InsertOrUpdateAsync(addOrEditBasic, true, verifyExp1); diff --git a/IRaCIS.Core.Application/Service/Common/MailService.cs b/IRaCIS.Core.Application/Service/Common/MailService.cs index 7568688a3..cad0d3a7a 100644 --- a/IRaCIS.Core.Application/Service/Common/MailService.cs +++ b/IRaCIS.Core.Application/Service/Common/MailService.cs @@ -92,7 +92,7 @@ namespace IRaCIS.Application.Services messageToSend.To.Add(new MailboxAddress(userName, emailAddress)); //主题 messageToSend.Subject = "[来自展影IRC] 关于重置邮箱的提醒"; - + var builder = new BodyBuilder(); @@ -115,7 +115,6 @@ namespace IRaCIS.Application.Services } - messageToSend.Body = builder.ToMessageBody(); @@ -495,7 +494,7 @@ namespace IRaCIS.Application.Services } - + //医生生成账号加入 或者已存在账号加入到项目中 public async Task DoctorJoinTrialEmail(Guid trialId, Guid doctorId, string baseUrl, string rootUrl) { var doctor = await _doctorTypeRepository.FindAsync(doctorId); diff --git a/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs b/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs index 6e802c895..fe02470e3 100644 --- a/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs +++ b/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs @@ -9,6 +9,8 @@ using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Infrastructure; +using IRaCIS.Core.Application.Helper; namespace IRaCIS.Core.Application.Service { @@ -31,6 +33,7 @@ namespace IRaCIS.Core.Application.Service /// 同步系统配置的文档到想项目中 /// /// + /// /// /// private async Task SyncSystemEmainCofigDocListAsync(Guid trialId, CriterionType? criterionTypeEnum) @@ -56,6 +59,91 @@ namespace IRaCIS.Core.Application.Service await _trialEmailNoticeConfigRepository.SaveChangesAsync(); } + + + private async Task FillWordTemplate(Guid trialId, CriterionType criterionTypeEnum, CommonDocumentBusinessScenario businessScenarioEnum) + { + + + + + + } + + + private async Task FillWordTemplateAndEmailConfig(Guid trialId, Guid visitTaskId, Guid trialReadingCriterionId, CommonDocumentBusinessScenario businessScenarioEnum) + { + var criterionTypeEnum = await _repository.Where(t => t.TrialId == trialId && t.Id == trialReadingCriterionId).Select(t => t.CriterionType).FirstOrDefaultAsync(); + + + var emailConfig = await _trialEmailNoticeConfigRepository.Where(t => t.TrialId == trialId && t.CriterionTypeEnum == criterionTypeEnum && t.BusinessScenarioEnum == businessScenarioEnum).FirstOrDefaultAsync(); + + if (emailConfig == null) + { + throw new BusinessValidationFailedException("找不到该项目标准场景下邮件的配置"); + } + + //填充邮件基本配置 + + var sendEmailConfig = new SMTPEmailConfig(); + + sendEmailConfig.TopicDescription = "入组确认测试"; + + foreach (var item in emailConfig.ReceiveEmailList) + { + sendEmailConfig.ToMailAddressList.Add(new MimeKit.MailboxAddress(string.Empty, item)); + } + + foreach (var item in emailConfig.CopyEmailList) + { + sendEmailConfig.CopyToMailAddressList.Add(new MimeKit.MailboxAddress(string.Empty, item)); + } + + + //邮件内容html + var pathToFile = _hostEnvironment.WebRootPath + + Path.DirectorySeparatorChar.ToString() + + "EmailTemplate" + + Path.DirectorySeparatorChar.ToString() + + "SubjectEnrollConfirm.html"; + + using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile)) + { + var templateInfo = SourceReader.ReadToEnd(); + + + sendEmailConfig.HtmlBodyStr = string.Format(templateInfo, + $" 附件为入组确认报告,请查收 " + ); + } + + //邮件附件 + + var path= FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, emailConfig.FilePath); + + //sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig() + //{ + // FileName = emailConfig.FileName, + // FileStream = + //}); + + + if (businessScenarioEnum == CommonDocumentBusinessScenario.EnrollConfirmed) + { + + } + else if(businessScenarioEnum == CommonDocumentBusinessScenario.PDConfirmed) + { + + } + + return sendEmailConfig; + + } + + + + public async Task> GetTrialEmailNoticeConfigList(TrialEmailNoticeConfigQuery inQuery) {