调研表修改

Uat_Study
hang 2023-08-07 11:47:33 +08:00
parent 711c3f3639
commit 228254db09
3 changed files with 219 additions and 399 deletions

View File

@ -15,6 +15,7 @@ using MailKit.Security;
using MimeKit;
using IRaCIS.Core.Application.Helper;
using IRaCIS.Core.Application.Filter;
using IRaCIS.Core.Infrastructure.Extention;
namespace IRaCIS.Core.Application.Contracts
{
@ -107,7 +108,7 @@ namespace IRaCIS.Core.Application.Contracts
}
/// <summary>
/// 发送验证码
///site 调研 发送验证码
/// </summary>
/// <param name="userInfo"></param>
/// <returns></returns>
@ -150,225 +151,187 @@ namespace IRaCIS.Core.Application.Contracts
public async Task<IResponseOutput> VerifySendCode(LoginDto userInfo, [FromServices] ITokenService _tokenService)
{
var isReplaceUser = !string.IsNullOrEmpty(userInfo.ReplaceUserEmailOrPhone);
#region 历史版本 删除前
//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(_localizer["TrialSiteSurvey_NoRecordToUpdate"]);
}
//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(_localizer["TrialSiteSurvey_NoRecordToUpdate"]);
//}
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(_localizer["TrialSiteSurvey_RecordUnderReview"]);
}
//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(_localizer["TrialSiteSurvey_RecordUnderReview"]);
//}
//自己的记录锁定了 只能更新自己的,不能更新别人的(但是别人能更新自己锁定的)
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(_localizer["TrialSiteSurvey_LockedByCurrentUser"]);
}
////自己的记录锁定了 只能更新自己的,不能更新别人的(但是别人能更新自己锁定的)
//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(_localizer["TrialSiteSurvey_LockedByCurrentUser"]);
//}
//自己的锁定了 如果有其他未锁定的,也不能更新自己的
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))
{
////自己的锁定了 如果有其他未锁定的,也不能更新自己的
//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(_localizer["TrialSiteSurvey_LockedByOtherUsers"]);
}
// //---当前中心,您提交的调研记录表已锁定。当前存在其他人员提交的调研记录表未锁定,不允许更新您之前提交的调研记录。
// return ResponseOutput.NotOk(_localizer["TrialSiteSurvey_LockedByOtherUsers"]);
//}
////存在未锁定的记录,却去更新已锁定的
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(_localizer["TrialSiteSurvey_UnlockedRecordsExist"]);
}
//////存在未锁定的记录,却去更新已锁定的
//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(_localizer["TrialSiteSurvey_UnlockedRecordsExist"]);
//}
#endregion
var verificationRecord = await _repository
.FirstOrDefaultAsync<VerificationCode>(t => (t.EmailOrPhone == userInfo.EmailOrPhone) && t.Code == userInfo.verificationCode && t.CodeType == userInfo.verificationType);
#region 20230804 修改调研表逻辑
var verifyRecord = await _repository.FirstOrDefaultAsync<VerificationCode>(t => (t.EmailOrPhone == userInfo.EmailOrPhone) && t.Code == userInfo.verificationCode && t.CodeType == userInfo.verificationType);
//检查数据库是否存在该验证码
if (verificationRecord == null)
if (verifyRecord == null)
{
//---验证码错误。
return ResponseOutput.NotOk(_localizer["TrialSiteSurvey_WrongVerificationCode"]);
}
else if (verifyRecord.ExpirationTime < DateTime.Now)
{
return ResponseOutput.NotOk(_localizer["TrialSiteSurvey_WrongVerificationCode"]);
}
else
{
//检查验证码是否失效
if (verificationRecord.ExpirationTime < DateTime.Now)
{
//---验证码已经过期。
return ResponseOutput.NotOk(_localizer["TrialSiteSurvey_ExpiredVerificationCode"]);
}
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().IfNullThrowException();
//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<TrialSiteSurvey>(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<TrialSiteSurvey>(userInfo));
}
else
{
//该site 下不存在该邮箱的记录
if (!dbEntityList.Any(t => t.Email == userInfo.EmailOrPhone || t.Phone == userInfo.EmailOrPhone))
{
//---该中心下已经有其他用户已填写的调研表,您不被允许继续填写
return ResponseOutput.NotOk(_localizer["TrialSiteSurvey_AlreadyFilledByOtherUsers"]);
}
//有没有该邮箱 未锁定的
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.BatchDeleteAsync<VerificationCode>(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.NewGuid(),
IsReviewer = false,
IsAdmin = false,
RealName = "SiteSurvey",
UserName = "SiteSurvey",
Sex = 0,
//UserType = "ShareType",
UserTypeEnum = UserTypeEnum.Undefined,
Code = "SiteSurvey",
}))
});
}
//验证码正确 不处理
}
TrialSiteSurvey? currentEntity = null;
//普通登录
if (userInfo.IsUpdate == false)
{
var dbEntityList = await _trialSiteSurveyRepository.Where(t => t.TrialId == userInfo.TrialId && t.SiteId == userInfo.SiteId).ToListAsync();
//没有记录 new一份
if (dbEntityList.Count == 0)
{
currentEntity = await _repository.AddAsync(_mapper.Map<TrialSiteSurvey>(userInfo));
}
else
{
//找到当前最新的调研表
var currentLatest = dbEntityList.OrderByDescending(t => t.CreateTime).FirstOrDefault();
if (currentLatest.Email != userInfo.EmailOrPhone)
{
//---该中心下已经有其他用户已填写的调研表,您不被允许继续填写
return ResponseOutput.NotOk(_localizer["TrialSiteSurvey_AlreadyFilledByOtherUsers"]);
}
currentEntity = currentLatest;
}
}
//更新调研表
else
{
//找到最新的调研表
var currentLatest = await _trialSiteSurveyRepository.Where(t => t.TrialId == userInfo.TrialId && t.SiteId == userInfo.SiteId,true).OrderByDescending(t => t.CreateTime).FirstOrDefaultAsync();
if (currentLatest == null)
{
return ResponseOutput.NotOk("当前site没有调研表可以更新请确认");
}
if(currentLatest.Email != userInfo.ReplaceUserEmailOrPhone)
{
//---该中心不存在该交接人的中心调研记录表,不允许选择更新。
return ResponseOutput.NotOk(_localizer["TrialSiteSurvey_NoRecordToUpdate"]);
}
//未锁定的状态 就改为废除
if(currentLatest.State!= TrialSiteSurveyEnum.PMCreatedAndLock)
{
currentLatest.IsDeleted = true;
}
//锁定的 需要改状态么?
else
{
}
var copy = currentLatest.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; t.IsGenerateSuccess = false; });
currentEntity = await _repository.AddAsync(copy);
}
//删除验证码历史记录
await _repository.BatchDeleteAsync<VerificationCode>(t => t.EmailOrPhone == userInfo.EmailOrPhone && t.Code == userInfo.verificationCode && t.CodeType == userInfo.verificationType);
await _repository.SaveChangesAsync();
return ResponseOutput.Ok(new
{
TrialSiteSurveyId = currentEntity!.Id,
Token = _tokenService.GetToken(IRaCISClaims.Create(new UserBasicInfo()
{
Id = Guid.NewGuid(),
IsReviewer = false,
IsAdmin = false,
RealName = "SiteSurvey",
UserName = "SiteSurvey",
Sex = 0,
//UserType = "ShareType",
UserTypeEnum = UserTypeEnum.Undefined,
Code = "SiteSurvey",
}))
});
#endregion
}
@ -487,25 +450,11 @@ namespace IRaCIS.Core.Application.Contracts
.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<TrialSiteUserSurveyAllDTO>(_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<TrialSiteUserSurveyAllDTO>(_mapper.ConfigurationProvider);
return await query.ToPagedListAsync(queryParam.PageIndex, queryParam.PageSize, queryParam.SortField, queryParam.Asc);
@ -556,18 +505,18 @@ namespace IRaCIS.Core.Application.Contracts
//---中心调研已锁定,不允许操作。
return ResponseOutput.NotOk(_localizer["TrialSiteSurvey_Locked"]);
}
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager )
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager)
{
//没有SPM 给填表人发
messageToSend.To.Add(new MailboxAddress(String.Empty, survey.Email));
//没有SPM 给填表人发
messageToSend.To.Add(new MailboxAddress(String.Empty, survey.Email));
survey.State = TrialSiteSurveyEnum.ToSubmit;
survey.State = TrialSiteSurveyEnum.ToSubmit;
survey.PreliminaryUserId = null;
survey.ReviewerUserId = null;
survey.PreliminaryTime = null;
survey.ReviewerTime = null;
survey.PreliminaryUserId = null;
survey.ReviewerUserId = null;
survey.PreliminaryTime = null;
survey.ReviewerTime = null;
}
@ -620,29 +569,8 @@ namespace IRaCIS.Core.Application.Contracts
}
/// <summary>
/// 驳回
/// </summary>
/// <param name="trialId"></param>
/// <param name="trialSiteSurveyId"></param>
/// <returns></returns>
[HttpPut("{trialId:guid}/{trialSiteSurveyId:guid}")]
[Obsolete]
public async Task<IResponseOutput> SubmissionRejection(Guid trialId, Guid trialSiteSurveyId)
{
if (await _repository.AnyAsync<TrialSiteSurvey>(t => t.State == TrialSiteSurveyEnum.PMCreatedAndLock && t.Id == trialSiteSurveyId))
{
//---中心调研已锁定,不允许操作。
return ResponseOutput.NotOk(_localizer["TrialSiteSurvey_Locked"]);
}
await _trialSiteSurveyRepository.BatchUpdateNoTrackingAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.ToSubmit });
return ResponseOutput.Ok();
}
[HttpPut("{trialId:guid}/{trialSiteSurveyId:guid}")]
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })]
@ -696,60 +624,40 @@ namespace IRaCIS.Core.Application.Contracts
}).ToListAsync();
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.Undefined)
{
//是第一次
if (!siteUserList.Any(t => t.IsGenerateSuccess))
{
var currentUserList = siteUserList.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId).ToList();
var currentUserList = siteUserList.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId).ToList();
if (!currentUserList.Any(t => t.Code == "1") || !currentUserList.Any(t => t.Code == "5"))
{
throw new BusinessValidationFailedException("本次提交必须有CRC和影像阅片人信息");
}
if (!currentUserList.Any(t => t.Code == "1") || !currentUserList.Any(t => t.Code == "5"))
{
throw new BusinessValidationFailedException("本次提交必须有CRC和影像阅片人信息");
}
if (!currentUserList.Any(t => t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator) ||
!currentUserList.Any(t => t.UserTypeEnum == UserTypeEnum.SR))
{
throw new BusinessValidationFailedException("本次提交生成账号必须要有CRC和SR");
}
await _trialSiteSurveyRepository.UpdatePartialFromQueryAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.SPMApproved });
}
else if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager)
{
foreach (var group in (siteUserList.Where(t => t.IsGenerateAccount && t.TrialSiteSurveyId == trialSiteSurveyId)
.GroupBy(t => new { t.Email, t.IsGenerateAccount, t.UserTypeId })))
{
if (group.Count() > 1)
{
throw new BusinessValidationFailedException("同一邮箱同一用户类型,生成账号的数据只允许存在一条!");
}
}
//是第一次
if (!siteUserList.Any(t => t.IsGenerateSuccess))
{
var currentUserList = siteUserList.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId).ToList();
if (!currentUserList.Any(t => t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator) ||
!currentUserList.Any(t => t.UserTypeEnum == UserTypeEnum.SR))
{
throw new BusinessValidationFailedException("本次提交生成账号必须要有CRC 和SR");
}
}
//已生成的不管 管的只需要是 生成失败的并且需要生成账号的
var needGenerateList = _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsGenerateAccount && t.IsJoin != true).ProjectTo<TrialSiteUserSurveyView>(_mapper.ConfigurationProvider).ToList();
//await SendInviteEmail(new InviteEmailCommand() { TrialId = trialId, RouteUrl = siteSurvyeSubmit.RouteUrl, UserList = needGenerateList });
var needGenerateList = _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId && t.IsGenerateAccount && t.IsGenerateSuccess != true).ProjectTo<TrialSiteUserSurveyView>(_mapper.ConfigurationProvider).ToList();
await GenerateAccountAsync(needGenerateList, trialId);
await SendSiteSurveyUserJoinEmail(new TrialSiteUserSurveyJoinCommand() { TrialId = trialId, TrialSiteSurveyId = trialSiteSurveyId, RouteUrl = siteSurvyeSubmit.RouteUrl, BaseUrl = siteSurvyeSubmit.BaseUrl, UserList = needGenerateList });
await DealSiteUserQuitSiteAsync(trialId, trialSiteSurvey.SiteId, needGenerateList);
}
await _trialSiteSurveyRepository.SaveChangesAsync();
@ -811,18 +719,13 @@ namespace IRaCIS.Core.Application.Contracts
await _trialSiteUserSurveyRepository.BatchUpdateNoTrackingAsync(t => t.Id == item.Id, u => new TrialSiteUserSurvey() { IsGenerateSuccess = true, SystemUserId = sysUserInfo.Id });
}
await _trialSiteUserSurveyRepository.SaveChangesAsync();
}
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })]
public async Task<IResponseOutput> SendSiteSurveyUserJoinEmail(TrialSiteUserSurveyJoinCommand joinCommand)
private async Task<IResponseOutput> SendSiteSurveyUserJoinEmail(TrialSiteUserSurveyJoinCommand joinCommand)
{
var trialSiteSurvey = await _trialSiteSurveyRepository.FirstAsync(t => t.Id == joinCommand.TrialSiteSurveyId);
@ -846,17 +749,20 @@ namespace IRaCIS.Core.Application.Contracts
if (!await _trialUserRepository.AnyAsync(t => t.TrialId == trialId && t.UserId == userId, true))
{
await _repository.AddAsync(new TrialUser() { TrialId = trialId, UserId = userId, JoinTime = DateTime.Now });
await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl);
}
if (!await _repository.AnyAsync<TrialSiteUser>(t => t.TrialId == trialId && t.UserId == userId && t.SiteId == siteId, true))
{
await _repository.AddAsync(new TrialSiteUser() { TrialId = trialId, SiteId = siteId, UserId = userId });
await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl);
}
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 _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl);
}
@ -869,123 +775,25 @@ namespace IRaCIS.Core.Application.Contracts
}
#region 废弃
//Site 调研邀请
public async Task<IResponseOutput> SendInviteEmail(InviteEmailCommand inviteEmailCommand)
private async Task DealSiteUserQuitSiteAsync(Guid trialId, Guid siteId, List<TrialSiteUserSurveyView> list)
{
//跟踪查询该site下的所有的用户
var siteUserList = await _repository.Where<TrialSiteUser>(t => t.TrialId == trialId && t.SiteId == siteId, true).ToListAsync();
var trialInfo = await _repository.FirstOrDefaultAsync<Trial>(t => t.Id == inviteEmailCommand.TrialId);
foreach (var item in inviteEmailCommand.UserList)
foreach (var siteUser in siteUserList)
{
var messageToSend = new MimeMessage();
//发件地址
messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com"));
//收件地址
messageToSend.To.Add(new MailboxAddress(String.Empty, item.Email));
//主题
//$"[来自展影IRC] [{trialInfo.ResearchProgramNo}] 邀请信";
messageToSend.Subject = _localizer["TrialSiteSurvey_IRCInvitation", 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)
//当前中心用户 不在调研表存在,就将该人退出
if (!list.Any(t => t.SystemUserId == siteUser.UserId))
{
lock (lockObj)
{
var saveItem = _mapper.Map<User>(item);
saveItem.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1;
saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(User)); ;
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());
_ = _repository.AddAsync(saveItem).Result;
_ = _repository.SaveChangesAsync().Result;
sysUserInfo = saveItem;
}
}
builder.HtmlBody = @$"<body style='font-family: 微软雅黑;padding: 0;margin: 0;'>
<div style='padding-left: 40px;background: #f6f6f6'>
<div style='padding-top: 20px;'>
<div style='line-height: 40px;font-size: 18px'>
{sysUserInfo.LastName + "/" + sysUserInfo.FirstName}:
</div>
<div style='line-height: 40px;padding-left: 40px;margin-bottom: 10px;'>
{_localizer["TrialSiteSurvey_IRCInvitationContent", trialInfo.ResearchProgramNo]}
</div>
<a href=' {inviteEmailCommand.RouteUrl + "?Id=" + item.Id + "&IsExternalUser=0"}' style='margin-left:60px;font-size:14px;text-decoration: none;display: inline-block;height: 40px;width: 140px;background: #00D1B2;color:#fff;border-radius: 5px;line-height: 40px;text-align: center;margin-bottom: 100px;'>
</a>
</div>
</div>
</body>";
messageToSend.Body = builder.ToMessageBody();
using (var smtp = new MailKit.Net.Smtp.SmtpClient())
{
smtp.ServerCertificateValidationCallback = (s, c, h, e) => true;
smtp.MessageSent += (sender, args) =>
{
_ = _trialSiteUserSurveyRepository.BatchUpdateNoTrackingAsync(t => t.Id == item.Id, u => new TrialSiteUserSurvey() { IsGenerateSuccess = true, InviteState = TrialSiteUserStateEnum.HasSend, ConfirmTime = null, RejectReason = String.Empty, SystemUserId = sysUserInfo.Id, ExpireTime = DateTime.Now.AddDays(7) }).Result;
};
await smtp.ConnectAsync("smtp.163.com", 465, SecureSocketOptions.StartTls);
await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH");
await smtp.SendAsync(messageToSend);
await smtp.DisconnectAsync(true);
siteUser.IsDeleted = true;
siteUser.DeletedTime = DateTime.Now;
}
}
return ResponseOutput.Ok();
await _repository.SaveChangesAsync();
}
#endregion
}
}

