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..edddbe06c 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,7 @@ 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 +785,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 +814,7 @@ namespace IRaCIS.Core.Application.Contracts } + //发送邮件的时候需要用到该字段 item.SystemUserId = sysUserInfo.Id; @@ -846,7 +849,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 +864,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/SiteSurvey/TrialSiteUserSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteUserSurveyService.cs index 013c157b3..aad23f9b1 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteUserSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteUserSurveyService.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Application.Filter; +using IRaCIS.Core.Infrastructure; namespace IRaCIS.Core.Application.Contracts { @@ -38,7 +39,7 @@ namespace IRaCIS.Core.Application.Contracts [HttpPost("{trialId:guid}")] public async Task AddOrUpdateTrialSiteUserSurvey(TrialSiteUserSurveyAddOrEdit addOrEditTrialSiteUserSurvey) { - + if (await _trialSiteUserSurveyRepository.Where(t => t.Id == addOrEditTrialSiteUserSurvey.Id).AnyAsync(t => t.TrialSiteSurvey.State == TrialSiteSurveyEnum.PMCreatedAndLock)) { return ResponseOutput.NotOk("已锁定,不允许操作"); @@ -61,6 +62,44 @@ namespace IRaCIS.Core.Application.Contracts } + + if (addOrEditTrialSiteUserSurvey.IsGenerateAccount ) + { + var trialId= _trialSiteUserSurveyRepository.Where(t=>t.Id == addOrEditTrialSiteUserSurvey.TrialSiteSurveyId).Select(t=>t.TrialSiteSurvey.TrialId).FirstOrDefault(); + + var trialType = _repository.Where(t => t.Id == trialId).Select(t => t.TrialType).FirstOrDefault(); + + var item = addOrEditTrialSiteUserSurvey; + + //找下系统中是否存在该用户类型的 并且邮箱 或者手机的账户 + var sysUserInfo = await _repository.Where(t => t.UserTypeId == item.UserTypeId && t.EMail == item.Email).Include(t => t.UserTypeRole).FirstOrDefaultAsync(); + + if (sysUserInfo == null) + { + sysUserInfo = new User() { IsZhiZhun=false,IsTestUser= (trialType == TrialType.NoneOfficial) }; + } + + if (trialType == TrialType.OfficialTrial || trialType == TrialType.Training) + { + + if (sysUserInfo.IsTestUser) + { + throw new BusinessValidationFailedException("正式类型 、培训类型的项目 不允许加入测试用户 "); + + } + } + + if (trialType == TrialType.NoneOfficial) + { + + if (sysUserInfo.IsTestUser == false) + { + throw new BusinessValidationFailedException("测试项目 不允许加入正式用户 "); + + } + } + } + var entity = await _trialSiteUserSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteUserSurvey, true); return ResponseOutput.Ok(entity.Id.ToString()); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs index f5f70b230..b8d5c918a 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 ) + { + 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..795223969 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 { @@ -49,9 +49,9 @@ namespace IRaCIS.Core.Application.Triggers if (trialInfo.TrialType == TrialType.NoneOfficial) { - if (user.IsTestUser == false && user.IsZhiZhun == false) + if (user.IsTestUser == false ) { - throw new BusinessValidationFailedException("测试项目 不允许加入外部正式用户 "); + throw new BusinessValidationFailedException("测试项目 不允许加入正式用户 "); } }