From 25116a9f0e613c6c2a5a5670a61a02f21c52bf2f Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 25 Dec 2024 16:02:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E5=BF=83=E8=B0=83=E7=A0=94=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E5=88=9D=E6=AD=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Common/MailService.cs | 31 +++++++++---------- .../TrialSiteUser/DTO/UserTrialViewModel.cs | 2 ++ .../TrialSiteUser/TrialExternalUserService.cs | 11 ++++--- .../TrialSiteUser/TrialMaintenanceService.cs | 2 +- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Common/MailService.cs b/IRaCIS.Core.Application/Service/Common/MailService.cs index 1eb6bc7d7..20ea82681 100644 --- a/IRaCIS.Core.Application/Service/Common/MailService.cs +++ b/IRaCIS.Core.Application/Service/Common/MailService.cs @@ -1,6 +1,7 @@ using IRaCIS.Application.Contracts; using IRaCIS.Core.Application.Auth; using IRaCIS.Core.Application.Helper; +using IRaCIS.Core.Domain.Models; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; using MailKit; @@ -31,7 +32,7 @@ namespace IRaCIS.Core.Application.Service Task SiteSurveyUserJoinEmail(Guid trialId, Guid userId, string baseUrl, string rootUrl); - Task ExternalUserJoinEmail(Guid trialId, Guid userId, Guid userTypeId, string baseUrl, string rootUrl); + Task ExternalUserJoinEmail(Guid trialId, Guid userId, string baseUrl, string rootUrl); Task DoctorJoinTrialEmail(Guid trialId, Guid doctorId, string baseUrl, string rootUrl); @@ -428,13 +429,13 @@ namespace IRaCIS.Core.Application.Service } //外部用户 加入项目 - public async Task ExternalUserJoinEmail(Guid trialId, Guid userId, Guid userTypeId, string baseUrl, string rootUrl) + public async Task ExternalUserJoinEmail(Guid trialId, Guid userId, string baseUrl, string rootUrl) { var trialInfo = (await _trialRepository.FirstOrDefaultAsync(t => t.Id == trialId)).IfNullThrowException(); var sysUserInfo = (await _identityUserRepository.Where(t => t.Id == userId).FirstOrDefaultAsync()).IfNullThrowException(); - var userType = await _userTypeRepository.FirstAsync(t => t.Id == userTypeId); + var userTypes = await _userRoleRepository.Where(t => t.IdentityUserId == sysUserInfo.Id).Select(t => t.UserTypeRole.UserTypeShortName).ToListAsync(); var messageToSend = new MimeMessage(); //发件地址 @@ -454,7 +455,7 @@ namespace IRaCIS.Core.Application.Service var domain = baseUrl.Substring(0, baseUrl.IndexOf("/login")); - var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&lang=" + (_userInfo.IsEn_Us ? "en" : "zh") + "&access_token=" + token; + var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&lang=" + (_userInfo.IsEn_Us ? "en" : "zh") + "&access_token=" + token; var redirectUrl = $"{domain}/api/User/UserRedirect?url={System.Web.HttpUtility.UrlEncode(routeUrl)}"; @@ -472,7 +473,7 @@ namespace IRaCIS.Core.Application.Service trialInfo.ResearchProgramNo, trialInfo.TrialCode, sysUserInfo.UserName, - userType.UserTypeShortName, + string.Join(',', userTypes), sysUserInfo.IsFirstAdd ? redirectUrl : baseUrl ); @@ -487,16 +488,13 @@ namespace IRaCIS.Core.Application.Service } - #endregion - - - - - //Site调研 用户加入项目 public async Task SiteSurveyUserJoinEmail(Guid trialId, Guid userId, string baseUrl, string rootUrl) { - var sysUserInfo = (await _userRoleRepository.Where(t => t.Id == userId).Include(t => t.UserTypeRole).FirstOrDefaultAsync()).IfNullThrowException(); + var sysUserInfo = (await _identityUserRepository.Where(t => t.Id == userId).FirstOrDefaultAsync()).IfNullThrowException(); + + + var userTypes = await _userRoleRepository.Where(t => t.IdentityUserId == sysUserInfo.Id).Select(t => t.UserTypeRole.UserTypeShortName).ToListAsync(); var trialInfo = await _trialRepository.FirstOrDefaultAsync(t => t.Id == trialId); @@ -513,10 +511,10 @@ namespace IRaCIS.Core.Application.Service if (sysUserInfo.IsFirstAdd) { - await _userRoleRepository.BatchUpdateNoTrackingAsync(t => t.Id == sysUserInfo.Id, u => new UserRole() { EmailToken = token }); + await _identityUserRepository.BatchUpdateNoTrackingAsync(t => t.Id == sysUserInfo.Id, u => new Domain.Models.IdentityUser() { EmailToken = token }); } - var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&UserType=" + sysUserInfo.UserTypeRole.UserTypeShortName + "&lang=" + (_userInfo.IsEn_Us ? "en" : "zh") + "&access_token=" + token; + var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&lang=" + (_userInfo.IsEn_Us ? "en" : "zh") + "&access_token=" + token; var domain = baseUrl.Substring(0, baseUrl.IndexOf("/login")); @@ -535,8 +533,8 @@ namespace IRaCIS.Core.Application.Service trialInfo.ExperimentName, trialInfo.ResearchProgramNo, trialInfo.TrialCode, - sysUserInfo.UserName, - sysUserInfo.UserTypeRole.UserTypeShortName, + sysUserInfo.UserName, + string.Join(',', userTypes), sysUserInfo.IsFirstAdd ? redirectUrl : baseUrl ); @@ -553,6 +551,7 @@ namespace IRaCIS.Core.Application.Service } + #endregion //医生生成账号加入 或者已存在账号加入到项目中 diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs index b7eb58319..5b6e282b7 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs @@ -205,6 +205,8 @@ namespace IRaCIS.Application.Contracts public string FullName { get; set; } = String.Empty; + public string UserTypeShortName { get; set; } + public bool IsSelect { get; set; } } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs index ffebd8d03..8a76144ae 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs @@ -13,6 +13,8 @@ using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; using Medallion.Threading; using Microsoft.AspNetCore.Mvc; +using DocumentFormat.OpenXml.Spreadsheet; +using IRaCIS.Core.Domain.Models; namespace IRaCIS.Core.Application.Service { @@ -276,15 +278,16 @@ namespace IRaCIS.Core.Application.Service } } - //判断TrialUser中是否存在 不存在就插入 注意退出了,也不能再加进来 - + } - await _mailVerificationService.ExternalUserJoinEmail(trialId, userId,userTypeId, sendEmail.BaseUrl, sendEmail.RouteUrl); + foreach (var item in sendEmail.SendUsers.GroupBy(t=>t.SystemUserId)) + { + await _mailVerificationService.ExternalUserJoinEmail(trialId, item.Key, sendEmail.BaseUrl, sendEmail.RouteUrl); } - return ResponseOutput.Ok(); + return ResponseOutput.Ok(); } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs index 26fd2f0fd..bfaaa5413 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs @@ -150,7 +150,7 @@ namespace IRaCIS.Core.Application.Service OrganizationName = t.IdentityUser.OrganizationName, Phone = t.IdentityUser.Phone, UserName = t.IdentityUser.UserName, - + UserTypeShortName=t.UserTypeRole.UserTypeShortName, IsSelect = t.UserRoleTrials.Any(t => t.TrialId == inQuery.TrialId), });