View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Application.Filter;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Application.Contracts;
namespace IRaCIS.Core.Application.Contracts
{
@ -105,7 +106,15 @@ namespace IRaCIS.Core.Application.Contracts
}
var entity = await _trialSiteUserSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteUserSurvey, true);
var verifyExp1 = new EntityVerifyExp<TrialSiteUserSurvey>()
{
VerifyExp = u => u.UserTypeId == addOrEditTrialSiteUserSurvey.UserTypeId && u.Email == addOrEditTrialSiteUserSurvey.Email,
VerifyMsg = "同一邮箱同一用户类型,生成账号的数据只允许存在一条!",
IsVerify=addOrEditTrialSiteUserSurvey.IsGenerateAccount
};
var entity = await _trialSiteUserSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteUserSurvey, true, verifyExp1);
return ResponseOutput.Ok(entity.Id.ToString());

View File

@ -85,13 +85,6 @@ namespace IRaCIS.Core.Domain.Models
public Guid? SystemUserId { get; set; }
public DateTime? ExpireTime { get; set; }
public bool IsJoin { get; set; }
public DateTime? ConfirmTime { get; set; }
public string RejectReason { get; set; } = string.Empty;
/// <summary>
/// IsGenerateAccount
@ -104,7 +97,17 @@ namespace IRaCIS.Core.Domain.Models
public TrialSiteUserStateEnum InviteState { get; set; } = TrialSiteUserStateEnum.WaitSent;
#region 废弃
public DateTime? ExpireTime { get; set; }
public bool IsJoin { get; set; }
public DateTime? ConfirmTime { get; set; }
public string RejectReason { get; set; } = string.Empty;
#endregion
}