Squashed commit of the following:
commitae30d4b2cbAuthor: 陈淳 <454313500@qq.com> Date: Fri Apr 26 19:08:18 2024 +0800 fix: 修复值对象查询导致问题,已同步sqlsugar更新 commit4c12626b44Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 18:15:57 2024 +0800 feat: 添加值对象 commitd389dcbedfAuthor: 陈淳 <454313500@qq.com> Date: Mon Apr 22 18:06:09 2024 +0800 feat: 添加值对象 commit58ff8f45cfAuthor: 陈淳 <454313500@qq.com> Date: Mon Apr 22 15:54:25 2024 +0800 feat: 去除新增的缓存操作 commit826271c84dAuthor: 陈淳 <454313500@qq.com> Date: Mon Apr 22 15:39:41 2024 +0800 feat: 添加缓存crud
This commit is contained in:
@@ -0,0 +1,119 @@
|
|||||||
|
using Volo.Abp.Application.Dtos;
|
||||||
|
using Volo.Abp.Caching;
|
||||||
|
using Volo.Abp.Domain.Entities;
|
||||||
|
using Volo.Abp.Domain.Repositories;
|
||||||
|
using Volo.Abp.MultiTenancy;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Ddd.Application
|
||||||
|
{
|
||||||
|
public abstract class YiCacheCrudAppService<TEntity, TEntityDto, TKey> : YiCrudAppService<TEntity, TEntityDto, TKey, PagedAndSortedResultRequestDto>
|
||||||
|
where TEntity : class, IEntity<TKey>
|
||||||
|
where TEntityDto : IEntityDto<TKey>
|
||||||
|
{
|
||||||
|
protected YiCacheCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class YiCacheCrudAppService<TEntity, TEntityDto, TKey, TGetListInput>
|
||||||
|
: YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TEntityDto>
|
||||||
|
where TEntity : class, IEntity<TKey>
|
||||||
|
where TEntityDto : IEntityDto<TKey>
|
||||||
|
{
|
||||||
|
protected YiCacheCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class YiCacheCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput>
|
||||||
|
: YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TCreateInput>
|
||||||
|
where TEntity : class, IEntity<TKey>
|
||||||
|
where TEntityDto : IEntityDto<TKey>
|
||||||
|
{
|
||||||
|
protected YiCacheCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class YiCacheCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
|
||||||
|
: YiCrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
|
||||||
|
where TEntity : class, IEntity<TKey>
|
||||||
|
where TEntityDto : IEntityDto<TKey>
|
||||||
|
{
|
||||||
|
protected YiCacheCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class YiCacheCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
|
||||||
|
: YiCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
|
||||||
|
where TEntity : class, IEntity<TKey>
|
||||||
|
where TGetOutputDto : IEntityDto<TKey>
|
||||||
|
where TGetListOutputDto : IEntityDto<TKey>
|
||||||
|
{
|
||||||
|
protected IDistributedCache<TEntity> Cache => LazyServiceProvider.LazyGetRequiredService<IDistributedCache<TEntity>>();
|
||||||
|
|
||||||
|
protected string GetCacheKey(TKey id) => typeof(TEntity).Name + ":" + CurrentTenant.Id ?? Guid.Empty + ":" + id.ToString();
|
||||||
|
protected YiCacheCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<TGetOutputDto> UpdateAsync(TKey id, TUpdateInput input)
|
||||||
|
{
|
||||||
|
var output = await base.UpdateAsync(id, input);
|
||||||
|
await Cache.RemoveAsync(GetCacheKey(id));
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
|
||||||
|
{
|
||||||
|
//两种方式:
|
||||||
|
//1:全表缓存,使用缓存直接查询
|
||||||
|
//2:非全部缓存,查询到的数据直接添加到缓存
|
||||||
|
|
||||||
|
//判断是否该实体为全表缓存
|
||||||
|
throw new NotImplementedException();
|
||||||
|
|
||||||
|
//IDistributedCache 有局限性,条件查询无法进行缓存了
|
||||||
|
//if (true)
|
||||||
|
//{
|
||||||
|
// return await GetListByCacheAsync(input);
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// return await GetListByDbAsync(input);
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual async Task<PagedResultDto<TGetListOutputDto>> GetListByDbAsync(TGetListInput input)
|
||||||
|
{
|
||||||
|
//如果不是全表缓存,可以走这个啦
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
protected virtual async Task<PagedResultDto<TGetListOutputDto>> GetListByCacheAsync(TGetListInput input)
|
||||||
|
{
|
||||||
|
//如果是全表缓存,可以走这个啦
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override async Task<TEntity> GetEntityByIdAsync(TKey id)
|
||||||
|
{
|
||||||
|
var output = await Cache.GetOrAddAsync(GetCacheKey(id), async () => await base.GetEntityByIdAsync(id));
|
||||||
|
return output!;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task DeleteAsync(IEnumerable<TKey> id)
|
||||||
|
{
|
||||||
|
await base.DeleteAsync(id);
|
||||||
|
foreach (var itemId in id)
|
||||||
|
{
|
||||||
|
await Cache.RemoveAsync(GetCacheKey(itemId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
|
using Volo.Abp.Caching;
|
||||||
using Yi.Framework.Ddd.Application;
|
using Yi.Framework.Ddd.Application;
|
||||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.DictionaryType;
|
using Yi.Framework.Rbac.Application.Contracts.Dtos.DictionaryType;
|
||||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||||
@@ -36,6 +38,5 @@ namespace Yi.Framework.Rbac.Application.Services
|
|||||||
Items = await MapToGetListOutputDtosAsync(entities)
|
Items = await MapToGetListOutputDtosAsync(entities)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using SqlSugar;
|
|||||||
using TencentCloud.Tcr.V20190924.Models;
|
using TencentCloud.Tcr.V20190924.Models;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
|
using Volo.Abp.Caching;
|
||||||
using Volo.Abp.EventBus.Local;
|
using Volo.Abp.EventBus.Local;
|
||||||
using Volo.Abp.Users;
|
using Volo.Abp.Users;
|
||||||
using Yi.Framework.Ddd.Application;
|
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.Entities;
|
||||||
using Yi.Framework.Rbac.Domain.Managers;
|
using Yi.Framework.Rbac.Domain.Managers;
|
||||||
using Yi.Framework.Rbac.Domain.Repositories;
|
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.Consts;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Etos;
|
using Yi.Framework.Rbac.Domain.Shared.Etos;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.OperLog;
|
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
|
public class UserService : YiCrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, Guid, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>,IUserService
|
||||||
//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, _userCache) =
|
||||||
(userManager, userRepository, currentUser, deptService, repository, localEventBus);
|
(userManager, userRepository, currentUser, deptService, repository, localEventBus, userCache);
|
||||||
private UserManager _userManager { get; set; }
|
private UserManager _userManager { get; set; }
|
||||||
private ISqlSugarRepository<UserEntity, Guid> _repository;
|
private ISqlSugarRepository<UserEntity, Guid> _repository;
|
||||||
private IUserRepository _userRepository { get; set; }
|
private IUserRepository _userRepository { get; set; }
|
||||||
@@ -77,6 +80,14 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
|||||||
return result;
|
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>
|
||||||
/// 添加用户
|
/// 添加用户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -99,13 +110,13 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
|||||||
{
|
{
|
||||||
throw new UserFriendlyException(UserConst.User_Exist);
|
throw new UserFriendlyException(UserConst.User_Exist);
|
||||||
}
|
}
|
||||||
var entities = await MapToEntityAsync(input);
|
var entitiy = await MapToEntityAsync(input);
|
||||||
|
|
||||||
entities.BuildPassword();
|
entitiy.BuildPassword();
|
||||||
|
|
||||||
//using (var uow = _unitOfWorkManager.CreateContext())
|
//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.GiveUserSetRoleAsync(new List<Guid> { returnEntity.Id }, input.RoleIds);
|
||||||
await _userManager.GiveUserSetPostAsync(new List<Guid> { returnEntity.Id }, input.PostIds);
|
await _userManager.GiveUserSetPostAsync(new List<Guid> { returnEntity.Id }, input.PostIds);
|
||||||
//uow.Commit();
|
//uow.Commit();
|
||||||
@@ -152,17 +163,17 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
|||||||
//更新密码,特殊处理
|
//更新密码,特殊处理
|
||||||
if (input.Password is not null)
|
if (input.Password is not null)
|
||||||
{
|
{
|
||||||
entity.Password = input.Password;
|
entity.EncryPassword.Password = input.Password;
|
||||||
entity.BuildPassword();
|
entity.BuildPassword();
|
||||||
}
|
}
|
||||||
await MapToEntityAsync(input, entity);
|
await MapToEntityAsync(input, entity);
|
||||||
//using (var uow = _unitOfWorkManager.CreateContext())
|
|
||||||
//{
|
|
||||||
var res1 = await _repository.UpdateAsync(entity);
|
var res1 = await _repository.UpdateAsync(entity);
|
||||||
await _userManager.GiveUserSetRoleAsync(new List<Guid> { id }, input.RoleIds);
|
await _userManager.GiveUserSetRoleAsync(new List<Guid> { id }, input.RoleIds);
|
||||||
await _userManager.GiveUserSetPostAsync(new List<Guid> { id }, input.PostIds);
|
await _userManager.GiveUserSetPostAsync(new List<Guid> { id }, input.PostIds);
|
||||||
// uow.Commit();
|
|
||||||
//}
|
await _userCache.RefreshAsync(new UserInfoCacheKey(_currentUser.GetId()));
|
||||||
|
|
||||||
return await MapToGetOutputDtoAsync(entity);
|
return await MapToGetOutputDtoAsync(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +190,7 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
|||||||
|
|
||||||
await _repository.UpdateAsync(entity);
|
await _repository.UpdateAsync(entity);
|
||||||
var dto = await MapToGetOutputDtoAsync(entity);
|
var dto = await MapToGetOutputDtoAsync(entity);
|
||||||
|
await _userCache.RefreshAsync(new UserInfoCacheKey(_currentUser.GetId()));
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,13 +212,16 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
|||||||
}
|
}
|
||||||
entity.State = state;
|
entity.State = state;
|
||||||
await _repository.UpdateAsync(entity);
|
await _repository.UpdateAsync(entity);
|
||||||
|
await _userCache.RefreshAsync(new UserInfoCacheKey(id));
|
||||||
return await MapToGetOutputDtoAsync(entity);
|
return await MapToGetOutputDtoAsync(entity);
|
||||||
}
|
}
|
||||||
[OperLog("删除用户", OperEnum.Delete)]
|
[OperLog("删除用户", OperEnum.Delete)]
|
||||||
[Permission("system:user:delete")]
|
[Permission("system:user:delete")]
|
||||||
public override async Task DeleteAsync(Guid id)
|
public override async Task DeleteAsync(Guid id)
|
||||||
{
|
{
|
||||||
|
|
||||||
await base.DeleteAsync(id);
|
await base.DeleteAsync(id);
|
||||||
|
await _userCache.RefreshAsync(new UserInfoCacheKey(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Permission("system:user:export")]
|
[Permission("system:user:export")]
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Volo.Abp.Auditing;
|
|||||||
using Volo.Abp.Domain.Entities;
|
using Volo.Abp.Domain.Entities;
|
||||||
using Yi.Framework.Core.Data;
|
using Yi.Framework.Core.Data;
|
||||||
using Yi.Framework.Core.Helper;
|
using Yi.Framework.Core.Helper;
|
||||||
|
using Yi.Framework.Rbac.Domain.Entities.ValueObjects;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Enums;
|
using Yi.Framework.Rbac.Domain.Shared.Enums;
|
||||||
|
|
||||||
namespace Yi.Framework.Rbac.Domain.Entities
|
namespace Yi.Framework.Rbac.Domain.Entities
|
||||||
@@ -22,7 +23,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
|||||||
public UserEntity(string userName, string password, long phone, string nick = "萌新")
|
public UserEntity(string userName, string password, long phone, string nick = "萌新")
|
||||||
{
|
{
|
||||||
UserName = userName;
|
UserName = userName;
|
||||||
Password = password;
|
EncryPassword.Password = password;
|
||||||
Phone = phone;
|
Phone = phone;
|
||||||
Nick = nick;
|
Nick = nick;
|
||||||
BuildPassword();
|
BuildPassword();
|
||||||
@@ -55,14 +56,20 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
|||||||
public string UserName { get; set; } = string.Empty;
|
public string UserName { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 密码
|
/// 加密密码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Password { get; set; } = string.Empty;
|
[SugarColumn(IsOwnsOne = true)]
|
||||||
|
public EncryPasswordValueObject EncryPassword { get; set; } = new EncryPasswordValueObject();
|
||||||
|
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/// 加密盐值
|
///// 密码
|
||||||
/// </summary>
|
///// </summary>
|
||||||
public string Salt { get; set; } = string.Empty;
|
//public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
///// <summary>
|
||||||
|
///// 加密盐值
|
||||||
|
///// </summary>
|
||||||
|
//public string Salt { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 头像
|
/// 头像
|
||||||
@@ -175,14 +182,14 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
|||||||
//如果不传值,那就把自己的password当作传进来的password
|
//如果不传值,那就把自己的password当作传进来的password
|
||||||
if (password == null)
|
if (password == null)
|
||||||
{
|
{
|
||||||
if (Password == null)
|
if (EncryPassword?.Password == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(Password));
|
throw new ArgumentNullException(nameof(EncryPassword.Password));
|
||||||
}
|
}
|
||||||
password = Password;
|
password = EncryPassword.Password;
|
||||||
}
|
}
|
||||||
Salt = MD5Helper.GenerateSalt();
|
EncryPassword.Salt = MD5Helper.GenerateSalt();
|
||||||
Password = MD5Helper.SHA2Encode(password, Salt);
|
EncryPassword.Password = MD5Helper.SHA2Encode(password, EncryPassword.Salt);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,12 +200,12 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool JudgePassword(string password)
|
public bool JudgePassword(string password)
|
||||||
{
|
{
|
||||||
if (Salt is null)
|
if (EncryPassword.Salt is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(Salt);
|
throw new ArgumentNullException(EncryPassword.Salt);
|
||||||
}
|
}
|
||||||
var p = MD5Helper.SHA2Encode(password, Salt);
|
var p = MD5Helper.SHA2Encode(password, EncryPassword.Salt);
|
||||||
if (Password == MD5Helper.SHA2Encode(password, Salt))
|
if (EncryPassword.Password == MD5Helper.SHA2Encode(password, EncryPassword.Salt))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Volo.Abp.Domain.Values;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Rbac.Domain.Entities.ValueObjects
|
||||||
|
{
|
||||||
|
public class EncryPasswordValueObject : ValueObject
|
||||||
|
{
|
||||||
|
public EncryPasswordValueObject() { }
|
||||||
|
public EncryPasswordValueObject(string password) { this.Password = password; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 密码
|
||||||
|
/// </summary>
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加密盐值
|
||||||
|
/// </summary>
|
||||||
|
public string Salt { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
protected override IEnumerable<object> GetAtomicValues()
|
||||||
|
{
|
||||||
|
yield return Password;
|
||||||
|
yield return Salt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -154,7 +154,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
|||||||
{
|
{
|
||||||
userAction.Invoke(user);
|
userAction.Invoke(user);
|
||||||
}
|
}
|
||||||
if (user.Password == MD5Helper.SHA2Encode(password, user.Salt))
|
if (user.EncryPassword.Password == MD5Helper.SHA2Encode(password, user.EncryPassword.Salt))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
|||||||
{
|
{
|
||||||
throw new UserFriendlyException("无效更新!原密码错误!");
|
throw new UserFriendlyException("无效更新!原密码错误!");
|
||||||
}
|
}
|
||||||
user.Password = newPassword;
|
user.EncryPassword.Password = newPassword;
|
||||||
user.BuildPassword();
|
user.BuildPassword();
|
||||||
await _repository.UpdateAsync(user);
|
await _repository.UpdateAsync(user);
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
|||||||
{
|
{
|
||||||
var user = await _repository.GetByIdAsync(userId);
|
var user = await _repository.GetByIdAsync(userId);
|
||||||
// EntityHelper.TrySetId(user, () => GuidGenerator.Create(), true);
|
// EntityHelper.TrySetId(user, () => GuidGenerator.Create(), true);
|
||||||
user.Password = password;
|
user.EncryPassword.Password = password;
|
||||||
user.BuildPassword();
|
user.BuildPassword();
|
||||||
return await _repository.UpdateAsync(user);
|
return await _repository.UpdateAsync(user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,42 +95,26 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<UserRoleMenuDto> GetInfoAsync(Guid userId)
|
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;
|
return output;
|
||||||
}
|
}
|
||||||
|
private async Task<UserRoleMenuDto> GetInfoByCacheAsync(Guid userId)
|
||||||
/// <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)
|
|
||||||
{
|
{
|
||||||
//此处优先从缓存中获取
|
//此处优先从缓存中获取
|
||||||
UserRoleMenuDto output = null;
|
UserRoleMenuDto output = null;
|
||||||
var tokenExpiresMinuteTime = LazyServiceProvider.GetRequiredService<IOptions<JwtOptions>>().Value.ExpiresMinuteTime;
|
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 () =>
|
async () =>
|
||||||
{
|
{
|
||||||
|
var user = await _userRepository.GetUserAllInfoAsync(userId);
|
||||||
var data = EntityMapToDto(user);
|
var data = EntityMapToDto(user);
|
||||||
//系统用户数据被重置,老前端访问重新授权
|
//系统用户数据被重置,老前端访问重新授权
|
||||||
if (data is null)
|
if (data is null)
|
||||||
{
|
{
|
||||||
throw new AbpAuthorizationException();
|
throw new AbpAuthorizationException();
|
||||||
}
|
}
|
||||||
data.Menus.Clear();
|
//data.Menus.Clear();
|
||||||
output = data;
|
output = data;
|
||||||
return new UserInfoCacheItem(data);
|
return new UserInfoCacheItem(data);
|
||||||
},
|
},
|
||||||
@@ -143,6 +127,24 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
|||||||
return output!;
|
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)
|
private UserRoleMenuDto EntityMapToDto(UserEntity user)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -152,8 +154,8 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
|||||||
//{
|
//{
|
||||||
// throw new UserFriendlyException($"数据错误,用户id:{nameof(userId)} 不存在,请重新登录");
|
// throw new UserFriendlyException($"数据错误,用户id:{nameof(userId)} 不存在,请重新登录");
|
||||||
//}
|
//}
|
||||||
user.Password = string.Empty;
|
user.EncryPassword.Password = string.Empty;
|
||||||
user.Salt = string.Empty;
|
user.EncryPassword.Salt = string.Empty;
|
||||||
|
|
||||||
//超级管理员特殊处理
|
//超级管理员特殊处理
|
||||||
if (UserConst.Admin.Equals(user.UserName))
|
if (UserConst.Admin.Equals(user.UserName))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using Volo.Abp.Data;
|
using Volo.Abp.Data;
|
||||||
using Volo.Abp.DependencyInjection;
|
using Volo.Abp.DependencyInjection;
|
||||||
using Yi.Framework.Rbac.Domain.Entities;
|
using Yi.Framework.Rbac.Domain.Entities;
|
||||||
|
using Yi.Framework.Rbac.Domain.Entities.ValueObjects;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Enums;
|
using Yi.Framework.Rbac.Domain.Shared.Enums;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Options;
|
using Yi.Framework.Rbac.Domain.Shared.Options;
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
@@ -27,7 +28,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
Name = "大橙子",
|
Name = "大橙子",
|
||||||
UserName = "cc",
|
UserName = "cc",
|
||||||
Nick = "橙子",
|
Nick = "橙子",
|
||||||
Password = _options.AdminPassword,
|
EncryPassword = new EncryPasswordValueObject(_options.AdminPassword),
|
||||||
Email = "454313500@qq.com",
|
Email = "454313500@qq.com",
|
||||||
Phone = 13800000000,
|
Phone = 13800000000,
|
||||||
Sex = SexEnum.Male,
|
Sex = SexEnum.Male,
|
||||||
@@ -47,7 +48,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
Name = "大测试",
|
Name = "大测试",
|
||||||
UserName = "test",
|
UserName = "test",
|
||||||
Nick = "测试",
|
Nick = "测试",
|
||||||
Password = "123456",
|
EncryPassword=new EncryPasswordValueObject("123456"),
|
||||||
Email = "454313500@qq.com",
|
Email = "454313500@qq.com",
|
||||||
Phone = 15900000000,
|
Phone = 15900000000,
|
||||||
Sex = SexEnum.Woman,
|
Sex = SexEnum.Woman,
|
||||||
@@ -68,7 +69,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
Name = "游客",
|
Name = "游客",
|
||||||
UserName = "guest",
|
UserName = "guest",
|
||||||
Nick = "测试",
|
Nick = "测试",
|
||||||
Password = "123456",
|
EncryPassword = new EncryPasswordValueObject("123456"),
|
||||||
Email = "454313500@qq.com",
|
Email = "454313500@qq.com",
|
||||||
Phone = 15900000000,
|
Phone = 15900000000,
|
||||||
Sex = SexEnum.Woman,
|
Sex = SexEnum.Woman,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<AbpVersion>8.0.5</AbpVersion>
|
<AbpVersion>8.0.5</AbpVersion>
|
||||||
<SqlSugarVersion>5.1.4.149</SqlSugarVersion>
|
<SqlSugarVersion>5.1.4.154-preview01</SqlSugarVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user