邮件初步调整完毕
parent
39f5110464
commit
2c80ca7812
|
@ -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
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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<IActionResult> TemplateExportWordAsync(string code, object data, IRepository<CommonDocument>? _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);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 替换表格Key
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="table"></param>
|
|
||||||
/// <param name="list"></param>
|
|
||||||
/// <param name="field"></param>
|
|
||||||
|
|
||||||
private static void ReplaceTableKey(XWPFTable table, IList list, String field)
|
|
||||||
{
|
|
||||||
List<XWPFParagraph> paras = new List<XWPFParagraph>();
|
|
||||||
// 获取最后一行数据,最后一行设置值
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -85,14 +85,6 @@
|
||||||
<param name="type"></param>
|
<param name="type"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:IRaCIS.Core.Application.Service.NpoiWordHelper.ReplaceTableKey(NPOI.XWPF.UserModel.XWPFTable,System.Collections.IList,System.String)">
|
|
||||||
<summary>
|
|
||||||
替换表格Key
|
|
||||||
</summary>
|
|
||||||
<param name="table"></param>
|
|
||||||
<param name="list"></param>
|
|
||||||
<param name="field"></param>
|
|
||||||
</member>
|
|
||||||
<member name="T:IRaCIS.Core.Application.Service.TaskAllocationRuleService">
|
<member name="T:IRaCIS.Core.Application.Service.TaskAllocationRuleService">
|
||||||
<summary>
|
<summary>
|
||||||
分配规则
|
分配规则
|
||||||
|
@ -725,17 +717,9 @@
|
||||||
<param name="inDto"></param>
|
<param name="inDto"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:IRaCIS.Core.Application.Service.TrialEmailNoticeConfigService.SyncSystemEmainCofigDocListAsync(System.Guid)">
|
|
||||||
<summary>
|
|
||||||
同步系统配置的文档到想项目中 ---废弃
|
|
||||||
</summary>
|
|
||||||
<param name="trialId"></param>
|
|
||||||
<returns></returns>
|
|
||||||
|
|
||||||
</member>
|
|
||||||
<member name="M:IRaCIS.Core.Application.Service.TrialEmailNoticeConfigService.BaseBusinessScenarioSendEmailAsync(System.Guid,System.Nullable{System.Boolean},IRaCIS.Core.Domain.Share.Common.EmailStoreSendMode,System.String)">
|
<member name="M:IRaCIS.Core.Application.Service.TrialEmailNoticeConfigService.BaseBusinessScenarioSendEmailAsync(System.Guid,System.Nullable{System.Boolean},IRaCIS.Core.Domain.Share.Common.EmailStoreSendMode,System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
测试邮件 带附件 填充word --前端不需
|
测试邮件 带附件 填充word
|
||||||
</summary>
|
</summary>
|
||||||
<param name="visitTaskId"></param>
|
<param name="visitTaskId"></param>
|
||||||
<param name="isHandSend"> 为空 代表 正常任务自动发送,为true 代表医学审核手动发送 为false 代表医学审核自动发送 </param>
|
<param name="isHandSend"> 为空 代表 正常任务自动发送,为true 代表医学审核手动发送 为false 代表医学审核自动发送 </param>
|
||||||
|
|
|
@ -18,6 +18,7 @@ using System.Linq;
|
||||||
using System.Net.Mail;
|
using System.Net.Mail;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static IRaCIS.Core.Domain.Share.StaticData;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Service
|
namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
|
@ -29,6 +30,8 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
Task SendTrialQCQuestionEmailAsync(Guid trialId);
|
Task SendTrialQCQuestionEmailAsync(Guid trialId);
|
||||||
Task SendTrialImageQuestionAsync(Guid trialId);
|
Task SendTrialImageQuestionAsync(Guid trialId);
|
||||||
|
|
||||||
|
Task<(TrialEmailNoticeConfig?, SMTPEmailConfig?)> BuildEmailConfig(Guid trialId, EmailBusinessScenario businessScenario, Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc, Guid? siteId = null, Guid? trialReadingCriterionId = null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EmailSendService : BaseService, IEmailSendService
|
public class EmailSendService : BaseService, IEmailSendService
|
||||||
|
@ -42,7 +45,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
private readonly IDictionaryService _dictionaryService;
|
private readonly IDictionaryService _dictionaryService;
|
||||||
private readonly IOptionsMonitor<SystemEmailSendConfig> _SystemEmailSendConfig;
|
private readonly IOptionsMonitor<SystemEmailSendConfig> _SystemEmailSendConfig;
|
||||||
|
|
||||||
public readonly static string EmailNamePlaceholder = "EmailNamePlaceholder";
|
public static string EmailNamePlaceholder => StaticData. EmailSend.EmailNamePlaceholder;
|
||||||
|
|
||||||
public EmailSendService(IRepository<TrialEmailNoticeConfig> trialEmailNoticeConfigRepository, IRepository<EmailNoticeConfig> emailNoticeConfigRepository, IRepository<Trial> trialRepository, IOptionsMonitor<SystemEmailSendConfig> systemEmailSendConfig, IDictionaryService dictionaryService)
|
public EmailSendService(IRepository<TrialEmailNoticeConfig> trialEmailNoticeConfigRepository, IRepository<EmailNoticeConfig> emailNoticeConfigRepository, IRepository<Trial> trialRepository, IOptionsMonitor<SystemEmailSendConfig> systemEmailSendConfig, IDictionaryService dictionaryService)
|
||||||
{
|
{
|
||||||
|
@ -92,27 +95,30 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
if (isEnrollment == true)
|
if (isEnrollment == true)
|
||||||
{
|
{
|
||||||
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
||||||
{
|
{
|
||||||
var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, taskInfo.ResearchProgramNo, taskInfo.SubjectCode);
|
var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, taskInfo.ResearchProgramNo, taskInfo.SubjectCode);
|
||||||
|
|
||||||
var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN,
|
var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN,
|
||||||
EmailNamePlaceholder, taskInfo.ResearchProgramNo, taskInfo.SubjectCode, resultStr);
|
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);
|
await SendTrialEmailAsync(taskInfo.TrialId, businessScenarioEnum, topicAndHtmlFunc, taskInfo.SiteId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
||||||
{
|
{
|
||||||
var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, taskInfo.ResearchProgramNo, taskInfo.SubjectCode, taskInfo.VisitName);
|
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,
|
var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN,
|
||||||
EmailNamePlaceholder, taskInfo.ResearchProgramNo, taskInfo.SubjectCode, taskInfo.VisitName, resultStr);
|
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);
|
await SendTrialEmailAsync(taskInfo.TrialId, businessScenarioEnum, topicAndHtmlFunc, taskInfo.SiteId);
|
||||||
|
@ -160,11 +166,12 @@ namespace IRaCIS.Core.Application.Service
|
||||||
if (sendStat != null && (sendStat.ToBeClaimedCount > 0 || sendStat.ToBeReviewedCount > 0))
|
if (sendStat != null && (sendStat.ToBeClaimedCount > 0 || sendStat.ToBeReviewedCount > 0))
|
||||||
{
|
{
|
||||||
|
|
||||||
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
||||||
{
|
{
|
||||||
var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, trialInfo.ResearchProgramNo);
|
var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, trialInfo.ResearchProgramNo);
|
||||||
var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN,
|
var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN,
|
||||||
user.FullName, DateTime.Now, sendStat.ToBeClaimedCount, sendStat.ToBeReviewedCount, _SystemEmailSendConfig.CurrentValue.SiteUrl);
|
user.FullName, DateTime.Now, sendStat.ToBeClaimedCount, sendStat.ToBeReviewedCount, _SystemEmailSendConfig.CurrentValue.SiteUrl);
|
||||||
|
|
||||||
return (topicStr, htmlBodyStr, false, userId);
|
return (topicStr, htmlBodyStr, false, userId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -211,13 +218,15 @@ namespace IRaCIS.Core.Application.Service
|
||||||
if (sendStat != null && (sendStat.ToBeDealedCount > 0 || sendStat.ReUploadTobeDealedCount > 0))
|
if (sendStat != null && (sendStat.ToBeDealedCount > 0 || sendStat.ReUploadTobeDealedCount > 0))
|
||||||
{
|
{
|
||||||
|
|
||||||
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
||||||
{
|
{
|
||||||
var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, trialInfo.ResearchProgramNo);
|
var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, trialInfo.ResearchProgramNo);
|
||||||
var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN,
|
var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN,
|
||||||
|
|
||||||
user.FullName, DateTime.Now, sendStat.ToBeDealedCount - sendStat.ReUploadTobeDealedCount, sendStat.ReUploadTobeDealedCount, _SystemEmailSendConfig.CurrentValue.SiteUrl);
|
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);
|
await SendTrialEmailAsync(trialId, EmailBusinessScenario.QCQuestion, topicAndHtmlFunc);
|
||||||
|
@ -261,12 +270,13 @@ namespace IRaCIS.Core.Application.Service
|
||||||
if (sendStat != null && (sendStat.ToBeDealedCount > 0))
|
if (sendStat != null && (sendStat.ToBeDealedCount > 0))
|
||||||
{
|
{
|
||||||
|
|
||||||
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
||||||
{
|
{
|
||||||
var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, trialInfo.ResearchProgramNo);
|
var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, trialInfo.ResearchProgramNo);
|
||||||
var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN,
|
var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN,
|
||||||
user.FullName, DateTime.Now, sendStat.ToBeDealedCount, _SystemEmailSendConfig.CurrentValue.SiteUrl);
|
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);
|
await SendTrialEmailAsync(trialId, EmailBusinessScenario.ImageQuestion, topicAndHtmlFunc);
|
||||||
|
@ -277,7 +287,19 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task SendTrialEmailAsync(Guid trialId, EmailBusinessScenario businessScenario, Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc, Guid? siteId = null, Guid? trialReadingCriterionId = null)
|
public async Task SendTrialEmailAsync(Guid trialId, EmailBusinessScenario businessScenario, Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc, Guid? siteId = null, Guid? trialReadingCriterionId = null, Func<TrialEmailNoticeConfig, SMTPEmailConfig, SMTPEmailConfig> 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<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc, Guid? siteId = null, Guid? trialReadingCriterionId = null)
|
||||||
{
|
{
|
||||||
//找到配置
|
//找到配置
|
||||||
var trialEmailConfig = await _trialEmailNoticeConfigRepository.Where(t => t.TrialId == trialId && t.TrialReadingCriterionId == trialReadingCriterionId && t.BusinessScenarioEnum == businessScenario, ignoreQueryFilters: true)
|
var trialEmailConfig = await _trialEmailNoticeConfigRepository.Where(t => t.TrialId == trialId && t.TrialReadingCriterionId == trialReadingCriterionId && t.BusinessScenarioEnum == businessScenario, ignoreQueryFilters: true)
|
||||||
|
@ -286,13 +308,13 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
if (trialEmailConfig == null || trialEmailConfig.IsAutoSend == false)
|
if (trialEmailConfig == null || trialEmailConfig.IsAutoSend == false)
|
||||||
{
|
{
|
||||||
return;
|
return (null,null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var sendEmailConfig = new SMTPEmailConfig();
|
var sendEmailConfig = new SMTPEmailConfig();
|
||||||
|
|
||||||
var (topicStr, htmlBodyStr, isEn_us, onlyToUserId) = topicAndHtmlFunc(trialEmailConfig);
|
var (topicStr, htmlBodyStr, isEn_us, onlyToUserId) = topicAndHtmlFunc(trialEmailConfig);
|
||||||
|
|
||||||
|
|
||||||
sendEmailConfig.TopicDescription = topicStr;
|
sendEmailConfig.TopicDescription = topicStr;
|
||||||
|
@ -393,11 +415,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) ;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ using IRaCIS.Core.Domain.Share.Common;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Spire.Doc;
|
using Spire.Doc;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Service
|
namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
|
@ -43,7 +45,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
private readonly IRepository<Subject> _subjectRepository;
|
private readonly IRepository<Subject> _subjectRepository;
|
||||||
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
||||||
|
|
||||||
|
private readonly IEmailSendService _emailSendService;
|
||||||
|
|
||||||
|
|
||||||
public TrialEmailNoticeConfigService(
|
public TrialEmailNoticeConfigService(
|
||||||
|
@ -56,7 +58,8 @@ namespace IRaCIS.Core.Application.Service
|
||||||
IRepository<SubjectVisit> subjectVisitRepository,
|
IRepository<SubjectVisit> subjectVisitRepository,
|
||||||
IRepository<TrialEmailBlackUser> trialEmailBlackUserRepository,
|
IRepository<TrialEmailBlackUser> trialEmailBlackUserRepository,
|
||||||
IRepository<EmailNoticeConfig> emailNoticeConfigRepository
|
IRepository<EmailNoticeConfig> emailNoticeConfigRepository
|
||||||
)
|
,
|
||||||
|
IEmailSendService emailSendService)
|
||||||
{
|
{
|
||||||
_trialEmailNoticeConfigRepository = trialEmailNoticeConfigRepository;
|
_trialEmailNoticeConfigRepository = trialEmailNoticeConfigRepository;
|
||||||
_visitTaskRepository = visitTaskRepository;
|
_visitTaskRepository = visitTaskRepository;
|
||||||
|
@ -67,6 +70,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
_subjectVisitRepository = subjectVisitRepository;
|
_subjectVisitRepository = subjectVisitRepository;
|
||||||
_trialEmailBlackUserRepository = trialEmailBlackUserRepository;
|
_trialEmailBlackUserRepository = trialEmailBlackUserRepository;
|
||||||
_emailNoticeConfigRepository = emailNoticeConfigRepository;
|
_emailNoticeConfigRepository = emailNoticeConfigRepository;
|
||||||
|
_emailSendService = emailSendService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -87,7 +91,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
IsConfigureEmail = x.IsConfigureEmail,
|
IsConfigureEmail = x.IsConfigureEmail,
|
||||||
EmailSMTPServerPort = x.EmailSMTPServerPort
|
EmailSMTPServerPort = x.EmailSMTPServerPort
|
||||||
|
|
||||||
}).FirstOrDefaultAsync();
|
}).FirstAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -135,60 +139,6 @@ namespace IRaCIS.Core.Application.Service
|
||||||
return ResponseOutput.Ok();
|
return ResponseOutput.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 同步系统配置的文档到想项目中 ---废弃
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="trialId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
///
|
|
||||||
private async Task SyncSystemEmainCofigDocListAsync(Guid trialId)
|
|
||||||
{
|
|
||||||
|
|
||||||
//判断流程配置是否确认 确认了一定确认了标准 可以进行同步
|
|
||||||
|
|
||||||
if (_repository.Where<Trial>(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<ReadingQuestionCriterionTrial>(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<TrialEmailNoticeConfig>(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<bool> DealMedicalReviewTasKGenerateAndIsSendAsync(Guid trialId, bool? isHandSend, string pdAnswer, List<Guid> taskIdList, List<Guid> minUserIdList)
|
private async Task<bool> DealMedicalReviewTasKGenerateAndIsSendAsync(Guid trialId, bool? isHandSend, string pdAnswer, List<Guid> taskIdList, List<Guid> minUserIdList)
|
||||||
|
@ -237,15 +187,12 @@ namespace IRaCIS.Core.Application.Service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return isNeedSend;
|
return isNeedSend;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 测试邮件 带附件 填充word --前端不需
|
/// 测试邮件 带附件 填充word
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="visitTaskId"></param>
|
/// <param name="visitTaskId"></param>
|
||||||
/// <param name="isHandSend"> 为空 代表 正常任务自动发送,为true 代表医学审核手动发送 为false 代表医学审核自动发送 </param>
|
/// <param name="isHandSend"> 为空 代表 正常任务自动发送,为true 代表医学审核手动发送 为false 代表医学审核自动发送 </param>
|
||||||
|
@ -255,8 +202,8 @@ namespace IRaCIS.Core.Application.Service
|
||||||
/// <exception cref="BusinessValidationFailedException"></exception>
|
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||||
public async Task<string> BaseBusinessScenarioSendEmailAsync(Guid visitTaskId, bool? isHandSend, EmailStoreSendMode emailStoreMode, string sendFileRelativePath)
|
public async Task<string> BaseBusinessScenarioSendEmailAsync(Guid visitTaskId, bool? isHandSend, EmailStoreSendMode emailStoreMode, string sendFileRelativePath)
|
||||||
{
|
{
|
||||||
|
var isEn_us = _userInfo.IsEn_Us;
|
||||||
EmailBusinessScenario? businessScenarioEnum = null;
|
EmailBusinessScenario businessScenarioEnum = EmailBusinessScenario.None;
|
||||||
|
|
||||||
#region 任务关联的项目配置 标准信息及配置,subject 信息
|
#region 任务关联的项目配置 标准信息及配置,subject 信息
|
||||||
var taskInfo = await _visitTaskRepository.Where(t => t.Id == visitTaskId).Select(t => new
|
var taskInfo = await _visitTaskRepository.Where(t => t.Id == visitTaskId).Select(t => new
|
||||||
|
@ -352,286 +299,122 @@ namespace IRaCIS.Core.Application.Service
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 发收件人配置 确保无误
|
#region 邮件内容装配
|
||||||
|
|
||||||
|
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
//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();
|
return (topicStr, htmlBodyStr, isEn_us, null);
|
||||||
|
};
|
||||||
//收件人 如果是CRC CRA 要按照中心发送
|
|
||||||
var toUserTypeEnumList = emailConfig.TrialEmailNoticeUserList.Where(t => t.EmailUserType == EmailUserType.To).Select(c => c.UserType).ToList();
|
|
||||||
|
|
||||||
|
|
||||||
|
var (trialEmailConfig, sendEmailConfig) = await _emailSendService.BuildEmailConfig(taskInfo.TrialId, businessScenarioEnum, topicAndHtmlFunc, taskInfo.SiteId);
|
||||||
var toUserList = _repository.Where<TrialSiteUser>(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<TrialUser>(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");
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 不同场景 Tile 设置
|
//自动发送
|
||||||
|
if (sendEmailConfig != null)
|
||||||
if (businessScenarioEnum == EmailBusinessScenario.EnrollConfirmed)
|
|
||||||
{
|
{
|
||||||
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();
|
if (await _repository.Where<ReadingTableQuestionAnswer>().AnyAsync(x => x.VisitTaskId == visitTaskId && x.Answer == TargetState.Exist.GetEnumInt() &&
|
||||||
|
x.ReadingTableQuestionTrial.QuestionMark == QuestionMark.State && x.ReadingQuestionTrial.LesionType == LesionType.TargetLesion))
|
||||||
|
|
||||||
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<ReadingTableQuestionAnswer>().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<Guid>() { visitTaskId }, minUserIdList);
|
|
||||||
|
|
||||||
|
|
||||||
if (answer == "是")
|
|
||||||
{
|
{
|
||||||
//把另外一个人的任务设置为不加急(如果项目加急是否 subject 加急是否)
|
answer = "是";
|
||||||
var urgent = _repository.Where<SubjectVisit>(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 });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//如果其他阅片人已经做了,说明发送了入组确认报告,第二个人做完就不发送了
|
||||||
|
|
||||||
|
//入组确认一直交给第一个人,如果第一个人重阅 还未做完,第二个人先做完了,此时不发
|
||||||
|
|
||||||
|
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<Guid>() { visitTaskId }, minUserIdList);
|
||||||
|
|
||||||
|
|
||||||
|
if (answer == "是")
|
||||||
|
{
|
||||||
|
//把另外一个人的任务设置为不加急(如果项目加急是否 subject 加急是否)
|
||||||
|
var urgent = _repository.Where<SubjectVisit>(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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (businessScenarioEnum == EmailBusinessScenario.PDConfirmed)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
//有序
|
|
||||||
|
|
||||||
if (taskInfo.IsReadingTaskViewInOrder)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//有序
|
||||||
|
|
||||||
//双重
|
if (taskInfo.IsReadingTaskViewInOrder)
|
||||||
if (taskInfo.ReadingType == ReadingMethod.Double)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//仲裁在访视上 就没有全局阅片 没有阅片期
|
|
||||||
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 (taskInfo.ArbitrationRule == ArbitrationRule.Visit)
|
||||||
if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2)
|
|
||||||
{
|
{
|
||||||
|
//找到 访视,裁判 所有有效任务(不可能有全局的) 访视和裁判任务的SourceSubjectVisitId 一样
|
||||||
answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
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);
|
//这里要求 到这里已经如果有裁判 已经生成裁判了保存数据库
|
||||||
|
//双人阅片,没有产生裁判 第二个人读完发
|
||||||
}
|
if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2)
|
||||||
//双人 产生裁判,并且裁判完成 发
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
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;
|
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);
|
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;
|
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
|
else
|
||||||
{
|
{
|
||||||
//---发送PD 进展邮件中发现任务数据有问题!
|
|
||||||
throw new BusinessValidationFailedException(_localizer["TrialEmailN_PDProgressEmailTask"]);
|
//---双重有序阅片 没有定义该仲裁规则处理逻辑,请联系业务和后台开发核查!
|
||||||
|
throw new BusinessValidationFailedException(_localizer["TrialEmailN_DoubleBlindedError"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//屏蔽单重阅片添加
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
isNeedSend = false;
|
||||||
//---双重有序阅片 没有定义该仲裁规则处理逻辑,请联系业务和后台开发核查!
|
return string.Empty;
|
||||||
throw new BusinessValidationFailedException(_localizer["TrialEmailN_DoubleBlindedError"]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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<ReadModule>(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<Guid>() { visitTaskId }, minUserIdList);
|
||||||
|
|
||||||
|
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
//---有序阅片配置有误(应为单重或者双重阅片),请核查!
|
||||||
|
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_BlindedSequencedReading"]);
|
||||||
|
//}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//屏蔽无序阅片添加
|
||||||
//屏蔽单重阅片添加
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
isNeedSend = false;
|
isNeedSend = false;
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 发邮件屏蔽单重的
|
#region 发送邮件屏蔽无序的
|
||||||
////单重
|
// //无序
|
||||||
//else if (taskInfo.ReadingType == ReadingMethod.Single)
|
//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<Guid>() { visitTaskId }, minUserIdList);
|
||||||
// }
|
// }
|
||||||
|
// //双重 截止访视只在阅片期的时候存在 要求PD确认的访视 肯定是非截止访视
|
||||||
|
// else if (taskInfo.ReadingType == ReadingMethod.Double && taskInfo.ArbitrationRule == ArbitrationRule.Visit)
|
||||||
// //要求PD 确认的访视 是截止访视 还是非截止访视(根据该访视有没有配置阅片期来判断)
|
|
||||||
|
|
||||||
// if (taskInfo.ReadingCategory == ReadingCategory.Visit)
|
|
||||||
// {
|
// {
|
||||||
// //存在阅片期 那么就是截止访视
|
// //在两位阅片人读完访视后,如果有裁判者等裁判读完,如果无裁判则等第二个人的读完
|
||||||
// if (await _repository.Where<ReadModule>(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;
|
// 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
|
// else
|
||||||
// {
|
// {
|
||||||
//---单重有序阅片 该类型的任务不应进入此处逻辑,请联系后台开发核查!
|
//---无序阅片配置有误(应为单重无仲裁对象,双重针对访视仲裁),请核查!
|
||||||
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_SingleBlindedSequenced"]);
|
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_UnblindedSequencedReading"]);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List<Guid>() { visitTaskId }, minUserIdList);
|
|
||||||
|
|
||||||
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
//---有序阅片配置有误(应为单重或者双重阅片),请核查!
|
|
||||||
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_BlindedSequencedReading"]);
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//屏蔽无序阅片添加
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
isNeedSend = false;
|
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;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 发送邮件屏蔽无序的
|
var value = new Dictionary<string, object>()
|
||||||
// //无序
|
{
|
||||||
//else
|
["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<Guid>() { visitTaskId }, minUserIdList);
|
return relativePath;
|
||||||
// }
|
}
|
||||||
// //双重 截止访视只在阅片期的时候存在 要求PD确认的访视 肯定是非截止访视
|
|
||||||
// else if (taskInfo.ReadingType == ReadingMethod.Double && taskInfo.ArbitrationRule == ArbitrationRule.Visit)
|
|
||||||
// {
|
//正常的即时生成邮件 并发送邮件
|
||||||
// //在两位阅片人读完访视后,如果有裁判者等裁判读完,如果无裁判则等第二个人的读完
|
if (isNeedSend)
|
||||||
|
{
|
||||||
// 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();
|
|
||||||
|
MemoryStream memoryStream = new MemoryStream();
|
||||||
// //这里要求 到这里已经如果有裁判 已经生成裁判了保存数据库
|
MemoryStream pdfMemoryStream = new MemoryStream();
|
||||||
// if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2)
|
|
||||||
// {
|
|
||||||
|
MiniSoftware.MiniWord.SaveAsByTemplate(memoryStream, path, value);
|
||||||
// answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
Document document = new Document();
|
||||||
|
|
||||||
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList);
|
document.LoadFromStream(memoryStream, FileFormat.Docx);
|
||||||
// }
|
document.SaveToStream(pdfMemoryStream, FileFormat.PDF);
|
||||||
// else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1)
|
pdfMemoryStream.Seek(0, SeekOrigin.Begin);
|
||||||
// {
|
|
||||||
// var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value;
|
sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig()
|
||||||
// answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Visit, taskInfo.CriterionType);
|
{
|
||||||
|
FileName = $"{taskInfo.SubjectCode}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? trialEmailConfig.AttachName : trialEmailConfig.AttachNameCN)}.pdf",
|
||||||
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList);
|
|
||||||
|
FileStream = pdfMemoryStream
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
await SendEmailHelper.SendEmailAsync(sendEmailConfig);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// isNeedSend = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
//---无序阅片配置有误(应为单重无仲裁对象,双重针对访视仲裁),请核查!
|
|
||||||
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_UnblindedSequencedReading"]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
else
|
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;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = new Dictionary<string, object>()
|
|
||||||
{
|
|
||||||
["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
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
|
|
||||||
public enum EmailBusinessScenario
|
public enum EmailBusinessScenario
|
||||||
{
|
{
|
||||||
|
None=-1,
|
||||||
EnrollConfirmed = 1,
|
EnrollConfirmed = 1,
|
||||||
|
|
||||||
PDConfirmed = 2,
|
PDConfirmed = 2,
|
||||||
|
|
|
@ -141,6 +141,11 @@ public static class StaticData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class EmailSend
|
||||||
|
{
|
||||||
|
public static string EmailNamePlaceholder = "EmailNamePlaceholder";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 医生学位等级
|
/// 医生学位等级
|
||||||
|
|
Loading…
Reference in New Issue