diff --git a/IRaCIS.Core.Application/Helper/FileFormatConvertHelper.cs b/IRaCIS.Core.Application/Helper/FileFormatConvertHelper.cs deleted file mode 100644 index bca41c8f0..000000000 --- a/IRaCIS.Core.Application/Helper/FileFormatConvertHelper.cs +++ /dev/null @@ -1,16 +0,0 @@ -using DocumentFormat.OpenXml.Bibliography; -using NPOI.XWPF.UserModel; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace IRaCIS.Core.Application.Helper -{ - public class FileFormatConvertHelper - { - - - } -} diff --git a/IRaCIS.Core.Application/Helper/NpoiWordHelper.cs b/IRaCIS.Core.Application/Helper/NpoiWordHelper.cs deleted file mode 100644 index 2e9932140..000000000 --- a/IRaCIS.Core.Application/Helper/NpoiWordHelper.cs +++ /dev/null @@ -1,171 +0,0 @@ - -using IRaCIS.Core.Application.Helper; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using NPOI.OpenXmlFormats.Wordprocessing; -using NPOI.XWPF.UserModel; -using System.Collections; -using System.Reflection; - -namespace IRaCIS.Core.Application.Service; - -public static class NpoiWordHelper -{ - public static async Task TemplateExportWordAsync(string code, object data, IRepository? _commonDocumentRepository, IWebHostEnvironment _hostEnvironment) - { - //var (physicalPath, fileNmae) = await FileStoreHelper.GetCommonDocPhysicalFilePathAsync(_hostEnvironment, _commonDocumentRepository, code); - - var physicalPath = code; - - - using (FileStream stream = File.OpenRead(physicalPath)) - { - XWPFDocument doc = new XWPFDocument(stream); - //遍历段落 - foreach (var para in doc.Paragraphs) - { - ReplaceKey(para, data); - } - //遍历表格 - var tables = doc.Tables; - foreach (var table in tables) - { - //ReplaceTableKey(table, data, "Data"); - } - - foreach (var table in tables) - { - foreach (var row in table.Rows) - { - foreach (var cell in row.GetTableCells()) - { - foreach (var para in cell.Paragraphs) - { - ReplaceKey(para, data); - } - } - } - } - - FileStream out1 = new FileStream("table.docx", FileMode.Create); - doc.Write(out1); - out1.Close(); - return new FileStreamResult(stream, "application/msword") - { - FileDownloadName = $"replaced_{DateTime.Now.ToString("yyyyMMddHHmmss")}.docx" - }; - } - - - - - - - - - - - - - - - } - - private static void ReplaceKey(XWPFParagraph para, object model) - { - string text = para.ParagraphText; - - Type t = model.GetType(); - PropertyInfo[] pi = t.GetProperties(); - foreach (PropertyInfo p in pi) - { - //$$与模板中$$对应,也可以改成其它符号,比如{$name},务必做到唯一 - if (text.Contains("$" + p.Name + "$")) - { - text = text.Replace("$" + p.Name + "$", p.GetValue(model)?.ToString()); - } - } - - //var runs = para.Runs; - //string styleid = para.Style; - //for (int i = 0; i < runs.Count; i++) - //{ - // var run = runs[i]; - // text = run.ToString(); - // Type t = model.GetType(); - // PropertyInfo[] pi = t.GetProperties(); - // foreach (PropertyInfo p in pi) - // { - // //$$与模板中$$对应,也可以改成其它符号,比如{$name},务必做到唯一 - // if (text.Contains("$" + p.Name + "$")) - // { - // text = text.Replace("$" + p.Name + "$", p.GetValue(model)?.ToString()); - // } - // } - // runs[i].SetText(text, 0); - //} - } - - - - - /// - /// 替换表格Key - /// - /// - /// - /// - - private static void ReplaceTableKey(XWPFTable table, IList list, String field) - { - List paras = new List(); - // 获取最后一行数据,最后一行设置值 - Int32 iLastRowIndex = 0; - for (int iIndex = 0; iIndex < table.Rows.Count; iIndex++) - { - if (iIndex == table.Rows.Count - 1) - { - iLastRowIndex = iIndex; - foreach (var cell in table.Rows[iIndex].GetTableCells()) - { - foreach (var para in cell.Paragraphs) - { - paras.Add(para); - } - } - } - } - // 删除最后一行 - table.RemoveRow(iLastRowIndex); - - for (int iIndex = 0; iIndex < list.Count; iIndex++) - { - object data = list[iIndex]; - Type t = data.GetType(); - PropertyInfo[] pi = t.GetProperties(); - // 表增加行 - XWPFTableRow m_row = table.CreateRow(); - CT_Row m_NewRow = new CT_Row(); - String text = String.Empty; - Int32 jIndex = 0; - paras.ForEach(para => - { - text = para.ParagraphText; - foreach (PropertyInfo p in pi) - { - if (text.Contains("$" + field + "." + p.Name + "$")) - { - m_row.GetCell(jIndex).SetText(p.GetValue(data, null).ToString()); - } - } - jIndex++; - }); - m_row = new XWPFTableRow(m_NewRow, table); - table.AddRow(m_row); - - } - } - - - -} \ No newline at end of file diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 3d4f9bf33..9724e186a 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -85,14 +85,6 @@ - - - 替换表格Key - - - - - 分配规则 @@ -725,17 +717,9 @@ - - - 同步系统配置的文档到想项目中 ---废弃 - - - - - - 测试邮件 带附件 填充word --前端不需 + 测试邮件 带附件 填充word 为空 代表 正常任务自动发送,为true 代表医学审核手动发送 为false 代表医学审核自动发送 diff --git a/IRaCIS.Core.Application/Service/Document/EmailSendService.cs b/IRaCIS.Core.Application/Service/Document/EmailSendService.cs index fae472eec..490fe0cd7 100644 --- a/IRaCIS.Core.Application/Service/Document/EmailSendService.cs +++ b/IRaCIS.Core.Application/Service/Document/EmailSendService.cs @@ -18,6 +18,7 @@ using System.Linq; using System.Net.Mail; using System.Text; using System.Threading.Tasks; +using static IRaCIS.Core.Domain.Share.StaticData; namespace IRaCIS.Core.Application.Service { @@ -29,6 +30,8 @@ namespace IRaCIS.Core.Application.Service Task SendTrialQCQuestionEmailAsync(Guid trialId); Task SendTrialImageQuestionAsync(Guid trialId); + + Task<(TrialEmailNoticeConfig?, SMTPEmailConfig?)> BuildEmailConfig(Guid trialId, EmailBusinessScenario businessScenario, Func topicAndHtmlFunc, Guid? siteId = null, Guid? trialReadingCriterionId = null); } public class EmailSendService : BaseService, IEmailSendService @@ -39,18 +42,16 @@ namespace IRaCIS.Core.Application.Service private readonly IRepository _trialRepository; - private readonly IDictionaryService _dictionaryService; private readonly IOptionsMonitor _SystemEmailSendConfig; - public readonly static string EmailNamePlaceholder = "EmailNamePlaceholder"; + public static string EmailNamePlaceholder => StaticData. EmailSend.EmailNamePlaceholder; - public EmailSendService(IRepository trialEmailNoticeConfigRepository, IRepository emailNoticeConfigRepository, IRepository trialRepository, IOptionsMonitor systemEmailSendConfig, IDictionaryService dictionaryService) + public EmailSendService(IRepository trialEmailNoticeConfigRepository, IRepository emailNoticeConfigRepository, IRepository trialRepository, IOptionsMonitor systemEmailSendConfig) { _trialEmailNoticeConfigRepository = trialEmailNoticeConfigRepository; _emailNoticeConfigRepository = emailNoticeConfigRepository; _trialRepository = trialRepository; _SystemEmailSendConfig = systemEmailSendConfig; - _dictionaryService = dictionaryService; } //入组确认/PD确认 @@ -92,27 +93,30 @@ namespace IRaCIS.Core.Application.Service if (isEnrollment == true) { - Func topicAndHtmlFunc = trialEmailConfig => + Func topicAndHtmlFunc = trialEmailConfig => { var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, taskInfo.ResearchProgramNo, taskInfo.SubjectCode); var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN, EmailNamePlaceholder, taskInfo.ResearchProgramNo, taskInfo.SubjectCode, resultStr); - return (topicStr, htmlBodyStr, isEn_us, null); + + + return (topicStr, htmlBodyStr, isEn_us, null); }; await SendTrialEmailAsync(taskInfo.TrialId, businessScenarioEnum, topicAndHtmlFunc, taskInfo.SiteId); } else { - Func topicAndHtmlFunc = trialEmailConfig => + Func topicAndHtmlFunc = trialEmailConfig => { var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, taskInfo.ResearchProgramNo, taskInfo.SubjectCode, taskInfo.VisitName); var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN, EmailNamePlaceholder, taskInfo.ResearchProgramNo, taskInfo.SubjectCode, taskInfo.VisitName, resultStr); - return (topicStr, htmlBodyStr, isEn_us, null); + + return (topicStr, htmlBodyStr, isEn_us, null); }; await SendTrialEmailAsync(taskInfo.TrialId, businessScenarioEnum, topicAndHtmlFunc, taskInfo.SiteId); @@ -160,11 +164,12 @@ namespace IRaCIS.Core.Application.Service if (sendStat != null && (sendStat.ToBeClaimedCount > 0 || sendStat.ToBeReviewedCount > 0)) { - Func topicAndHtmlFunc = trialEmailConfig => + Func topicAndHtmlFunc = trialEmailConfig => { var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, trialInfo.ResearchProgramNo); var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN, user.FullName, DateTime.Now, sendStat.ToBeClaimedCount, sendStat.ToBeReviewedCount, _SystemEmailSendConfig.CurrentValue.SiteUrl); + return (topicStr, htmlBodyStr, false, userId); }; @@ -211,13 +216,15 @@ namespace IRaCIS.Core.Application.Service if (sendStat != null && (sendStat.ToBeDealedCount > 0 || sendStat.ReUploadTobeDealedCount > 0)) { - Func topicAndHtmlFunc = trialEmailConfig => + Func topicAndHtmlFunc = trialEmailConfig => { var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, trialInfo.ResearchProgramNo); var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN, user.FullName, DateTime.Now, sendStat.ToBeDealedCount - sendStat.ReUploadTobeDealedCount, sendStat.ReUploadTobeDealedCount, _SystemEmailSendConfig.CurrentValue.SiteUrl); - return (topicStr, htmlBodyStr, false, userId); + + + return (topicStr, htmlBodyStr, false, userId); }; await SendTrialEmailAsync(trialId, EmailBusinessScenario.QCQuestion, topicAndHtmlFunc); @@ -261,12 +268,13 @@ namespace IRaCIS.Core.Application.Service if (sendStat != null && (sendStat.ToBeDealedCount > 0)) { - Func topicAndHtmlFunc = trialEmailConfig => + Func topicAndHtmlFunc = trialEmailConfig => { var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, trialInfo.ResearchProgramNo); var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN, user.FullName, DateTime.Now, sendStat.ToBeDealedCount, _SystemEmailSendConfig.CurrentValue.SiteUrl); - return (topicStr, htmlBodyStr, isEn_us, userId); + + return (topicStr, htmlBodyStr, isEn_us, userId); }; await SendTrialEmailAsync(trialId, EmailBusinessScenario.ImageQuestion, topicAndHtmlFunc); @@ -277,7 +285,19 @@ namespace IRaCIS.Core.Application.Service - public async Task SendTrialEmailAsync(Guid trialId, EmailBusinessScenario businessScenario, Func topicAndHtmlFunc, Guid? siteId = null, Guid? trialReadingCriterionId = null) + public async Task SendTrialEmailAsync(Guid trialId, EmailBusinessScenario businessScenario, Func topicAndHtmlFunc, Guid? siteId = null, Guid? trialReadingCriterionId = null, Func emailAttachFunc=null) + { + var (trialEmailConfig, sendEmailConfig) = await BuildEmailConfig(trialId, businessScenario, topicAndHtmlFunc, siteId, trialReadingCriterionId); + + if (sendEmailConfig != null) + { + + await SendEmailHelper.SendEmailAsync(sendEmailConfig); + } + } + + + public async Task<(TrialEmailNoticeConfig?, SMTPEmailConfig?)> BuildEmailConfig(Guid trialId, EmailBusinessScenario businessScenario, Func topicAndHtmlFunc, Guid? siteId = null, Guid? trialReadingCriterionId = null) { //找到配置 var trialEmailConfig = await _trialEmailNoticeConfigRepository.Where(t => t.TrialId == trialId && t.TrialReadingCriterionId == trialReadingCriterionId && t.BusinessScenarioEnum == businessScenario, ignoreQueryFilters: true) @@ -286,13 +306,13 @@ namespace IRaCIS.Core.Application.Service if (trialEmailConfig == null || trialEmailConfig.IsAutoSend == false) { - return; + return (null,null); } else { var sendEmailConfig = new SMTPEmailConfig(); - var (topicStr, htmlBodyStr, isEn_us, onlyToUserId) = topicAndHtmlFunc(trialEmailConfig); + var (topicStr, htmlBodyStr, isEn_us, onlyToUserId) = topicAndHtmlFunc(trialEmailConfig); sendEmailConfig.TopicDescription = topicStr; @@ -393,11 +413,25 @@ namespace IRaCIS.Core.Application.Service } } - await SendEmailHelper.SendEmailAsync(sendEmailConfig); + //邮件附件 这里是原格式发送,不是PDF + + //if (trialEmailConfig.AttachCNPath != string.Empty && trialEmailConfig.AttachPath != string.Empty) + //{ + // var phyPath = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, isEn_us? trialEmailConfig.AttachName: trialEmailConfig.AttachNameCN); + + // //先预先生成了邮件,发送预先生成的邮件 + // sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig() + // { + // FileName = $"{attachPrefix}_{Path.GetFileName(_userInfo.IsEn_Us ? trialEmailConfig.AttachName : trialEmailConfig.AttachNameCN)}", + + // FileStream = File.OpenRead(phyPath), + // }); + //} + + return (trialEmailConfig,sendEmailConfig) ; + } } - - } } diff --git a/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs b/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs index 7a68d55ef..70ad72dd1 100644 --- a/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs +++ b/IRaCIS.Core.Application/Service/Document/TrialEmailNoticeConfigService.cs @@ -21,6 +21,8 @@ using IRaCIS.Core.Domain.Share.Common; using System.IO; using System.Linq; using Spire.Doc; +using Microsoft.AspNetCore.Http; +using System; namespace IRaCIS.Core.Application.Service { @@ -43,7 +45,7 @@ namespace IRaCIS.Core.Application.Service private readonly IRepository _subjectRepository; private readonly IRepository _subjectVisitRepository; - + private readonly IEmailSendService _emailSendService; public TrialEmailNoticeConfigService( @@ -56,6 +58,7 @@ namespace IRaCIS.Core.Application.Service IRepository subjectVisitRepository, IRepository trialEmailBlackUserRepository, IRepository emailNoticeConfigRepository +, IEmailSendService emailSendService ) { _trialEmailNoticeConfigRepository = trialEmailNoticeConfigRepository; @@ -67,6 +70,7 @@ namespace IRaCIS.Core.Application.Service _subjectVisitRepository = subjectVisitRepository; _trialEmailBlackUserRepository = trialEmailBlackUserRepository; _emailNoticeConfigRepository = emailNoticeConfigRepository; + _emailSendService = emailSendService; } /// @@ -87,7 +91,7 @@ namespace IRaCIS.Core.Application.Service IsConfigureEmail = x.IsConfigureEmail, EmailSMTPServerPort = x.EmailSMTPServerPort - }).FirstOrDefaultAsync(); + }).FirstAsync(); } /// @@ -135,60 +139,6 @@ namespace IRaCIS.Core.Application.Service return ResponseOutput.Ok(); } - /// - /// 同步系统配置的文档到想项目中 ---废弃 - /// - /// - /// - /// - private async Task SyncSystemEmainCofigDocListAsync(Guid trialId) - { - - //判断流程配置是否确认 确认了一定确认了标准 可以进行同步 - - if (_repository.Where(t => t.Id == trialId).Any(t => t.IsTrialProcessConfirmed == true)) - { - - //只要有系统标准的文档 说明同步过了 - var trialDocCount = _trialEmailNoticeConfigRepository.Where(t => t.TrialId == trialId).Count(); - - if (trialDocCount == 0) - { - //找到确认的标准 - var list = await _repository.Where(t => t.TrialId == trialId && t.IsConfirm).Select(t => new { t.CriterionType, TrialReadingCriterionId = t.Id }).ToListAsync(); - - var confirmedCriterionTypeList = list.Select(t => (CriterionType?)t.CriterionType).ToList(); - - var docmentList = _repository.Where(t => t.BusinessScenarioEnum == EmailBusinessScenario.EnrollConfirmed || t.BusinessScenarioEnum == EmailBusinessScenario.PDConfirmed) - //.Where(t => (confirmedCriterionTypeList.Contains(t.CriterionTypeEnum)) || t.CriterionTypeEnum == null).Select(t => new { t.Path, t.Name, t.Code, t.BusinessScenarioEnum, t.CriterionTypeEnum }) - .ToList(); - - - - foreach (var item in docmentList) - { - await _trialEmailNoticeConfigRepository.AddAsync(new TrialEmailNoticeConfig() - { - TrialId = trialId, - TrialReadingCriterionId = list.Where(t => t.CriterionType == item.CriterionTypeEnum).FirstOrDefault()?.TrialReadingCriterionId, - //FileName = item.Name, - //FilePath = item.Path, - BusinessScenarioEnum = item.BusinessScenarioEnum, - Code = item.Code - }); - } - - } - - - } - - - - await _trialEmailNoticeConfigRepository.SaveChangesAsync(); - } - - private async Task DealMedicalReviewTasKGenerateAndIsSendAsync(Guid trialId, bool? isHandSend, string pdAnswer, List taskIdList, List minUserIdList) @@ -237,15 +187,12 @@ namespace IRaCIS.Core.Application.Service } } - - - return isNeedSend; } /// - /// 测试邮件 带附件 填充word --前端不需 + /// 测试邮件 带附件 填充word /// /// /// 为空 代表 正常任务自动发送,为true 代表医学审核手动发送 为false 代表医学审核自动发送 @@ -255,8 +202,8 @@ namespace IRaCIS.Core.Application.Service /// public async Task BaseBusinessScenarioSendEmailAsync(Guid visitTaskId, bool? isHandSend, EmailStoreSendMode emailStoreMode, string sendFileRelativePath) { - - EmailBusinessScenario? businessScenarioEnum = null; + var isEn_us = _userInfo.IsEn_Us; + EmailBusinessScenario businessScenarioEnum = EmailBusinessScenario.None; #region 任务关联的项目配置 标准信息及配置,subject 信息 var taskInfo = await _visitTaskRepository.Where(t => t.Id == visitTaskId).Select(t => new @@ -352,286 +299,122 @@ namespace IRaCIS.Core.Application.Service #endregion - #region 发收件人配置 确保无误 + #region 邮件内容装配 - - var emailConfig = await _trialEmailNoticeConfigRepository.Where(t => t.TrialId == taskInfo.TrialId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.BusinessScenarioEnum == businessScenarioEnum) - .Include(t => t.TrialEmailNoticeUserList).FirstOrDefaultAsync(); - - - if (emailConfig == null || (emailConfig.IsAutoSend == false && isHandSend == null)) + Func topicAndHtmlFunc = trialEmailConfig => { - //throw new BusinessValidationFailedException("找不到该项目标准场景下邮件的配置"); + var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, taskInfo.ResearchProgramNo, taskInfo.SubjectCode); - return string.Empty; - } + var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN, + StaticData.EmailSend.EmailNamePlaceholder, taskInfo.ResearchProgramNo, taskInfo.SubjectCode); - var sendEmailConfig = new SMTPEmailConfig(); - - //收件人 如果是CRC CRA 要按照中心发送 - var toUserTypeEnumList = emailConfig.TrialEmailNoticeUserList.Where(t => t.EmailUserType == EmailUserType.To).Select(c => c.UserType).ToList(); + return (topicStr, htmlBodyStr, isEn_us, null); + }; - - var toUserList = _repository.Where(t => t.TrialId == taskInfo.TrialId && toUserTypeEnumList.Contains(t.User.UserTypeEnum) && t.SiteId == taskInfo.SiteId).Select(t => new { t.User.EMail, t.User.FullName }).ToList(); - - var copyUserTypeEnumList = emailConfig.TrialEmailNoticeUserList.Where(t => t.EmailUserType == EmailUserType.Copy).Select(c => c.UserType).ToList(); - var copyUserList = _repository.Where(t => t.TrialId == taskInfo.TrialId && copyUserTypeEnumList.Contains(t.User.UserTypeEnum)).Select(t => new { t.User.EMail, t.User.FullName }).ToList(); - - - if (toUserList.Count() == 0) - { - //---没有收件人,无法发送邮件 - throw new BusinessValidationFailedException(_localizer["TrialEmailN_NoRecipient"]); - } - - - if (emailConfig.FromEmail.Contains("@") && !string.IsNullOrEmpty(emailConfig.FromEmail)) - { - - sendEmailConfig.FromEmailAddress = new MimeKit.MailboxAddress(emailConfig.FromName, emailConfig.FromEmail); - sendEmailConfig.AuthorizationCode = emailConfig.AuthorizationCode; - sendEmailConfig.UserName = emailConfig.FromEmail; - - sendEmailConfig.Host = emailConfig.SMTPServerAddress; - sendEmailConfig.Port = emailConfig.SMTPServerPort; - - - //测试 - //sendEmailConfig.ToMailAddressList.Add(new MimeKit.MailboxAddress("ddd", "872297557@qq.com")); - - } - else - { - //---项目发件邮箱配置有误,请核实 - throw new BusinessValidationFailedException(_localizer["TrialEmailN_InvalidEmailConfig"]); - } - - foreach (var item in toUserList) - { - - if (item.EMail.Contains("@") && !string.IsNullOrEmpty(item.EMail)) - { - - sendEmailConfig.ToMailAddressList.Add(new MimeKit.MailboxAddress(item.FullName, item.EMail)); - - } - } - foreach (var item in copyUserList) - { - - if (item.EMail.Contains("@") && !string.IsNullOrEmpty(item.EMail)) - { - - sendEmailConfig.CopyToMailAddressList.Add(new MimeKit.MailboxAddress(item.FullName, item.EMail)); - - } - } - #endregion - - #region 确保 邮件Html存在 - - //邮件附件 - var path = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, _userInfo.IsEn_Us ? emailConfig.AttachPath : emailConfig.AttachCNPath); - - if (!File.Exists(path)) - { - //---找不到该项目标准场景下邮件模板 - throw new BusinessValidationFailedException(_localizer["TrialEmailN_EmailTemplateNotFound"]); - } - - - var pathToFile = _hostEnvironment.WebRootPath - + Path.DirectorySeparatorChar.ToString() - + "EmailTemplate" - + Path.DirectorySeparatorChar.ToString() - //+ "SubjectEnrollConfirmOrPDProgress.html"; - + (_userInfo.IsEn_Us ? "SubjectEnrollConfirmOrPDProgress_US.html" : "SubjectEnrollConfirmOrPDProgress.html"); + var (trialEmailConfig, sendEmailConfig) = await _emailSendService.BuildEmailConfig(taskInfo.TrialId, businessScenarioEnum, topicAndHtmlFunc, taskInfo.SiteId); #endregion - #region 不同场景 Tile 设置 - - if (businessScenarioEnum == EmailBusinessScenario.EnrollConfirmed) + //自动发送 + if (sendEmailConfig != null) { - sendEmailConfig.TopicDescription = _localizer["TrialEmailN_EnrollmentConfirmation", taskInfo.ResearchProgramNo, taskInfo.SubjectCode]; + #region 不同标准 不同项目配置 发送邮件的时机 处理具体逻辑 - using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile)) + var answer = "否"; + var isNeedSend = true; + var minUserIdList = _trialUserRepository.Where(t => t.User.UserTypeEnum == Domain.Share.UserTypeEnum.MIM && t.TrialId == taskInfo.TrialId).Select(t => t.UserId).ToList(); + + + + //入组确认 根据每个标准配置的是否自动发送,发送邮件与否 + if (businessScenarioEnum == EmailBusinessScenario.EnrollConfirmed) { - var templateInfo = SourceReader.ReadToEnd(); - - - sendEmailConfig.HtmlBodyStr = string.Format(templateInfo, - //--- 附件为疾病进展确认报告,请查收 - _localizer["TrialEmailN_SubjectDiseaseProgression"] - ); - } - } - else if (businessScenarioEnum == EmailBusinessScenario.PDConfirmed) - { - sendEmailConfig.TopicDescription = _localizer["TrialEmailN_PDReport", taskInfo.ResearchProgramNo, taskInfo.SubjectCode]; - - using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile)) - { - var templateInfo = SourceReader.ReadToEnd(); - - - sendEmailConfig.HtmlBodyStr = string.Format(templateInfo, - //--- 附件为疾病进展确认报告,请查收 - _localizer["TrialEmailN_SubjectDiseaseProgression"] - ); - } - } - else - { - // - } - - #endregion - - - #region 不同标准 不同项目配置 发送邮件的时机 处理具体逻辑 - - var answer = "否"; - var isNeedSend = true; - var minUserIdList = _trialUserRepository.Where(t => t.User.UserTypeEnum == Domain.Share.UserTypeEnum.MIM && t.TrialId == taskInfo.TrialId).Select(t => t.UserId).ToList(); - - - - //入组确认 根据每个标准配置的是否自动发送,发送邮件与否 - if (businessScenarioEnum == EmailBusinessScenario.EnrollConfirmed) - { - if (await _repository.Where().AnyAsync(x => x.VisitTaskId == visitTaskId && x.Answer == TargetState.Exist.GetEnumInt() && - x.ReadingTableQuestionTrial.QuestionMark == QuestionMark.State && x.ReadingQuestionTrial.LesionType == LesionType.TargetLesion)) - { - answer = "是"; - } - - - //如果其他阅片人已经做了,说明发送了入组确认报告,第二个人做完就不发送了 - - //入组确认一直交给第一个人,如果第一个人重阅 还未做完,第二个人先做完了,此时不发 - - var existFirstEnrollTask = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.IsAnalysisCreate == false - && t.ReadingTaskState == ReadingTaskState.HaveSigned && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId).OrderBy(t => t.SignTime).FirstOrDefaultAsync(); - - //入组确认的医生已确定 - if ((existFirstEnrollTask != null) && (taskInfo.DoctorUserId != existFirstEnrollTask.DoctorUserId)) - { - isNeedSend = false; - } - else - { - isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List() { visitTaskId }, minUserIdList); - - - if (answer == "是") + if (await _repository.Where().AnyAsync(x => x.VisitTaskId == visitTaskId && x.Answer == TargetState.Exist.GetEnumInt() && + x.ReadingTableQuestionTrial.QuestionMark == QuestionMark.State && x.ReadingQuestionTrial.LesionType == LesionType.TargetLesion)) { - //把另外一个人的任务设置为不加急(如果项目加急是否 subject 加急是否) - var urgent = _repository.Where(t => t.Id == taskInfo.SourceSubjectVisitId).Select(t => new { IsSubjectUrgent = t.Subject.IsUrgent, t.Trial.IsUrgent }).FirstOrDefault(); - - if (urgent?.IsUrgent == false || urgent?.IsSubjectUrgent == false) - { - await _visitTaskRepository.BatchUpdateNoTrackingAsync(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && - t.Id != visitTaskId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId, u => new VisitTask() { IsUrgent = false }); - } + answer = "是"; } + //如果其他阅片人已经做了,说明发送了入组确认报告,第二个人做完就不发送了 + + //入组确认一直交给第一个人,如果第一个人重阅 还未做完,第二个人先做完了,此时不发 + + var existFirstEnrollTask = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.IsAnalysisCreate == false + && t.ReadingTaskState == ReadingTaskState.HaveSigned && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId).OrderBy(t => t.SignTime).FirstOrDefaultAsync(); + + //入组确认的医生已确定 + if ((existFirstEnrollTask != null) && (taskInfo.DoctorUserId != existFirstEnrollTask.DoctorUserId)) + { + isNeedSend = false; + } + else + { + isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List() { visitTaskId }, minUserIdList); + + + if (answer == "是") + { + //把另外一个人的任务设置为不加急(如果项目加急是否 subject 加急是否) + var urgent = _repository.Where(t => t.Id == taskInfo.SourceSubjectVisitId).Select(t => new { IsSubjectUrgent = t.Subject.IsUrgent, t.Trial.IsUrgent }).FirstOrDefault(); + + if (urgent?.IsUrgent == false || urgent?.IsSubjectUrgent == false) + { + await _visitTaskRepository.BatchUpdateNoTrackingAsync(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && + t.Id != visitTaskId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId, u => new VisitTask() { IsUrgent = false }); + } + } + + + } + + + + } - - - - - } - else if (businessScenarioEnum == EmailBusinessScenario.PDConfirmed) - { - - - //有序 - - if (taskInfo.IsReadingTaskViewInOrder) + else if (businessScenarioEnum == EmailBusinessScenario.PDConfirmed) { + //有序 - //双重 - if (taskInfo.ReadingType == ReadingMethod.Double) + if (taskInfo.IsReadingTaskViewInOrder) { - //仲裁在访视上 就没有全局阅片 没有阅片期 - if (taskInfo.ArbitrationRule == ArbitrationRule.Visit) + + //双重 + if (taskInfo.ReadingType == ReadingMethod.Double) { - //找到 访视,裁判 所有有效任务(不可能有全局的) 访视和裁判任务的SourceSubjectVisitId 一样 - var taskList = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect && - (t.ReadingCategory == ReadingCategory.Visit || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync(); - //这里要求 到这里已经如果有裁判 已经生成裁判了保存数据库 - //双人阅片,没有产生裁判 第二个人读完发 - if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2) + //仲裁在访视上 就没有全局阅片 没有阅片期 + if (taskInfo.ArbitrationRule == ArbitrationRule.Visit) { - - answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType); + //找到 访视,裁判 所有有效任务(不可能有全局的) 访视和裁判任务的SourceSubjectVisitId 一样 + var taskList = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect && + (t.ReadingCategory == ReadingCategory.Visit || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync(); - isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList); - - } - //双人 产生裁判,并且裁判完成 发 - else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1) - { - var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value; - answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Visit, taskInfo.CriterionType); - - isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList); - - } - else - { - isNeedSend = false; - - } - - - - - } - //仲裁在阅片期 - else if (taskInfo.ArbitrationRule == ArbitrationRule.Reading) - { - //是访视任务 不可能是裁判任务(访视上不会生成裁判),也不会是全局任务(全局任务 SourceSubjectVisitId=null ) - if (taskInfo.SourceSubjectVisitId != null) - { - - //访视类型的任务 根本就不需要发送邮件 - - isNeedSend = false; - - } - //是全局任务 或者全局的裁判任务 (如果是全局任务,那么此时裁判任务已经生成) - else if (taskInfo.SouceReadModuleId != null) - { - var taskList = await _visitTaskRepository.Where(t => t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect && t.SouceReadModuleId == taskInfo.SouceReadModuleId - && (t.ReadingCategory == ReadingCategory.Global || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync(); - - //两个全局没有裁判 - if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Global) == 2) + //这里要求 到这里已经如果有裁判 已经生成裁判了保存数据库 + //双人阅片,没有产生裁判 第二个人读完发 + if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2) { answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType); - isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList); - } - //双人全局产生裁判 - else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Global).Count() == 2) - { + isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList); + + } + //双人 产生裁判,并且裁判完成 发 + else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1) + { var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value; - answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Global, taskInfo.CriterionType); + answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Visit, taskInfo.CriterionType); isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList); @@ -641,255 +424,312 @@ namespace IRaCIS.Core.Application.Service isNeedSend = false; } + + + + + } + //仲裁在阅片期 + else if (taskInfo.ArbitrationRule == ArbitrationRule.Reading) + { + //是访视任务 不可能是裁判任务(访视上不会生成裁判),也不会是全局任务(全局任务 SourceSubjectVisitId=null ) + if (taskInfo.SourceSubjectVisitId != null) + { + + //访视类型的任务 根本就不需要发送邮件 + + isNeedSend = false; + + } + //是全局任务 或者全局的裁判任务 (如果是全局任务,那么此时裁判任务已经生成) + else if (taskInfo.SouceReadModuleId != null) + { + var taskList = await _visitTaskRepository.Where(t => t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect && t.SouceReadModuleId == taskInfo.SouceReadModuleId + && (t.ReadingCategory == ReadingCategory.Global || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync(); + + //两个全局没有裁判 + if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Global) == 2) + { + + answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType); + + isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList); + } + //双人全局产生裁判 + else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Global).Count() == 2) + { + + var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value; + answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Global, taskInfo.CriterionType); + + isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList); + + } + else + { + isNeedSend = false; + + } + } + else + { + //---发送PD 进展邮件中发现任务数据有问题! + throw new BusinessValidationFailedException(_localizer["TrialEmailN_PDProgressEmailTask"]); + } + + + } else { - //---发送PD 进展邮件中发现任务数据有问题! - throw new BusinessValidationFailedException(_localizer["TrialEmailN_PDProgressEmailTask"]); + + //---双重有序阅片 没有定义该仲裁规则处理逻辑,请联系业务和后台开发核查! + throw new BusinessValidationFailedException(_localizer["TrialEmailN_DoubleBlindedError"]); } - } + + //屏蔽单重阅片添加 else { - - //---双重有序阅片 没有定义该仲裁规则处理逻辑,请联系业务和后台开发核查! - throw new BusinessValidationFailedException(_localizer["TrialEmailN_DoubleBlindedError"]); + isNeedSend = false; + return string.Empty; } + #region 发邮件屏蔽单重的 + ////单重 + //else if (taskInfo.ReadingType == ReadingMethod.Single) + //{ + // //仲裁在访视上 或者在阅片期 + // if (taskInfo.ArbitrationRule != ArbitrationRule.None) + // { + + //---单重有序阅片配置有误(不应该有仲裁对象配置),请核查! + // throw new BusinessValidationFailedException(_localizer["TrialEmailN_SingleBlindedSet"]); + // } + + + // //要求PD 确认的访视 是截止访视 还是非截止访视(根据该访视有没有配置阅片期来判断) + + // if (taskInfo.ReadingCategory == ReadingCategory.Visit) + // { + // //存在阅片期 那么就是截止访视 + // if (await _repository.Where(t => t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.SubjectVisitId == taskInfo.SourceSubjectVisitId && t.ReadingSetType == ReadingSetType.ImageReading).AnyAsync()) + // { + // isNeedSend = false; + // } + // else//非截止访视 在访视读完后,发送 + // { + // answer = await TranslatePdStateAsync(visitTaskId, ReadingCategory.Visit, taskInfo.CriterionType); + // } + // } + // //截止访视 在访视读完,并完成全局阅片后发送全局的结果 + // else if (taskInfo.ReadingCategory == ReadingCategory.Global) + // { + // answer = await TranslatePdStateAsync(visitTaskId, ReadingCategory.Global, taskInfo.CriterionType); + // } + // else + // { + //---单重有序阅片 该类型的任务不应进入此处逻辑,请联系后台开发核查! + // throw new BusinessValidationFailedException(_localizer["TrialEmailN_SingleBlindedSequenced"]); + // } + + // isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List() { visitTaskId }, minUserIdList); + + + //} + //else + //{ + //---有序阅片配置有误(应为单重或者双重阅片),请核查! + // throw new BusinessValidationFailedException(_localizer["TrialEmailN_BlindedSequencedReading"]); + //} + + #endregion + + + } - - //屏蔽单重阅片添加 + //屏蔽无序阅片添加 else { isNeedSend = false; return string.Empty; } - #region 发邮件屏蔽单重的 - ////单重 - //else if (taskInfo.ReadingType == ReadingMethod.Single) + #region 发送邮件屏蔽无序的 + // //无序 + //else //{ - // //仲裁在访视上 或者在阅片期 - // if (taskInfo.ArbitrationRule != ArbitrationRule.None) - // { + // //单重 - //---单重有序阅片配置有误(不应该有仲裁对象配置),请核查! - // throw new BusinessValidationFailedException(_localizer["TrialEmailN_SingleBlindedSet"]); + + // if (taskInfo.ReadingType == ReadingMethod.Single && taskInfo.ArbitrationRule == ArbitrationRule.None) + // { + // answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType); + + // isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List() { visitTaskId }, minUserIdList); // } - - - // //要求PD 确认的访视 是截止访视 还是非截止访视(根据该访视有没有配置阅片期来判断) - - // if (taskInfo.ReadingCategory == ReadingCategory.Visit) + // //双重 截止访视只在阅片期的时候存在 要求PD确认的访视 肯定是非截止访视 + // else if (taskInfo.ReadingType == ReadingMethod.Double && taskInfo.ArbitrationRule == ArbitrationRule.Visit) // { - // //存在阅片期 那么就是截止访视 - // if (await _repository.Where(t => t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.SubjectVisitId == taskInfo.SourceSubjectVisitId && t.ReadingSetType == ReadingSetType.ImageReading).AnyAsync()) + // //在两位阅片人读完访视后,如果有裁判者等裁判读完,如果无裁判则等第二个人的读完 + + // var taskList = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect + // && (t.ReadingCategory == ReadingCategory.Visit || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync(); + + // //这里要求 到这里已经如果有裁判 已经生成裁判了保存数据库 + // if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2) + // { + + // answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType); + + // isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList); + // } + // else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1) + // { + // var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value; + // answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Visit, taskInfo.CriterionType); + + // isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList); + + + // } + // else // { // isNeedSend = false; // } - // else//非截止访视 在访视读完后,发送 - // { - // answer = await TranslatePdStateAsync(visitTaskId, ReadingCategory.Visit, taskInfo.CriterionType); - // } - // } - // //截止访视 在访视读完,并完成全局阅片后发送全局的结果 - // else if (taskInfo.ReadingCategory == ReadingCategory.Global) - // { - // answer = await TranslatePdStateAsync(visitTaskId, ReadingCategory.Global, taskInfo.CriterionType); + // } // else // { - //---单重有序阅片 该类型的任务不应进入此处逻辑,请联系后台开发核查! - // throw new BusinessValidationFailedException(_localizer["TrialEmailN_SingleBlindedSequenced"]); + //---无序阅片配置有误(应为单重无仲裁对象,双重针对访视仲裁),请核查! + // throw new BusinessValidationFailedException(_localizer["TrialEmailN_UnblindedSequencedReading"]); // } - // isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List() { visitTaskId }, minUserIdList); - - - //} - //else - //{ - //---有序阅片配置有误(应为单重或者双重阅片),请核查! - // throw new BusinessValidationFailedException(_localizer["TrialEmailN_BlindedSequencedReading"]); //} #endregion - - - - } - //屏蔽无序阅片添加 else { isNeedSend = false; + } + + #endregion + + + #region MiniWord 组织字典 发送 + + + if (emailStoreMode == EmailStoreSendMode.NotStoreLocalOnlySentEmail) + { + + var phyPath = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, sendFileRelativePath); + + var attachPrefix = $"{taskInfo.SubjectCode}"; + + //先预先生成了邮件,发送预先生成的邮件 + sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig() + { + FileName = $"{attachPrefix}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? trialEmailConfig.AttachName : trialEmailConfig!.AttachNameCN)}.pdf", + + FileStream = File.OpenRead(phyPath), + }); + + + await SendEmailHelper.SendEmailAsync(sendEmailConfig); + return string.Empty; } - #region 发送邮件屏蔽无序的 - // //无序 - //else - //{ - // //单重 + var value = new Dictionary() + { + ["SponsorName"] = taskInfo.SponsorName, + ["ResearchProgramNo"] = taskInfo.ResearchProgramNo, + ["TrialSiteCode"] = taskInfo.TrialSiteCode, + ["SubjectCode"] = taskInfo.SubjectCode, + ["VisitName"] = taskInfo.SourceSubjectVisitId != null ? taskInfo.VisitName : taskInfo.ModuleVisitName, + ["EarliestScanDate"] = taskInfo.SourceSubjectVisitId != null ? taskInfo.VisitEarliestScanDate?.ToString("yyyy-MM-dd") : taskInfo.ModuleEarliestScanDate?.ToString("yyyy-MM-dd"), + ["SignTime"] = taskInfo.SignTime?.ToString("yyyy-MM-dd"), + ["Result"] = answer + + }; + + var path = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, _userInfo.IsEn_Us ? trialEmailConfig.AttachPath : trialEmailConfig.AttachCNPath); + + var (serverFilePath, relativePath, fileRealName) = FileStoreHelper.GetSubjectEnrollConfirmOrPDEmailPath(_hostEnvironment, Path.GetFileName(path), taskInfo.TrialId, taskInfo.SiteId, taskInfo.SubjectId, true); + + if (emailStoreMode == EmailStoreSendMode.StoreLocalSend || emailStoreMode == EmailStoreSendMode.OnlyStoreLocalNotSentEmail) + { + + MemoryStream wordMemoryStream = new MemoryStream(); + + Document document = new Document(); + + MiniSoftware.MiniWord.SaveAsByTemplate(wordMemoryStream, path, value); + + document.LoadFromStream(wordMemoryStream, FileFormat.Docx); + + document.SaveToFile(serverFilePath, FileFormat.PDF); - // if (taskInfo.ReadingType == ReadingMethod.Single && taskInfo.ArbitrationRule == ArbitrationRule.None) - // { - // answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType); + } + //手动生成发送的邮件内容,但是并不发送 + if (emailStoreMode == EmailStoreSendMode.OnlyStoreLocalNotSentEmail) + { + isNeedSend = false; - // isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List() { visitTaskId }, minUserIdList); - // } - // //双重 截止访视只在阅片期的时候存在 要求PD确认的访视 肯定是非截止访视 - // else if (taskInfo.ReadingType == ReadingMethod.Double && taskInfo.ArbitrationRule == ArbitrationRule.Visit) - // { - // //在两位阅片人读完访视后,如果有裁判者等裁判读完,如果无裁判则等第二个人的读完 - - // var taskList = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect - // && (t.ReadingCategory == ReadingCategory.Visit || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync(); - - // //这里要求 到这里已经如果有裁判 已经生成裁判了保存数据库 - // if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2) - // { - - // answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType); - - // isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList); - // } - // else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1) - // { - // var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value; - // answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Visit, taskInfo.CriterionType); - - // isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList); + return relativePath; + } + + + //正常的即时生成邮件 并发送邮件 + if (isNeedSend) + { + + + MemoryStream memoryStream = new MemoryStream(); + MemoryStream pdfMemoryStream = new MemoryStream(); + + + MiniSoftware.MiniWord.SaveAsByTemplate(memoryStream, path, value); + Document document = new Document(); + + document.LoadFromStream(memoryStream, FileFormat.Docx); + document.SaveToStream(pdfMemoryStream, FileFormat.PDF); + pdfMemoryStream.Seek(0, SeekOrigin.Begin); + + sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig() + { + FileName = $"{taskInfo.SubjectCode}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? trialEmailConfig.AttachName : trialEmailConfig.AttachNameCN)}.pdf", + + FileStream = pdfMemoryStream + }); + + + await SendEmailHelper.SendEmailAsync(sendEmailConfig); + + } + + + + return string.Empty; - // } - // else - // { - // isNeedSend = false; - // } - // } - // else - // { - //---无序阅片配置有误(应为单重无仲裁对象,双重针对访视仲裁),请核查! - // throw new BusinessValidationFailedException(_localizer["TrialEmailN_UnblindedSequencedReading"]); - // } - //} #endregion } else { - isNeedSend = false; - } - - #endregion - - - #region MiniWord 组织字典 发送 - - - if (emailStoreMode == EmailStoreSendMode.NotStoreLocalOnlySentEmail) - { - - var phyPath = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, sendFileRelativePath); - - - //先预先生成了邮件,发送预先生成的邮件 - sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig() - { - FileName = $"{taskInfo.SubjectCode}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? emailConfig.AttachName : emailConfig.AttachNameCN)}.pdf", - - FileStream = File.OpenRead(phyPath), - }); - - - await SendEmailHelper.SendEmailAsync(sendEmailConfig); - return string.Empty; } - var value = new Dictionary() - { - ["SponsorName"] = taskInfo.SponsorName, - ["ResearchProgramNo"] = taskInfo.ResearchProgramNo, - ["TrialSiteCode"] = taskInfo.TrialSiteCode, - ["SubjectCode"] = taskInfo.SubjectCode, - ["VisitName"] = taskInfo.SourceSubjectVisitId != null ? taskInfo.VisitName : taskInfo.ModuleVisitName, - ["EarliestScanDate"] = taskInfo.SourceSubjectVisitId != null ? taskInfo.VisitEarliestScanDate?.ToString("yyyy-MM-dd") : taskInfo.ModuleEarliestScanDate?.ToString("yyyy-MM-dd"), - ["SignTime"] = taskInfo.SignTime?.ToString("yyyy-MM-dd"), - ["Result"] = answer - - }; - - var (serverFilePath, relativePath, fileRealName) = FileStoreHelper.GetSubjectEnrollConfirmOrPDEmailPath(_hostEnvironment, Path.GetFileName(path), taskInfo.TrialId, taskInfo.SiteId, taskInfo.SubjectId, true); - - if (emailStoreMode == EmailStoreSendMode.StoreLocalSend || emailStoreMode == EmailStoreSendMode.OnlyStoreLocalNotSentEmail) - { - - MemoryStream wordMemoryStream = new MemoryStream(); - - Document document = new Document(); - - MiniSoftware.MiniWord.SaveAsByTemplate(wordMemoryStream, path, value); - - document.LoadFromStream(wordMemoryStream, FileFormat.Docx); - - document.SaveToFile(serverFilePath, FileFormat.PDF); - } - //手动生成发送的邮件内容,但是并不发送 - if (emailStoreMode == EmailStoreSendMode.OnlyStoreLocalNotSentEmail) - { - isNeedSend = false; - - return relativePath; - } - - - //正常的即时生成邮件 并发送邮件 - if (isNeedSend) - { - - - MemoryStream memoryStream = new MemoryStream(); - MemoryStream pdfMemoryStream = new MemoryStream(); - - - MiniSoftware.MiniWord.SaveAsByTemplate(memoryStream, path, value); - Document document = new Document(); - - document.LoadFromStream(memoryStream, FileFormat.Docx); - document.SaveToStream(pdfMemoryStream, FileFormat.PDF); - pdfMemoryStream.Seek(0, SeekOrigin.Begin); - - sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig() - { - FileName = $"{taskInfo.SubjectCode}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? emailConfig.AttachName : emailConfig.AttachNameCN)}.pdf", - - FileStream = pdfMemoryStream - }); - - - await SendEmailHelper.SendEmailAsync(sendEmailConfig); - - } - - - - return string.Empty; - - - - - - #endregion } @@ -1388,13 +1228,14 @@ namespace IRaCIS.Core.Application.Service /// /// /// + [HttpPost] public async Task> GetSysEmailNoticeConfigList(EmailNoticeConfigQuery queryEmailNoticeConfig) { var emailNoticeConfigQueryable = _emailNoticeConfigRepository .WhereIf(queryEmailNoticeConfig.BusinessScenarioEnum != null, t => t.BusinessScenarioEnum == queryEmailNoticeConfig.BusinessScenarioEnum) .WhereIf(queryEmailNoticeConfig.IsReturnRequired != null, t => t.IsReturnRequired == queryEmailNoticeConfig.IsReturnRequired) .WhereIf(queryEmailNoticeConfig.IsEnable != null, t => t.IsEnable == queryEmailNoticeConfig.IsEnable) - + .WhereIf(queryEmailNoticeConfig.IsDistinguishCriteria != null, t => t.IsDistinguishCriteria == queryEmailNoticeConfig.IsDistinguishCriteria) .ProjectTo(_mapper.ConfigurationProvider, new { trialId = queryEmailNoticeConfig.TrialId }); return await emailNoticeConfigQueryable.ToPagedListAsync(queryEmailNoticeConfig.PageIndex, queryEmailNoticeConfig.PageSize, queryEmailNoticeConfig.SortField, queryEmailNoticeConfig.Asc); diff --git a/IRaCIS.Core.Domain.Share/Common/EmailScenarioEnum.cs b/IRaCIS.Core.Domain.Share/Common/EmailScenarioEnum.cs index b46f6ac5c..1d4ecdf1a 100644 --- a/IRaCIS.Core.Domain.Share/Common/EmailScenarioEnum.cs +++ b/IRaCIS.Core.Domain.Share/Common/EmailScenarioEnum.cs @@ -36,7 +36,7 @@ namespace IRaCIS.Core.Domain.Share public enum EmailBusinessScenario { - + None=-1, EnrollConfirmed = 1, PDConfirmed = 2, diff --git a/IRaCIS.Core.Domain/_Config/_StaticData.cs b/IRaCIS.Core.Domain/_Config/_StaticData.cs index 5bfb2f3e5..d7616e7cd 100644 --- a/IRaCIS.Core.Domain/_Config/_StaticData.cs +++ b/IRaCIS.Core.Domain/_Config/_StaticData.cs @@ -141,6 +141,11 @@ public static class StaticData } + public static class EmailSend + { + public static string EmailNamePlaceholder = "EmailNamePlaceholder"; + } + /// /// 医生学位等级