diff --git a/IRaCIS.Core.Application/Auth/IRaCISClaims.cs b/IRaCIS.Core.Application/Auth/IRaCISClaims.cs index b25b4b05e..446140787 100644 --- a/IRaCIS.Core.Application/Auth/IRaCISClaims.cs +++ b/IRaCIS.Core.Application/Auth/IRaCISClaims.cs @@ -20,6 +20,8 @@ namespace IRaCIS.Core.Application.Auth public int IsAdmin { get; } + public bool IsTestUser { get; set; } + public string Phone { get; set; } = String.Empty; public static IRaCISClaims Create(UserBasicInfo user) @@ -31,6 +33,7 @@ namespace IRaCIS.Core.Application.Auth RealName = user.RealName, UserTypeEnum=user.UserTypeEnum, UserTypeId=user.UserTypeId, + IsTestUser=user.IsTestUser, Code = user.Code, PermissionStr = user.PermissionStr, diff --git a/IRaCIS.Core.Application/Auth/TokenService.cs b/IRaCIS.Core.Application/Auth/TokenService.cs index bb40d200b..4890a0339 100644 --- a/IRaCIS.Core.Application/Auth/TokenService.cs +++ b/IRaCIS.Core.Application/Auth/TokenService.cs @@ -35,7 +35,9 @@ namespace IRaCIS.Core.Application.Auth new Claim(JwtIRaCISClaimType.UserTypeEnum,user.UserTypeEnum.ToString()), new Claim(JwtIRaCISClaimType.UserTypeEnumInt,((int)user.UserTypeEnum).ToString()), new Claim(JwtIRaCISClaimType.UserTypeShortName,user.UserTypeShortName), - new Claim(JwtIRaCISClaimType.PermissionStr,user.PermissionStr) + new Claim(JwtIRaCISClaimType.PermissionStr,user.PermissionStr), + + new Claim(JwtIRaCISClaimType.IsTestUser,user.IsTestUser.ToString()) }; ////创建令牌 diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 5f0de0114..6d15cb18f 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -3888,6 +3888,11 @@ 问题标识 + + + 问题英文名称 + + ReadingTableQuestionSystemAddOrEdit 列表查询参数模型 @@ -3931,6 +3936,11 @@ 问题标识 + + + 问题英文名称 + + PageName @@ -4209,6 +4219,16 @@ 数据来源 + + + 问题英文名称 + + + + + 问题英文分组 + + 数值类型 @@ -4349,6 +4369,16 @@ 序号标记 + + + 问题英文名称 + + + + + 问题英文分组 + + 自定义计算标记 @@ -4634,6 +4664,16 @@ 序号标记 + + + 问题英文名称 + + + + + 问题英文分组 + + Id @@ -4804,6 +4844,16 @@ 限制编辑 + + + 问题英文名称 + + + + + 问题英文分组 + + 返回的对象 diff --git a/IRaCIS.Core.Application/Service/Common/MailService.cs b/IRaCIS.Core.Application/Service/Common/MailService.cs index 585de9810..50ee01b20 100644 --- a/IRaCIS.Core.Application/Service/Common/MailService.cs +++ b/IRaCIS.Core.Application/Service/Common/MailService.cs @@ -529,6 +529,14 @@ namespace IRaCIS.Application.Services var saveItem = new User() { FirstName = doctor.FirstName, LastName = doctor.LastName, EMail = doctor.EMail }; + var trialType = await _trialRepository.Where(t => t.Id == trialId).Select(t => t.TrialType).FirstOrDefaultAsync(); + + if (trialType == TrialType.NoneOfficial) + { + saveItem.IsTestUser = true; + } + + saveItem.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1; saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(User)); diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs index 54b1c0a20..57a089d1b 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs @@ -39,6 +39,8 @@ namespace IRaCIS.Application.Contracts public UserTypeEnum UserTypeEnum { get; set; } + + public bool IsTestUser { get; set; } public bool IsAdmin { get; set; } = false; public string UserTypeShortName { get; set; } = string.Empty; public bool PasswordChanged { get; set; } @@ -145,6 +147,8 @@ namespace IRaCIS.Application.Contracts public string DepartmentName { get; set; } = String.Empty; public string PositionName { get; set; } = String.Empty; + + public bool IsTestUser { get; set; } } /// diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index 7d6853590..781891b8b 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -695,7 +695,7 @@ namespace IRaCIS.Core.Application.Contracts //await SendInviteEmail(new InviteEmailCommand() { TrialId = trialId, RouteUrl = siteSurvyeSubmit.RouteUrl, UserList = needGenerateList }); - await GenerateAccountAsync(needGenerateList); + await GenerateAccountAsync(needGenerateList,trialId); await SendSiteSurveyUserJoinEmail(new TrialSiteUserSurveyJoinCommand() { TrialId = trialId, TrialSiteSurveyId = trialSiteSurveyId, RouteUrl = siteSurvyeSubmit.RouteUrl, BaseUrl = siteSurvyeSubmit.BaseUrl, UserList = needGenerateList }); @@ -706,7 +706,7 @@ namespace IRaCIS.Core.Application.Contracts - private async Task GenerateAccountAsync(List needGenerateList) + private async Task GenerateAccountAsync(List needGenerateList,Guid trialId) { foreach (var item in needGenerateList) { @@ -722,6 +722,13 @@ namespace IRaCIS.Core.Application.Contracts { var saveItem = _mapper.Map(item); + var trialType = _repository.Where(t => t.Id == trialId).Select(t => t.TrialType).FirstOrDefault(); + + if (trialType == TrialType.NoneOfficial) + { + saveItem.IsTestUser = true; + } + saveItem.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1; saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(User)); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs index 0d236d4cb..d029a6b8e 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs @@ -110,10 +110,17 @@ namespace IRaCIS.Core.Application.Service } else { + var trialType = await _repository.Where(t => t.Id == addOrEditTrialExternalUser.TrialId).Select(t => t.TrialType).FirstOrDefaultAsync(); + //生成账户 并插入 var generateUser = _mapper.Map(addOrEditTrialExternalUser); + if (trialType == TrialType.NoneOfficial) + { + generateUser.IsTestUser = true; + } + generateUser.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1; diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs index a811eeae5..5aeb3d61c 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs @@ -105,15 +105,21 @@ namespace IRaCIS.Application.Services [HttpPost] public async Task> GetTrialUserScreeningList(TrialUserQuery trialUserQuery) { + var trialType = _trialRepository.Where(t => t.Id == trialUserQuery.TrialId).Select(t => t.TrialType).FirstOrDefault(); + //之前已经选择的用户 不放在列表中,现在又要改回去 废弃 var query = _repository.Where(t => t.UserTypeEnum != UserTypeEnum.SuperAdmin) - .WhereIf(!string.IsNullOrWhiteSpace(trialUserQuery.UserRealName), t => (t.FullName).Contains(trialUserQuery.UserRealName)) - .WhereIf(!string.IsNullOrWhiteSpace(trialUserQuery.UserName), t => t.UserName.Contains(trialUserQuery.UserName)) + + //正式或者培训的项目不能允许测试用户 + .WhereIf( trialType==TrialType.OfficialTrial||trialType==TrialType.Training, t => t.IsTestUser==false) + + .WhereIf(!string.IsNullOrWhiteSpace(trialUserQuery.UserRealName), t => (t.FullName).Contains(trialUserQuery.UserRealName)) + .WhereIf(!string.IsNullOrWhiteSpace(trialUserQuery.UserName), t => t.UserName.Contains(trialUserQuery.UserName)) //.WhereIf(!string.IsNullOrWhiteSpace(trialUserQuery.OrganizationName), t => t.OrganizationName.Contains(trialUserQuery.OrganizationName)) - .WhereIf(trialUserQuery.UserTypeEnum != null, t => t.UserTypeEnum == trialUserQuery.UserTypeEnum) + .WhereIf(trialUserQuery.UserTypeEnum != null, t => t.UserTypeEnum == trialUserQuery.UserTypeEnum) //.WhereIf(_userInfo.IsAdmin, t => t.UserTypeRole.Type == UserTypeGroup.TrialUser) //.WhereIf(!_userInfo.IsAdmin, t => t.UserTypeRole.Type == UserTypeGroup.TrialUser || t.UserTypeEnum != UserTypeEnum.ProjectManager) - .ProjectTo(_mapper.ConfigurationProvider, new { trialId = trialUserQuery.TrialId }); + .ProjectTo(_mapper.ConfigurationProvider, new { trialId = trialUserQuery.TrialId }); return await query.ToPagedListAsync(trialUserQuery.PageIndex, trialUserQuery.PageSize, string.IsNullOrWhiteSpace(trialUserQuery.SortField) ? "UserRealName" : trialUserQuery.SortField, trialUserQuery.Asc); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs index f79f66a45..cd5c8b42a 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs @@ -138,6 +138,12 @@ namespace IRaCIS.Application.Services throw new BusinessValidationFailedException("只有PM/APM拥有操作权限!"); } + //测试用户 只能创建非正式项目 + if(_userInfo.IsTestUser && trialAddModel.TrialType != TrialType.NoneOfficial) + { + throw new BusinessValidationFailedException("测试用户 只能创建非正式项目"); + } + if (trialAddModel.Id == Guid.Empty || trialAddModel.Id == null) { if (await _trialRepository.AnyAsync(u => u.TrialCode == trialAddModel.TrialCode)) diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 09671bbe5..a025364f1 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -105,6 +105,7 @@ namespace IRaCIS.Application.Services //await _visitTaskRepositoryy.UpdatePartialFromQueryAsync( Guid.Parse("78360000-3E2C-0016-9B53-08DA6A002040"), c => new VisitTask() { UpdateTime = DateTime.Now.AddMinutes(1) }); + var a= _userInfo.IsTestUser; var list1 = await _repository.Where().Select(t => t.TranslateValue(t.Value, t.ValueCN,true)).ToListAsync(); var list2 = await _repository.Where().Select(t => t.TranslateValue(t.Value, t.ValueCN, false)).ToListAsync(); diff --git a/IRaCIS.Core.Application/Triggers/AddlTrialUserTrigger.cs b/IRaCIS.Core.Application/Triggers/AddlTrialUserTrigger.cs new file mode 100644 index 000000000..528f3bd09 --- /dev/null +++ b/IRaCIS.Core.Application/Triggers/AddlTrialUserTrigger.cs @@ -0,0 +1,52 @@ +using EntityFrameworkCore.Triggered; +using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Infrastructure; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IRaCIS.Core.Application.Triggers +{ + + // 统一处理 外部用户、中心调研、参与医生加入到项目 + public class AddlTrialUserTrigger : IBeforeSaveTrigger + + { + private readonly IRepository _trialRepository; + private readonly IRepository _userRepository; + + public AddlTrialUserTrigger(IRepository trialRepository, IRepository userRepository) + { + _trialRepository = trialRepository; + + _userRepository = userRepository; + + } + public async Task BeforeSave(ITriggerContext context, CancellationToken cancellationToken) + { + var trialUser = context.Entity; + + if (context.ChangeType == ChangeType.Added) + { + //批量添加的时候,使用Find 不会多次查询,优先从跟踪的内存中查找 + var trialInfo = await _trialRepository.FindAsync(trialUser.TrialId); + + if(trialInfo.TrialType==Domain.Share.TrialType.OfficialTrial || trialInfo.TrialType == Domain.Share.TrialType.Training ) + { + // 必须包在同一个事务,有的时候是数据库还没用户,不能直接查询数据库 + var user = await _userRepository.FindAsync(trialUser.UserId); + + if (user.IsTestUser) + { + throw new BusinessValidationFailedException("正式类型 、培训类型的项目 不允许加入测试用户 "); + + } + } + } + } + } + + +} \ No newline at end of file diff --git a/IRaCIS.Core.Domain.Share/AuthUser/IUserInfo.cs b/IRaCIS.Core.Domain.Share/AuthUser/IUserInfo.cs index b719b0d67..1d9e56684 100644 --- a/IRaCIS.Core.Domain.Share/AuthUser/IUserInfo.cs +++ b/IRaCIS.Core.Domain.Share/AuthUser/IUserInfo.cs @@ -25,6 +25,8 @@ namespace IRaCIS.Core.Domain.Share bool IsAdmin { get; } + bool IsTestUser { get; } + string UserTypeShortName { get; } string UserTypeEnumStr { get; } diff --git a/IRaCIS.Core.Domain.Share/AuthUser/UserInfo.cs b/IRaCIS.Core.Domain.Share/AuthUser/UserInfo.cs index 2664a3f2e..94d83f80f 100644 --- a/IRaCIS.Core.Domain.Share/AuthUser/UserInfo.cs +++ b/IRaCIS.Core.Domain.Share/AuthUser/UserInfo.cs @@ -154,6 +154,20 @@ namespace IRaCIS.Core.Domain.Share } } + public bool IsTestUser + { + get + { + var isTestUserClaime = _accessor?.HttpContext?.User?.FindFirst(JwtIRaCISClaimType.IsTestUser); + + if (isTestUserClaime != null && !string.IsNullOrEmpty(isTestUserClaime.Value)) + { + return bool.Parse(isTestUserClaime.Value); + } + return false; + } + } + public string UserToken { get @@ -304,6 +318,8 @@ namespace IRaCIS.Core.Domain.Share public const string UserTypeShortName = "userTypeShortName"; public const string IsAdmin = "isAdmin"; + public const string IsTestUser = "isTestUser"; + public const string PermissionStr = "permissionStr"; diff --git a/IRaCIS.Core.Domain/Management/User.cs b/IRaCIS.Core.Domain/Management/User.cs index 9d913fd92..4239ad586 100644 --- a/IRaCIS.Core.Domain/Management/User.cs +++ b/IRaCIS.Core.Domain/Management/User.cs @@ -77,6 +77,9 @@ namespace IRaCIS.Core.Domain.Models //ҽ˺ź󣬻ֵ public Guid? DoctorId { get; set; } + + public bool IsTestUser { get; set; } + [Projectable] public string FullName => LastName + " / " + FirstName; //[Projectable] public string FullName => $"{LastName} / {FirstName}";