修改入组发送邮件逻辑
This commit is contained in:
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using IRaCIS.Core.Application.Service.WorkLoad.DTO;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using IRaCIS.Core.Application.Auth;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace IRaCIS.Application.Services
|
||||
{
|
||||
@@ -376,38 +377,61 @@ namespace IRaCIS.Application.Services
|
||||
//更新入组表
|
||||
var intoGroupList = await _enrollRepository.Where(t => t.TrialId == trialId,true).ToListAsync();
|
||||
|
||||
//验证邮件
|
||||
var emaiList = await _doctorRepository.Where(t => intoGroupList.Select(t => t.DoctorId).Contains(t.Id))
|
||||
.Select(t => new { t.EMail, t.FirstName, t.LastName }).ToListAsync();
|
||||
|
||||
|
||||
var errorList = emaiList.Where(t => !Regex.IsMatch(t.EMail, @"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$"))
|
||||
.ToList();
|
||||
|
||||
if (errorList.Count() > 0)
|
||||
{
|
||||
return ResponseOutput.NotOk(string.Join(',', errorList.Select(c => c.LastName+" / "+c.FirstName)) +"邮箱格式存在问题") ;
|
||||
}
|
||||
|
||||
if (confirmReviewerCommand.ConfirmState == 1) //确认入组
|
||||
{
|
||||
foreach (var intoGroupItem in intoGroupList)
|
||||
{
|
||||
if (confirmReviewerCommand.DoctorIdArray.Contains(intoGroupItem.DoctorId))
|
||||
{
|
||||
intoGroupItem.EnrollStatus = EnrollStatus.ConfirmIntoGroup;
|
||||
intoGroupItem.EnrollTime = DateTime.Now;
|
||||
|
||||
var userId = await _mailVerificationService.DoctorJoinTrialEmail(trialId, intoGroupItem.DoctorId, confirmReviewerCommand.BaseUrl, confirmReviewerCommand.RouteUrl);
|
||||
|
||||
if ( !await _trialUserRepository.AnyAsync(t=>t.TrialId==trialId && t.UserId== userId, true))
|
||||
//当邮件发送没有问题的时候,才修改状态 如果有问题,就当前不做处理
|
||||
try
|
||||
{
|
||||
await _trialUserRepository.AddAsync(new TrialUser() { TrialId = trialId, UserId = userId ,JoinTime = DateTime.Now });
|
||||
var userId = await _mailVerificationService.DoctorJoinTrialEmail(trialId, intoGroupItem.DoctorId, confirmReviewerCommand.BaseUrl, confirmReviewerCommand.RouteUrl);
|
||||
|
||||
if (!await _trialUserRepository.AnyAsync(t => t.TrialId == trialId && t.UserId == userId, true))
|
||||
{
|
||||
await _trialUserRepository.AddAsync(new TrialUser() { TrialId = trialId, UserId = userId, JoinTime = DateTime.Now });
|
||||
}
|
||||
|
||||
await _enrollRepository.BatchUpdateNoTrackingAsync(t => t.Id == intoGroupItem.Id, u => new Enroll() { DoctorUserId = userId });
|
||||
|
||||
if (!await _taskAllocationRuleRepository.AnyAsync(t => t.TrialId == trialId && t.DoctorUserId == userId && t.EnrollId == intoGroupItem.Id, true))
|
||||
{
|
||||
await _taskAllocationRuleRepository.AddAsync(new TaskAllocationRule() { TrialId = trialId, DoctorUserId = userId, EnrollId = intoGroupItem.Id });
|
||||
|
||||
}
|
||||
|
||||
await _enrollDetailRepository.AddAsync(new EnrollDetail()
|
||||
{
|
||||
DoctorId = intoGroupItem.DoctorId,
|
||||
TrialId = trialId,
|
||||
EnrollStatus = EnrollStatus.ConfirmIntoGroup,
|
||||
OptUserType = (int)SystemUserType.AdminUser, //后台用户
|
||||
});
|
||||
|
||||
intoGroupItem.EnrollStatus = EnrollStatus.ConfirmIntoGroup;
|
||||
intoGroupItem.EnrollTime = DateTime.Now;
|
||||
}
|
||||
|
||||
await _enrollRepository.BatchUpdateNoTrackingAsync(t => t.Id == intoGroupItem.Id, u => new Enroll() { DoctorUserId = userId });
|
||||
|
||||
if (!await _taskAllocationRuleRepository.AnyAsync(t => t.TrialId == trialId && t.DoctorUserId == userId&& t.EnrollId == intoGroupItem.Id, true))
|
||||
catch (Exception )
|
||||
{
|
||||
await _taskAllocationRuleRepository.AddAsync(new TaskAllocationRule() { TrialId = trialId, DoctorUserId = userId, EnrollId = intoGroupItem.Id });
|
||||
intoGroupItem.EnrollStatus = EnrollStatus.ConfirmIntoGroupFailed;
|
||||
|
||||
}
|
||||
|
||||
|
||||
await _enrollDetailRepository.AddAsync(new EnrollDetail()
|
||||
{
|
||||
DoctorId = intoGroupItem.DoctorId,
|
||||
TrialId = trialId,
|
||||
EnrollStatus = EnrollStatus.ConfirmIntoGroup,
|
||||
OptUserType = (int)SystemUserType.AdminUser, //后台用户
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user