fix: 修复值对象查询导致问题,已同步sqlsugar更新
This commit is contained in:
@@ -3,6 +3,7 @@ using SqlSugar;
|
||||
using TencentCloud.Tcr.V20190924.Models;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.EventBus.Local;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.Ddd.Application;
|
||||
@@ -12,6 +13,7 @@ using Yi.Framework.Rbac.Domain.Authorization;
|
||||
using Yi.Framework.Rbac.Domain.Entities;
|
||||
using Yi.Framework.Rbac.Domain.Managers;
|
||||
using Yi.Framework.Rbac.Domain.Repositories;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Caches;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Etos;
|
||||
using Yi.Framework.Rbac.Domain.Shared.OperLog;
|
||||
@@ -25,10 +27,11 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
||||
public class UserService : YiCrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, Guid, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>,IUserService
|
||||
//IUserService
|
||||
{
|
||||
public UserService(ISqlSugarRepository<UserEntity, Guid> repository, UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser, IDeptService deptService, ILocalEventBus localEventBus) : base(repository)
|
||||
private IDistributedCache<UserInfoCacheItem, UserInfoCacheKey> _userCache;
|
||||
public UserService(ISqlSugarRepository<UserEntity, Guid> repository, UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser, IDeptService deptService, ILocalEventBus localEventBus, IDistributedCache<UserInfoCacheItem, UserInfoCacheKey> userCache) : base(repository)
|
||||
=>
|
||||
(_userManager, _userRepository, _currentUser, _deptService, _repository, _localEventBus) =
|
||||
(userManager, userRepository, currentUser, deptService, repository, localEventBus);
|
||||
(_userManager, _userRepository, _currentUser, _deptService, _repository, _localEventBus, _userCache) =
|
||||
(userManager, userRepository, currentUser, deptService, repository, localEventBus, userCache);
|
||||
private UserManager _userManager { get; set; }
|
||||
private ISqlSugarRepository<UserEntity, Guid> _repository;
|
||||
private IUserRepository _userRepository { get; set; }
|
||||
@@ -77,6 +80,14 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected override UserEntity MapToEntity(UserCreateInputVo createInput)
|
||||
{
|
||||
var output= base.MapToEntity(createInput);
|
||||
output.EncryPassword = new Domain.Entities.ValueObjects.EncryPasswordValueObject(createInput.Password);
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户
|
||||
/// </summary>
|
||||
@@ -99,13 +110,13 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
||||
{
|
||||
throw new UserFriendlyException(UserConst.User_Exist);
|
||||
}
|
||||
var entities = await MapToEntityAsync(input);
|
||||
|
||||
entities.BuildPassword();
|
||||
var entitiy = await MapToEntityAsync(input);
|
||||
|
||||
entitiy.BuildPassword();
|
||||
|
||||
//using (var uow = _unitOfWorkManager.CreateContext())
|
||||
//{
|
||||
var returnEntity = await _repository.InsertReturnEntityAsync(entities);
|
||||
var returnEntity = await _repository.InsertReturnEntityAsync(entitiy);
|
||||
await _userManager.GiveUserSetRoleAsync(new List<Guid> { returnEntity.Id }, input.RoleIds);
|
||||
await _userManager.GiveUserSetPostAsync(new List<Guid> { returnEntity.Id }, input.PostIds);
|
||||
//uow.Commit();
|
||||
@@ -156,13 +167,13 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
||||
entity.BuildPassword();
|
||||
}
|
||||
await MapToEntityAsync(input, entity);
|
||||
//using (var uow = _unitOfWorkManager.CreateContext())
|
||||
//{
|
||||
|
||||
var res1 = await _repository.UpdateAsync(entity);
|
||||
await _userManager.GiveUserSetRoleAsync(new List<Guid> { id }, input.RoleIds);
|
||||
await _userManager.GiveUserSetPostAsync(new List<Guid> { id }, input.PostIds);
|
||||
// uow.Commit();
|
||||
//}
|
||||
|
||||
await _userCache.RefreshAsync(new UserInfoCacheKey(_currentUser.GetId()));
|
||||
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
|
||||
@@ -179,6 +190,7 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
||||
|
||||
await _repository.UpdateAsync(entity);
|
||||
var dto = await MapToGetOutputDtoAsync(entity);
|
||||
await _userCache.RefreshAsync(new UserInfoCacheKey(_currentUser.GetId()));
|
||||
return dto;
|
||||
}
|
||||
|
||||
@@ -200,13 +212,16 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
||||
}
|
||||
entity.State = state;
|
||||
await _repository.UpdateAsync(entity);
|
||||
await _userCache.RefreshAsync(new UserInfoCacheKey(id));
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
[OperLog("删除用户", OperEnum.Delete)]
|
||||
[Permission("system:user:delete")]
|
||||
public override async Task DeleteAsync(Guid id)
|
||||
{
|
||||
|
||||
await base.DeleteAsync(id);
|
||||
await _userCache.RefreshAsync(new UserInfoCacheKey(id));
|
||||
}
|
||||
|
||||
[Permission("system:user:export")]
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
||||
/// 加密密码
|
||||
/// </summary>
|
||||
[SugarColumn(IsOwnsOne = true)]
|
||||
public EncryPasswordValueObject EncryPassword { get; set; }
|
||||
public EncryPasswordValueObject EncryPassword { get; set; } = new EncryPasswordValueObject();
|
||||
|
||||
///// <summary>
|
||||
///// 密码
|
||||
@@ -182,7 +182,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
||||
//如果不传值,那就把自己的password当作传进来的password
|
||||
if (password == null)
|
||||
{
|
||||
if (EncryPassword.Password == null)
|
||||
if (EncryPassword?.Password == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(EncryPassword.Password));
|
||||
}
|
||||
|
||||
@@ -95,42 +95,26 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
||||
/// <returns></returns>
|
||||
public async Task<UserRoleMenuDto> GetInfoAsync(Guid userId)
|
||||
{
|
||||
var user = await _userRepository.GetUserAllInfoAsync(userId);
|
||||
var output = await GetInfoByCacheAsync(user);
|
||||
|
||||
var output = await GetInfoByCacheAsync(userId);
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量查询用户信息
|
||||
/// </summary>
|
||||
/// <param name="userIds"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<UserRoleMenuDto>> GetInfoListAsync(List<Guid> userIds)
|
||||
{
|
||||
List<UserRoleMenuDto> output = new List<UserRoleMenuDto>();
|
||||
var users = await _userRepository.GetListUserAllInfoAsync(userIds);
|
||||
foreach (var user in users)
|
||||
{
|
||||
output.Add(await GetInfoByCacheAsync(user));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
private async Task<UserRoleMenuDto> GetInfoByCacheAsync(UserEntity user)
|
||||
private async Task<UserRoleMenuDto> GetInfoByCacheAsync(Guid userId)
|
||||
{
|
||||
//此处优先从缓存中获取
|
||||
UserRoleMenuDto output = null;
|
||||
var tokenExpiresMinuteTime = LazyServiceProvider.GetRequiredService<IOptions<JwtOptions>>().Value.ExpiresMinuteTime;
|
||||
var cacheData = await _userCache.GetOrAddAsync(new UserInfoCacheKey(user.Id),
|
||||
var cacheData = await _userCache.GetOrAddAsync(new UserInfoCacheKey(userId),
|
||||
async () =>
|
||||
{
|
||||
var user = await _userRepository.GetUserAllInfoAsync(userId);
|
||||
var data = EntityMapToDto(user);
|
||||
//系统用户数据被重置,老前端访问重新授权
|
||||
if (data is null)
|
||||
{
|
||||
throw new AbpAuthorizationException();
|
||||
}
|
||||
data.Menus.Clear();
|
||||
//data.Menus.Clear();
|
||||
output = data;
|
||||
return new UserInfoCacheItem(data);
|
||||
},
|
||||
@@ -143,6 +127,24 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
||||
return output!;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 批量查询用户信息
|
||||
/// </summary>
|
||||
/// <param name="userIds"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<UserRoleMenuDto>> GetInfoListAsync(List<Guid> userIds)
|
||||
{
|
||||
List<UserRoleMenuDto> output = new List<UserRoleMenuDto>();
|
||||
foreach (var userId in userIds)
|
||||
{
|
||||
output.Add(await GetInfoByCacheAsync(userId));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private UserRoleMenuDto EntityMapToDto(UserEntity user)
|
||||
{
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<AbpVersion>8.0.5</AbpVersion>
|
||||
<SqlSugarVersion>5.1.4.149</SqlSugarVersion>
|
||||
<SqlSugarVersion>5.1.4.154-preview01</SqlSugarVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user