From 3f9ffb029bf4ba0af2926d55a8950bf591014084 Mon Sep 17 00:00:00 2001 From: "{872297557@qq.com}" <872297557@qq.com> Date: Tue, 17 Jan 2023 17:40:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs | 2 +- .../SiteSurvey/TrialSiteSurveyService.cs | 41 ++++++++++++++++--- .../TrialSiteUser/TrialExternalUserService.cs | 38 +++++++++++++++-- .../Service/WorkLoad/EnrollService.cs | 4 +- .../Triggers/AddlTrialUserTrigger.cs | 2 +- 5 files changed, 74 insertions(+), 13 deletions(-) diff --git a/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs index fac1bcfbd..8e737a5a2 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs @@ -42,7 +42,7 @@ namespace IRaCIS.Core.API triggerOptions.AddTrigger(); triggerOptions.AddTrigger(); triggerOptions.AddTrigger(); - triggerOptions.AddTrigger(); + //triggerOptions.AddTrigger(); triggerOptions.AddTrigger(); diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index f1a6dcb31..4344f8273 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -82,7 +82,7 @@ namespace IRaCIS.Core.Application.Contracts [AllowAnonymous] public async Task VerifyEmialGetDoctorInfo(VerifyEmialGetDoctorInfoInDto inDto) { - var verificationRecord = await _repository.GetQueryable().OrderByDescending(x=>x.ExpirationTime).Where(t => (t.EmailOrPhone == inDto.EmailOrPhone) && t.Code == inDto.VerificationCode && t.CodeType == VerifyType.Email).FirstOrDefaultAsync(); + var verificationRecord = await _repository.GetQueryable().OrderByDescending(x => x.ExpirationTime).Where(t => (t.EmailOrPhone == inDto.EmailOrPhone) && t.Code == inDto.VerificationCode && t.CodeType == VerifyType.Email).FirstOrDefaultAsync(); VerifyEmialGetDoctorInfoOutDto result = new VerifyEmialGetDoctorInfoOutDto(); var doctorInfo = await _doctorRepository.Where(x => x.EMail == inDto.EmailOrPhone).FirstOrDefaultAsync(); @@ -104,7 +104,7 @@ namespace IRaCIS.Core.Application.Contracts } else //验证码正确 并且 没有超时 { - result.Token= _tokenService.GetToken(IRaCISClaims.Create(new UserBasicInfo())); + result.Token = _tokenService.GetToken(IRaCISClaims.Create(new UserBasicInfo())); } } @@ -757,7 +757,7 @@ namespace IRaCIS.Core.Application.Contracts //await SendInviteEmail(new InviteEmailCommand() { TrialId = trialId, RouteUrl = siteSurvyeSubmit.RouteUrl, UserList = needGenerateList }); - await GenerateAccountAsync(needGenerateList,trialId); + await GenerateAccountAsync(needGenerateList, trialId); await SendSiteSurveyUserJoinEmail(new TrialSiteUserSurveyJoinCommand() { TrialId = trialId, TrialSiteSurveyId = trialSiteSurveyId, RouteUrl = siteSurvyeSubmit.RouteUrl, BaseUrl = siteSurvyeSubmit.BaseUrl, UserList = needGenerateList }); @@ -768,7 +768,7 @@ namespace IRaCIS.Core.Application.Contracts - private async Task GenerateAccountAsync(List needGenerateList,Guid trialId) + private async Task GenerateAccountAsync(List needGenerateList, Guid trialId) { foreach (var item in needGenerateList) { @@ -776,6 +776,12 @@ namespace IRaCIS.Core.Application.Contracts //找下系统中是否存在该用户类型的 并且邮箱 或者手机的账户 var sysUserInfo = await _userRepository.Where(t => t.UserTypeId == item.UserTypeId && t.EMail == item.Email).Include(t => t.UserTypeRole).FirstOrDefaultAsync(); + var trialType = _repository.Where(t => t.Id == trialId).Select(t => t.TrialType).FirstOrDefault(); + + + + + if (sysUserInfo == null) { @@ -784,13 +790,14 @@ namespace IRaCIS.Core.Application.Contracts { var saveItem = _mapper.Map(item); - var trialType = _repository.Where(t => t.Id == trialId).Select(t => t.TrialType).FirstOrDefault(); if (trialType == TrialType.NoneOfficial) { saveItem.IsTestUser = true; } + // 中心调研生成账号 都是外部的 + saveItem.IsZhiZhun = false; saveItem.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1; saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(User)); @@ -812,6 +819,26 @@ namespace IRaCIS.Core.Application.Contracts } + if (trialType == TrialType.OfficialTrial || trialType == TrialType.Training) + { + + if (sysUserInfo.IsTestUser) + { + throw new BusinessValidationFailedException("正式类型 、培训类型的项目 不允许加入测试用户 "); + + } + } + + if (trialType == TrialType.NoneOfficial) + { + + if (sysUserInfo.IsTestUser == false && sysUserInfo.IsZhiZhun == false) + { + throw new BusinessValidationFailedException("测试项目 不允许加入外部正式用户 "); + + } + } + //发送邮件的时候需要用到该字段 item.SystemUserId = sysUserInfo.Id; @@ -846,7 +873,6 @@ namespace IRaCIS.Core.Application.Contracts var userId = (Guid)userInfo.SystemUserId; var siteId = trialSiteSurvey.SiteId; - await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl); //判断TrialUser中是否存在 不存在就插入 @@ -862,6 +888,9 @@ namespace IRaCIS.Core.Application.Contracts await _trialSiteUserSurveyRepository.UpdatePartialFromQueryAsync(t => t.Id == userInfo.Id, u => new TrialSiteUserSurvey() { IsJoin = true }); } + + await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl); + } await _trialSiteSurveyRepository.UpdatePartialFromQueryAsync(t => t.Id == trialSiteSurvey.Id && t.State == TrialSiteSurveyEnum.SPMApproved, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.PMCreatedAndLock, ReviewerUserId = _userInfo.Id, ReviewerTime = DateTime.Now }); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs index f5f70b230..b775d26e5 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs @@ -103,6 +103,7 @@ namespace IRaCIS.Core.Application.Service var existUser = await _userRepository.FirstOrDefaultAsync(t => t.EMail == addOrEditTrialExternalUser.Email && t.UserTypeId == addOrEditTrialExternalUser.UserTypeId); + var trialType = await _repository.Where(t => t.Id == addOrEditTrialExternalUser.TrialId).Select(t => t.TrialType).FirstOrDefaultAsync(); if (existUser != null) { @@ -112,7 +113,6 @@ namespace IRaCIS.Core.Application.Service } else { - var trialType = await _repository.Where(t => t.Id == addOrEditTrialExternalUser.TrialId).Select(t => t.TrialType).FirstOrDefaultAsync(); //生成账户 并插入 @@ -120,9 +120,12 @@ namespace IRaCIS.Core.Application.Service if (trialType == TrialType.NoneOfficial) { - generateUser.IsTestUser = true; + generateUser.IsTestUser = true; } + // 外部人员生成账号 都是外部的 + generateUser.IsZhiZhun = false; + generateUser.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1; @@ -142,8 +145,35 @@ namespace IRaCIS.Core.Application.Service addEntity.IsSystemUser = false; addEntity.SystemUserId = newAddUser.Id; + + existUser = newAddUser; + } + #region 验证用户 能否加入 + + if (trialType == TrialType.OfficialTrial || trialType == TrialType.Training) + { + + if (existUser.IsTestUser) + { + throw new BusinessValidationFailedException("正式类型 、培训类型的项目 不允许加入测试用户 "); + + } + } + + if (trialType == TrialType.NoneOfficial) + { + + if (existUser.IsTestUser == false && existUser.IsZhiZhun == false) + { + throw new BusinessValidationFailedException("测试项目 不允许加入外部正式用户 "); + } + } + + #endregion + + await _trialExternalUseRepository.SaveChangesAsync(); @@ -219,7 +249,6 @@ namespace IRaCIS.Core.Application.Service var userId = userInfo.SystemUserId; - await _mailVerificationService.ExternalUserJoinEmail(trialId, userId, sendEmail.BaseUrl, sendEmail.RouteUrl); //判断TrialUser中是否存在 不存在就插入 注意退出了,也不能再加进来 @@ -235,6 +264,9 @@ namespace IRaCIS.Core.Application.Service await _userRepository.SaveChangesAsync(); } + + await _mailVerificationService.ExternalUserJoinEmail(trialId, userId, sendEmail.BaseUrl, sendEmail.RouteUrl); + } return ResponseOutput.Ok(); diff --git a/IRaCIS.Core.Application/Service/WorkLoad/EnrollService.cs b/IRaCIS.Core.Application/Service/WorkLoad/EnrollService.cs index 870ad4698..39d5e5f84 100644 --- a/IRaCIS.Core.Application/Service/WorkLoad/EnrollService.cs +++ b/IRaCIS.Core.Application/Service/WorkLoad/EnrollService.cs @@ -385,9 +385,9 @@ namespace IRaCIS.Application.Services intoGroupItem.EnrollStatus = EnrollStatus.ConfirmIntoGroup; intoGroupItem.EnrollTime = DateTime.Now; - var userId= await _mailVerificationService.DoctorJoinTrialEmail(trialId, intoGroupItem.DoctorId, confirmReviewerCommand.BaseUrl, confirmReviewerCommand.RouteUrl); + var userId = await _mailVerificationService.DoctorJoinTrialEmail(trialId, intoGroupItem.DoctorId, confirmReviewerCommand.BaseUrl, confirmReviewerCommand.RouteUrl); - if( !await _trialUserRepository.AnyAsync(t=>t.TrialId==trialId && t.UserId== userId, true)) + if ( !await _trialUserRepository.AnyAsync(t=>t.TrialId==trialId && t.UserId== userId, true)) { await _trialUserRepository.AddAsync(new TrialUser() { TrialId = trialId, UserId = userId ,JoinTime = DateTime.Now }); } diff --git a/IRaCIS.Core.Application/Triggers/AddlTrialUserTrigger.cs b/IRaCIS.Core.Application/Triggers/AddlTrialUserTrigger.cs index 2ca86d9ab..173541f9d 100644 --- a/IRaCIS.Core.Application/Triggers/AddlTrialUserTrigger.cs +++ b/IRaCIS.Core.Application/Triggers/AddlTrialUserTrigger.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace IRaCIS.Core.Application.Triggers { - // 统一处理 外部用户、中心调研、参与医生加入到项目 + // 统一处理 外部用户、中心调研(先添加 再发送邮件)、参与医生加入到项目 ----废弃 public class AddlTrialUserTrigger : IBeforeSaveTrigger {