From 5be941663bcd53a9f62ce7c0089399778a7a5414 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 9 Nov 2023 16:56:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=AD=E5=BF=83=E8=B0=83?= =?UTF-8?q?=E7=A0=94=E5=AF=BC=E5=85=A5=E5=92=8C=E5=A2=9E=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/UploadDownLoadController.cs | 104 ++++++++++++++++++ .../Service/Management/UserTypeService.cs | 4 +- .../Interface/ITrialSiteSurveyService.cs | 2 + .../SiteSurvey/TrialSiteSurveyService.cs | 1 + IRaCIS.Core.Domain.Share/User/UserType.cs | 7 +- 5 files changed, 111 insertions(+), 7 deletions(-) diff --git a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs index 93ad59670..a1dd8d861 100644 --- a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs +++ b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs @@ -946,6 +946,110 @@ 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)) + { + // 请用提供格式的模板excel上传需要处理的数据 + throw new BusinessValidationFailedException(StaticData.International("UploadDownLoad_TemplateUploadData")); + } + + (serverFilePath, relativePath) = FileStoreHelper.GetOtherFileUploadPath(_hostEnvironment, StaticData.Folder.TempFile, fileName); + + //FileStoreHelper.UploadOOS(serverFilePath, "testc/test", true); + + 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))) + { + //请确保Excel中 每一行的 中心编号,姓名,邮箱,用户类型数据记录完整再进行上传 + throw new BusinessValidationFailedException(StaticData.International("UploadDownLoad_EnsureCompleteData")); + } + + 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) + { + //在项目中未找到该Excel中部分或全部中心 + throw new BusinessValidationFailedException(StaticData.International("UploadDownLoad_InvalidCenters")); + } + + if (excelList.GroupBy(t => new { t.TrialSiteCode, t.UserTypeStr, t.Email }).Any(g => g.Count() > 1)) + { + // 同一邮箱,同一用户类型,只能生成一个账户,请核查Excel数据 + + throw new BusinessValidationFailedException(StaticData.International("UploadDownLoad_CheckDuplicateAccounts")); + } + + if (excelList.Any(t => !t.Email.Contains("@"))) + { + //有邮箱不符合邮箱格式,请核查Excel数据 + throw new BusinessValidationFailedException(StaticData.International("UploadDownLoad_InvalidEmail")); + } + var generateUserTypeList = new List() { "CRC", "CRA" }; + + if (excelList.Any(t => !generateUserTypeList.Contains(t.UserTypeStr.ToUpper()))) + { + //用户类型仅能为 CRC,SR,CRA 请核查Excel数据 + throw new BusinessValidationFailedException(StaticData.International("UploadDownLoad_InvalidUserType")); + } + if (excelList.Count == 0) + { + throw new BusinessValidationFailedException(StaticData.International("UploadDownLoad_NoValiddata")); + } + //处理好 用户类型 和用户类型枚举 + var sysUserTypeList = _usertypeRepository.Where(t => t.UserTypeEnum == UserTypeEnum.CRA || t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator ).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; + + + + } + + 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("CommonDocument/DownloadCommonDoc")] diff --git a/IRaCIS.Core.Application/Service/Management/UserTypeService.cs b/IRaCIS.Core.Application/Service/Management/UserTypeService.cs index 1e55c1dd3..c3553372b 100644 --- a/IRaCIS.Core.Application/Service/Management/UserTypeService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserTypeService.cs @@ -113,13 +113,13 @@ namespace IRaCIS.Core.Application.Contracts if (userTypeSelectEnum == UserTypeSelectEnum.ExternalUser) { - userTypeEnums = new List() { UserTypeEnum.CPM, UserTypeEnum.SPM, UserTypeEnum.CPM, UserTypeEnum.SMM, UserTypeEnum.CMM, UserTypeEnum.EA }; + userTypeEnums = new List() { UserTypeEnum.CPM, UserTypeEnum.SPM, UserTypeEnum.CPM, UserTypeEnum.SMM, UserTypeEnum.CMM, UserTypeEnum.EA , UserTypeEnum.MC }; } if (userTypeSelectEnum == UserTypeSelectEnum.InnerUser) { - userTypeEnums = new List() { UserTypeEnum.IQC, UserTypeEnum.APM, UserTypeEnum.MIM, UserTypeEnum.QA ,UserTypeEnum.MW}; + userTypeEnums = new List() { UserTypeEnum.IQC, UserTypeEnum.APM, UserTypeEnum.MIM, UserTypeEnum.QA ,UserTypeEnum.MW,UserTypeEnum.MC}; if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SuperAdmin) { diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/Interface/ITrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/Interface/ITrialSiteSurveyService.cs index 6bc2fc3ec..526f29ca7 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/Interface/ITrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/Interface/ITrialSiteSurveyService.cs @@ -20,5 +20,7 @@ namespace IRaCIS.Core.Application.Contracts //Task TrialSurveyLock(Guid trialSiteSurveyId, bool isLock); //IResponseOutput TrialSurveySubmmit(Guid trialId, Guid trialSiteSurveyId); Task VerifySendCode(LoginDto userInfo, [FromServices] ITokenService _tokenService); + + Task ImportGenerateAccountAndJoinTrialAsync(Guid trialId, string baseUrl, string routeUrl, 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 1e6b9451c..a2253fa03 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -1013,5 +1013,6 @@ namespace IRaCIS.Core.Application.Contracts } + } } diff --git a/IRaCIS.Core.Domain.Share/User/UserType.cs b/IRaCIS.Core.Domain.Share/User/UserType.cs index d38149bdd..29d582894 100644 --- a/IRaCIS.Core.Domain.Share/User/UserType.cs +++ b/IRaCIS.Core.Domain.Share/User/UserType.cs @@ -15,11 +15,6 @@ IQC = 3, - ////简历管理人员 - //ResumeManager=4, - ////简历运维人员 - //ReviewerCoordinator = 5, - ReviewerCoordinator = 4, // 大屏展示 @@ -58,6 +53,8 @@ AIR=21, + MC=30, + //医生用户类型暂不处理 ShareImage = 125,