外部用户修改
This commit is contained in:
@@ -254,12 +254,27 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
[NotDefault]
|
||||
public Guid TrialId { get; set; }
|
||||
|
||||
|
||||
public string RouteUrl { get; set; } = string.Empty;
|
||||
|
||||
public List<TrialSiteUserSurveyView> UserList { get; set; } = new List<TrialSiteUserSurveyView>();
|
||||
}
|
||||
|
||||
|
||||
public class TrialSiteUserSurveyJoinCommand
|
||||
{
|
||||
[NotDefault]
|
||||
public Guid TrialId { get; set; }
|
||||
|
||||
public Guid TrialSiteSurveyId { get; set; }
|
||||
|
||||
public string BaseUrl { get; set; } = string.Empty;
|
||||
|
||||
public string RouteUrl { get; set; } = string.Empty;
|
||||
|
||||
public List<TrialSiteUserSurveyView> UserList { get; set; } = new List<TrialSiteUserSurveyView>();
|
||||
}
|
||||
|
||||
|
||||
public class TrialSiteSurvyeSubmitDTO
|
||||
{
|
||||
@@ -269,6 +284,7 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
public Guid TrialSiteSurveyId { get; set; }
|
||||
|
||||
|
||||
public string BaseUrl { get; set; } = string.Empty;
|
||||
public string RouteUrl { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
{
|
||||
var verificationType = VerifyType.Email;
|
||||
//检查手机或者邮箱是否有效
|
||||
if ( !Regex.IsMatch(userInfo.Email, @"^[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("Please input a legal email");
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
|
||||
var trialInfo = await _repository.FirstOrDefaultAsync<Trial>(t => t.Id == userInfo.TrialId);
|
||||
|
||||
await _mailVerificationService.AnolymousSendEmail(trialInfo.ResearchProgramNo,userInfo.Email, verificationCode);
|
||||
await _mailVerificationService.AnolymousSendEmail(trialInfo.ResearchProgramNo, userInfo.Email, verificationCode);
|
||||
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
@@ -681,6 +681,228 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 提交 后台自动识别是谁提交
|
||||
/// </summary>
|
||||
/// <param name="siteSurvyeSubmit"></param>
|
||||
/// <returns></returns>
|
||||
//[TypeFilter(typeof(TrialResourceFilter))]
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> 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.BatchUpdateNoTrackingAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted });
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
await _trialSiteSurveyRepository.BatchUpdateNoTrackingAsync(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.BatchUpdateNoTrackingAsync(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 = (await _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId).FirstOrDefaultAsync()).IfNullThrowException();
|
||||
|
||||
|
||||
|
||||
//已生成的不管 管的只需要是 生成失败的并且需要生成账号的
|
||||
var needGenerateList = _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsGenerateAccount && t.IsGenerateSuccess == false).ProjectTo<TrialSiteUserSurveyView>(_mapper.ConfigurationProvider).ToList();
|
||||
|
||||
|
||||
//await SendInviteEmail(new InviteEmailCommand() { TrialId = trialId, RouteUrl = siteSurvyeSubmit.RouteUrl, UserList = needGenerateList });
|
||||
|
||||
|
||||
await GenerateAccountAsync(needGenerateList);
|
||||
await SendSiteSurveyUserJoinEmail(new TrialSiteUserSurveyJoinCommand() { TrialId = trialId, RouteUrl = siteSurvyeSubmit.RouteUrl, BaseUrl = siteSurvyeSubmit.BaseUrl, UserList = needGenerateList });
|
||||
|
||||
await _trialSiteSurveyRepository.BatchUpdateNoTrackingAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.SPMApproved, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.PMCreatedAndLock, ReviewerUserId = _userInfo.Id, ReviewerTime = DateTime.Now });
|
||||
|
||||
}
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async Task GenerateAccountAsync(List<TrialSiteUserSurveyView> needGenerateList)
|
||||
{
|
||||
foreach (var item in needGenerateList)
|
||||
{
|
||||
|
||||
//找下系统中是否存在该用户类型的 并且邮箱 或者手机的账户
|
||||
var sysUserInfo = await _userRepository.Where(t => t.UserTypeId == item.UserTypeId && t.EMail == item.Email).Include(t => t.UserTypeRole).FirstOrDefaultAsync();
|
||||
|
||||
|
||||
if (sysUserInfo == null)
|
||||
{
|
||||
|
||||
lock (lockObj)
|
||||
{
|
||||
var saveItem = _mapper.Map<User>(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<UserType>(t => t.Id == saveItem.UserTypeId).Select(t => t.UserTypeEnum).First();
|
||||
|
||||
//saveItem.Password = MD5Helper.Md5(verificationCode.ToString());
|
||||
|
||||
var newUser = _userRepository.AddAsync(saveItem).Result;
|
||||
|
||||
|
||||
_ = _userRepository.SaveChangesAsync().Result;
|
||||
|
||||
|
||||
sysUserInfo = newUser;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await _trialSiteUserSurveyRepository.UpdatePartialFromQueryAsync(t => t.Id == item.Id, u => new TrialSiteUserSurvey() { IsGenerateSuccess = true, SystemUserId = sysUserInfo.Id });
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
await _trialSiteUserSurveyRepository.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
public async Task<IResponseOutput> SendSiteSurveyUserJoinEmail(TrialSiteUserSurveyJoinCommand joinCommand)
|
||||
{
|
||||
var trialSiteSurvey = (await _trialSiteSurveyRepository.Where(t => t.Id == joinCommand.TrialSiteSurveyId).FirstOrDefaultAsync()).IfNullThrowException();
|
||||
|
||||
var trialInfo = await _repository.FirstOrDefaultAsync<Trial>(t => t.Id == joinCommand.TrialId);
|
||||
|
||||
foreach (var userInfo in joinCommand.UserList)
|
||||
{
|
||||
var messageToSend = new MimeMessage();
|
||||
//发件地址
|
||||
messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com"));
|
||||
//收件地址
|
||||
messageToSend.To.Add(new MailboxAddress(String.Empty, userInfo.Email));
|
||||
//主题
|
||||
messageToSend.Subject = $"[来自展影IRC] [{ trialInfo.ResearchProgramNo}]邀请信";
|
||||
|
||||
|
||||
var builder = new BodyBuilder();
|
||||
|
||||
var sysUserInfo = (await _userRepository.Where(t => t.Id == userInfo.SystemUserId).FirstOrDefaultAsync()).IfNullThrowException();
|
||||
|
||||
|
||||
builder.HtmlBody = @$"<body style='font-family: 微软雅黑;padding: 0;margin: 0;'>
|
||||
<div style='padding-left: 40px;background: #f6f6f6'>
|
||||
<div style='padding-top: 20px;padding-bottom:40px'>
|
||||
<div style='line-height: 40px;font-size: 18px'>
|
||||
尊敬的 {sysUserInfo.LastName + "/" + sysUserInfo.FirstName} ,您好:
|
||||
</div>
|
||||
<div style='line-height: 40px;padding-left: 40px;margin-bottom: 10px;'>
|
||||
展影医疗作为 实验方案号 {"'" + trialInfo.ResearchProgramNo + "'"} 项目的IRC供应商,诚邀您参加该项目IRC相关工作,欢迎您提供指导和建议,非常感谢!
|
||||
该项目采用电子化工作流,系统及您的账号信息如下:
|
||||
</div>
|
||||
<div style='border: 1px solid #eee;box-sizing:border-box;width: 80%;background: #fff;padding: 20px;line-height: 40px;font-size: 14px;border-radius: 5px;margin-left: 60px;margin-bottom: 30px;'>
|
||||
<div>
|
||||
项目编号: {trialInfo.TrialCode}
|
||||
</div>
|
||||
<div>
|
||||
试验方案号: {trialInfo.ResearchProgramNo}
|
||||
</div>
|
||||
<div>
|
||||
试验名称: {trialInfo.ExperimentName}
|
||||
</div>
|
||||
<div>
|
||||
用户名: {sysUserInfo.UserName}
|
||||
</div>
|
||||
<div>
|
||||
角色: {sysUserInfo.UserTypeRole.UserTypeShortName}
|
||||
</div>
|
||||
<div>
|
||||
{(sysUserInfo.IsFirstAdd ? "系统登录地址:" + joinCommand.BaseUrl : "首次登陆前,请通过该链接修改您的账户信息:" + joinCommand.RouteUrl)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>";
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
var trialId = joinCommand.TrialId;
|
||||
var userId = sysUserInfo.Id;
|
||||
var siteId = trialSiteSurvey.SiteId;
|
||||
|
||||
//判断TrialUser中是否存在 不存在就插入
|
||||
if (!await _repository.AnyAsync<TrialUser>(t => t.TrialId == trialId && t.UserId == userId))
|
||||
{
|
||||
|
||||
await _repository.AddAsync(new TrialUser() { TrialId = trialId, UserId = userId });
|
||||
|
||||
await _repository.AddAsync(new TrialSiteUser() { TrialId = trialId, SiteId = siteId, UserId = userId });
|
||||
|
||||
await _userRepository.BatchUpdateNoTrackingAsync(t => t.Id == userId, u => new User() { Status = UserStateEnum.Enable });
|
||||
|
||||
await _trialSiteUserSurveyRepository.UpdatePartialFromQueryAsync(t => t.Id == userInfo.Id, u => new TrialSiteUserSurvey() { IsJoin = true });
|
||||
|
||||
|
||||
await _userRepository.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//废弃
|
||||
//Site 调研邀请
|
||||
public async Task<IResponseOutput> SendInviteEmail(InviteEmailCommand inviteEmailCommand)
|
||||
{
|
||||
@@ -852,9 +1074,5 @@ namespace IRaCIS.Core.Application.Contracts
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user