diff --git a/src/Shentun.Peis.Domain/CacheService.cs b/src/Shentun.Peis.Domain/CacheService.cs index 67f31aa..319f79b 100644 --- a/src/Shentun.Peis.Domain/CacheService.cs +++ b/src/Shentun.Peis.Domain/CacheService.cs @@ -1,9 +1,11 @@ -using Microsoft.EntityFrameworkCore; +using AutoMapper.Internal.Mappers; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; using NPOI.SS.Formula.Functions; using Shentun.Peis.Enums; using Shentun.Peis.Models; +using Shentun.Peis.MyUser; using Shentun.Peis.SysParmValues; using System; using System.Collections.Generic; @@ -21,7 +23,7 @@ namespace Shentun.Peis { public class CacheService : ISingletonDependency { - private readonly IDistributedCache _userCache; + private readonly IDistributedCache _userCache; private readonly IMemoryCache _customerOrgCache; //private readonly IDistributedCache _customerOrgCache; private readonly IDistributedCache _customerOrgTopNameCache; @@ -60,7 +62,7 @@ namespace Shentun.Peis private readonly IDistributedCache _customerOrgDisplayModeCache; public CacheService( - IDistributedCache userCache, + IDistributedCache userCache, IMemoryCache customerOrgCache, IDistributedCache nationCache, IRepository userRepository, @@ -131,12 +133,44 @@ namespace Shentun.Peis _diagnosisLevelRepository = diagnosisLevelRepository; } - private async Task GetUserAsync(Guid id) + private async Task GetUserAsync(Guid id) { var entity = await _userCache.GetOrAddAsync( id, //缓存键 - async () => await _userRepository.FirstOrDefaultAsync(m => m.Id == id) + async () => + { + var dataEntity = await _userRepository.FirstOrDefaultAsync(m => m.Id == id); + + var userSign = dataEntity.GetProperty("user_sign"); + var userPhoto = dataEntity.GetProperty("user_photo"); + var entDto = new IdentityUserWithExtensionDto + { + ConcurrencyStamp = dataEntity.ConcurrencyStamp, + CreationTime = dataEntity.CreationTime, + CreatorId = dataEntity.CreatorId, + DeleterId = dataEntity.DeleterId, + DeletionTime = dataEntity.DeletionTime, + Email = dataEntity.Email, + EmailConfirmed = dataEntity.EmailConfirmed, + Id = dataEntity.Id, + IsActive = dataEntity.IsActive, + IsDeleted = dataEntity.IsDeleted, + LastModificationTime = dataEntity.LastModificationTime, + LastModifierId = dataEntity.LastModifierId, + LockoutEnabled = dataEntity.LockoutEnabled, + LockoutEnd = dataEntity.LockoutEnd, + Name = dataEntity.Name, + PhoneNumber = dataEntity.PhoneNumber, + PhoneNumberConfirmed = dataEntity.PhoneNumberConfirmed, + Surname = dataEntity.Surname, + TenantId = dataEntity.TenantId, + UserName = dataEntity.UserName, + UserPhoto = userPhoto, + UserSign = userSign + }; + return entDto; + } ); return entity; } @@ -155,14 +189,17 @@ namespace Shentun.Peis } public async Task GetUserSignAsync(Guid? id) - { + { if (id == null || id == default(Guid) || !id.HasValue) { return ""; } var entity = await GetUserAsync((Guid)id); if (entity != null) - return entity.GetProperty("user_sign"); + { + return entity.UserSign; + } + else return ""; }