From 2569ef3828030237a6e069a6d2753dc4ab903a91 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 21 Oct 2022 13:51:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=84=E4=BB=B6=E9=82=AE=E4=BB=B6=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helper/SendEmailHelper.cs | 8 +- .../IRaCIS.Core.Application.xml | 7 ++ .../DTO/TrialEmailNoticeConfigViewModel.cs | 19 +++-- .../Document/TrialEmailNoticeConfigService.cs | 81 +++++++++++-------- .../Document/TrialEmailNoticeConfig.cs | 4 +- 5 files changed, 74 insertions(+), 45 deletions(-) diff --git a/IRaCIS.Core.Application/Helper/SendEmailHelper.cs b/IRaCIS.Core.Application/Helper/SendEmailHelper.cs index 5db0001ce..6243d519d 100644 --- a/IRaCIS.Core.Application/Helper/SendEmailHelper.cs +++ b/IRaCIS.Core.Application/Helper/SendEmailHelper.cs @@ -53,11 +53,10 @@ public static class SendEmailHelper { messageToSend.To.Add(item); } - //抄送 foreach (var copyToMailAddress in sMTPEmailConfig.CopyToMailAddressList) { - messageToSend.Cc.Add(copyToMailAddress); + //messageToSend.Cc.Add(copyToMailAddress); } } @@ -72,7 +71,9 @@ public static class SendEmailHelper foreach (var item in sMTPEmailConfig.EmailAttachMentConfigList) { - builder.Attachments.Add(item.FileName, item.FileData); + //builder.Attachments.Add(item.FileName, item.FileData); + + builder.Attachments.Add(item.FileName, item.FileStream); } @@ -97,6 +98,7 @@ public static class SendEmailHelper await smtp.DisconnectAsync(true); } + } } diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index a29265f3e..bb99b7dfd 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -4461,6 +4461,13 @@ + + + 重置项目标准的重置状态 + + 项目标准Id + + 获取系统肿瘤信息 diff --git a/IRaCIS.Core.Application/Service/Document/DTO/TrialEmailNoticeConfigViewModel.cs b/IRaCIS.Core.Application/Service/Document/DTO/TrialEmailNoticeConfigViewModel.cs index 9afff7fbf..523ddb8ae 100644 --- a/IRaCIS.Core.Application/Service/Document/DTO/TrialEmailNoticeConfigViewModel.cs +++ b/IRaCIS.Core.Application/Service/Document/DTO/TrialEmailNoticeConfigViewModel.cs @@ -7,6 +7,7 @@ using System; using IRaCIS.Core.Domain.Share; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using Newtonsoft.Json; namespace IRaCIS.Core.Application.ViewModel { @@ -42,23 +43,25 @@ namespace IRaCIS.Core.Application.ViewModel public CommonDocumentBusinessScenario BusinessScenarioEnum { get; set; } - public string Code { get; set; } + public string Code { get; set; } = string.Empty; public Guid TrialId { get; set; } - public string AuthorizationCode { get; set; } + public string AuthorizationCode { get; set; } = string.Empty; + - public List ReceiveEmailList { get; set; } public List CopyEmailList { get; set; } + [JsonIgnore] + public string ReceiveEmailsStr { get; set; } = string.Empty; - public string ReceiveEmailsStr { get; set; } - public string CopyEmailsStr { get; set; } + [JsonIgnore] + public string CopyEmailsStr { get; set; } = string.Empty; - public string FromEmail { get; set; } + public string FromEmail { get; set; } = string.Empty; public bool IsUrgent { get; set; } @@ -68,8 +71,8 @@ namespace IRaCIS.Core.Application.ViewModel public bool IsReturnRequired { get; set; } - public string FilePath { get; set; } - public string FileName { get; set; } + public string FilePath { get; set; } = string.Empty; + public string FileName { get; set; } = string.Empty; } diff --git a/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs b/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs index 904a5dc35..5317845cc 100644 --- a/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs +++ b/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs @@ -61,17 +61,16 @@ namespace IRaCIS.Core.Application.Service - private async Task FillWordTemplate(Guid trialId, CriterionType criterionTypeEnum, CommonDocumentBusinessScenario businessScenarioEnum) - { - - - - - - } - - - public async Task FillWordTemplateAndEmailConfig(Guid trialId, Guid visitTaskId, Guid trialReadingCriterionId, CommonDocumentBusinessScenario businessScenarioEnum) + /// + /// 测试邮件 带附件 填充word --前端不需要用 + /// + /// + /// + /// + /// + /// + /// + public 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(); @@ -87,8 +86,6 @@ namespace IRaCIS.Core.Application.Service var sendEmailConfig = new SMTPEmailConfig(); - sendEmailConfig.TopicDescription = "入组确认测试"; - foreach (var item in emailConfig.ReceiveEmailList) { sendEmailConfig.ToMailAddressList.Add(new MimeKit.MailboxAddress(item, item)); @@ -96,7 +93,10 @@ namespace IRaCIS.Core.Application.Service foreach (var item in emailConfig.CopyEmailList) { - sendEmailConfig.CopyToMailAddressList.Add(new MimeKit.MailboxAddress(item, item)); + if (item.Contains("@") && !string.IsNullOrEmpty(item)) + { + sendEmailConfig.CopyToMailAddressList.Add(new MimeKit.MailboxAddress(item.Trim(), item.Trim())); + } } @@ -107,40 +107,56 @@ namespace IRaCIS.Core.Application.Service + Path.DirectorySeparatorChar.ToString() + "SubjectEnrollConfirmOrPDProgress.html"; - using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile)) + + if (businessScenarioEnum == CommonDocumentBusinessScenario.EnrollConfirmed) { - var templateInfo = SourceReader.ReadToEnd(); + + sendEmailConfig.TopicDescription = "入组确认测试"; + + using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile)) + { + var templateInfo = SourceReader.ReadToEnd(); - sendEmailConfig.HtmlBodyStr = string.Format(templateInfo, - $" 附件为入组确认报告,请查收 " - ); + sendEmailConfig.HtmlBodyStr = string.Format(templateInfo, + $" 附件为入组确认报告,请查收 " + ); + } + } + else if (businessScenarioEnum == CommonDocumentBusinessScenario.PDConfirmed) + { + + sendEmailConfig.TopicDescription = "疾病进展测试"; + + using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile)) + { + var templateInfo = SourceReader.ReadToEnd(); + + + sendEmailConfig.HtmlBodyStr = string.Format(templateInfo, + $" 附件为疾病进展确认报告,请查收 " + ); + } } //邮件附件 + var path = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, emailConfig.FilePath); - var path= FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, emailConfig.FilePath); + if (!File.Exists(path)) + { + throw new BusinessValidationFailedException("找不到该项目标准场景下邮件模板"); + } sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig() { FileName = emailConfig.FileName, - FileData= File.ReadAllBytes(path) + FileStream = System.IO.File.OpenRead(path) }); - if (businessScenarioEnum == CommonDocumentBusinessScenario.EnrollConfirmed) - { - } - else if(businessScenarioEnum == CommonDocumentBusinessScenario.PDConfirmed) - { - - } - - await SendEmailHelper.SendEmailAsync(sendEmailConfig); - - return sendEmailConfig; + await SendEmailHelper.SendEmailAsync(sendEmailConfig); } @@ -178,6 +194,7 @@ namespace IRaCIS.Core.Application.Service public async Task DeleteTrialEmailNoticeConfig(Guid trialEmailNoticeConfigId) { var success = await _trialEmailNoticeConfigRepository.DeleteFromQueryAsync(t => t.Id == trialEmailNoticeConfigId, true); + return ResponseOutput.Ok(); } diff --git a/IRaCIS.Core.Domain/Document/TrialEmailNoticeConfig.cs b/IRaCIS.Core.Domain/Document/TrialEmailNoticeConfig.cs index 7805d3941..8733b8fe1 100644 --- a/IRaCIS.Core.Domain/Document/TrialEmailNoticeConfig.cs +++ b/IRaCIS.Core.Domain/Document/TrialEmailNoticeConfig.cs @@ -31,10 +31,10 @@ namespace IRaCIS.Core.Domain.Models [NotMapped] - public List ReceiveEmailList => ReceiveEmailsStr.Split('|', StringSplitOptions.RemoveEmptyEntries).Select(t=>t.Trim()).ToList(); + public List ReceiveEmailList => ReceiveEmailsStr.Split('|', StringSplitOptions.RemoveEmptyEntries).Where(t => !string.IsNullOrEmpty(t)).Select(t=>t.Trim()).ToList(); [NotMapped] - public List CopyEmailList => CopyEmailsStr.Split('|', StringSplitOptions.RemoveEmptyEntries).Select(t => t.Trim()).ToList(); + public List CopyEmailList => CopyEmailsStr.Split('|', StringSplitOptions.RemoveEmptyEntries).Where(t=> !string.IsNullOrEmpty(t)).Select(t => t.Trim()).ToList(); [Required] public bool IsUrgent { get; set; }