|
|
|
@ -1,5 +1,4 @@ |
|
|
|
using AutoMapper.Internal.Mappers; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.Extensions.Caching.Distributed; |
|
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
using NPOI.SS.Formula.Functions; |
|
|
|
@ -23,7 +22,7 @@ namespace Shentun.Peis |
|
|
|
{ |
|
|
|
public class CacheService : ISingletonDependency |
|
|
|
{ |
|
|
|
private readonly IDistributedCache<IdentityUserWithExtensionDto, Guid> _userCache; |
|
|
|
private readonly IDistributedCache<IdentityUser, Guid> _userCache; |
|
|
|
private readonly IMemoryCache _customerOrgCache; |
|
|
|
//private readonly IDistributedCache<CustomerOrg, Guid> _customerOrgCache;
|
|
|
|
private readonly IDistributedCache<string, Guid> _customerOrgTopNameCache; |
|
|
|
@ -61,8 +60,10 @@ namespace Shentun.Peis |
|
|
|
|
|
|
|
private readonly IDistributedCache<string, string> _customerOrgDisplayModeCache; |
|
|
|
|
|
|
|
private readonly IMemoryCache _userExtensionCache; |
|
|
|
|
|
|
|
public CacheService( |
|
|
|
IDistributedCache<IdentityUserWithExtensionDto, Guid> userCache, |
|
|
|
IDistributedCache<IdentityUser, Guid> userCache, |
|
|
|
IMemoryCache customerOrgCache, |
|
|
|
IDistributedCache<Nation, string> nationCache, |
|
|
|
IRepository<IdentityUser, Guid> userRepository, |
|
|
|
@ -90,7 +91,8 @@ namespace Shentun.Peis |
|
|
|
SysParmValueManager sysParmValueManager, |
|
|
|
IDistributedCache<string, string> customerOrgDisplayModeCache, |
|
|
|
IDistributedCache<DiagnosisLevel, short> diagnosisLevelCache, |
|
|
|
IRepository<DiagnosisLevel, short> diagnosisLevelRepository) |
|
|
|
IRepository<DiagnosisLevel, short> diagnosisLevelRepository, |
|
|
|
IMemoryCache userExtensionCache) |
|
|
|
{ |
|
|
|
_userCache = userCache; |
|
|
|
_userRepository = userRepository; |
|
|
|
@ -131,9 +133,10 @@ namespace Shentun.Peis |
|
|
|
_customerOrgDisplayModeCache = customerOrgDisplayModeCache; |
|
|
|
_diagnosisLevelCache = diagnosisLevelCache; |
|
|
|
_diagnosisLevelRepository = diagnosisLevelRepository; |
|
|
|
_userExtensionCache = userExtensionCache; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<IdentityUserWithExtensionDto> GetUserAsync(Guid id) |
|
|
|
private async Task<IdentityUser> GetUserAsync(Guid id) |
|
|
|
{ |
|
|
|
|
|
|
|
var entity = await _userCache.GetOrAddAsync( |
|
|
|
@ -142,34 +145,34 @@ namespace Shentun.Peis |
|
|
|
{ |
|
|
|
var dataEntity = await _userRepository.FirstOrDefaultAsync(m => m.Id == id); |
|
|
|
|
|
|
|
var userSign = dataEntity.GetProperty<string>("user_sign"); |
|
|
|
var userPhoto = dataEntity.GetProperty<string>("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; |
|
|
|
//var userSign = dataEntity.GetProperty<string>("user_sign");
|
|
|
|
//var userPhoto = dataEntity.GetProperty<string>("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 dataEntity; |
|
|
|
} |
|
|
|
); |
|
|
|
return entity; |
|
|
|
@ -194,15 +197,53 @@ namespace Shentun.Peis |
|
|
|
{ |
|
|
|
return ""; |
|
|
|
} |
|
|
|
var entity = await GetUserAsync((Guid)id); |
|
|
|
if (entity != null) |
|
|
|
{ |
|
|
|
return entity.UserSign; |
|
|
|
|
|
|
|
string cacheKey = $"userExtension_{id.ToString()}"; |
|
|
|
|
|
|
|
var userExtension = (IdentityUserWithExtensionDto)_userExtensionCache.Get(cacheKey); |
|
|
|
if (userExtension == null) |
|
|
|
{ |
|
|
|
var userEntity = await _userRepository.GetAsync(o => o.Id == id); |
|
|
|
var userSign = userEntity.GetProperty<string>("user_sign"); |
|
|
|
var userPhoto = userEntity.GetProperty<string>("user_photo"); |
|
|
|
userExtension = new IdentityUserWithExtensionDto |
|
|
|
{ |
|
|
|
ConcurrencyStamp = userEntity.ConcurrencyStamp, |
|
|
|
CreationTime = userEntity.CreationTime, |
|
|
|
CreatorId = userEntity.CreatorId, |
|
|
|
DeleterId = userEntity.DeleterId, |
|
|
|
DeletionTime = userEntity.DeletionTime, |
|
|
|
Email = userEntity.Email, |
|
|
|
EmailConfirmed = userEntity.EmailConfirmed, |
|
|
|
Id = userEntity.Id, |
|
|
|
IsActive = userEntity.IsActive, |
|
|
|
IsDeleted = userEntity.IsDeleted, |
|
|
|
LastModificationTime = userEntity.LastModificationTime, |
|
|
|
LastModifierId = userEntity.LastModifierId, |
|
|
|
LockoutEnabled = userEntity.LockoutEnabled, |
|
|
|
LockoutEnd = userEntity.LockoutEnd, |
|
|
|
Name = userEntity.Name, |
|
|
|
PhoneNumber = userEntity.PhoneNumber, |
|
|
|
PhoneNumberConfirmed = userEntity.PhoneNumberConfirmed, |
|
|
|
Surname = userEntity.Surname, |
|
|
|
TenantId = userEntity.TenantId, |
|
|
|
UserName = userEntity.UserName, |
|
|
|
UserPhoto = userPhoto, |
|
|
|
UserSign = userSign |
|
|
|
}; |
|
|
|
_userExtensionCache.Set(cacheKey, userExtension); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
if (userExtension == null) |
|
|
|
{ |
|
|
|
return ""; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return userExtension.UserSign; |
|
|
|
} |
|
|
|
} |
|
|
|
private async Task<Sex> GetSexAsync(char id) |
|
|
|
{ |
|
|
|
|
|
|
|
|