public Task Handle(UpdateUserEvent @event) { _logger.LogInformation("Handling 'UpdateUserEvent' event", @event.Id, AppDomain.CurrentDomain.FriendlyName, @event); TimeSpan timeSpan = TimeSpan.FromMinutes(_cacheKeyManager.CacheTime); _locker.PerformActionWithLock(_cacheKeyManager.BuilerRedisEventLockKey(@event), timeSpan, () => { var command = new UpdateUserEventCommand( @event.OtherId, @event.UserName, @event.ContactNumber ); _bus.SendCommand(command).Wait(); if (_notifications.HasNotifications()) { var(errorCode, errorMessage) = _notifications.GetNotificationMessage(); _logger.LogError( $"Handling 'UpdateUserEvent' event Error Code:{errorCode},Message:{errorMessage}", @event); } }); return(Task.CompletedTask); }
public Task Handle(CreateUserEvent @event, [FromCap] CapHeader header, CancellationToken cancellationToken) { //需要重新设置身份认证头 EngineContext.Current.ClaimManager.CapEventBusReSetClaim(header); _logger.LogInformation($"Handling 'CreateUserEvent' eventId:{@event.Id}"); var cacheConfig = EngineContext.Current.GetAppModuleConfig <CacheConfig>(); var timeSpan = TimeSpan.FromSeconds(cacheConfig.CacheBaseConfig.DefaultCacheTime); _locker.PerformActionWithLock(@event.Id.ToString(), timeSpan, () => { var command = new EventCreateUserCommand( @event.UserAccount, @event.UserPassword.ToMd5(), @event.UserName, @event.ContactNumber, DataState.Enable, UserType.TenantAdminUser, //此处创建的为租户管理员 @event.TenantId ); _bus.SendCommand(command, cancellationToken).Wait(cancellationToken); if (_notifications.HasNotifications()) { var errorMessage = _notifications.GetNotificationMessage(); _logger.LogError( $"Handling 'CreateUserEvent' event Error Code:{400},Message:{errorMessage}", @event); } }); return(Task.CompletedTask); }
public async Task <RoleEditViewModel> CreateAsync([FromForm] RoleEditViewModel model) { var command = new CreateRoleCommand(model.Name, model.Desc, model.UserIds); await _bus.SendCommand(command); if (_notifications.HasNotifications()) { var errorMessage = _notifications.GetNotificationMessage(); throw new GirvsException(StatusCodes.Status400BadRequest, errorMessage); } model.Id = command.Id; return(model); }
public async Task <UserEditViewModel> CreateAsync([FromForm] UserEditViewModel model) { var currentUser = EngineContext.Current.GetCurrentUser(); if (currentUser == null) { throw new GirvsException(StatusCodes.Status401Unauthorized, "未登录"); } //如果超级管理员创建的用户,则是特殊用户,如果是租户管理创建的用户,则是普通用户 var targetUserType = currentUser.UserType == UserType.AdminUser ? UserType.SpecialUser : UserType.GeneralUser; var command = new CreateUserCommand( model.UserAccount, model.UserPassword.ToMd5(), model.UserName, model.ContactNumber, model.State, targetUserType, null ); await _bus.SendCommand(command); if (_notifications.HasNotifications()) { var errorMessage = _notifications.GetNotificationMessage(); throw new GirvsException(StatusCodes.Status400BadRequest, errorMessage); } else { model.Id = command.Id; return(model); } }
public Task Handle(AuthorizeEvent @event, [FromCap] CapHeader header, CancellationToken cancellationToken) { _logger.LogInformation($"Handling 'AuthorizeEvent' eventId:{@event.Id}"); //需要重新设置身份认证头 EngineContext.Current.ClaimManager.CapEventBusReSetClaim(header); var cacheConfig = EngineContext.Current.GetAppModuleConfig <CacheConfig>(); var timeSpan = TimeSpan.FromSeconds(cacheConfig.CacheBaseConfig.DefaultCacheTime); var isLock = _locker.PerformActionWithLock(@event.Id.ToString(), timeSpan, () => { var servicePermissionCommandModels = new List <ServicePermissionCommandModel>(); foreach (var permissionAuthoriz in @event.AuthorizePermissions) { servicePermissionCommandModels.Add(new ServicePermissionCommandModel() { ServiceName = permissionAuthoriz.ServiceName, ServiceId = permissionAuthoriz.ServiceId, Permissions = permissionAuthoriz.Permissions, OperationPermissionModels = permissionAuthoriz.OperationPermissionModels }); } var serviceDataRuleCommandModels = new List <ServiceDataRuleCommandModel>(); foreach (var authorizeDataRule in @event.AuthorizeDataRules) { foreach (var dataRuleFieldModel in authorizeDataRule.AuthorizeDataRuleFieldModels) { serviceDataRuleCommandModels.Add(new ServiceDataRuleCommandModel() { EntityTypeName = authorizeDataRule.EntityTypeName, EntityDesc = authorizeDataRule.EntityDesc, FieldName = dataRuleFieldModel.FieldName, FieldType = dataRuleFieldModel.FieldType, FieldValue = dataRuleFieldModel.FieldValue, ExpressionType = dataRuleFieldModel.ExpressionType, FieldDesc = dataRuleFieldModel.FieldDesc, UserType = dataRuleFieldModel.UserType }); } } var command = new NeedAuthorizeListCommand(servicePermissionCommandModels, serviceDataRuleCommandModels); _bus.SendCommand(command).Wait(cancellationToken); if (_notifications.HasNotifications()) { var errorMessage = _notifications.GetNotificationMessage(); _logger.LogError( $"Handling 'AuthorizeEvent' event Error Code:{400},Message:{errorMessage}", @event); } }); _logger.LogInformation($"本次事件处理过程中,Reids锁的情况为:{isLock} 事件ID为:{@event.Id}"); return(Task.CompletedTask); }