From f1a70bb6adf98d5031b47113f898563b90d0cde8 Mon Sep 17 00:00:00 2001 From: he <10978375@qq.com> Date: Wed, 11 Jan 2023 14:52:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRaCIS.Core.Application.xml | 22 ++++++ .../Service/Common/MailService.cs | 71 +++++++++++++++++++ .../Service/Doctor/DTO/DoctorModel.cs | 8 +++ .../Service/Doctor/DoctorService.cs | 6 +- .../DTO/TrialSiteSurveyViewModel.cs | 17 +++++ .../SiteSurvey/TrialSiteSurveyService.cs | 62 +++++++++++++++- .../WorkLoad/DTO/DoctorWorkLoadViewModel.cs | 7 +- .../Service/WorkLoad/DoctorWorkloadService.cs | 2 +- .../Dcotor/DoctorCriterionFile.cs | 5 ++ 9 files changed, 195 insertions(+), 5 deletions(-) diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 62ac3efaa..ebf3c21a9 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -6743,6 +6743,20 @@ TrialSiteSurveyService + + + 发送验证码 + + + + + + + 验证邮箱验证码 获取医生信息Id + + + + 发送验证码 @@ -8326,6 +8340,14 @@ + + + 发送验证码 + + + + + 医生文档关联关系维护 diff --git a/IRaCIS.Core.Application/Service/Common/MailService.cs b/IRaCIS.Core.Application/Service/Common/MailService.cs index 50ee01b20..cdd1685d2 100644 --- a/IRaCIS.Core.Application/Service/Common/MailService.cs +++ b/IRaCIS.Core.Application/Service/Common/MailService.cs @@ -16,6 +16,8 @@ namespace IRaCIS.Application.Services Task AnolymousSendEmail(string researchProgramNo, string emailAddress, int verificationCode); + Task SendEmailVerification(string emailAddress, int verificationCode); + Task SiteSurveyRejectEmail(MimeMessage messageToSend); Task SendMailEditEmail(Guid userId, string userName, string emailAddress, int verificationCode); @@ -208,6 +210,75 @@ namespace IRaCIS.Application.Services await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig, sucessHandle); } + /// + /// 发送验证码 + /// + /// + /// + /// + public async Task SendEmailVerification(string emailAddress, int verificationCode) + { + + + var messageToSend = new MimeMessage(); + //发件地址 + messageToSend.From.Add(new MailboxAddress(_systemEmailConfig.FromName, _systemEmailConfig.FromEmail)); + //收件地址 + messageToSend.To.Add(new MailboxAddress(String.Empty, emailAddress)); + //主题 + messageToSend.Subject = $"[来自展影IRC]的提醒"; + + + + + var builder = new BodyBuilder(); + + var pathToFile = _hostEnvironment.WebRootPath + + Path.DirectorySeparatorChar.ToString() + + "EmailTemplate" + + Path.DirectorySeparatorChar.ToString() + + "UserOptCommon.html"; + + using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile)) + { + var templateInfo = SourceReader.ReadToEnd(); + + + builder.HtmlBody = string.Format(templateInfo, + "", + "您正在参与展影医疗IRC项目", + verificationCode + ); + } + + messageToSend.Body = builder.ToMessageBody(); + + + + EventHandler sucessHandle = (sender, args) => + { + // args.Response + var code = verificationCode.ToString(); + _ = _verificationCodeRepository.AddAsync(new VerificationCode() + { + CodeType = VerifyType.Email, + HasSend = true, + Code = code, + UserId = Guid.Empty,//此时不知道用户 + EmailOrPhone = emailAddress, + ExpirationTime = DateTime.Now.AddMinutes(3) + }).Result; + _ = _verificationCodeRepository.SaveChangesAsync().Result; + }; + + + + await SendEmailHelper.SendEmailAsync(messageToSend, _systemEmailConfig, sucessHandle); + + + } + + //中心调研 登陆 public async Task AnolymousSendEmail(string researchProgramNo, string emailAddress, int verificationCode) { diff --git a/IRaCIS.Core.Application/Service/Doctor/DTO/DoctorModel.cs b/IRaCIS.Core.Application/Service/Doctor/DTO/DoctorModel.cs index e4d72d0da..29e30ac2c 100644 --- a/IRaCIS.Core.Application/Service/Doctor/DTO/DoctorModel.cs +++ b/IRaCIS.Core.Application/Service/Doctor/DTO/DoctorModel.cs @@ -685,6 +685,10 @@ namespace IRaCIS.Application.Contracts public class AddDoctorCriterionFileDto { + public Guid? Id { get; set; } + + public bool IsEnable { get; set; } = true; + /// /// 文件名称 /// @@ -710,6 +714,8 @@ namespace IRaCIS.Application.Contracts /// public string Remark { get; set; } + + /// /// 文件类型 /// @@ -726,6 +732,8 @@ namespace IRaCIS.Application.Contracts /// public string FileName { get; set; } + public bool IsEnable { get; set; } + /// /// 文件路径 /// diff --git a/IRaCIS.Core.Application/Service/Doctor/DoctorService.cs b/IRaCIS.Core.Application/Service/Doctor/DoctorService.cs index 00a8bc7fe..471e36ea9 100644 --- a/IRaCIS.Core.Application/Service/Doctor/DoctorService.cs +++ b/IRaCIS.Core.Application/Service/Doctor/DoctorService.cs @@ -471,7 +471,7 @@ namespace IRaCIS.Application.Services } /// - /// 添加医生标准文件 + /// 添加修改医生标准文件 /// /// /// @@ -479,6 +479,10 @@ namespace IRaCIS.Application.Services public async Task AddDoctorCriterionFile(AddDoctorCriterionFileDto inDto) { + if (await _doctorCriterionFileRepository.AnyAsync(x => x.DoctorId == inDto.DoctorId && x.FileType == inDto.FileType && x.IsEnable && x.CriterionType == inDto.CriterionType && x.Id != inDto.Id)) + { + throw new BusinessValidationFailedException("当前标准已添加过此类型文件"); + } var entity = await _doctorCriterionFileRepository.InsertOrUpdateAsync(inDto, true); return ResponseOutput.Ok(entity.Id.ToString()); diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs b/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs index 3b7c447f5..2f6e3a08c 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs @@ -194,7 +194,24 @@ namespace IRaCIS.Core.Application.Contracts } + public class VerifyEmialGetDoctorInfoInDto + { + public string VerificationCode { get; set; } + public string EmailOrPhone { get; set; } + } + + public class VerifyEmialGetDoctorInfoOutDto + { + public Guid? DoctorId { get; set; } + + public string Token { get; set; } + } + + public class SendEmialVerifyCodeInDto + { + public string Email { get; set; } = string.Empty; + } public class SiteSurveySendVerifyCode { diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index a0fd6f3e7..f58cba0d1 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -28,13 +28,14 @@ namespace IRaCIS.Core.Application.Contracts private readonly IRepository _trialSiteUserSurveyRepository; private readonly IRepository _userRepository; private readonly IRepository _trialSiteRepository; - + private readonly IRepository _doctorRepository; private readonly IRepository _trialUserRepository; private readonly ITokenService _tokenService; private readonly IMailVerificationService _mailVerificationService; public TrialSiteSurveyService(IRepository trialSiteSurveyRepository, IRepository trialUserRepository, IRepository trialSiteUserSurveyRepository, IRepository userRepository, IRepository trialSiteRepository, + IRepository doctorRepository, ITokenService tokenService, IMailVerificationService mailVerificationService) { @@ -43,12 +44,71 @@ namespace IRaCIS.Core.Application.Contracts _userRepository = userRepository; _trialUserRepository = trialUserRepository; _trialSiteRepository = trialSiteRepository; + this._doctorRepository = doctorRepository; _tokenService = tokenService; _mailVerificationService = mailVerificationService; } private object lockObj { get; set; } = new object(); + /// + /// 发送验证码 + /// + /// + /// + [AllowAnonymous] + public async Task SendEmialVerifyCode(SendEmialVerifyCodeInDto userInfo) + { + //检查手机或者邮箱是否有效 + if (!Regex.IsMatch(userInfo.Email, @"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$")) + { + throw new BusinessValidationFailedException("请输入正确的邮箱地址。"); + } + + //邮箱 + + //验证码 6位 + int verificationCode = new Random().Next(100000, 1000000); + await _mailVerificationService.SendEmailVerification(userInfo.Email, verificationCode); + return ResponseOutput.Ok(); + } + + /// + /// 验证邮箱验证码 获取医生信息Id + /// + /// + /// + [HttpPost] + [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(); + VerifyEmialGetDoctorInfoOutDto result = new VerifyEmialGetDoctorInfoOutDto(); + + var doctorInfo = await _doctorRepository.Where(x => x.EMail == inDto.EmailOrPhone).FirstOrDefaultAsync(); + + result.DoctorId = doctorInfo == null ? null : doctorInfo.Id; + //检查数据库是否存在该验证码 + if (verificationRecord == null) + { + throw new BusinessValidationFailedException("验证码错误。"); + } + else + { + //检查验证码是否失效 + if (verificationRecord.ExpirationTime < DateTime.Now) + { + throw new BusinessValidationFailedException("验证码已经过期。"); + } + else //验证码正确 并且 没有超时 + { + result.Token= _tokenService.GetToken(IRaCISClaims.Create(new UserBasicInfo())); + } + } + + return result; + } + /// /// 发送验证码 /// diff --git a/IRaCIS.Core.Application/Service/WorkLoad/DTO/DoctorWorkLoadViewModel.cs b/IRaCIS.Core.Application/Service/WorkLoad/DTO/DoctorWorkLoadViewModel.cs index 5ef5cb838..36a9a7497 100644 --- a/IRaCIS.Core.Application/Service/WorkLoad/DTO/DoctorWorkLoadViewModel.cs +++ b/IRaCIS.Core.Application/Service/WorkLoad/DTO/DoctorWorkLoadViewModel.cs @@ -283,7 +283,8 @@ namespace IRaCIS.Application.Contracts EnrollId = EnrollId, ToDoQuantity= ReadingTaskStateList.Where(x=>x.ReadingTaskState != ReadingTaskState.HaveSigned&&x.CriterionType== t.CriterionType).Count(), CompletionQuantity = ReadingTaskStateList.Where(x => x.ReadingTaskState == ReadingTaskState.HaveSigned && x.CriterionType == t.CriterionType).Count(), - CriterionFileList = CriterionFileList.Where(x=>x.CriterionType==t.CriterionType).ToList(), + StatementCriterionFileList = CriterionFileList.Where(x=>x.CriterionType==t.CriterionType&&x.FileType==CriterionFileType.Statement).ToList(), + AcknowledgementCriterionFileList = CriterionFileList.Where(x => x.CriterionType == t.CriterionType && x.FileType == CriterionFileType.Acknowledgement).ToList(), TrialReadingCriterionId = t.TrialReadingCriterionId, ReadingCategorys = CriterionReadingCategoryList.Where(c => c.TrialReadingCriterionId == t.TrialReadingCriterionId).Select(t => t.ReadingCategory).OrderBy(c => c).ToList() }).ToList(); @@ -383,7 +384,9 @@ namespace IRaCIS.Application.Contracts public int CompletionQuantity { get; set; } - public List CriterionFileList { get; set; } + public List StatementCriterionFileList { get; set; } + + public List AcknowledgementCriterionFileList { get; set; } public List ReadingCategorys { get; set; } = new List(); diff --git a/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs b/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs index 338265292..4b020c7ef 100644 --- a/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs +++ b/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs @@ -207,7 +207,7 @@ namespace IRaCIS.Application.Services IsEnable = allocateRule.IsEnable, TrialReadingCriterionList = intoGroup.Trial.ReadingQuestionCriterionTrialList.Where(t=>t.IsConfirm).Select(t=>new TrialReadingCriterionDto() { TrialReadingCriterionId=t.Id,TrialReadingCriterionName=t.CriterionName,CriterionType=t.CriterionType,IsOncologyReading=t.IsOncologyReading,IsArbitrationReading=t.IsArbitrationReading,IsGlobalReading=t.IsGlobalReading,ReadingInfoSignTime=t.ReadingInfoSignTime,ReadingType=t.ReadingType}).ToList(), - CriterionFileList= doctor.CriterionFileList.Select(x=> new CriterionFile() { + CriterionFileList= doctor.CriterionFileList.Where(x=>x.IsEnable).Select(x=> new CriterionFile() { CriterionType=x.CriterionType, DoctorId=x.DoctorId, FileName=x.FileName, diff --git a/IRaCIS.Core.Domain/Dcotor/DoctorCriterionFile.cs b/IRaCIS.Core.Domain/Dcotor/DoctorCriterionFile.cs index 6661804a7..47fa4c0b7 100644 --- a/IRaCIS.Core.Domain/Dcotor/DoctorCriterionFile.cs +++ b/IRaCIS.Core.Domain/Dcotor/DoctorCriterionFile.cs @@ -56,6 +56,11 @@ namespace IRaCIS.Core.Domain.Models /// public DateTime CreateTime { get; set; } + /// + /// 是否启用 + /// + public bool IsEnable { get; set; } = true; + [JsonIgnore] [ForeignKey("DoctorId")] public Doctor Doctor { get; set; }