//-------------------------------------------------------------------- // 此代码由T4模板自动生成 byzhouhang 20210918 // 生成时间 2021-12-23 13:20:59 // 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。 //-------------------------------------------------------------------- using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Domain.Share; using System.Text.RegularExpressions; using IRaCIS.Core.Infrastructure; using IRaCIS.Application.Services; using IRaCIS.Core.Application.Auth; using IRaCIS.Application.Contracts; using Microsoft.AspNetCore.Authorization; using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Infra.EFCore; using MailKit.Security; using MimeKit; namespace IRaCIS.Core.Application.Contracts { /// /// TrialSiteSurveyService /// [ApiExplorerSettings(GroupName = "Trial")] public class TrialSiteSurveyService : BaseService, ITrialSiteSurveyService { private readonly IRepository _trialSiteSurveyRepository; private readonly IRepository _trialSiteUserSurveyRepository; private readonly IRepository _userRepository; public TrialSiteSurveyService(IRepository trialSiteSurveyRepository,IRepository trialSiteUserSurveyRepository,IRepository userRepository) { _trialSiteSurveyRepository = trialSiteSurveyRepository; _trialSiteUserSurveyRepository = trialSiteUserSurveyRepository; _userRepository = userRepository; } private object lockObj { get; set; } = new object(); /// /// 发送验证码 /// /// /// /// [AllowAnonymous] public async Task SendVerifyCode(SiteSurveySendVerifyCode userInfo, [FromServices] IMailVerificationService _mailVerificationService) { var verificationType = userInfo.verificationType; //检查手机或者邮箱是否有效 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_-]+)+$")) { 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.EmailOrPhone, verificationCode); } //手机短信 else { } return ResponseOutput.Ok(); } /// /// 验证后 如果数据库该项目不存在该邮箱 那么就插入记录 存在 /// /// /// /// /// [HttpPost] [AllowAnonymous] public async Task VerifySendCode(LoginDto userInfo, [FromServices] ITokenService _tokenService) { var isReplaceUser = !string.IsNullOrEmpty(userInfo.ReplaceUserEmailOrPhone); if (userInfo.IsUpdate && isReplaceUser && !await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.ReplaceUserEmailOrPhone || t.Phone == userInfo.ReplaceUserEmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId)) { return ResponseOutput.NotOk("该项目Site不存在该交接人的调研记录,不允许选择更新"); } if (userInfo.IsUpdate && await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State != TrialSiteSurveyEnum.PMCreatedAndLock)) { return ResponseOutput.NotOk("您的记录未锁定,不允许选择更新,若已经提交,可被驳回后进行操作"); } //自己的记录锁定了 只能更新自己的,不能更新别人的(但是别人能更新自己锁定的) if (userInfo.IsUpdate && userInfo.ReplaceUserEmailOrPhone != userInfo.EmailOrPhone && await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock)) { //自己的锁了 想更新别人的 return ResponseOutput.NotOk("当前Site 您的调研记录已锁定,不允许更新其他人邮箱调研记录"); } //自己的锁定了 如果有其他未锁定的,也不能更新自己的 if (userInfo.IsUpdate && userInfo.ReplaceUserEmailOrPhone == userInfo.EmailOrPhone && await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock) && await _trialSiteSurveyRepository.AnyAsync(t => (t.Email != userInfo.EmailOrPhone && t.Phone != userInfo.EmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State != TrialSiteSurveyEnum.PMCreatedAndLock)) { return ResponseOutput.NotOk("当前Site 您的调研记录已锁定,也存在其他未锁定的记录,不允许更新自己的调研记录"); } ////存在未锁定的记录,却去更新已锁定的 if (userInfo.IsUpdate && userInfo.ReplaceUserEmailOrPhone != userInfo.EmailOrPhone && await _trialSiteSurveyRepository.AnyAsync(t => t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State != TrialSiteSurveyEnum.PMCreatedAndLock) && await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.ReplaceUserEmailOrPhone || t.Phone == userInfo.ReplaceUserEmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock) && !await _trialSiteSurveyRepository.AnyAsync(t => (t.Email == userInfo.ReplaceUserEmailOrPhone || t.Phone == userInfo.ReplaceUserEmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State != TrialSiteSurveyEnum.PMCreatedAndLock) ) { return ResponseOutput.NotOk("当前Site 存在未锁定的调研记录,不允许更新已锁定邮箱的调研记录"); } //var verificationRecord = await _repository // .FirstOrDefaultAsync(t => (t.EmailOrPhone == userInfo.EmailOrPhone) && t.Code == userInfo.verificationCode && t.CodeType == userInfo.verificationType); ////检查数据库是否存在该验证码 //if (verificationRecord == null) //{ // return ResponseOutput.NotOk("Verification code error"); //} //else //{ // //检查验证码是否失效 // if (verificationRecord.ExpirationTime < DateTime.Now) // { // return ResponseOutput.NotOk("The verification code has expired"); // } // else //验证码正确 并且 没有超时 { TrialSiteSurvey dbEntity = null; //替换交接人 if (isReplaceUser) { //该交接人的记录 是否有未锁定的 有就用未锁定的,没有就用 锁定的最后一条 var noLockedLastSurvey = await _trialSiteSurveyRepository.Where(t => (t.Email == userInfo.ReplaceUserEmailOrPhone || t.Phone == userInfo.ReplaceUserEmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock == false, true) .Include(u => u.TrialSiteEquipmentSurveyList).Include(u => u.TrialSiteUserSurveyList).OrderByDescending(t => t.CreateTime).FirstOrDefaultAsync(); //都是锁定的 if (noLockedLastSurvey == null) { var latestLock = await _trialSiteSurveyRepository.Where(t => t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId).OrderByDescending(t => t.CreateTime).FirstOrDefaultAsync(); if (latestLock!.Email != userInfo.ReplaceUserEmailOrPhone) { return ResponseOutput.NotOk($"该邮箱{userInfo.ReplaceUserEmailOrPhone }对应的调查表不是最新锁定的记录,不允许更新!"); } var lockedLastSurvey = await _trialSiteSurveyRepository.Where(t => (t.Email == userInfo.ReplaceUserEmailOrPhone || t.Phone == userInfo.ReplaceUserEmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId && t.State == TrialSiteSurveyEnum.PMCreatedAndLock == true) .Include(u => u.TrialSiteEquipmentSurveyList).Include(u => u.TrialSiteUserSurveyList).OrderByDescending(t => t.CreateTime).FirstOrDefaultAsync().IfNullThrowConvertException(); //Copy 一份 更换邮箱 var copy = lockedLastSurvey.Clone(); copy.State = TrialSiteSurveyEnum.ToSubmit; copy.Email = userInfo.EmailOrPhone; if (userInfo.ReplaceUserEmailOrPhone != userInfo.EmailOrPhone) { copy.UserName = String.Empty; copy.Phone = String.Empty; } copy.Id = Guid.Empty; copy.TrialSiteEquipmentSurveyList.ForEach(t => t.Id = Guid.Empty); copy.TrialSiteUserSurveyList.ForEach(t => t.Id = Guid.Empty); dbEntity = await _repository.AddAsync(copy); } else { //有未锁定的 更新下邮箱 noLockedLastSurvey.Email = userInfo.EmailOrPhone; noLockedLastSurvey.UserName = String.Empty; noLockedLastSurvey.Phone = String.Empty; dbEntity = noLockedLastSurvey; } ////邮箱相同的话 就是同一个人进来 copy一份 //if (userInfo.EmailOrPhone == userInfo.ReplaceUserEmailOrPhone) //{ // dbEntity = await _repository.Where(t => (t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone) && t.SiteId == userInfo.SiteId && t.TrialId == userInfo.TrialId).Include(u => u.TrialSiteEquipmentSurveyList).Include(u => u.TrialSiteUserSurveyList).FirstOrDefaultAsync().IfNullThrowConvertException(); // var clone = dbEntity.Clone(); // clone.Id = Guid.Empty; // clone.TrialSiteEquipmentSurveyList.ForEach(t => t.Id = Guid.Empty); // clone.TrialSiteUserSurveyList.ForEach(t => t.Id = Guid.Empty); // clone.State = TrialSiteSurveyEnum.ToSubmit; // dbEntity = await _repository.AddAsync(clone); //} } else { var dbEntityList = await _trialSiteSurveyRepository.Where(t => t.TrialId == userInfo.TrialId && t.SiteId == userInfo.SiteId).ToListAsync(); //没有记录 new一份 if (dbEntityList.Count == 0) { dbEntity = await _repository.AddAsync(_mapper.Map(userInfo)); } else { //该site 下不存在该邮箱的记录 if (!dbEntityList.Any(t => t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone)) { return ResponseOutput.NotOk("该Site下已经有其他用户已填写的调研表,您不被允许继续填写"); } //有没有该邮箱 未锁定的 var nolockEntity = dbEntityList.Where(t => t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone).FirstOrDefault(t => t.State != TrialSiteSurveyEnum.PMCreatedAndLock); // 未锁定的 为空 if (nolockEntity == null) { //查看最新锁定的 dbEntity = dbEntityList.Where(t => t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone).OrderByDescending(t => t.CreateTime).FirstOrDefault(t => t.State == TrialSiteSurveyEnum.PMCreatedAndLock).IfNullThrowException(); } else //有未锁定的 直接用未锁定的 { dbEntity = nolockEntity; } } //_mapper.Map(userInfo, dbEntity); } //删除验证码历史记录 await _repository.DeleteFromQueryAsync(t => t.EmailOrPhone == userInfo.EmailOrPhone && t.Code == userInfo.verificationCode && t.CodeType == userInfo.verificationType); await _repository.SaveChangesAsync(); return ResponseOutput.Ok(new { TrialSiteSurveyId = dbEntity!.Id, Token = _tokenService.GetToken(IRaCISClaims.Create(new UserBasicInfo() { Id = Guid.Empty, IsReviewer = false, IsAdmin = false, RealName = "SiteSurvey", UserName = "SiteSurvey", Sex = 0, //UserType = "ShareType", UserTypeEnum = UserTypeEnum.Undefined, Code = "SiteSurvey", })) }); } //} } /// /// 直接查询相关所有数据 /// /// [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) { 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)) { return ResponseOutput.NotOk("已锁定,不允许操作"); } var success = await _trialSiteSurveyRepository.DeleteFromQueryAsync(t => t.Id == trialSiteSurveyId); return ResponseOutput.Result(success); } /// /// 获取 项目 某个site的调研记录 /// /// [HttpPost("{trialId:guid}")] public async Task> GetTrialSiteSurveyList(Guid trialId, TrialSiteSurveyQueryDTO trialSiteSurveyQueryDTO) { var trialSiteSurveyQueryable = _trialSiteSurveyRepository.Where(t => t.TrialId == trialId).IgnoreQueryFilters() //.WhereIf(trialSiteSurveyQueryDTO.si != null, t => t.SiteId == siteId) .WhereIf(!string.IsNullOrWhiteSpace(trialSiteSurveyQueryDTO.SiteName), t => t.Site.SiteName.Contains(trialSiteSurveyQueryDTO.SiteName)) .WhereIf(!string.IsNullOrWhiteSpace(trialSiteSurveyQueryDTO.TrialSiteAliasName), t => t.TrialSite.TrialSiteAliasName.Contains(trialSiteSurveyQueryDTO.TrialSiteAliasName)) .WhereIf(!string.IsNullOrWhiteSpace(trialSiteSurveyQueryDTO.TrialSiteCode), t => t.TrialSite.TrialSiteAliasName.Contains(trialSiteSurveyQueryDTO.TrialSiteCode)) //.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM, t => t.State >= TrialSiteSurveyEnum.ToSubmit) //.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.APM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM, t => t.State >= TrialSiteSurveyEnum.SPMApproved) .ProjectTo(_mapper.ConfigurationProvider); return await trialSiteSurveyQueryable.ToListAsync(); } //[HttpPut("{trialId:guid}/{isReplaceUser:bool}")] //public async Task CopyTrialSurveyInitInfo(CopyTrialSiteSurveyDTO copyDto, bool isReplaceUser) //{ // var survey = await _repository.Where(t => t.Id == copyDto.TrialSiteSurveyId).FirstOrDefaultAsync(); // if (survey == null) return Null404NotFound(survey); // survey.Id = Guid.Empty; // if (isReplaceUser) // { // survey.UserName = copyDto.UserName; // survey.Email = copyDto.Email; // survey.Phone = copyDto.Phone; // } // else // { // } // return ResponseOutput.Ok(); //} /// /// 初始登陆界面 项目基本信息+下拉框数据 /// /// /// [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; } /// /// 驳回 /// /// /// /// [HttpPut("{trialId:guid}/{trialSiteSurveyId:guid}")] 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.UpdateFromQueryAsync(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.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted }); } else { await _trialSiteSurveyRepository.UpdateFromQueryAsync(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)).IfNullThrowConvertException(); if (survey.State != TrialSiteSurveyEnum.ToSubmit) { return ResponseOutput.NotOk("只允许废除未提交的记录"); } survey.IsAbandon = true; await _repository.SaveChangesAsync(); 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.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted }); } else { await _trialSiteSurveyRepository.UpdateFromQueryAsync(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) { //if (_repository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsCorrect == false).Any()) //{ // return ResponseOutput.NotOk("人员信息有不正确项,不允许提交"); //} await _trialSiteSurveyRepository.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.CRCSubmitted, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.SPMApproved }); } 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 (_trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsCorrect == false).Any()) //{ // return ResponseOutput.NotOk("人员信息有不正确项,不允许提交"); //} //已生成的不管 管的只需要是 生成失败的并且需要生成账号的 var needGenerateList = _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsGenerateAccount && t.IsGenerateSuccess == false).ToList(); var trialInfo = await _repository.FirstOrDefaultAsync(t => t.Id == trialId); foreach (var item in needGenerateList) { 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 Notice)"; 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); saveItem.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1; saveItem.UserCode = AppSettings.UserCodePrefix + saveItem.Code.ToString("D4"); saveItem.UserName = saveItem.UserCode; saveItem.UserTypeEnum = _repository.Where(t => t.Id == saveItem.UserTypeId).Select(t => t.UserTypeEnum).First(); saveItem.Password = MD5Helper.Md5(verificationCode.ToString()); _ = _repository.AddAsync(saveItem).Result; _ = _repository.SaveChangesAsync().Result; sysUserInfo = saveItem; } } if (sysUserInfo.IsFirstAdd) { await _userRepository.UpdateFromQueryAsync(t => t.Id == sysUserInfo.Id, u => new User() { Password = MD5Helper.Md5(verificationCode.ToString()) }); } builder.HtmlBody = @$"
{sysUserInfo.LastName + "/" + sysUserInfo.FirstName}:
您参与的临床试验项目 {trialInfo.ExperimentName} ,独立影像评估相关工作将在网上进行。项目及账号信息为:
项目编号: {trialInfo.TrialCode}
试验方案号: {trialInfo.ResearchProgramNo}
试验名称: {trialInfo.ExperimentName}
用户名: {sysUserInfo.UserName}
密码: {(sysUserInfo.IsFirstAdd ? verificationCode.ToString() + "(请在登录后进行修改)" : "***(您已有账号, 若忘记密码, 请通过邮箱找回)")}
角色: {sysUserInfo.UserTypeRole.UserTypeShortName}
系统登录地址: {siteSurvyeSubmit.LoginUrl} (请确认加入后再登陆)
查看并确认
"; messageToSend.Body = builder.ToMessageBody(); using (var smtp = new MailKit.Net.Smtp.SmtpClient()) { smtp.ServerCertificateValidationCallback = (s, c, h, e) => true; smtp.MessageSent += (sender, args) => { _= _trialSiteUserSurveyRepository.UpdateFromQueryAsync(t => t.Id == item.Id, u => new TrialSiteUserSurvey() { IsGenerateSuccess = true, SystemUserId = sysUserInfo.Id , ExpireTime = DateTime.Now.AddDays(7) }).Result; }; 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.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.SPMApproved, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.PMCreatedAndLock }); } return ResponseOutput.Ok(); } ///// ///// 锁定 ///// ///// ///// ///// //[TypeFilter(typeof(TrialResourceFilter))] //[HttpPost("{trialSiteSurveyId:guid}/{trialId:guid}/{isLock:bool}")] //public async Task TrialSurveyLock(Guid trialSiteSurveyId, bool isLock) //{ // if (await _repository.Where(t => t.Id == trialSiteSurveyId).AnyAsync(t => t.TrialSiteUserSurveyList.Any(k => k.IsGenerateAccount && k.IsGenerateSuccess == false))) // { // ResponseOutput.NotOk("有用户账户没生成,不允许锁定"); // } // await _repository.UpdateFromQueryAsync(t => t.Id == trialSiteSurveyId, k => new TrialSiteSurvey() { State==TrialSiteSurveyEnum.PMCreatedAndLock }); // return ResponseOutput.Ok(); //} } }