diff --git a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs index 7e2bd5d35..6117602a2 100644 --- a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs +++ b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs @@ -938,96 +938,6 @@ namespace IRaCIS.Core.API.Controllers } - - [HttpPost] - [UnitOfWork] - public async Task UploadTrialSiteSurveyUser(Guid trialId, - [FromServices] IRepository _trialSiteRepository, - [FromServices] IRepository _usertypeRepository, - [FromServices] ITrialSiteSurveyService _trialSiteSurveyService) - { - var (serverFilePath, relativePath, fileName) = (string.Empty, string.Empty, string.Empty); - await FileUploadAsync(async (realFileName) => - { - fileName = realFileName; - - if (!fileName.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase)) - { - throw new BusinessValidationFailedException("请用提供格式的模板excel上传需要处理的数据"); - } - - (serverFilePath, relativePath) = FileStoreHelper.GetTrialSiteSurveyFilePath(_hostEnvironment, fileName, trialId); - - return serverFilePath; - }); - - //去掉空白行 - var excelList = MiniExcel.Query(serverFilePath).ToList() - .Where(t => !(string.IsNullOrWhiteSpace(t.TrialSiteCode) && string.IsNullOrWhiteSpace(t.FirstName) && string.IsNullOrWhiteSpace(t.LastName)) && string.IsNullOrWhiteSpace(t.Email) - && string.IsNullOrWhiteSpace(t.Phone) && string.IsNullOrWhiteSpace(t.UserTypeStr) && string.IsNullOrWhiteSpace(t.OrganizationName)); - - if (excelList.Any(t => string.IsNullOrWhiteSpace(t.TrialSiteCode) || string.IsNullOrWhiteSpace(t.FirstName) || string.IsNullOrWhiteSpace(t.LastName) || string.IsNullOrWhiteSpace(t.Email) || string.IsNullOrWhiteSpace(t.UserTypeStr))) - { - throw new BusinessValidationFailedException("请确保Excel中 每一行的 中心编号,姓名,邮箱,用户类型数据记录完整再进行上传"); - } - - var siteCodeList = excelList.Select(t => t.TrialSiteCode.Trim()).Distinct().ToList(); - - if (_trialSiteRepository.Where(t => siteCodeList.Contains(t.TrialSiteCode)).Count() != siteCodeList.Count) - { - throw new BusinessValidationFailedException("在项目中未找到该Excel中部分或全部中心"); - } - - if (excelList.GroupBy(t => new { t.UserTypeStr, t.Email }).Any(g => g.Count() > 1)) - { - throw new BusinessValidationFailedException("同一邮箱,同一用户类型,只能生成一个账户,请核查Excel数据"); - } - - if (excelList.Any(t => t.Email.Contains("@"))) - { - throw new BusinessValidationFailedException("有邮箱不符合邮箱格式,请核查Excel数据"); - } - var generateUserTypeList = new List() { "CRC", "SR", "CRA" }; - - if (excelList.Any(t => !generateUserTypeList.Contains(t.UserTypeStr.ToUpper()))) - { - throw new BusinessValidationFailedException("用户类型仅能为 CRC,SR,CRA 请核查Excel数据"); - } - - //处理好 用户类型 和用户类型枚举 - var sysUserTypeList = _usertypeRepository.Where(t => t.UserTypeEnum == UserTypeEnum.CRA || t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator || t.UserTypeEnum == UserTypeEnum.SR).Select(t => new { UserTypeId = t.Id, t.UserTypeEnum }).ToList(); - var siteList= _trialSiteRepository.Where(t=>t.TrialId==trialId && siteCodeList.Contains(t.TrialSiteCode)).Select(t=>new {t.TrialSiteCode,t.SiteId}).ToList(); - - foreach (var item in excelList) - { - switch (item.UserTypeStr.ToUpper()) - { - case "CRC": - - item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator).UserTypeId; - item.UserTypeEnum = UserTypeEnum.ClinicalResearchCoordinator; - break; - - case "CRA": - item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.CRA).UserTypeId; - item.UserTypeEnum = UserTypeEnum.CRA; - break; - - case "SR": - item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.SR).UserTypeId; - item.UserTypeEnum = UserTypeEnum.SR; - break; - - } - - item.SiteId = siteList.FirstOrDefault(t => t.TrialSiteCode.ToUpper() == item.TrialSiteCode.ToUpper()).SiteId; - } - - await _trialSiteSurveyService.ImportGenerateAccountAndJoinTrialAsync(trialId, excelList.ToList()); - - return ResponseOutput.Ok(); - - } } @@ -1123,6 +1033,100 @@ namespace IRaCIS.Core.API.Controllers _userInfo = userInfo; } + + [HttpPost, Route("TrialSiteSurvey/UploadTrialSiteSurveyUser")] + [DisableFormValueModelBinding] + [UnitOfWork] + public async Task UploadTrialSiteSurveyUser(Guid trialId, string baseUrl, string routeUrl, + [FromServices] IRepository _trialSiteRepository, + [FromServices] IRepository _usertypeRepository, + [FromServices] ITrialSiteSurveyService _trialSiteSurveyService) + { + var (serverFilePath, relativePath, fileName) = (string.Empty, string.Empty, string.Empty); + await FileUploadAsync(async (realFileName) => + { + fileName = realFileName; + + if (!fileName.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase)) + { + throw new BusinessValidationFailedException("请用提供格式的模板excel上传需要处理的数据"); + } + + (serverFilePath, relativePath) = FileStoreHelper.GetTrialSiteSurveyFilePath(_hostEnvironment, fileName, trialId); + + return serverFilePath; + }); + + //去掉空白行 + var excelList = MiniExcel.Query(serverFilePath).ToList() + .Where(t => !(string.IsNullOrWhiteSpace(t.TrialSiteCode) && string.IsNullOrWhiteSpace(t.FirstName) && string.IsNullOrWhiteSpace(t.LastName) && string.IsNullOrWhiteSpace(t.Email) + && string.IsNullOrWhiteSpace(t.Phone) && string.IsNullOrWhiteSpace(t.UserTypeStr) && string.IsNullOrWhiteSpace(t.OrganizationName))).ToList(); + + if (excelList.Any(t => string.IsNullOrWhiteSpace(t.TrialSiteCode) || string.IsNullOrWhiteSpace(t.FirstName) || string.IsNullOrWhiteSpace(t.LastName) || string.IsNullOrWhiteSpace(t.Email) || string.IsNullOrWhiteSpace(t.UserTypeStr))) + { + throw new BusinessValidationFailedException("请确保Excel中 每一行的 中心编号,姓名,邮箱,用户类型数据记录完整再进行上传"); + } + + var siteCodeList = excelList.Select(t => t.TrialSiteCode.Trim().ToUpper()).Distinct().ToList(); + + if (_trialSiteRepository.Where(t => t.TrialId==trialId && siteCodeList.Contains(t.TrialSiteCode.ToUpper())).Count() != siteCodeList.Count) + { + throw new BusinessValidationFailedException("在项目中未找到该Excel中部分或全部中心"); + } + + if (excelList.GroupBy(t => new { t.UserTypeStr, t.Email }).Any(g => g.Count() > 1)) + { + throw new BusinessValidationFailedException("同一邮箱,同一用户类型,只能生成一个账户,请核查Excel数据"); + } + + if (excelList.Any(t => !t.Email.Contains("@"))) + { + throw new BusinessValidationFailedException("有邮箱不符合邮箱格式,请核查Excel数据"); + } + var generateUserTypeList = new List() { "CRC", "SR", "CRA" }; + + if (excelList.Any(t => !generateUserTypeList.Contains(t.UserTypeStr.ToUpper()))) + { + throw new BusinessValidationFailedException("用户类型仅能为 CRC,SR,CRA 请核查Excel数据"); + } + + //处理好 用户类型 和用户类型枚举 + var sysUserTypeList = _usertypeRepository.Where(t => t.UserTypeEnum == UserTypeEnum.CRA || t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator || t.UserTypeEnum == UserTypeEnum.SR).Select(t => new { UserTypeId = t.Id, t.UserTypeEnum }).ToList(); + var siteList = _trialSiteRepository.Where(t => t.TrialId == trialId && siteCodeList.Contains(t.TrialSiteCode)).Select(t => new { t.TrialSiteCode, t.SiteId }).ToList(); + + foreach (var item in excelList) + { + switch (item.UserTypeStr.ToUpper()) + { + case "CRC": + + item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator).UserTypeId; + item.UserTypeEnum = UserTypeEnum.ClinicalResearchCoordinator; + break; + + case "CRA": + item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.CRA).UserTypeId; + item.UserTypeEnum = UserTypeEnum.CRA; + break; + + case "SR": + item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.SR).UserTypeId; + item.UserTypeEnum = UserTypeEnum.SR; + break; + + } + + item.SiteId = siteList.FirstOrDefault(t => t.TrialSiteCode.ToUpper() == item.TrialSiteCode.ToUpper()).SiteId; + } + + await _trialSiteSurveyService.ImportGenerateAccountAndJoinTrialAsync(trialId, baseUrl, routeUrl, excelList.ToList()); + + return ResponseOutput.Ok(); + + } + + + /// 缩略图 [AllowAnonymous] [HttpGet("Common/LocalFilePreview")] diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteUserSurveyViewModel.cs b/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteUserSurveyViewModel.cs index d2959bb4f..d272c3cba 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteUserSurveyViewModel.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/DTO/TrialSiteUserSurveyViewModel.cs @@ -137,12 +137,12 @@ namespace IRaCIS.Core.Application.Contracts public class SiteSurveyUserImportDto { - public string TrialSiteCode { get;set; } - public string FirstName { get; set; } - public string LastName { get; set; } - public string Email { get; set; } - public string Phone { get; set; } - public string OrganizationName { get; set; } + public string TrialSiteCode { get;set; }=string.Empty; + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string Phone { get; set; } = string.Empty; + public string OrganizationName { get; set; } = string.Empty; [ExcelColumnName("UserType")] public string UserTypeStr { get; set; } diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/Interface/ITrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/Interface/ITrialSiteSurveyService.cs index 61ee8a14e..52a6ba09a 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/Interface/ITrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/Interface/ITrialSiteSurveyService.cs @@ -21,6 +21,6 @@ namespace IRaCIS.Core.Application.Contracts //IResponseOutput TrialSurveySubmmit(Guid trialId, Guid trialSiteSurveyId); Task VerifySendCode(LoginDto userInfo, [FromServices] ITokenService _tokenService); - Task ImportGenerateAccountAndJoinTrialAsync(Guid trialId, List list); + Task ImportGenerateAccountAndJoinTrialAsync(Guid trialId, string baseUrl,string rootUrl, List list); } } \ No newline at end of file diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index ac7241796..3e680e5a2 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -838,14 +838,16 @@ namespace IRaCIS.Core.Application.Contracts //判断TrialUser中是否存在 不存在就插入 - if (!await _trialUserRepository.AnyAsync(t => t.TrialId == trialId && t.UserId == userId, true)) + + var findTrialUser = await _trialUserRepository.FirstOrDefaultAsync(t => t.TrialId == trialId && t.UserId == userId, true); + if (findTrialUser==null) { await _repository.AddAsync(new TrialUser() { TrialId = trialId, UserId = userId, JoinTime = DateTime.Now }); await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl); } - else + else if(findTrialUser.IsDeleted==true) { await _trialUserRepository.UpdatePartialFromQueryAsync(t => t.TrialId == trialId && t.UserId == userId, c => new TrialUser() { @@ -853,13 +855,14 @@ namespace IRaCIS.Core.Application.Contracts DeletedTime = null, JoinTime = DateTime.Now, }); + + await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl); } if (!await _repository.AnyAsync(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); } else { @@ -935,7 +938,7 @@ namespace IRaCIS.Core.Application.Contracts - public async Task ImportGenerateAccountAndJoinTrialAsync(Guid trialId, List list) + public async Task ImportGenerateAccountAndJoinTrialAsync(Guid trialId, string baseUrl, string routeUrl, List list) { @@ -977,18 +980,22 @@ namespace IRaCIS.Core.Application.Contracts } item.IsGeneratedAccount = true; - - + } var userId = sysUserInfo.Id; + var siteId = item.SiteId; - - if (!await _trialUserRepository.AnyAsync(t=>t.TrialId==trialId && t.UserId== userId, true)) + //判断是否加入到项目 + var findTrialUser = await _trialUserRepository.FirstOrDefaultAsync(t => t.TrialId == trialId && t.UserId == userId, true); + if (findTrialUser == null) { await _repository.AddAsync(new TrialUser() { TrialId = trialId, UserId = userId, JoinTime = DateTime.Now }); + + await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, baseUrl, routeUrl); + } - else + else if (findTrialUser.IsDeleted == true) { await _trialUserRepository.UpdatePartialFromQueryAsync(t => t.TrialId == trialId && t.UserId == userId, c => new TrialUser() { @@ -996,6 +1003,8 @@ namespace IRaCIS.Core.Application.Contracts DeletedTime = null, JoinTime = DateTime.Now, }); + + await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, baseUrl, routeUrl); } @@ -1003,7 +1012,6 @@ namespace IRaCIS.Core.Application.Contracts { await _repository.AddAsync(new TrialSiteUser() { TrialId = trialId, SiteId = siteId, UserId = userId }); - await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl); } else { @@ -1014,9 +1022,12 @@ namespace IRaCIS.Core.Application.Contracts }); } + await _userRepository.BatchUpdateNoTrackingAsync(t => t.Id == userId, u => new User() { Status = UserStateEnum.Enable }); + + await _trialSiteUserRepository.SaveChangesAsync(); + } - //判断是否加入到项目 } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs index 493e04861..0806cb981 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs @@ -280,52 +280,9 @@ namespace IRaCIS.Application.Services public async Task DeleteTrial(Guid trialId) { - - var trial = (await _trialRepository.FirstOrDefaultAsync(u => u.Id == trialId, true)).IfNullThrowException(); - - if (_verifyConfig.CurrentValue.OpenTrialRelationDelete) { - - #region 项目真删除废弃 - - //if (trial.VisitPlanConfirmed) - //{ - // return ResponseOutput.NotOk("Trial访视计划已经确认,无法删除"); - //} - - //if (await _repository.AnyAsync(u => u.TrialId == trialId)) - //{ - // return ResponseOutput.NotOk("该Trial有医生入组或在入组流程中,无法删除"); - //} - - //if (await _repository.AnyAsync(u => u.TrialId == trialId)) - //{ - // return ResponseOutput.NotOk("该Trial下面有Site,无法删除"); - //} - - ////PM 可以删除项目 仅仅在没有site 参与者只有他自己的时候 - //if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager) - //{ - // //参与者仅有他自己时,可以删除 - // if (await _trialUserRepository.CountAsync(t => t.TrialId == trialId) == 1) - // { - - // var success1 = await _repository.BatchDeleteAsync(o => o.Id == trialId) || - // await _repository.BatchDeleteAsync(t => t.TrialId == trialId) || - // await _repository.BatchDeleteAsync(t => t.TrialId == trialId); - - // return ResponseOutput.Result(success1); - // } - //} - - //if (await _repository.AnyAsync(u => u.TrialId == trialId)) - //{ - // return ResponseOutput.NotOk("该Trial下面有参与者,无法删除"); - //} - #endregion - - + await _repository.BatchDeleteAsync(o => o.SubjectVisit.TrialId == trialId); await _repository.BatchDeleteAsync(o => o.TrialId == trialId); @@ -344,9 +301,6 @@ namespace IRaCIS.Application.Services - - - await _repository.BatchDeleteAsync(t => t.SubjectVisit.TrialId == trialId); await _repository.BatchDeleteAsync(t => t.SubjectVisit.TrialId == trialId); await _repository.BatchDeleteAsync(t => t.SubjectVisit.TrialId == trialId); @@ -438,7 +392,6 @@ namespace IRaCIS.Application.Services await _repository.BatchDeleteAsync(t => t.OriginalReReadingTask.TrialId == trialId); await _repository.BatchDeleteAsync(t => t.TrialId == trialId); - await _repository.BatchDeleteAsync(t => t.TrialId == trialId); await _repository.BatchDeleteAsync(t => t.TrialId == trialId) ; return ResponseOutput.Ok(); @@ -454,41 +407,6 @@ namespace IRaCIS.Application.Services } - [AllowAnonymous] - [HttpDelete, Route("{trialId:guid}")] - public async Task DeleteTrialTaskData(Guid trialId) - { - - //await _repository.BatchDeleteAsync(t => t.TrialId == trialId) || - // await _repository.BatchDeleteAsync(t => t.TrialId == trialId) || - // await _repository.BatchDeleteAsync(t => t.TrialId == trialId) || - - - - - //await _repository.BatchDeleteAsync(t => t.TrialId == trialId); - // await _repository.BatchDeleteAsync(t => t.TrialId == trialId); - - - // await _repository.BatchDeleteAsync(t => t.TaskMedicalReview.TrialId == trialId); - // await _repository.BatchDeleteAsync(t => t.TaskMedicalReview.TrialId == trialId); - - - // await _repository.BatchDeleteAsync(t => t.VisitTask.TrialId == trialId); - - // await _repository.BatchDeleteAsync(t => t.TrialId == trialId); - - // await _repository.BatchDeleteAsync(t => t.TrialId == trialId); - // await _repository.BatchDeleteAsync(t => t.TrialId == trialId) ; - - // await _repository.BatchDeleteAsync(t => t.VisitTask.TrialId == trialId); - // await _repository.BatchDeleteAsync(t => t.TrialId == trialId); - - // await _repository.BatchDeleteAsync(t => t.OriginalReReadingTask.TrialId == trialId); - // await _repository.BatchDeleteAsync(t => t.TrialId == trialId); - - return ResponseOutput.Ok(); - }