完成邮件基本逻辑
parent
03c2a67fe4
commit
ef63c19c93
|
@ -18,6 +18,9 @@ using IRaCIS.Core.Domain.Models;
|
||||||
using DocumentFormat.OpenXml.Office2013.Excel;
|
using DocumentFormat.OpenXml.Office2013.Excel;
|
||||||
using IRaCIS.Core.Application.Contracts;
|
using IRaCIS.Core.Application.Contracts;
|
||||||
using DocumentFormat.OpenXml.Vml;
|
using DocumentFormat.OpenXml.Vml;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using IP2Region.Net.XDB;
|
||||||
|
using NPOI.SS.Formula.Eval;
|
||||||
|
|
||||||
namespace IRaCIS.Application.Services
|
namespace IRaCIS.Application.Services
|
||||||
{
|
{
|
||||||
|
@ -728,6 +731,142 @@ namespace IRaCIS.Application.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//用户反馈邮件
|
||||||
|
|
||||||
|
public async Task UserFeedBack(Guid feedBackId)
|
||||||
|
{
|
||||||
|
var feedBack = await _repository.Where<UserFeedBack>(t => t.Id == feedBackId).Include(t => t.CreateUser).ThenInclude(t => t.UserTypeRole).FirstNotNullAsync();
|
||||||
|
|
||||||
|
var messageToSend = new MimeMessage();
|
||||||
|
//发件地址
|
||||||
|
messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail));
|
||||||
|
|
||||||
|
var isHaveTrialId = feedBack.TrialId != null;
|
||||||
|
|
||||||
|
var companyName = _userInfo.IsEn_Us ? _systemEmailConfig.CompanyShortName : _systemEmailConfig.CompanyShortNameCN;
|
||||||
|
|
||||||
|
|
||||||
|
var emailList = await _repository.Where<User>(t => t.UserTypeEnum == UserTypeEnum.Admin || t.UserTypeEnum == UserTypeEnum.ZYSS ||
|
||||||
|
(isHaveTrialId ? t.UserTrials.Any(t => t.User.UserTypeEnum == UserTypeEnum.ProjectManager && t.TrialId == feedBack.TrialId) : true)).Select(t => new { t.EMail, t.UserTypeEnum, t.FullName }).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
//影像阅片反馈 pm
|
||||||
|
if (feedBack.VisitTaskId != null)
|
||||||
|
{
|
||||||
|
foreach (var email in emailList)
|
||||||
|
{
|
||||||
|
if (email.UserTypeEnum == UserTypeEnum.ProjectManager)
|
||||||
|
{
|
||||||
|
//收件地址
|
||||||
|
messageToSend.To.Add(new MailboxAddress(email.FullName, email.EMail));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var userNames = string.Join(',', emailList.Where(email => email.UserTypeEnum == UserTypeEnum.ProjectManager).Select(t => t.FullName));
|
||||||
|
|
||||||
|
var emailType = await _repository.Where<Dictionary>(t => t.Parent.Code == "Email_BusinessScenario" && t.ParentId != null && t.Code == ((int)EmailBusinessScenario.UserResetEmail).ToString()).Select(t => _userInfo.IsEn_Us ? t.Value : t.ValueCN).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
|
||||||
|
var info = await _repository.Where<VisitTask>(t => t.Id == feedBack.VisitTaskId).Select(t => new { t.Trial.ResearchProgramNo, t.Trial.TrialCode, SubejctCode = t.Subject.Code, t.SourceSubjectVisit.VisitName }).FirstNotNullAsync();
|
||||||
|
|
||||||
|
Func<(string topicStr, string htmlBodyStr), (string topicStr, string htmlBodyStr)> emailConfigFunc = input =>
|
||||||
|
{
|
||||||
|
var topicStr = string.Format(input.topicStr, info.SubejctCode, info.VisitName, info.ResearchProgramNo);
|
||||||
|
|
||||||
|
var htmlBodyStr = string.Format(ReplaceCompanyName(input.htmlBodyStr),
|
||||||
|
userNames,
|
||||||
|
info.TrialCode,
|
||||||
|
info.SubejctCode,
|
||||||
|
info.VisitName,
|
||||||
|
feedBack.CreateUser.UserTypeRole.UserTypeShortName,
|
||||||
|
feedBack.CreateUser.FullName,
|
||||||
|
emailType,
|
||||||
|
feedBack.QuestionDescription,
|
||||||
|
_systemEmailConfig.SiteUrl
|
||||||
|
);
|
||||||
|
|
||||||
|
return (topicStr, htmlBodyStr);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.UserResetEmail, messageToSend, emailConfigFunc);
|
||||||
|
|
||||||
|
}
|
||||||
|
//项目相关的反馈 pm admin
|
||||||
|
else if (feedBack.TrialId != null)
|
||||||
|
{
|
||||||
|
foreach (var email in emailList)
|
||||||
|
{
|
||||||
|
if (email.UserTypeEnum == UserTypeEnum.ProjectManager || email.UserTypeEnum == UserTypeEnum.Admin)
|
||||||
|
{
|
||||||
|
//收件地址
|
||||||
|
messageToSend.To.Add(new MailboxAddress(email.FullName, email.EMail));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var userNames = string.Join(',', emailList.Where(email => email.UserTypeEnum == UserTypeEnum.ProjectManager || email.UserTypeEnum == UserTypeEnum.Admin).Select(t => t.FullName));
|
||||||
|
|
||||||
|
var emailType = await _repository.Where<Dictionary>(t => t.Parent.Code == "Email_BusinessScenario" && t.ParentId != null && t.Code == ((int)EmailBusinessScenario.UserResetEmail).ToString()).Select(t => _userInfo.IsEn_Us ? t.Value : t.ValueCN).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
|
||||||
|
var info = await _repository.Where<Trial>(t => t.Id == feedBack.TrialId).Select(t => new { t.ResearchProgramNo, t.TrialCode }).FirstNotNullAsync();
|
||||||
|
|
||||||
|
Func<(string topicStr, string htmlBodyStr), (string topicStr, string htmlBodyStr)> emailConfigFunc = input =>
|
||||||
|
{
|
||||||
|
var topicStr = string.Format(input.topicStr, info.ResearchProgramNo);
|
||||||
|
|
||||||
|
var htmlBodyStr = string.Format(ReplaceCompanyName(input.htmlBodyStr),
|
||||||
|
userNames,
|
||||||
|
info.TrialCode,
|
||||||
|
feedBack.CreateUser.UserTypeRole.UserTypeShortName,
|
||||||
|
feedBack.CreateUser.FullName,
|
||||||
|
emailType,
|
||||||
|
feedBack.QuestionDescription,
|
||||||
|
_systemEmailConfig.SiteUrl
|
||||||
|
);
|
||||||
|
|
||||||
|
return (topicStr, htmlBodyStr);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.UserResetEmail, messageToSend, emailConfigFunc);
|
||||||
|
|
||||||
|
}
|
||||||
|
//项目无关的反馈 admin zyss
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var email in emailList)
|
||||||
|
{
|
||||||
|
if (email.UserTypeEnum == UserTypeEnum.ZYSS || email.UserTypeEnum == UserTypeEnum.Admin)
|
||||||
|
{
|
||||||
|
//收件地址
|
||||||
|
messageToSend.To.Add(new MailboxAddress(email.FullName, email.EMail));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var userNames = string.Join(',', emailList.Where(email => email.UserTypeEnum == UserTypeEnum.ZYSS || email.UserTypeEnum == UserTypeEnum.Admin).Select(t => t.FullName));
|
||||||
|
|
||||||
|
Func<(string topicStr, string htmlBodyStr), (string topicStr, string htmlBodyStr)> emailConfigFunc = input =>
|
||||||
|
{
|
||||||
|
var topicStr = string.Format(input.topicStr);
|
||||||
|
|
||||||
|
var htmlBodyStr = string.Format(ReplaceCompanyName(input.htmlBodyStr),
|
||||||
|
userNames,
|
||||||
|
feedBack.CreateUser.UserTypeRole.UserTypeShortName,
|
||||||
|
feedBack.CreateUser.FullName,
|
||||||
|
feedBack.QuestionDescription,
|
||||||
|
_systemEmailConfig.SiteUrl
|
||||||
|
);
|
||||||
|
|
||||||
|
return (topicStr, htmlBodyStr);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.UserResetEmail, messageToSend, emailConfigFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,8 +85,7 @@ namespace IRaCIS.Core.Application.ViewModel
|
||||||
public int State { get; set; }
|
public int State { get; set; }
|
||||||
public Guid? TrialSiteId { get; set; }
|
public Guid? TrialSiteId { get; set; }
|
||||||
|
|
||||||
[NotDefault]
|
public Guid? TrialId { get; set; }
|
||||||
public Guid TrialId { get; set; }
|
|
||||||
|
|
||||||
public Guid? VisitTaskId { get; set; }
|
public Guid? VisitTaskId { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace IRaCIS.Core.Domain.Models
|
||||||
public Guid? TrialSiteId { get; set; }
|
public Guid? TrialSiteId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public Guid TrialId { get; set; }
|
public Guid? TrialId { get; set; }
|
||||||
|
|
||||||
public string ScreenshotListStr { get; set; }
|
public string ScreenshotListStr { get; set; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue