From fe6ac1a8be95b522b751df6a1d5981740d27443a Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Tue, 19 Apr 2022 12:52:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E6=9F=A5=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/QC/QCOperationService.cs | 2 +- .../SiteSurvey/TrialSiteSurveyService.cs | 1103 +++++++++-------- .../ConsistencyVerificationHandler.cs | 2 +- .../Visit/VisitPlanInfluenceStudy.cs | 2 +- 4 files changed, 555 insertions(+), 554 deletions(-) diff --git a/IRaCIS.Core.Application/Service/QC/QCOperationService.cs b/IRaCIS.Core.Application/Service/QC/QCOperationService.cs index 89e3f595f..f6a3d22ce 100644 --- a/IRaCIS.Core.Application/Service/QC/QCOperationService.cs +++ b/IRaCIS.Core.Application/Service/QC/QCOperationService.cs @@ -985,7 +985,7 @@ namespace IRaCIS.Core.Application.Image.QA bodyPart=x.BodyPartForEdit, seriesNum=x.SeriesCount, fileNum = x.InstanceCount, - studyTime=x.StudyTime.ToString("yyyy-MM-dd") + studyTime=x.StudyTime?.ToString("yyyy-MM-dd") }) }); diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index a08429368..39550809c 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -130,395 +130,396 @@ namespace IRaCIS.Core.Application.Contracts - //var verificationRecord = await _repository - // .FirstOrDefaultAsync(t => (t.EmailOrPhone == userInfo.EmailOrPhone) && t.Code == userInfo.verificationCode && t.CodeType == userInfo.verificationType); + 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 //验证码正确 并且 没有超时 + //检查数据库是否存在该验证码 + if (verificationRecord == null) { - 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.BatchDeleteAsync(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", - })) - }); - + return ResponseOutput.NotOk("Verification code error"); } - //} - - } - - - /// - /// 直接查询相关所有数据 - /// - /// - [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) + else { - if (await _trialSiteSurveyRepository.AnyAsync(t => t.Id == addOrEditTrialSiteSurvey.Id && t.State == TrialSiteSurveyEnum.PMCreatedAndLock)) + //检查验证码是否失效 + 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.BatchDeleteAsync(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 entity = await _trialSiteSurveyRepository.InsertOrUpdateAsync(addOrEditTrialSiteSurvey, true); - return ResponseOutput.Ok(entity.Id.ToString()); - } + var success = await _trialSiteSurveyRepository.BatchDeleteAsync(t => t.Id == trialSiteSurveyId); - - /// - /// 删除调研表 - /// - /// - /// - [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("已锁定,不允许操作"); + return ResponseOutput.Result(success); } - var success = await _trialSiteSurveyRepository.BatchDeleteAsync(t => t.Id == trialSiteSurveyId); - 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)) + /// + /// 获取 项目 site的调研记录 New + /// + /// + [HttpPost] + public async Task> GetTrialSiteSurveyList(TrialSiteSurveyQueryDTO surveyQueryDTO) { - return ResponseOutput.NotOk("已锁定,不允许操作"); + 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); } - if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM) + + /// + /// 项目Site调研用户列表 所有site的调研用户 最新的调研表的记录的用户 new + /// + /// + public async Task> TrialSiteSurveyUserList(TrialSiteUserSurveyAllQuery queryParam) { - //SPM 给填表人发 - messageToSend.To.Add(new MailboxAddress(String.Empty, survey.Email)); - survey.State = TrialSiteSurveyEnum.ToSubmit; + 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); } - 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) + + + /// + /// 初始登陆界面 项目基本信息+下拉框数据 + /// + /// + /// + [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)) { - - //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; + return ResponseOutput.NotOk("已锁定,不允许操作"); } - else + + if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SPM || _userInfo.UserTypeEnumInt == (int)UserTypeEnum.CPM) { - //没有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 siteInfo = await _trialSiteRepository.FirstOrDefaultAsync(t => t.TrialId == trialSiteSubmitBackCommand.TrialId && t.SiteId == survey.SiteId, true); + var builder = new BodyBuilder(); - builder.HtmlBody = @$" + 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 = @$"
@@ -557,146 +558,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) + using (var smtp = new MailKit.Net.Smtp.SmtpClient()) { - await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted }); + 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 + + 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)) { - await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.ToSubmit }); + return ResponseOutput.NotOk("已锁定,不允许操作"); } - } - 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 = "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) + 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)); - lock (lockObj) + if (hasSPMOrCPM) { - var saveItem = _mapper.Map(item); + await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted }); - saveItem.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1; + } + else + { + await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.ToSubmit }); + } + } + return ResponseOutput.Ok(); - 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; + [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 = "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); + + 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; + } + } - } - - builder.HtmlBody = @$" + builder.HtmlBody = @$"
@@ -715,104 +716,104 @@ 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; - - smtp.MessageSent += (sender, args) => + using (var smtp = new MailKit.Net.Smtp.SmtpClient()) { - _ = _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.ServerCertificateValidationCallback = (s, c, h, e) => true; - }; + 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(); } - - return ResponseOutput.Ok(); - } - - /// - /// 提交 后台自动识别是谁提交 - /// - /// - /// - //[TypeFilter(typeof(TrialResourceFilter))] - [HttpPost] - public async Task TrialSurveySubmit(TrialSiteSurvyeSubmitDTO siteSurvyeSubmit) - { - - var trialId = siteSurvyeSubmit.TrialId; - var trialSiteSurveyId = siteSurvyeSubmit.TrialSiteSurveyId; - - if (_userInfo.IsAdmin) + /// + /// 提交 后台自动识别是谁提交 + /// + /// + /// + //[TypeFilter(typeof(TrialResourceFilter))] + [HttpPost] + public async Task TrialSurveySubmit(TrialSiteSurvyeSubmitDTO siteSurvyeSubmit) { - return ResponseOutput.NotOk("不允许Admin操作"); - } + var trialId = siteSurvyeSubmit.TrialId; + var trialSiteSurveyId = siteSurvyeSubmit.TrialSiteSurveyId; - 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) + if (_userInfo.IsAdmin) { - await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.CRCSubmitted }); - + return ResponseOutput.NotOk("不允许Admin操作"); } - else + + + if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.Undefined) { - await _trialSiteSurveyRepository.BatchUpdateAsync(t => t.Id == trialSiteSurveyId && t.State == TrialSiteSurveyEnum.ToSubmit, u => new TrialSiteSurvey() { State = TrialSiteSurveyEnum.SPMApproved }); + 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(); + + + 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 }); } - } - 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(); - - - 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/_MediatR/Handlers/ConsistencyVerificationHandler.cs b/IRaCIS.Core.Application/_MediatR/Handlers/ConsistencyVerificationHandler.cs index 2f6677c54..3596fd22d 100644 --- a/IRaCIS.Core.Application/_MediatR/Handlers/ConsistencyVerificationHandler.cs +++ b/IRaCIS.Core.Application/_MediatR/Handlers/ConsistencyVerificationHandler.cs @@ -59,7 +59,7 @@ namespace IRaCIS.Core.Application.MediatR.Handlers { SubjectVisitId = sv.Id, SiteCode = trialSite.TrialSiteCode, - StudyDate = study.StudyTime.ToString("yyyy-MM-dd"), + StudyDate = study.StudyTime == null?string.Empty: ((DateTime)study.StudyTime).ToString("yyyy-MM-dd"), StudyId = study.Id, Modality = study.Modalities, SubjectCode = subject.Code, diff --git a/IRaCIS.Core.Domain/Visit/VisitPlanInfluenceStudy.cs b/IRaCIS.Core.Domain/Visit/VisitPlanInfluenceStudy.cs index 329bb7f84..8fe4ad542 100644 --- a/IRaCIS.Core.Domain/Visit/VisitPlanInfluenceStudy.cs +++ b/IRaCIS.Core.Domain/Visit/VisitPlanInfluenceStudy.cs @@ -26,7 +26,7 @@ namespace IRaCIS.Core.Domain.Models public bool IsOverWindowNowNotOverWindow { get; set; } - public DateTime StudyTime { get; set; } + public DateTime? StudyTime { get; set; } public string HistoryWindow { get; set; }