diff --git a/IRaCIS.Core.API/Controllers/ExtraController.cs b/IRaCIS.Core.API/Controllers/ExtraController.cs index e8016d431..fb245ad1c 100644 --- a/IRaCIS.Core.API/Controllers/ExtraController.cs +++ b/IRaCIS.Core.API/Controllers/ExtraController.cs @@ -116,7 +116,7 @@ namespace IRaCIS.Api.Controllers [FromServices] IReadingImageTaskService readingImageTaskService, [FromServices] IOptionsMonitor _verifyConfig, [FromServices] IOptionsMonitor _emailConfig, - [FromServices]IMapper _mapper, + [FromServices] IMapper _mapper, [FromServices] IMailVerificationService _mailVerificationService) { var emailConfig = _emailConfig.CurrentValue; @@ -312,8 +312,8 @@ namespace IRaCIS.Api.Controllers { var token = _tokenService.GetToken(new UserTokenInfo() { - UserRoleId = Guid.NewGuid(), - UserName = "Share001", + UserRoleId = Guid.NewGuid(), + UserName = "Share001", UserTypeEnum = UserTypeEnum.ShareImage, }); @@ -375,7 +375,7 @@ namespace IRaCIS.Api.Controllers [HttpGet("User/UserRedirect")] [AllowAnonymous] - public async Task UserRedirect([FromServices] IRepository _userRoleRepository, string url, [FromServices] ILogger _logger) + public async Task UserRedirect([FromServices] IRepository _useRepository, string url, [FromServices] ILogger _logger) { var decodeUrl = System.Web.HttpUtility.UrlDecode(url); @@ -391,7 +391,7 @@ namespace IRaCIS.Api.Controllers var errorUrl = domainStrList[0] + "//" + domainStrList[2] + "/error"; - if (!await _userRoleRepository.AnyAsync(t => t.Id == Guid.Parse(userId) && t.EmailToken == token && t.IsFirstAdd)) + if (!await _useRepository.AnyAsync(t => t.Id == Guid.Parse(userId) && t.EmailToken == token && t.IsFirstAdd)) { decodeUrl = errorUrl + $"?lang={lang}&ErrorMessage={System.Web.HttpUtility.UrlEncode(lang == "zh" ? "您的初始化链接已过期" : "Error!The initialization link has expired. Return")} "; } diff --git a/IRaCIS.Core.Application/Service/Common/MailService.cs b/IRaCIS.Core.Application/Service/Common/MailService.cs index 20ea82681..b1648d436 100644 --- a/IRaCIS.Core.Application/Service/Common/MailService.cs +++ b/IRaCIS.Core.Application/Service/Common/MailService.cs @@ -558,7 +558,7 @@ namespace IRaCIS.Core.Application.Service public async Task DoctorJoinTrialEmail(Guid trialId, Guid doctorId, string baseUrl, string rootUrl) { var doctor = await _doctorTypeRepository.FindAsync(doctorId); - UserRole sysUserInfo = new UserRole(); + var sysUserInfo = new IdentityUser(); var userType = await _userTypeRepository.FirstAsync(t => t.UserTypeEnum == UserTypeEnum.IndependentReviewer); @@ -572,7 +572,7 @@ namespace IRaCIS.Core.Application.Service if (!isDoctorHaveAccount) { - var saveItem = new UserRole() { FirstName = doctor.FirstName, LastName = doctor.LastName, EMail = doctor.EMail }; + var saveItem = new IdentityUser() { FirstName = doctor.FirstName, LastName = doctor.LastName, EMail = doctor.EMail }; var trialType = await _trialRepository.Where(t => t.Id == trialId).Select(t => t.TrialType).FirstOrDefaultAsync(); @@ -584,28 +584,26 @@ namespace IRaCIS.Core.Application.Service saveItem.Code = _userRoleRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1; - saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(UserRole)); + saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(IdentityUser)); saveItem.UserName = saveItem.UserCode; - saveItem.UserTypeEnum = UserTypeEnum.IndependentReviewer; - saveItem.DoctorId = doctorId; - saveItem.UserTypeId = userType.Id; + saveItem.UserRoleList = new List() { new UserRole() { DoctorId = doctorId, UserTypeEnum = UserTypeEnum.IndependentReviewer, UserTypeId = userType.Id } }; - var savedUser = await _userRoleRepository.AddAsync(saveItem); + var savedUser = await _identityUserRepository.AddAsync(saveItem); //下面获取Token 需要这部分信息 sysUserInfo = savedUser.Clone(); - sysUserInfo.UserTypeRole = userType; + await _userRoleRepository.SaveChangesAsync(); } else { - sysUserInfo = (await _userRoleRepository.Where(t => t.DoctorId == doctorId).Include(t => t.UserTypeRole).FirstOrDefaultAsync()).IfNullThrowException(); + sysUserInfo = (await _identityUserRepository.Where(t => t.UserRoleList.Any(t => t.DoctorId == doctorId)).Include(t => t.UserRoleList).FirstOrDefaultAsync()).IfNullThrowException(); } } @@ -620,14 +618,14 @@ namespace IRaCIS.Core.Application.Service - var token = _tokenService.GetToken(new UserTokenInfo() { UserRoleId = sysUserInfo.Id }); + var token = _tokenService.GetToken(new UserTokenInfo() { IdentityUserId = sysUserInfo.Id }); if (sysUserInfo.IsFirstAdd) { - await _userRoleRepository.BatchUpdateNoTrackingAsync(t => t.Id == sysUserInfo.Id, u => new UserRole() { EmailToken = token }); + await _identityUserRepository.BatchUpdateNoTrackingAsync(t => t.Id == sysUserInfo.Id, u => new Domain.Models.IdentityUser() { EmailToken = token }); } - var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&UserType=" + userType.UserTypeShortName + "&lang=" + (_userInfo.IsEn_Us ? "en" : "zh") + "&access_token=" + token; + var routeUrl = rootUrl + "?UserId=" + sysUserInfo.Id + "&Email=" + sysUserInfo.EMail + "&UserName=" + sysUserInfo.UserName + "&lang=" + (_userInfo.IsEn_Us ? "en" : "zh") + "&access_token=" + token; var domain = baseUrl.Substring(0, baseUrl.IndexOf("/login")); diff --git a/IRaCIS.Core.Application/Service/Doctor/_MapConfig.cs b/IRaCIS.Core.Application/Service/Doctor/_MapConfig.cs index cc7e997f9..3ad9f5fdc 100644 --- a/IRaCIS.Core.Application/Service/Doctor/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Doctor/_MapConfig.cs @@ -120,7 +120,7 @@ namespace IRaCIS.Core.Application.Service #region 医生基本信息 CreateMap() - .ForMember(d => d.DoctorUserName, u => u.MapFrom(t => t.User.UserName)); + .ForMember(d => d.DoctorUserName, u => u.MapFrom(t => t.UserRole.UserName)); CreateMap().IncludeMembers(t => t.Hospital).Include() .ForMember(d => d.AccountUserName, u => u.MapFrom(s => s.EnrollList.Where(t => t.DoctorUserId != null).Select(c => c.DoctorUser.UserName).FirstOrDefault())) .ForMember(d => d.Department, u => u.MapFrom(s => s.Department.Value)) diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs index 8a76144ae..b3e8a683d 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs @@ -58,7 +58,7 @@ namespace IRaCIS.Core.Application.Service /// //[Authorize(Policy = IRaCISPolicy.PM_APM)] [UnitOfWork] - [TrialGlobalLimit( "AfterStopCannNotOpt" )] + [TrialGlobalLimit("AfterStopCannNotOpt")] public async Task AddOrUpdateTrialExternalUser(TrialExternalUserAddAndSendEmail addOrEditTrialExternalUser) { @@ -104,6 +104,15 @@ namespace IRaCIS.Core.Application.Service addEntity.IsSystemUser = true; addEntity.SystemUserId = existSysUser.Id; + if (!existSysUser.UserRoleList.Any(t => t.UserTypeId == addOrEditTrialExternalUser.UserTypeId)) + { + var addRole = _mapper.Map(existSysUser); + addRole.UserTypeEnum = _userTypeRepository.Where(t => t.Id == addOrEditTrialExternalUser.UserTypeId).Select(t => t.UserTypeEnum).First(); + addRole.UserTypeId = addOrEditTrialExternalUser.UserTypeId; + addRole.IsUserRoleDisabled = true; + existSysUser.UserRoleList.Add(addRole); + } + } else { @@ -241,7 +250,7 @@ namespace IRaCIS.Core.Application.Service //New 省掉邀请流程 [HttpPost] //[Authorize(Policy = IRaCISPolicy.PM_APM)] - [TrialGlobalLimit( "AfterStopCannNotOpt" )] + [TrialGlobalLimit("AfterStopCannNotOpt")] [UnitOfWork] public async Task SendExternalUserJoinEmail(TrialExternalUserSendEmail sendEmail) { @@ -254,9 +263,9 @@ namespace IRaCIS.Core.Application.Service var findTrialUser = await _trialIdentityUserRepository.FirstOrDefaultAsync(t => t.TrialId == trialId && t.IdentityUserId == userId, true); - var findUserRoleId = await _identityUserRepository.Where(t => t.Id == userId,true).SelectMany(t => t.UserRoleList).Where(t => t.UserTypeId == userTypeId).Select(t => t.Id).FirstOrDefaultAsync(); + var findUserRoleId = await _identityUserRepository.Where(t => t.Id == userId, true).SelectMany(t => t.UserRoleList).Where(t => t.UserTypeId == userTypeId).Select(t => t.Id).FirstOrDefaultAsync(); - if (findTrialUser == null || findUserRoleId==Guid.Empty) + if (findTrialUser == null || findUserRoleId == Guid.Empty) { return ResponseOutput.NotOk("database dirty data "); } @@ -264,10 +273,10 @@ namespace IRaCIS.Core.Application.Service { var findTrialUserRole = await _trialUserRoleRepository.FirstOrDefaultAsync(t => t.TrialId == trialId && t.UserRole.IdentityUserId == userId && t.UserRole.UserTypeId == userTypeId, true); - if (findTrialUserRole==null) + if (findTrialUserRole == null) { - await _trialUserRoleRepository.AddAsync(new TrialUserRole() { TrialId = trialId, TrialUserId=findTrialUser.Id, UserId = findUserRoleId, JoinTime = DateTime.Now }); + await _trialUserRoleRepository.AddAsync(new TrialUserRole() { TrialId = trialId, TrialUserId = findTrialUser.Id, UserId = findUserRoleId, JoinTime = DateTime.Now }); await _userRoleRepository.BatchUpdateNoTrackingAsync(t => t.IdentityUserId == userId, u => new UserRole() { Status = UserStateEnum.Enable }); @@ -280,9 +289,9 @@ namespace IRaCIS.Core.Application.Service } - foreach (var item in sendEmail.SendUsers.GroupBy(t=>t.SystemUserId)) + foreach (var item in sendEmail.SendUsers.GroupBy(t => t.SystemUserId)) { - await _mailVerificationService.ExternalUserJoinEmail(trialId, item.Key, sendEmail.BaseUrl, sendEmail.RouteUrl); + await _mailVerificationService.ExternalUserJoinEmail(trialId, item.Key, sendEmail.BaseUrl, sendEmail.RouteUrl); } diff --git a/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs b/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs index 57e23df69..805eb24dd 100644 --- a/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs +++ b/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs @@ -242,7 +242,7 @@ namespace IRaCIS.Core.Application.Service Id = x.Id }).ToList(), - ReadingTaskStateList = doctor.User.VisitTaskList.Where(x => x.TaskState == TaskState.Effect && x.TrialId == trialId).Select(x => new DoctorUserTask() + ReadingTaskStateList = intoGroup.DoctorUser.VisitTaskList.Where(x => x.TaskState == TaskState.Effect && x.TrialId == trialId).Select(x => new DoctorUserTask() { ReadingTaskState = x.ReadingTaskState, TrialReadingCriterionId = x.TrialReadingCriterionId, diff --git a/IRaCIS.Core.Domain/Dcotor/Doctor.cs b/IRaCIS.Core.Domain/Dcotor/Doctor.cs index e5a00ef6f..bbc3e79de 100644 --- a/IRaCIS.Core.Domain/Dcotor/Doctor.cs +++ b/IRaCIS.Core.Domain/Dcotor/Doctor.cs @@ -39,7 +39,7 @@ public class Doctor : BaseFullAuditEntity public List CriterionFileList { get; set; } [JsonIgnore] - public UserRole User { get; set; } + public UserRole UserRole { get; set; } #endregion public bool AcceptingNewTrial { get; set; }