fix: 修复值对象查询导致问题,已同步sqlsugar更新

This commit is contained in:
陈淳
2024-04-26 19:08:18 +08:00
parent 4c12626b44
commit ae30d4b2cb
4 changed files with 53 additions and 36 deletions

View File

@@ -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")]