From 41e8ddf8feddb498df320f4913e9138a466a01e8 Mon Sep 17 00:00:00 2001 From: wxd <123@qq.com> Date: Mon, 2 Dec 2024 10:30:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=A2=9E=E5=8A=A0=E6=89=A9=E5=B1=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Shentun.Peis.Domain/CacheService.cs | 51 +++++++++++++++++++++---- 1 file changed, 44 insertions(+), 7 deletions(-) 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 ""; }