diff --git a/IRaCIS.Core.Application/Service/Common/DTO/EmailNoticeConfigViewModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/EmailNoticeConfigViewModel.cs index 3ac45cfe9..c473097a0 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/EmailNoticeConfigViewModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/EmailNoticeConfigViewModel.cs @@ -63,7 +63,7 @@ namespace IRaCIS.Core.Application.Contracts public bool? IsDistinguishCriteria { get; set; } - public int? SystemLevel { get; set; } + public SysEmailLevel? SystemLevel { get; set; } } @@ -129,7 +129,7 @@ namespace IRaCIS.Core.Application.Contracts public List CopyUserTypeList { get; set; } - public int? SystemLevel { get; set; } + public SysEmailLevel SystemLevel { get; set; } } diff --git a/IRaCIS.Core.Application/Service/Common/EmailNoticeConfigService.cs b/IRaCIS.Core.Application/Service/Common/EmailNoticeConfigService.cs index 60ef71673..a9d45632e 100644 --- a/IRaCIS.Core.Application/Service/Common/EmailNoticeConfigService.cs +++ b/IRaCIS.Core.Application/Service/Common/EmailNoticeConfigService.cs @@ -28,7 +28,9 @@ namespace IRaCIS.Core.Application.Contracts [HttpPost] public async Task> GetEmailNoticeConfigList(EmailNoticeConfigQuery queryEmailNoticeConfig) { - var emailNoticeConfigQueryable = _emailNoticeConfigrepository.WhereIf(queryEmailNoticeConfig.SystemLevel!=null, t =>t.SystemLevel == queryEmailNoticeConfig.SystemLevel) + var emailNoticeConfigQueryable = _emailNoticeConfigrepository + .WhereIf(queryEmailNoticeConfig.SystemLevel == null, t => t.SystemLevel == SysEmailLevel.not_sys) + .WhereIf(queryEmailNoticeConfig.SystemLevel!=null, t =>t.SystemLevel == queryEmailNoticeConfig.SystemLevel) .WhereIf(queryEmailNoticeConfig.IsDistinguishCriteria != null, t => t.IsDistinguishCriteria == queryEmailNoticeConfig.IsDistinguishCriteria) .WhereIf(queryEmailNoticeConfig.CriterionTypeEnum != null, t => t.CriterionTypeEnum == queryEmailNoticeConfig.CriterionTypeEnum) .WhereIf(queryEmailNoticeConfig.BusinessScenarioEnum != null, t => t.BusinessScenarioEnum == queryEmailNoticeConfig.BusinessScenarioEnum) diff --git a/IRaCIS.Core.Application/Service/Common/MailService.cs b/IRaCIS.Core.Application/Service/Common/MailService.cs index 9fa965d6b..4a5c6764d 100644 --- a/IRaCIS.Core.Application/Service/Common/MailService.cs +++ b/IRaCIS.Core.Application/Service/Common/MailService.cs @@ -21,6 +21,7 @@ using DocumentFormat.OpenXml.Vml; using System.Net.Mail; using IP2Region.Net.XDB; using NPOI.SS.Formula.Eval; +using System.Linq; namespace IRaCIS.Application.Services { @@ -97,7 +98,7 @@ namespace IRaCIS.Application.Services } - private async Task GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario scenario, MimeMessage messageToSend, + private async Task GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario scenario, MimeMessage messageToSend, Func<(string topicStr, string htmlBodyStr), (string topicStr, string htmlBodyStr)> emailFunc) { var configInfo = await _emailNoticeConfigrepository.Where(t => t.BusinessScenarioEnum == scenario).FirstOrDefaultAsync(); @@ -130,7 +131,19 @@ namespace IRaCIS.Application.Services messageToSend.Body = builder.ToMessageBody(); - return messageToSend; + return configInfo; + } + + public async Task GetEmailConfigInfoAsync(EmailBusinessScenario scenario) + { + var configInfo = await _emailNoticeConfigrepository.Where(t => t.BusinessScenarioEnum == scenario).Include(t=>t.EmailNoticeUserTypeList).FirstOrDefaultAsync(); + + if (configInfo == null) + { + throw new BusinessValidationFailedException("系统未找到当前场景邮件配置信息,请联系运维人员核查"); + } + + return configInfo; } @@ -188,7 +201,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(mfaType == UserMFAType.Login ? EmailBusinessScenario.MFALogin : EmailBusinessScenario.MFAUnlock, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(mfaType == UserMFAType.Login ? EmailBusinessScenario.MFALogin : EmailBusinessScenario.MFAUnlock, messageToSend, emailConfigFunc); var sucessHandle = GetEmailSuccessHandle(userId, verificationCode, emailAddress); @@ -226,7 +239,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.UserResetEmail, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.UserResetEmail, messageToSend, emailConfigFunc); var sucessHandle = GetEmailSuccessHandle(userId, verificationCode, emailAddress); @@ -265,7 +278,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.UnloginUseEmailResetPassword, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.UnloginUseEmailResetPassword, messageToSend, emailConfigFunc); ////此时不知道用户 var sucessHandle = GetEmailSuccessHandle(Guid.Empty, verificationCode, emailAddress); @@ -309,7 +322,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.UnloginUseEmailResetPassword, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.UnloginUseEmailResetPassword, messageToSend, emailConfigFunc); //此时不知道用户 var sucessHandle = GetEmailSuccessHandle(Guid.Empty, verificationCode, emailAddress); @@ -351,7 +364,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.SiteSurveyLogin, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.SiteSurveyLogin, messageToSend, emailConfigFunc); //此时不知道用户 var sucessHandle = GetEmailSuccessHandle(Guid.Empty, verificationCode, emailAddress); @@ -397,7 +410,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.SiteSurveyReject, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.SiteSurveyReject, messageToSend, emailConfigFunc); @@ -450,7 +463,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.SysCreateUser, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.SysCreateUser, messageToSend, emailConfigFunc); await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig); @@ -487,7 +500,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.SysResetPassword, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.SysResetPassword, messageToSend, emailConfigFunc); await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig); } @@ -544,7 +557,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(sysUserInfo.IsFirstAdd ? EmailBusinessScenario.SiteUseOrExternalUserFirstrJoinTrial : EmailBusinessScenario.SiteUserOrExternalUserExistJoinTrial, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(sysUserInfo.IsFirstAdd ? EmailBusinessScenario.SiteUseOrExternalUserFirstrJoinTrial : EmailBusinessScenario.SiteUserOrExternalUserExistJoinTrial, messageToSend, emailConfigFunc); await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig); @@ -604,7 +617,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(sysUserInfo.IsFirstAdd ? EmailBusinessScenario.SiteUseOrExternalUserFirstrJoinTrial : EmailBusinessScenario.SiteUserOrExternalUserExistJoinTrial, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(sysUserInfo.IsFirstAdd ? EmailBusinessScenario.SiteUseOrExternalUserFirstrJoinTrial : EmailBusinessScenario.SiteUserOrExternalUserExistJoinTrial, messageToSend, emailConfigFunc); await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig, null); @@ -722,7 +735,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(sysUserInfo.IsFirstAdd ? EmailBusinessScenario.DoctorUserFirstJoinTrial : EmailBusinessScenario.DoctorUserExistJoinTrial, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(sysUserInfo.IsFirstAdd ? EmailBusinessScenario.DoctorUserFirstJoinTrial : EmailBusinessScenario.DoctorUserExistJoinTrial, messageToSend, emailConfigFunc); await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig, null); @@ -745,9 +758,12 @@ namespace IRaCIS.Application.Services var companyName = _userInfo.IsEn_Us ? _systemEmailConfig.CompanyShortName : _systemEmailConfig.CompanyShortNameCN; + var emailConfigInfo = await GetEmailConfigInfoAsync(EmailBusinessScenario.IRImageError); - var emailList = await _repository.Where(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(); + var userTypeEnumList = emailConfigInfo.EmailNoticeUserTypeList.Where(t => t.EmailUserType == EmailUserType.To).Select(t => t.UserType).ToList(); + + var emailList = await _repository.Where(t => userTypeEnumList.Contains(t.UserTypeEnum) && + (isHaveTrialId ? t.UserTrials.Any(t => t.TrialId == feedBack.TrialId) : true)).Select(t => new { t.EMail, t.UserTypeEnum, t.FullName }).ToListAsync(); //影像阅片反馈 pm @@ -789,7 +805,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.IRImageError, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.IRImageError, messageToSend, emailConfigFunc); } //项目相关的反馈 pm admin @@ -819,7 +835,7 @@ namespace IRaCIS.Application.Services userNames, info.TrialCode, feedBack.CreateUser.UserTypeRole.UserTypeShortName, - feedBack.CreateUser.FullName, + feedBack.CreateUser.FullName, emailType, feedBack.QuestionDescription, _systemEmailConfig.SiteUrl @@ -829,7 +845,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.TrialFeedBack, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.TrialFeedBack, messageToSend, emailConfigFunc); } //项目无关的反馈 admin zyss @@ -862,7 +878,7 @@ namespace IRaCIS.Application.Services }; - messageToSend = await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.SysFeedBack, messageToSend, emailConfigFunc); + await GetEmailSubejctAndHtmlInfoAndBuildAsync(EmailBusinessScenario.SysFeedBack, messageToSend, emailConfigFunc); } await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig); diff --git a/IRaCIS.Core.Domain/Common/EmailNoticeConfig.cs b/IRaCIS.Core.Domain/Common/EmailNoticeConfig.cs index 94de1e7fa..613bc008e 100644 --- a/IRaCIS.Core.Domain/Common/EmailNoticeConfig.cs +++ b/IRaCIS.Core.Domain/Common/EmailNoticeConfig.cs @@ -69,7 +69,7 @@ namespace IRaCIS.Core.Domain.Models - public int? SystemLevel { get; set; } + public SysEmailLevel SystemLevel { get; set; } /// /// 是否区分标准 @@ -127,6 +127,8 @@ namespace IRaCIS.Core.Domain.Models public enum SysEmailLevel { + not_sys=0, + //系统 不配置角色 sys_not_role=1,