diff --git a/IRaCIS.Core.Application/Service/Common/MailService.cs b/IRaCIS.Core.Application/Service/Common/MailService.cs index 02c1b14e5..82996e084 100644 --- a/IRaCIS.Core.Application/Service/Common/MailService.cs +++ b/IRaCIS.Core.Application/Service/Common/MailService.cs @@ -1,5 +1,6 @@ using IRaCIS.Core.Infra.EFCore; using IRaCIS.Core.Domain.Models; +using IRaCIS.Core.Domain.Share; using MailKit.Security; using MimeKit; @@ -9,11 +10,11 @@ namespace IRaCIS.Application.Services { Task SendMail(Guid userId, string userName, string emailAddress, int verificationCode); - Task AnolymousSendEmail(string emailAddress, int verificationCode); + Task AnolymousSendEmail(string researchProgramNo ,string emailAddress, int verificationCode); Task SendMailEditEmail(Guid userId, string userName, string emailAddress, int verificationCode); - Task AnolymousSendEmailForResetAccount(string emailAddress, int verificationCode); + Task AnolymousSendEmailForResetAccount( string emailAddress, int verificationCode); } public class MailVerificationService : IMailVerificationService @@ -41,13 +42,15 @@ namespace IRaCIS.Application.Services //收件地址 messageToSend.To.Add(new MailboxAddress(userName, emailAddress)); //主题 - messageToSend.Subject = "Reset email (Verification Code)"; + messageToSend.Subject = "重置邮箱"; messageToSend.Body = new TextPart("plain") { - Text = $@"Hey {userName},you are modify your email . The verification code is: {verificationCode}, which is valid within 3 minutes. If it is not your own operation, please ignore it! - - -- GRR" + Text = $@" {userName},您好: + 感谢您使用展影云平台。 + 您正在进行邮箱重置操作,验证码是: {verificationCode},请在3分钟内输入该验证码,进行后续操作。如非本人操作,请忽略该邮件 + 此邮件属系统自动发出,无需回复。 + 上海展影医疗科技有限公司" }; using (var smtp = new MailKit.Net.Smtp.SmtpClient()) { @@ -80,59 +83,7 @@ namespace IRaCIS.Application.Services } } - - - public async Task SendMail(Guid userId, string userName, string emailAddress, int verificationCode) - { - - - var messageToSend = new MimeMessage(); - //发件地址 - messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com")); - //收件地址 - messageToSend.To.Add(new MailboxAddress(userName, emailAddress)); - //主题 - messageToSend.Subject = "Reset PassWord (Verification Code)"; - - messageToSend.Body = new TextPart("plain") - { - Text = $@"Hey {userName},you are resetting your password via email. The verification code is: {verificationCode}, which is valid within 3 minutes. If it is not your own operation, please ignore it! - - -- GRR" - }; - using (var smtp = new MailKit.Net.Smtp.SmtpClient()) - { - smtp.MessageSent += (sender, args) => - { - // args.Response - var code = verificationCode.ToString(); - _ = _verificationCodeRepository.AddAsync(new VerificationCode() - { - CodeType = 0, - HasSend = true, - Code = code, - UserId = userId, - ExpirationTime = DateTime.Now.AddMinutes(3) - }).Result; - _ = _verificationCodeRepository.SaveChangesAsync().Result; - - }; - - smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; - - await smtp.ConnectAsync("smtp.163.com", 25, SecureSocketOptions.StartTls); - - await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH"); - - await smtp.SendAsync(messageToSend); - - await smtp.DisconnectAsync(true); - - } - } - - - public async Task AnolymousSendEmailForResetAccount(string emailAddress, int verificationCode) + public async Task AnolymousSendEmailForResetAccount( string emailAddress, int verificationCode) { var messageToSend = new MimeMessage(); //发件地址 @@ -140,13 +91,15 @@ namespace IRaCIS.Application.Services //收件地址 messageToSend.To.Add(new MailboxAddress(String.Empty, emailAddress)); //主题 - messageToSend.Subject = "Reset Password (Verification Code)"; + messageToSend.Subject = "重置密码"; messageToSend.Body = new TextPart("plain") { - Text = $@"Hey ,you are reset passwoed. The verification code is: {verificationCode}, If it is not your own operation, please ignore it! - - -- GRR" + Text = $@" 您好: + 感谢您使用展影云平台。 + 您正在进行邮箱重置密码操作,验证码是: {verificationCode},请在3分钟内输入该验证码,进行后续操作。如非本人操作,请忽略该邮件 + 此邮件属系统自动发出,无需回复。 + 上海展影医疗科技有限公司" }; using (var smtp = new MailKit.Net.Smtp.SmtpClient()) { @@ -180,24 +133,24 @@ namespace IRaCIS.Application.Services } - public async Task AnolymousSendEmail(string emailAddress, int verificationCode) + public async Task AnolymousSendEmail(string researchProgramNo,string emailAddress, int verificationCode) { - var messageToSend = new MimeMessage(); //发件地址 messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com")); //收件地址 messageToSend.To.Add(new MailboxAddress(String.Empty, emailAddress)); //主题 - messageToSend.Subject = "GRR Site survey (Verification Code)"; + messageToSend.Subject = $"[{researchProgramNo}]中心调研"; messageToSend.Body = new TextPart("plain") { - Text = $@"Hey ,you are login for site survey via email. The verification code is: {verificationCode}, which is valid within 3 minutes. If it is not your own operation, please ignore it! - - -- GRR" + Text = $@" 感谢您使用展影云平台。 + 您正在参与展影医疗IRC项目中心调研工作,验证码是:: {verificationCode},请在3分钟内输入该验证码,进行后续操作。如非本人操作,请忽略该邮件。 + 此邮件属系统自动发出,无需回复。 + 上海展影医疗科技有限公司" }; using (var smtp = new MailKit.Net.Smtp.SmtpClient()) { @@ -207,7 +160,7 @@ namespace IRaCIS.Application.Services var code = verificationCode.ToString(); _ = _verificationCodeRepository.AddAsync(new VerificationCode() { - CodeType = 0, + CodeType = VerifyType.Email, HasSend = true, Code = code, UserId = Guid.Empty,//此时不知道用户 @@ -230,6 +183,59 @@ namespace IRaCIS.Application.Services } } + + + + + + public async Task SendMail(Guid userId, string userName, string emailAddress, int verificationCode) + { + + + var messageToSend = new MimeMessage(); + //发件地址 + messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com")); + //收件地址 + messageToSend.To.Add(new MailboxAddress(userName, emailAddress)); + //主题 + messageToSend.Subject = "Reset PassWord (Verification Code)"; + + messageToSend.Body = new TextPart("plain") + { + Text = $@"Hey {userName},you are resetting your password via email. The verification code is: {verificationCode}, which is valid within 3 minutes. If it is not your own operation, please ignore it! + + -- GRR" + }; + using (var smtp = new MailKit.Net.Smtp.SmtpClient()) + { + smtp.MessageSent += (sender, args) => + { + // args.Response + var code = verificationCode.ToString(); + _ = _verificationCodeRepository.AddAsync(new VerificationCode() + { + CodeType = 0, + HasSend = true, + Code = code, + UserId = userId, + ExpirationTime = DateTime.Now.AddMinutes(3) + }).Result; + _ = _verificationCodeRepository.SaveChangesAsync().Result; + + }; + + smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; + + await smtp.ConnectAsync("smtp.163.com", 25, SecureSocketOptions.StartTls); + + await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH"); + + await smtp.SendAsync(messageToSend); + + await smtp.DisconnectAsync(true); + + } + } public async Task SendEmailForExternalUser(string emailAddress, string verificationCode) { var messageToSend = new MimeMessage(); diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomInstanceModel.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomInstanceModel.cs index ff4135eb1..5b6c6ba4c 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomInstanceModel.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomInstanceModel.cs @@ -9,7 +9,7 @@ public string SeriesInstanceUid { get; set; } = string.Empty; public string SopInstanceUid { get; set; } = string.Empty; public int InstanceNumber { get; set; } - public DateTime InstanceTime { get; set; } + public DateTime? InstanceTime { get; set; } public bool CPIStatus { get; set; } public int ImageRows { get; set; } public int ImageColumns { get; set; } diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomSeriesModel.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomSeriesModel.cs index 66ebca996..ca172ed06 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomSeriesModel.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomSeriesModel.cs @@ -7,7 +7,7 @@ public string StudyInstanceUid { get; set; } = String.Empty; public string SeriesInstanceUid { get; set; } = String.Empty; public int SeriesNumber { get; set; } - public DateTime SeriesTime { get; set; } + public DateTime? SeriesTime { get; set; } public string Modality { get; set; } = String.Empty; public string Description { get; set; }=String.Empty; public int InstanceCount { get; set; } diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomStudyModel.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomStudyModel.cs index 088f2ef1b..ea1be8156 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomStudyModel.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/DicomStudyModel.cs @@ -11,7 +11,7 @@ public string StudyCode { get; set; } = string.Empty; - public DateTime StudyTime { get; set; } + public DateTime? StudyTime { get; set; } } public class DicomStudyDTO @@ -28,7 +28,7 @@ public int Status { get; set; } = 1; public string StudyInstanceUid { get; set; } = string.Empty; - public DateTime StudyTime { get; set; } + public DateTime? StudyTime { get; set; } public string Modalities { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/DicomArchiveService.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/DicomArchiveService.cs index 67e70e0de..8fdc6d9c5 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/DicomArchiveService.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/DicomArchiveService.cs @@ -224,7 +224,7 @@ namespace IRaCIS.Core.Application.Services Id = studyId, StudyInstanceUid = studyInstanceUid, /* StudyTime = dataset.GetSingleValueOrDefault(DicomTag.StudyDate, DateTime.Now).Add(dataset.GetSingleValueOrDefault(DicomTag.StudyTime, DateTime.Now).TimeOfDay),*///dataset.GetDateTime(DicomTag.StudyDate, DicomTag.StudyTime), - StudyTime = dataset.GetSingleValue(DicomTag.StudyDate)?.Add(dataset.GetSingleValueOrDefault(DicomTag.StudyTime, TimeSpan.Zero)), + StudyTime = dataset.GetSingleValueOrDefault(DicomTag.StudyDate,(DateTime?)null)?.Add(dataset.GetSingleValueOrDefault(DicomTag.StudyTime, TimeSpan.Zero)), Modalities = dataset.GetSingleValueOrDefault(DicomTag.Modality, string.Empty), Description = dataset.GetSingleValueOrDefault(DicomTag.StudyDescription, string.Empty), InstitutionName = dataset.GetSingleValueOrDefault(DicomTag.InstitutionName, string.Empty), @@ -358,7 +358,7 @@ namespace IRaCIS.Core.Application.Services SeriesInstanceUid = seriesInstanceUid, SeriesNumber = dataset.GetSingleValueOrDefault(DicomTag.SeriesNumber, 1), //SeriesTime = dataset.GetSingleValueOrDefault(DicomTag.SeriesDate, DateTime.Now).Add(dataset.GetSingleValueOrDefault(DicomTag.SeriesTime, DateTime.Now).TimeOfDay), - SeriesTime = dataset.GetSingleValue(DicomTag.SeriesDate)?.Add(dataset.GetSingleValueOrDefault(DicomTag.SeriesTime, TimeSpan.Zero)),// dataset.GetDateTime(DicomTag.SeriesDate, DicomTag.SeriesTime), + SeriesTime = dataset.GetSingleValueOrDefault(DicomTag.SeriesDate, (DateTime?)null)?.Add(dataset.GetSingleValueOrDefault(DicomTag.SeriesTime, TimeSpan.Zero)),// dataset.GetDateTime(DicomTag.SeriesDate, DicomTag.SeriesTime), Modality = dataset.GetSingleValueOrDefault(DicomTag.Modality, string.Empty), Description = dataset.GetSingleValueOrDefault(DicomTag.SeriesDescription, string.Empty), SliceThickness = dataset.GetSingleValueOrDefault(DicomTag.SliceThickness, string.Empty), @@ -413,7 +413,7 @@ namespace IRaCIS.Core.Application.Services SeriesInstanceUid = dicomSeries.SeriesInstanceUid, SopInstanceUid = sopInstanceUid, InstanceNumber = dataset.GetSingleValueOrDefault(DicomTag.InstanceNumber, 1), - InstanceTime = dataset.GetSingleValue(DicomTag.ContentDate)?.Add(dataset.GetSingleValueOrDefault(DicomTag.ContentTime, TimeSpan.Zero)), + InstanceTime = dataset.GetSingleValueOrDefault(DicomTag.ContentDate,(DateTime?)null)?.Add(dataset.GetSingleValueOrDefault(DicomTag.ContentTime, TimeSpan.Zero)), //dataset.GetSingleValueOrDefault(DicomTag.ContentDate,DateTime.Now);//, DicomTag.ContentTime) CPIStatus = false, ImageRows = dataset.GetSingleValueOrDefault(DicomTag.Rows, 0), diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 85eb5854b..f4abbffc3 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -53,16 +53,6 @@ namespace IRaCIS.Application.Services } - ////查找改邮箱或者手机的用户 - //var exist = await _userRepository.AnyAsync(t => t.EMail == email); - - //if (!exist) - //{ - // return ResponseOutput.NotOk("No user with this email exists."); - - //} - //var user = await _userRepository.FirstOrDefaultAsync(t => t.EMail == email); - //验证码 6位 int verificationCode = new Random().Next(100000, 1000000); @@ -73,6 +63,7 @@ namespace IRaCIS.Application.Services } + [HttpPut("{newEmail}/{verificationCode}")] public async Task SetNewEmail(string newEmail, string verificationCode) { @@ -108,15 +99,15 @@ namespace IRaCIS.Application.Services return ResponseOutput.NotOk("The mailbox for this user type already exists"); } - var success = await _userRepository.BatchUpdateAsync(t => t.Id == _userInfo.Id, u => new User() + await _userRepository.UpdatePartialFields(_userInfo.Id, u => new User() { EMail = newEmail - }); + }, true); //删除验证码历史记录 await _verificationCodeRepository.BatchDeleteAsync(t => t.UserId == _userInfo.Id && t.CodeType == 0); - return ResponseOutput.Result(success); + return ResponseOutput.Ok(); } } @@ -128,10 +119,10 @@ namespace IRaCIS.Application.Services { - var success = await _userRepository.BatchUpdateAsync(t => t.Id == _userInfo.Id, u => new User() + await _userRepository.UpdatePartialFields(_userInfo.Id, u => new User() { Phone = newPhone - }); + },true); return ResponseOutput.Ok(); } @@ -145,10 +136,10 @@ namespace IRaCIS.Application.Services { return ResponseOutput.NotOk("UserId already exists"); } - var success = await _userRepository.BatchUpdateAsync(t => t.Id == _userInfo.Id, u => new User() + await _userRepository.UpdatePartialFields(_userInfo.Id, u => new User() { UserName = newUserName - }); + },true); return ResponseOutput.Ok(); } @@ -163,13 +154,13 @@ namespace IRaCIS.Application.Services public async Task ResetPassword(Guid userId) { - var success = await _userRepository.BatchUpdateAsync(t => t.Id == userId, u => new User() + await _userRepository.UpdatePartialFields(userId, u => new User() { Password = MD5Helper.Md5(StaticData.DefaultPassword), IsFirstAdd = true - }); + }, true); - return ResponseOutput.Result(success); + return ResponseOutput.Ok(); } diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs b/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs index 85a772ad2..53d234504 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteSurveyViewModel.cs @@ -190,8 +190,11 @@ namespace IRaCIS.Core.Application.Contracts public class SiteSurveySendVerifyCode { - public VerifyType verificationType { get; set; } - public string EmailOrPhone { get; set; } = string.Empty; + //public VerifyType verificationType { get; set; } + public string Email { get; set; } = string.Empty; + + [NotDefault] + public Guid TrialId { get; set; } } diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index 39550809c..494155967 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -46,33 +46,58 @@ namespace IRaCIS.Core.Application.Contracts [AllowAnonymous] public async Task SendVerifyCode(SiteSurveySendVerifyCode userInfo, [FromServices] IMailVerificationService _mailVerificationService) { - var verificationType = userInfo.verificationType; + var verificationType = VerifyType.Email; //检查手机或者邮箱是否有效 - if (!Regex.IsMatch(userInfo.EmailOrPhone, @"/^1[34578]\d{9}$/") && !Regex.IsMatch(userInfo.EmailOrPhone, @"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$")) + if ( !Regex.IsMatch(userInfo.Email, @"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$")) { - - throw new BusinessValidationFailedException(verificationType == VerifyType.Email - ? "Please input a legal email" - : "Please input a legal phone"); - + throw new BusinessValidationFailedException("Please input a legal email"); } //邮箱 - if (verificationType == VerifyType.Email) - { - //验证码 6位 - int verificationCode = new Random().Next(100000, 1000000); - await _mailVerificationService.AnolymousSendEmail(userInfo.EmailOrPhone, verificationCode); - } - //手机短信 - else - { + //验证码 6位 + int verificationCode = new Random().Next(100000, 1000000); + + var trialInfo = await _repository.FirstOrDefaultAsync(t => t.Id == userInfo.TrialId); + + await _mailVerificationService.AnolymousSendEmail(trialInfo.ResearchProgramNo,userInfo.Email, verificationCode); - } return ResponseOutput.Ok(); + + #region MyRegion + + //var verificationType = VerifyType.Email; + ////检查手机或者邮箱是否有效 + //if (!Regex.IsMatch(userInfo.Email, @"/^1[34578]\d{9}$/") && !Regex.IsMatch(userInfo.Email, @"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$")) + //{ + + // throw new BusinessValidationFailedException(verificationType == VerifyType.Email + // ? "Please input a legal email" + // : "Please input a legal phone"); + + //} + + ////邮箱 + //if (verificationType == VerifyType.Email) + //{ + // //验证码 6位 + // int verificationCode = new Random().Next(100000, 1000000); + + // await _mailVerificationService.AnolymousSendEmail(userInfo.Email, verificationCode); + //} + ////手机短信 + //else + //{ + + //} + + //return ResponseOutput.Ok(); + + #endregion + + } /// @@ -301,225 +326,225 @@ namespace IRaCIS.Core.Application.Contracts } - /// - /// 直接查询相关所有数据 - /// - /// - [HttpGet("{trialId:guid}/{trialSiteSurveyId:guid}")] - public async Task GetSiteSurveyInfo(Guid trialSiteSurveyId, Guid trialId) + /// + /// 直接查询相关所有数据 + /// + /// + [HttpGet("{trialId:guid}/{trialSiteSurveyId:guid}")] + public async Task GetSiteSurveyInfo(Guid trialSiteSurveyId, Guid trialId) + { + var result = await _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId && t.TrialId == trialId) + .ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync().IfNullThrowException(); + + return result; + } + + + /// + /// 实际这里只会是更新 添加在login的时候做了 + /// + /// + /// + public async Task AddOrUpdateTrialSiteSurvey(TrialSiteSurveyAddOrEdit addOrEditTrialSiteSurvey) + { + + if (addOrEditTrialSiteSurvey.Id != null) { - var result = await _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId && t.TrialId == trialId) - .ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync().IfNullThrowException(); - - return result; - } - - - /// - /// 实际这里只会是更新 添加在login的时候做了 - /// - /// - /// - public async Task AddOrUpdateTrialSiteSurvey(TrialSiteSurveyAddOrEdit addOrEditTrialSiteSurvey) - { - - if (addOrEditTrialSiteSurvey.Id != null) - { - if (await _trialSiteSurveyRepository.AnyAsync(t => t.Id == addOrEditTrialSiteSurvey.Id && t.State == TrialSiteSurveyEnum.PMCreatedAndLock)) - { - return ResponseOutput.NotOk("已锁定,不允许操作"); - } - } - var entity = await _trialSiteSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteSurvey, true); - - return ResponseOutput.Ok(entity.Id.ToString()); - } - - - /// - /// 删除调研表 - /// - /// - /// - [HttpDelete("{trialSiteSurveyId:guid}/{trialId:guid}")] - public async Task DeleteTrialSiteSurvey(Guid trialSiteSurveyId) - { - - if (await _trialSiteSurveyRepository.AnyAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock)) + if (await _trialSiteSurveyRepository.AnyAsync(t => t.Id == addOrEditTrialSiteSurvey.Id && t.State == TrialSiteSurveyEnum.PMCreatedAndLock)) { return ResponseOutput.NotOk("已锁定,不允许操作"); } + } + var entity = await _trialSiteSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteSurvey, true); - var success = await _trialSiteSurveyRepository.BatchDeleteAsync(t => t.Id == trialSiteSurveyId); + return ResponseOutput.Ok(entity.Id.ToString()); + } - return ResponseOutput.Result(success); + + /// + /// 删除调研表 + /// + /// + /// + [HttpDelete("{trialSiteSurveyId:guid}/{trialId:guid}")] + public async Task DeleteTrialSiteSurvey(Guid trialSiteSurveyId) + { + + if (await _trialSiteSurveyRepository.AnyAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock)) + { + return ResponseOutput.NotOk("已锁定,不允许操作"); } + var success = await _trialSiteSurveyRepository.BatchDeleteAsync(t => t.Id == trialSiteSurveyId); - /// - /// 获取 项目 site的调研记录 New - /// - /// - [HttpPost] - public async Task> GetTrialSiteSurveyList(TrialSiteSurveyQueryDTO surveyQueryDTO) + return ResponseOutput.Result(success); + } + + + /// + /// 获取 项目 site的调研记录 New + /// + /// + [HttpPost] + public async Task> GetTrialSiteSurveyList(TrialSiteSurveyQueryDTO surveyQueryDTO) + { + var trialSiteSurveyQueryable = _trialSiteSurveyRepository.Where(t => t.TrialId == surveyQueryDTO.TrialId).IgnoreQueryFilters() + .WhereIf(surveyQueryDTO.SiteId != null, t => t.SiteId == surveyQueryDTO.SiteId) + .WhereIf(surveyQueryDTO.IsDeleted != null, t => t.IsDeleted == surveyQueryDTO.IsDeleted) + .WhereIf(!string.IsNullOrWhiteSpace(surveyQueryDTO.UserKeyInfo), t => t.UserName.Contains(surveyQueryDTO.UserKeyInfo) || t.Phone.Contains(surveyQueryDTO.UserKeyInfo) || t.Email.Contains(surveyQueryDTO.UserKeyInfo)) + .WhereIf(surveyQueryDTO.State != null, t => t.State == surveyQueryDTO.State) + .WhereIf(surveyQueryDTO.UpdateTimeBegin != null, t => t.UpdateTime >= surveyQueryDTO.UpdateTimeBegin) + .WhereIf(surveyQueryDTO.UpdateTimeEnd != null, t => t.UpdateTime <= surveyQueryDTO.UpdateTimeEnd) + + .ProjectTo(_mapper.ConfigurationProvider); + + return await trialSiteSurveyQueryable.ToPagedListAsync(surveyQueryDTO.PageIndex, surveyQueryDTO.PageSize, surveyQueryDTO.SortField, surveyQueryDTO.Asc); + } + + + /// + /// 项目Site调研用户列表 所有site的调研用户 最新的调研表的记录的用户 new + /// + /// + public async Task> TrialSiteSurveyUserList(TrialSiteUserSurveyAllQuery queryParam) + { + + + var groupSelectIdQuery = + _trialSiteSurveyRepository.Where(t => t.TrialId == queryParam.TrialId) + .WhereIf(queryParam.SiteId != null, t => t.SiteId == queryParam.SiteId) + .WhereIf(!string.IsNullOrEmpty(queryParam.FormWriterKeyInfo), t => (t.UserName).Contains(queryParam.FormWriterKeyInfo) || t.Email.Contains(queryParam.FormWriterKeyInfo) || t.Phone.Contains(queryParam.FormWriterKeyInfo)) + .GroupBy(t => t.SiteId) + .Select(g => g.OrderByDescending(u => u.CreateTime).Select(t => t.Id).First()); + + + var query = _trialSiteUserSurveyRepository + .Where(t => groupSelectIdQuery.Contains(t.TrialSiteSurveyId)) + .WhereIf(queryParam.UserTypeId != null, t => t.UserTypeId == queryParam.UserTypeId) + .WhereIf(queryParam.IsGenerateAccount != null, t => t.IsGenerateAccount == queryParam.IsGenerateAccount) + .WhereIf(queryParam.TrialRoleNameId != null, t => t.TrialRoleNameId == queryParam.TrialRoleNameId) + .WhereIf(queryParam.State != null && queryParam.State != TrialSiteUserStateEnum.OverTime, t => t.InviteState == queryParam.State) + .WhereIf(queryParam.State != null && queryParam.State == TrialSiteUserStateEnum.OverTime, t => t.InviteState == TrialSiteUserStateEnum.HasSend && t.ExpireTime < DateTime.Now) + .WhereIf(!string.IsNullOrEmpty(queryParam.UserName), t => (t.LastName + " / " + t.FirstName).Contains(queryParam.UserName)) + .WhereIf(!string.IsNullOrEmpty(queryParam.OrganizationName), t => t.OrganizationName.Contains(queryParam.OrganizationName)) + + .ProjectTo(_mapper.ConfigurationProvider); + + //var query = _trialSiteSurveyRepository.Where(t => t.TrialId == queryParam.TrialId && t.IsAbandon == false) + // .WhereIf(queryParam.SiteId != null, t => t.SiteId == queryParam.SiteId) + // .WhereIf(!string.IsNullOrEmpty(queryParam.FormWriterKeyInfo), t => (t.UserName).Contains(queryParam.FormWriterKeyInfo) || t.Email.Contains(queryParam.FormWriterKeyInfo) || t.Phone.Contains(queryParam.FormWriterKeyInfo)) + // .GroupBy(t => t.SiteId) + // .Select(g => g.OrderByDescending(u => u.CreateTime).FirstOrDefault()) + // .SelectMany(t => t.TrialSiteUserSurveyList) + //.WhereIf(queryParam.UserTypeId != null, t => t.UserTypeId == queryParam.UserTypeId) + //.WhereIf(queryParam.IsGenerateAccount != null, t => t.IsGenerateAccount == queryParam.IsGenerateAccount) + //.WhereIf(queryParam.TrialRoleNameId != null, t => t.TrialRoleNameId == queryParam.TrialRoleNameId) + //.WhereIf(queryParam.State != null && queryParam.State != TrialSiteUserStateEnum.OverTime, t => t.InviteState == queryParam.State) + //.WhereIf(queryParam.State != null && queryParam.State == TrialSiteUserStateEnum.OverTime, t => t.InviteState == TrialSiteUserStateEnum.HasSend && t.ExpireTime < DateTime.Now) + //.WhereIf(!string.IsNullOrEmpty(queryParam.UserKeyInfo), t => (t.LastName + " / " + t.FirstName).Contains(queryParam.UserKeyInfo) || t.Email.Contains(queryParam.UserKeyInfo) || t.Phone.Contains(queryParam.UserKeyInfo)) + //.ProjectTo(_mapper.ConfigurationProvider); + + return await query.ToPagedListAsync(queryParam.PageIndex, queryParam.PageSize, queryParam.SortField, queryParam.Asc); + + + + + //return await query.ToPagedListAsync(queryParam.PageIndex, queryParam.PageSize, queryParam.SortField, queryParam.Asc); + } + + + + /// + /// 初始登陆界面 项目基本信息+下拉框数据 + /// + /// + /// + [AllowAnonymous] + [HttpGet("{trialId:guid}")] + public async Task GetTrialSurveyInitInfo(Guid trialId) + { + var info = await _repository.Where(t => t.Id == trialId).ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync().IfNullThrowException(); + + return info; + } + + + /// + /// 驳回 New + /// + /// + public async Task SubmissionRejection(TrialSiteSubmitBackCommand trialSiteSubmitBackCommand) + { + var trialSiteSurveyId = trialSiteSubmitBackCommand.TrialSiteSurveyId; + + var survey = await _trialSiteSurveyRepository.FirstOrDefaultAsync(t => t.Id == trialSiteSurveyId); + + survey.LatestBackReason = trialSiteSubmitBackCommand.LatestBackReason; + + User user = null; + + var messageToSend = new MimeMessage(); + //发件地址 + messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com")); + + //主题 + messageToSend.Subject = "GRR Site survey ( Rejection )"; + + + if (await _repository.AnyAsync(t => t.State == TrialSiteSurveyEnum.PMCreatedAndLock && t.Id == trialSiteSurveyId)) { - var trialSiteSurveyQueryable = _trialSiteSurveyRepository.Where(t => t.TrialId == surveyQueryDTO.TrialId).IgnoreQueryFilters() - .WhereIf(surveyQueryDTO.SiteId != null, t => t.SiteId == surveyQueryDTO.SiteId) - .WhereIf(surveyQueryDTO.IsDeleted != null, t => t.IsDeleted == surveyQueryDTO.IsDeleted) - .WhereIf(!string.IsNullOrWhiteSpace(surveyQueryDTO.UserKeyInfo), t => t.UserName.Contains(surveyQueryDTO.UserKeyInfo) || t.Phone.Contains(surveyQueryDTO.UserKeyInfo) || t.Email.Contains(surveyQueryDTO.UserKeyInfo)) - .WhereIf(surveyQueryDTO.State != null, t => t.State == surveyQueryDTO.State) - .WhereIf(surveyQueryDTO.UpdateTimeBegin != null, t => t.UpdateTime >= surveyQueryDTO.UpdateTimeBegin) - .WhereIf(surveyQueryDTO.UpdateTimeEnd != null, t => t.UpdateTime <= surveyQueryDTO.UpdateTimeEnd) - - .ProjectTo(_mapper.ConfigurationProvider); - - return await trialSiteSurveyQueryable.ToPagedListAsync(surveyQueryDTO.PageIndex, surveyQueryDTO.PageSize, surveyQueryDTO.SortField, surveyQueryDTO.Asc); + return ResponseOutput.NotOk("已锁定,不允许操作"); } - - /// - /// 项目Site调研用户列表 所有site的调研用户 最新的调研表的记录的用户 new - /// - /// - public async Task> TrialSiteSurveyUserList(TrialSiteUserSurveyAllQuery queryParam) + if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM) { + //SPM 给填表人发 + messageToSend.To.Add(new MailboxAddress(String.Empty, survey.Email)); - var groupSelectIdQuery = - _trialSiteSurveyRepository.Where(t => t.TrialId == queryParam.TrialId) - .WhereIf(queryParam.SiteId != null, t => t.SiteId == queryParam.SiteId) - .WhereIf(!string.IsNullOrEmpty(queryParam.FormWriterKeyInfo), t => (t.UserName).Contains(queryParam.FormWriterKeyInfo) || t.Email.Contains(queryParam.FormWriterKeyInfo) || t.Phone.Contains(queryParam.FormWriterKeyInfo)) - .GroupBy(t => t.SiteId) - .Select(g => g.OrderByDescending(u => u.CreateTime).Select(t => t.Id).First()); - - - var query = _trialSiteUserSurveyRepository - .Where(t => groupSelectIdQuery.Contains(t.TrialSiteSurveyId)) - .WhereIf(queryParam.UserTypeId != null, t => t.UserTypeId == queryParam.UserTypeId) - .WhereIf(queryParam.IsGenerateAccount != null, t => t.IsGenerateAccount == queryParam.IsGenerateAccount) - .WhereIf(queryParam.TrialRoleNameId != null, t => t.TrialRoleNameId == queryParam.TrialRoleNameId) - .WhereIf(queryParam.State != null && queryParam.State != TrialSiteUserStateEnum.OverTime, t => t.InviteState == queryParam.State) - .WhereIf(queryParam.State != null && queryParam.State == TrialSiteUserStateEnum.OverTime, t => t.InviteState == TrialSiteUserStateEnum.HasSend && t.ExpireTime < DateTime.Now) - .WhereIf(!string.IsNullOrEmpty(queryParam.UserName), t => (t.LastName + " / " + t.FirstName).Contains(queryParam.UserName)) - .WhereIf(!string.IsNullOrEmpty(queryParam.OrganizationName), t => t.OrganizationName.Contains(queryParam.OrganizationName)) - - .ProjectTo(_mapper.ConfigurationProvider); - - //var query = _trialSiteSurveyRepository.Where(t => t.TrialId == queryParam.TrialId && t.IsAbandon == false) - // .WhereIf(queryParam.SiteId != null, t => t.SiteId == queryParam.SiteId) - // .WhereIf(!string.IsNullOrEmpty(queryParam.FormWriterKeyInfo), t => (t.UserName).Contains(queryParam.FormWriterKeyInfo) || t.Email.Contains(queryParam.FormWriterKeyInfo) || t.Phone.Contains(queryParam.FormWriterKeyInfo)) - // .GroupBy(t => t.SiteId) - // .Select(g => g.OrderByDescending(u => u.CreateTime).FirstOrDefault()) - // .SelectMany(t => t.TrialSiteUserSurveyList) - //.WhereIf(queryParam.UserTypeId != null, t => t.UserTypeId == queryParam.UserTypeId) - //.WhereIf(queryParam.IsGenerateAccount != null, t => t.IsGenerateAccount == queryParam.IsGenerateAccount) - //.WhereIf(queryParam.TrialRoleNameId != null, t => t.TrialRoleNameId == queryParam.TrialRoleNameId) - //.WhereIf(queryParam.State != null && queryParam.State != TrialSiteUserStateEnum.OverTime, t => t.InviteState == queryParam.State) - //.WhereIf(queryParam.State != null && queryParam.State == TrialSiteUserStateEnum.OverTime, t => t.InviteState == TrialSiteUserStateEnum.HasSend && t.ExpireTime < DateTime.Now) - //.WhereIf(!string.IsNullOrEmpty(queryParam.UserKeyInfo), t => (t.LastName + " / " + t.FirstName).Contains(queryParam.UserKeyInfo) || t.Email.Contains(queryParam.UserKeyInfo) || t.Phone.Contains(queryParam.UserKeyInfo)) - //.ProjectTo(_mapper.ConfigurationProvider); - - return await query.ToPagedListAsync(queryParam.PageIndex, queryParam.PageSize, queryParam.SortField, queryParam.Asc); - - - - - //return await query.ToPagedListAsync(queryParam.PageIndex, queryParam.PageSize, queryParam.SortField, queryParam.Asc); + survey.State = TrialSiteSurveyEnum.ToSubmit; } - - - - /// - /// 初始登陆界面 项目基本信息+下拉框数据 - /// - /// - /// - [AllowAnonymous] - [HttpGet("{trialId:guid}")] - public async Task GetTrialSurveyInitInfo(Guid trialId) + else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM) { - var info = await _repository.Where(t => t.Id == trialId).ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync().IfNullThrowException(); + var hasSPMOrCPM = await _trialSiteSurveyRepository.AnyAsync(t => t.TrialId == trialSiteSubmitBackCommand.TrialId && t.Trial.TrialUserList.Any(u => u.User.UserTypeEnum == UserTypeEnum.SPM || u.User.UserTypeEnum == UserTypeEnum.CPM)); - return info; - } - - - /// - /// 驳回 New - /// - /// - public async Task SubmissionRejection(TrialSiteSubmitBackCommand trialSiteSubmitBackCommand) - { - var trialSiteSurveyId = trialSiteSubmitBackCommand.TrialSiteSurveyId; - - var survey = await _trialSiteSurveyRepository.FirstOrDefaultAsync(t => t.Id == trialSiteSurveyId); - - survey.LatestBackReason = trialSiteSubmitBackCommand.LatestBackReason; - - User user = null; - - var messageToSend = new MimeMessage(); - //发件地址 - messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com")); - - //主题 - messageToSend.Subject = "GRR Site survey ( Rejection )"; - - - if (await _repository.AnyAsync(t => t.State == TrialSiteSurveyEnum.PMCreatedAndLock && t.Id == trialSiteSurveyId)) + if (hasSPMOrCPM) { - return ResponseOutput.NotOk("已锁定,不允许操作"); + + //PM 给SPM发 (初审人) + user = await _userRepository.FirstOrDefaultAsync(t => t.Id == survey.PreliminaryUserId); + + messageToSend.To.Add(new MailboxAddress(String.Empty, survey.PreliminaryUserId == null ? survey.Email : user.EMail)); + + survey.State = TrialSiteSurveyEnum.CRCSubmitted; + + survey.ReviewerUserId = null; + survey.ReviewerTime = null; } - - if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM) + else { - - //SPM 给填表人发 + //没有SPM 给填表人发 messageToSend.To.Add(new MailboxAddress(String.Empty, survey.Email)); survey.State = TrialSiteSurveyEnum.ToSubmit; + + survey.PreliminaryUserId = null; + survey.ReviewerUserId = null; + survey.PreliminaryTime = null; + survey.ReviewerTime = null; + + } - else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM) - { - var hasSPMOrCPM = await _trialSiteSurveyRepository.AnyAsync(t => t.TrialId == trialSiteSubmitBackCommand.TrialId && t.Trial.TrialUserList.Any(u => u.User.UserTypeEnum == UserTypeEnum.SPM || u.User.UserTypeEnum == UserTypeEnum.CPM)); - - if (hasSPMOrCPM) - { - - //PM 给SPM发 (初审人) - user = await _userRepository.FirstOrDefaultAsync(t => t.Id == survey.PreliminaryUserId); - - messageToSend.To.Add(new MailboxAddress(String.Empty, survey.PreliminaryUserId == null ? survey.Email : user.EMail)); - - survey.State = TrialSiteSurveyEnum.CRCSubmitted; - - survey.ReviewerUserId = null; - survey.ReviewerTime = null; - } - else - { - //没有SPM 给填表人发 - messageToSend.To.Add(new MailboxAddress(String.Empty, survey.Email)); - - survey.State = TrialSiteSurveyEnum.ToSubmit; - - survey.PreliminaryUserId = null; - survey.ReviewerUserId = null; - survey.PreliminaryTime = null; - survey.ReviewerTime = null; + } - } - } + var builder = new BodyBuilder(); + var trialInfo = await _repository.FirstOrDefaultAsync(t => t.Id == trialSiteSubmitBackCommand.TrialId); - var builder = new BodyBuilder(); + var siteInfo = await _trialSiteRepository.FirstOrDefaultAsync(t => t.TrialId == trialSiteSubmitBackCommand.TrialId && t.SiteId == survey.SiteId, true); - var trialInfo = await _repository.FirstOrDefaultAsync(t => t.Id == trialSiteSubmitBackCommand.TrialId); - - var siteInfo = await _trialSiteRepository.FirstOrDefaultAsync(t => t.TrialId == trialSiteSubmitBackCommand.TrialId && t.SiteId == survey.SiteId, true); - - builder.HtmlBody = @$" + builder.HtmlBody = @$"
@@ -558,146 +583,146 @@ namespace IRaCIS.Core.Application.Contracts
"; - messageToSend.Body = builder.ToMessageBody(); + messageToSend.Body = builder.ToMessageBody(); - using (var smtp = new MailKit.Net.Smtp.SmtpClient()) - { - - smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; - - - await smtp.ConnectAsync("smtp.163.com", 25, SecureSocketOptions.StartTls); - - - await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH"); - - - await smtp.SendAsync(messageToSend); - - - await smtp.DisconnectAsync(true); - } - - await _trialSiteSurveyRepository.SaveChangesAsync(); - - return ResponseOutput.Ok(); - } - - - /// - /// 驳回 - /// - /// - /// - /// - [HttpPut("{trialId:guid}/{trialSiteSurveyId:guid}")] - [Obsolete] - public async Task SubmissionRejection(Guid trialId, Guid trialSiteSurveyId) - { - if (await _repository.AnyAsync(t => t.State == TrialSiteSurveyEnum.PMCreatedAndLock && t.Id == trialSiteSurveyId)) - { - return ResponseOutput.NotOk("已锁定,不允许操作"); - } - - if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM) - { - await _repository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.ToSubmit }); - } - else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM) - { - var hasSPMOrCPM = await _trialSiteSurveyRepository.AnyAsync(t => t.TrialId == trialId && t.Trial.TrialUserList.Any(u => u.User.UserTypeEnum == UserTypeEnum.SPM || u.User.UserTypeEnum == UserTypeEnum.CPM)); - - if (hasSPMOrCPM) - { - await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted }); - - } - else - { - await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.ToSubmit }); - } - } - return ResponseOutput.Ok(); - - } - - - [HttpPut("{trialId:guid}/{trialSiteSurveyId:guid}")] - public async Task AbandonSiteSurvey(Guid trialSiteSurveyId) - { - var survey = (await _trialSiteSurveyRepository.FirstOrDefaultAsync(t => t.Id == trialSiteSurveyId, true)).IfNullThrowConvertException(); - - if (survey.State != TrialSiteSurveyEnum.ToSubmit) - { - return ResponseOutput.NotOk("只允许废除未提交的记录"); - } - - survey.IsDeleted = true; - - await _repository.SaveChangesAsync(); - - return ResponseOutput.Ok(); - - } - - - public async Task SendInviteEmail(InviteEmailCommand inviteEmailCommand) + using (var smtp = new MailKit.Net.Smtp.SmtpClient()) { - var trialInfo = await _repository.FirstOrDefaultAsync(t => t.Id == inviteEmailCommand.TrialId); + smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; - foreach (var item in inviteEmailCommand.UserList) + await smtp.ConnectAsync("smtp.163.com", 25, SecureSocketOptions.StartTls); + + + await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH"); + + + await smtp.SendAsync(messageToSend); + + + await smtp.DisconnectAsync(true); + } + + await _trialSiteSurveyRepository.SaveChangesAsync(); + + return ResponseOutput.Ok(); + } + + + /// + /// 驳回 + /// + /// + /// + /// + [HttpPut("{trialId:guid}/{trialSiteSurveyId:guid}")] + [Obsolete] + public async Task SubmissionRejection(Guid trialId, Guid trialSiteSurveyId) + { + if (await _repository.AnyAsync(t => t.State == TrialSiteSurveyEnum.PMCreatedAndLock && t.Id == trialSiteSurveyId)) + { + return ResponseOutput.NotOk("已锁定,不允许操作"); + } + + if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM) + { + await _repository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.ToSubmit }); + } + else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM) + { + var hasSPMOrCPM = await _trialSiteSurveyRepository.AnyAsync(t => t.TrialId == trialId && t.Trial.TrialUserList.Any(u => u.User.UserTypeEnum == UserTypeEnum.SPM || u.User.UserTypeEnum == UserTypeEnum.CPM)); + + if (hasSPMOrCPM) + { + await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted }); + + } + else + { + await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.ToSubmit }); + } + } + return ResponseOutput.Ok(); + + } + + + [HttpPut("{trialId:guid}/{trialSiteSurveyId:guid}")] + public async Task AbandonSiteSurvey(Guid trialSiteSurveyId) + { + var survey = (await _trialSiteSurveyRepository.FirstOrDefaultAsync(t => t.Id == trialSiteSurveyId, true)).IfNullThrowConvertException(); + + if (survey.State != TrialSiteSurveyEnum.ToSubmit) + { + return ResponseOutput.NotOk("只允许废除未提交的记录"); + } + + survey.IsDeleted = true; + + await _repository.SaveChangesAsync(); + + return ResponseOutput.Ok(); + + } + + + public async Task SendInviteEmail(InviteEmailCommand inviteEmailCommand) + { + + var trialInfo = await _repository.FirstOrDefaultAsync(t => t.Id == inviteEmailCommand.TrialId); + + + foreach (var item in inviteEmailCommand.UserList) + { + + var messageToSend = new MimeMessage(); + //发件地址 + messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com")); + //收件地址 + messageToSend.To.Add(new MailboxAddress(String.Empty, item.Email)); + //主题 + messageToSend.Subject = $"[{trialInfo.ResearchProgramNo}] 邀请"; + + var builder = new BodyBuilder(); + + //找下系统中是否存在该用户类型的 并且邮箱 或者手机的账户 + var sysUserInfo = await _userRepository.Where(t => t.UserTypeId == item.UserTypeId && t.EMail == item.Email).Include(t => t.UserTypeRole).FirstOrDefaultAsync(); + + //int verificationCode = new Random().Next(100000, 1000000); + + //var baseApiUrl = baseUrl.Remove(baseUrl.IndexOf("#")) + "api"; + + + if (sysUserInfo == null) { - var messageToSend = new MimeMessage(); - //发件地址 - messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com")); - //收件地址 - messageToSend.To.Add(new MailboxAddress(String.Empty, item.Email)); - //主题 - messageToSend.Subject = "GRR Site survey (Trial Invite)"; - - var builder = new BodyBuilder(); - - //找下系统中是否存在该用户类型的 并且邮箱 或者手机的账户 - var sysUserInfo = await _userRepository.Where(t => t.UserTypeId == item.UserTypeId && t.EMail == item.Email).Include(t => t.UserTypeRole).FirstOrDefaultAsync(); - - //int verificationCode = new Random().Next(100000, 1000000); - - //var baseApiUrl = baseUrl.Remove(baseUrl.IndexOf("#")) + "api"; - - - if (sysUserInfo == null) + lock (lockObj) { + var saveItem = _mapper.Map(item); - lock (lockObj) - { - var saveItem = _mapper.Map(item); + saveItem.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1; - saveItem.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1; + saveItem.UserCode = AppSettings.UserCodePrefix + saveItem.Code.ToString("D4"); - saveItem.UserCode = AppSettings.UserCodePrefix + saveItem.Code.ToString("D4"); + saveItem.UserName = saveItem.UserCode; - saveItem.UserName = saveItem.UserCode; + saveItem.UserTypeEnum = _repository.Where(t => t.Id == saveItem.UserTypeId).Select(t => t.UserTypeEnum).First(); - saveItem.UserTypeEnum = _repository.Where(t => t.Id == saveItem.UserTypeId).Select(t => t.UserTypeEnum).First(); + //saveItem.Password = MD5Helper.Md5(verificationCode.ToString()); - //saveItem.Password = MD5Helper.Md5(verificationCode.ToString()); + _ = _repository.AddAsync(saveItem).Result; - _ = _repository.AddAsync(saveItem).Result; - - _ = _repository.SaveChangesAsync().Result; + _ = _repository.SaveChangesAsync().Result; - sysUserInfo = saveItem; - } - + sysUserInfo = saveItem; } + } - builder.HtmlBody = @$" + + builder.HtmlBody = @$"
@@ -716,104 +741,104 @@ namespace IRaCIS.Core.Application.Contracts - messageToSend.Body = builder.ToMessageBody(); + messageToSend.Body = builder.ToMessageBody(); - using (var smtp = new MailKit.Net.Smtp.SmtpClient()) + using (var smtp = new MailKit.Net.Smtp.SmtpClient()) + { + + smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; + + smtp.MessageSent += (sender, args) => { - smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; + _ = _trialSiteUserSurveyRepository.BatchUpdateAsync(t => t.Id == item.Id, u => new TrialSiteUserSurvey() { IsGenerateSuccess = true, InviteState = TrialSiteUserStateEnum.HasSend, IsJoin = null, ConfirmTime = null, RejectReason = String.Empty, SystemUserId = sysUserInfo.Id, ExpireTime = DateTime.Now.AddDays(7) }).Result; - smtp.MessageSent += (sender, args) => - { - - _ = _trialSiteUserSurveyRepository.BatchUpdateAsync(t => t.Id == item.Id, u => new TrialSiteUserSurvey() { IsGenerateSuccess = true, InviteState = TrialSiteUserStateEnum.HasSend, IsJoin = null, ConfirmTime = null, RejectReason = String.Empty, SystemUserId = sysUserInfo.Id, ExpireTime = DateTime.Now.AddDays(7) }).Result; - - }; + }; - await smtp.ConnectAsync("smtp.163.com", 25, SecureSocketOptions.StartTls); + await smtp.ConnectAsync("smtp.163.com", 25, SecureSocketOptions.StartTls); - await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH"); + await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH"); - await smtp.SendAsync(messageToSend); + await smtp.SendAsync(messageToSend); - await smtp.DisconnectAsync(true); - } + await smtp.DisconnectAsync(true); + } + + } + + + return ResponseOutput.Ok(); + } + + /// + /// 提交 后台自动识别是谁提交 + /// + /// + /// + //[TypeFilter(typeof(TrialResourceFilter))] + [HttpPost] + public async Task TrialSurveySubmit(TrialSiteSurvyeSubmitDTO siteSurvyeSubmit) + { + + var trialId = siteSurvyeSubmit.TrialId; + var trialSiteSurveyId = siteSurvyeSubmit.TrialSiteSurveyId; + + if (_userInfo.IsAdmin) + { + return ResponseOutput.NotOk("不允许Admin操作"); + } + + + if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.Undefined) + { + var hasSPMOrCPM = await _trialSiteSurveyRepository.AnyAsync(t => t.TrialId == trialId && t.Trial.TrialUserList.Any(u => u.User.UserTypeEnum == UserTypeEnum.SPM || u.User.UserTypeEnum == UserTypeEnum.CPM)); + + if (hasSPMOrCPM) + { + await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted }); + + } + else + { + await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.SPMApproved }); } - - return ResponseOutput.Ok(); } - - /// - /// 提交 后台自动识别是谁提交 - /// - /// - /// - //[TypeFilter(typeof(TrialResourceFilter))] - [HttpPost] - public async Task TrialSurveySubmit(TrialSiteSurvyeSubmitDTO siteSurvyeSubmit) + else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM) { - var trialId = siteSurvyeSubmit.TrialId; - var trialSiteSurveyId = siteSurvyeSubmit.TrialSiteSurveyId; + await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.CRCSubmitted, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.SPMApproved, PreliminaryUserId = _userInfo.Id, PreliminaryTime = DateTime.Now }); - if (_userInfo.IsAdmin) - { - return ResponseOutput.NotOk("不允许Admin操作"); - } + } + else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager) + { + + var trialSiteSurvey = _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId).FirstOrDefault(); + + if (trialSiteSurvey == null) return Null404NotFound(trialSiteSurvey); - if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.Undefined) - { - var hasSPMOrCPM = await _trialSiteSurveyRepository.AnyAsync(t => t.TrialId == trialId && t.Trial.TrialUserList.Any(u => u.User.UserTypeEnum == UserTypeEnum.SPM || u.User.UserTypeEnum == UserTypeEnum.CPM)); - - if (hasSPMOrCPM) - { - await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted }); - - } - else - { - await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.SPMApproved }); - - } - - } - else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM) - { - - await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.CRCSubmitted, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.SPMApproved, PreliminaryUserId = _userInfo.Id, PreliminaryTime = DateTime.Now }); - - } - else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager) - { - - var trialSiteSurvey = _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId).FirstOrDefault(); - - if (trialSiteSurvey == null) return Null404NotFound(trialSiteSurvey); + //已生成的不管 管的只需要是 生成失败的并且需要生成账号的 + var needGenerateList = _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsGenerateAccount && t.IsGenerateSuccess == false).ProjectTo(_mapper.ConfigurationProvider).ToList(); - //已生成的不管 管的只需要是 生成失败的并且需要生成账号的 - var needGenerateList = _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsGenerateAccount && t.IsGenerateSuccess == false).ProjectTo(_mapper.ConfigurationProvider).ToList(); + await SendInviteEmail(new InviteEmailCommand() { TrialId = trialId, RouteUrl = siteSurvyeSubmit.RouteUrl, UserList = needGenerateList }); + await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.SPMApproved, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.PMCreatedAndLock, ReviewerUserId = _userInfo.Id, ReviewerTime = DateTime.Now }); - await SendInviteEmail(new InviteEmailCommand() { TrialId = trialId, RouteUrl = siteSurvyeSubmit.RouteUrl, UserList = needGenerateList }); - - await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.SPMApproved, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.PMCreatedAndLock, ReviewerUserId = _userInfo.Id, ReviewerTime = DateTime.Now }); - - } - - return ResponseOutput.Ok(); } - - - - + return ResponseOutput.Ok(); } + + + + + } +} diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs index 91d43ff00..0bb923bbf 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs @@ -222,7 +222,7 @@ namespace IRaCIS.Core.Application.Service //收件地址 messageToSend.To.Add(new MailboxAddress(String.Empty, userInfo.Email)); //主题 - messageToSend.Subject = "GRR External User survey (Invite)"; + messageToSend.Subject = $"[{trialInfo.ResearchProgramNo}] 邀请"; //var baseApiUrl = sendEmail.BaseUrl.Remove(sendEmail.BaseUrl.IndexOf("#")) + "api"; @@ -325,17 +325,18 @@ namespace IRaCIS.Core.Application.Service if (editTrialUserPreparation.IsJoin == true) { + var trialInfo = await _repository.FirstOrDefaultAsync(t => t.Id == needUpdate.TrialId); + var messageToSend = new MimeMessage(); //发件地址 messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com")); //收件地址 messageToSend.To.Add(new MailboxAddress(String.Empty, needUpdate.Email)); //主题 - messageToSend.Subject = $"GRR External User survey (Trial {(editTrialUserPreparation.IsJoin == false ? "Reject Success" : "Join Success")})"; + messageToSend.Subject = $"[{trialInfo.ResearchProgramNo}] 账号信息"; var builder = new BodyBuilder(); - var trialInfo = await _repository.FirstOrDefaultAsync(t => t.Id == needUpdate.TrialId); var sysUserInfo = await _userRepository.Where(t => t.Id == needUpdate.SystemUserId).Include(t => t.UserTypeRole).FirstOrDefaultAsync(); @@ -493,6 +494,8 @@ namespace IRaCIS.Core.Application.Service var success = await _trialExternalUseRepository.SaveChangesAsync(); + var trialInfo = await _repository.FirstOrDefaultAsync(t => t.Id == needUpdate.TrialSiteSurvey.TrialId); + var messageToSend = new MimeMessage(); //发件地址 @@ -500,11 +503,11 @@ namespace IRaCIS.Core.Application.Service //收件地址 messageToSend.To.Add(new MailboxAddress(String.Empty, editInfo.IsJoin == true ? needUpdate.Email : revieweUser.EMail)); //主题 - messageToSend.Subject = $"GRR Site survey (Trial {(editInfo.IsJoin == false ? "Reject" : "Join Success")})"; + messageToSend.Subject = $"[{trialInfo.ResearchProgramNo}] 账号信息"; + var builder = new BodyBuilder(); - var trialInfo = await _repository.FirstOrDefaultAsync(t => t.Id == needUpdate.TrialSiteSurvey.TrialId); var sysUserInfo = await _userRepository.Where(t => t.Id == needUpdate.SystemUserId).Include(t => t.UserTypeRole).FirstOrDefaultAsync(); @@ -554,61 +557,63 @@ namespace IRaCIS.Core.Application.Service
"; + + messageToSend.Body = builder.ToMessageBody(); + + using (var smtp = new MailKit.Net.Smtp.SmtpClient()) + { + + smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; + + await smtp.ConnectAsync("smtp.163.com", 25, SecureSocketOptions.StartTls); + + await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH"); + + await smtp.SendAsync(messageToSend); + + await smtp.DisconnectAsync(true); + } } - else - { + //else + //{ - builder.HtmlBody = @$" -
-
-
- {revieweUser.LastName + "/" + revieweUser.FirstName}: -
-
- 您好,{sysUserInfo.LastName + "/" + sysUserInfo.FirstName} 拒绝了参加 {trialInfo.ResearchProgramNo} 项目IRC相关工作的邀请。详细信息如下: -
-
-
- 项目编号: {trialInfo.TrialCode} -
-
- 试验方案号: {trialInfo.ResearchProgramNo} -
-
- 试验名称: {trialInfo.ExperimentName} -
-
- 用户名: {sysUserInfo.UserName} -
-
- 角色: {sysUserInfo.UserTypeRole.UserTypeShortName} -
-
- 拒绝原因: {editInfo.RejectReason} -
-
-
-
- "; + // builder.HtmlBody = @$" + //
+ //
+ //
+ // {revieweUser.LastName + "/" + revieweUser.FirstName}: + //
+ //
+ // 您好,{sysUserInfo.LastName + "/" + sysUserInfo.FirstName} 拒绝了参加 {trialInfo.ResearchProgramNo} 项目IRC相关工作的邀请。详细信息如下: + //
+ //
+ //
+ // 项目编号: {trialInfo.TrialCode} + //
+ //
+ // 试验方案号: {trialInfo.ResearchProgramNo} + //
+ //
+ // 试验名称: {trialInfo.ExperimentName} + //
+ //
+ // 用户名: {sysUserInfo.UserName} + //
+ //
+ // 角色: {sysUserInfo.UserTypeRole.UserTypeShortName} + //
+ //
+ // 拒绝原因: {editInfo.RejectReason} + //
+ //
+ //
+ //
+ // "; - } + //} - messageToSend.Body = builder.ToMessageBody(); - - using (var smtp = new MailKit.Net.Smtp.SmtpClient()) - { - - smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; - - await smtp.ConnectAsync("smtp.163.com", 25, SecureSocketOptions.StartTls); - - await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH"); - - await smtp.SendAsync(messageToSend); - - await smtp.DisconnectAsync(true); - } + return ResponseOutput.Ok(); diff --git a/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs b/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs index 62dbe26fa..9b61ccc1f 100644 --- a/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs +++ b/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs @@ -336,7 +336,7 @@ namespace IRaCIS.Core.Application.Contracts public string FirstName { get; set; } = string.Empty; public string LastName { get; set; } = string.Empty; - public DateTime StudyTime { get; set; } + public DateTime? StudyTime { get; set; } } public class StudyDTO diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index d1dd56264..950d63dcb 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -41,56 +41,7 @@ namespace IRaCIS.Core.Infra.EFCore #region 异步部分 - /// - /// 仅仅供字典表插入使用,因为efcore 动态映射列的问题 - /// - /// - /// - /// - /// - /// - public async Task InsertDictionaryAsync(TFrom from, params EntityVerifyExp[] verify) - { - var entity = _mapper.Map(from); - foreach (var verifyItem in verify.Where(t => t.verifyType != VerifyEnum.OnlyUpdate && t.IsVerify)) - { - if (await _dbSet.IgnoreQueryFilters().AnyAsync(verifyItem.VerifyExp).ConfigureAwait(false)) - { - throw new BusinessValidationFailedException(verifyItem.VerifyMsg); - } - } - - if (typeof(TEntity) == typeof(Dictionary)) - { - Type type = typeof(TFrom); - - //以下是不要ID这个字段的 比如自增列ID 就不能像上名那样写 - var properties = type.GetProperties().Where(t => t.Name != "Id"); - - - string strSqlName = string.Join(",", properties.Select(p => $"[{p.Name}]").ToArray()); - - string strSqlValue = string.Join(",", properties.Select(P => $"@{P.Name}").ToArray()); - - string strSql = $"insert into {nameof(Dictionary)} ( " + strSqlName + " ) values (" + strSqlValue + ")"; - - //para Sql是参数 - SqlParameter[] para = properties.Select(p => new SqlParameter($"@{p.Name}", p.GetValue(from, null))).ToArray(); - - - _dbContext.Database.ExecuteSqlRaw(strSql, para); - - return entity; - } - else - { - throw new Exception("仅仅供字典表插入使用,因为efcore 动态映射列的问题"); - //await _dbSet.BulkInsertAsync(new List() { entity }); - - //return entity; - } - } public async Task InsertOrUpdateAsync(TFrom from, bool autoSave = false, params EntityVerifyExp[] verify) { @@ -729,88 +680,8 @@ namespace IRaCIS.Core.Infra.EFCore } - /// - /// 杨中科 test 有问题 对于guid? 赋值null的时候 - /// - /// - /// - /// - //public async Task BatchUpdateAsync(Expression> where, - // Expression> updateFactory) - //{ - // var builder = _dbContext.BatchUpdate(); - - // Func func = updateFactory.Compile(); - - // List list = ((MemberInitExpression)updateFactory.Body).Bindings.Select((Func)(_param1 => _param1.Member.Name)).Select((Func)(_param1 => (PropertyInfo)typeof(TEntity).GetProperty(_param1, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))).ToList(); - - // TEntity applyObj = func(new TEntity()); - - // foreach (PropertyInfo prop in list) - // { - // var propName = prop.Name; - // var value = prop.GetValue(applyObj); - // builder.Set(propName, value?? DBNull.Value); - - // //PropertyInfo property = typeof(TEntity).GetProperty(prop.Name); - // //Type propertyType = property.PropertyType; - // //ParameterExpression parameterExpression = Expression.Parameter(typeof(TEntity)); - // //Type delegateType = typeof(Func<,>).MakeGenericType(typeof(TEntity), propertyType); - // //LambdaExpression nameExpr = Expression.Lambda(delegateType, (Expression)Expression.MakeMemberAccess((Expression)parameterExpression, (MemberInfo)property), parameterExpression); - // //Expression expression = (Expression)Expression.Constant(value); - - // //expression = (Expression)Expression.Convert(expression, propertyType); - - // //LambdaExpression valueExpr = Expression.Lambda(delegateType, expression, parameterExpression); - - - // //builder.Set< >(Func nameExpr, valueExpr); - - // } - // return await builder.Where(where).ExecuteAsync()>0; - //} - - //// Z.EntityFramework.Plus.EFCore - //public async Task BatchDeleteAsync(Expression> deleteFilter) - //{ - // return await _dbSet.IgnoreQueryFilters().Where(deleteFilter).DeleteFromQueryAsync() > 0; - //} - - //public async Task BatchUpdateAsync(Expression> where, Expression> updateFactory) - //{ - // return await _dbSet.IgnoreQueryFilters().Where(where).UpdateFromQueryAsync(updateFactory) > 0; - //} - - //public async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) - //{ - // _dbSet.UpdateRange(entities); - - // if (autoSave) - // { - // return await SaveChangesAsync(cancellationToken); - // } - // else - // { - // return false; - // } - //} - - - //public async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) - //{ - // _dbSet.RemoveRange(entities); - - // if (autoSave) - // { - // return await SaveChangesAsync(cancellationToken); - // } - // else - // { - // return false; - // } - //} #endregion @@ -912,7 +783,56 @@ namespace IRaCIS.Core.Infra.EFCore return _dbSet.AsNoTracking().ProjectTo(configuration, parameters, membersToExpand); } + /// + /// 仅仅供字典表插入使用,因为efcore 动态映射列的问题 + /// + /// + /// + /// + /// + /// + public async Task InsertDictionaryAsync(TFrom from, params EntityVerifyExp[] verify) + { + var entity = _mapper.Map(from); + foreach (var verifyItem in verify.Where(t => t.verifyType != VerifyEnum.OnlyUpdate && t.IsVerify)) + { + if (await _dbSet.IgnoreQueryFilters().AnyAsync(verifyItem.VerifyExp).ConfigureAwait(false)) + { + throw new BusinessValidationFailedException(verifyItem.VerifyMsg); + } + } + + if (typeof(TEntity) == typeof(Dictionary)) + { + Type type = typeof(TFrom); + + //以下是不要ID这个字段的 比如自增列ID 就不能像上名那样写 + var properties = type.GetProperties().Where(t => t.Name != "Id"); + + + string strSqlName = string.Join(",", properties.Select(p => $"[{p.Name}]").ToArray()); + + string strSqlValue = string.Join(",", properties.Select(P => $"@{P.Name}").ToArray()); + + string strSql = $"insert into {nameof(Dictionary)} ( " + strSqlName + " ) values (" + strSqlValue + ")"; + + //para Sql是参数 + SqlParameter[] para = properties.Select(p => new SqlParameter($"@{p.Name}", p.GetValue(from, null))).ToArray(); + + + _dbContext.Database.ExecuteSqlRaw(strSql, para); + + return entity; + } + else + { + throw new Exception("仅仅供字典表插入使用,因为efcore 动态映射列的问题"); + //await _dbSet.BulkInsertAsync(new List() { entity }); + + //return entity; + } + } #endregion }