|
|
|
@ -51,6 +51,9 @@ namespace Shentun.Peis |
|
|
|
|
|
|
|
private readonly SysParmValueManager _sysParmValueManager; |
|
|
|
|
|
|
|
|
|
|
|
private readonly IDistributedCache<string, string> _customerOrgDisplayModeCache; |
|
|
|
|
|
|
|
public CacheService( |
|
|
|
IDistributedCache<IdentityUser, Guid> userCache, |
|
|
|
IMemoryCache customerOrgCache, |
|
|
|
@ -77,7 +80,8 @@ namespace Shentun.Peis |
|
|
|
IDistributedCache<string, Guid> customerOrgTopNameCache, |
|
|
|
IDistributedCache<SampleType, Guid> sampleTypeCache, |
|
|
|
IRepository<SampleType, Guid> sampleTypeRepository, |
|
|
|
SysParmValueManager sysParmValueManager) |
|
|
|
SysParmValueManager sysParmValueManager, |
|
|
|
IDistributedCache<string, string> customerOrgDisplayModeCache) |
|
|
|
{ |
|
|
|
_userCache = userCache; |
|
|
|
_userRepository = userRepository; |
|
|
|
@ -115,6 +119,7 @@ namespace Shentun.Peis |
|
|
|
_sampleTypeCache = sampleTypeCache; |
|
|
|
_sampleTypeRepository = sampleTypeRepository; |
|
|
|
_sysParmValueManager = sysParmValueManager; |
|
|
|
_customerOrgDisplayModeCache = customerOrgDisplayModeCache; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<IdentityUser> GetUserAsync(Guid id) |
|
|
|
@ -353,9 +358,23 @@ namespace Shentun.Peis |
|
|
|
/// 获取一级单位
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="customerOrgDisplayMode">单位显示模式 0-显示一级单位 1-显示上一级单位</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<CustomerOrg> GetTopCustomerOrgAsync(Guid id) |
|
|
|
{ |
|
|
|
#region 获取单位显示模式 存缓存
|
|
|
|
string customerOrgDisplayMode = _customerOrgDisplayModeCache.Get("customer_org_display_mode"); |
|
|
|
if (string.IsNullOrWhiteSpace(customerOrgDisplayMode)) |
|
|
|
{ |
|
|
|
customerOrgDisplayMode = await _sysParmValueManager.GetSysParmValueAsync(Guid.Empty, "customer_org_display_mode"); |
|
|
|
if (string.IsNullOrWhiteSpace(customerOrgDisplayMode)) |
|
|
|
{ |
|
|
|
customerOrgDisplayMode = "0"; |
|
|
|
} |
|
|
|
_customerOrgDisplayModeCache.Set("customer_org_display_mode", customerOrgDisplayMode); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
var entity = (CustomerOrg)_customerOrgCache.Get(id); |
|
|
|
if (entity == null) |
|
|
|
{ |
|
|
|
@ -365,7 +384,21 @@ namespace Shentun.Peis |
|
|
|
|
|
|
|
if (entity.ParentId != null && entity.ParentId != Guid.Empty) |
|
|
|
{ |
|
|
|
entity = await GetTopCustomerOrgAsync((Guid)entity.ParentId); |
|
|
|
Guid parentId = (Guid)entity.ParentId; |
|
|
|
|
|
|
|
if (customerOrgDisplayMode == "0") |
|
|
|
{ |
|
|
|
entity = await GetTopCustomerOrgAsync(parentId); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
entity = (CustomerOrg)_customerOrgCache.Get(parentId); |
|
|
|
if (entity == null) |
|
|
|
{ |
|
|
|
entity = await _customerOrgRepository.GetAsync(o => o.Id == parentId); |
|
|
|
_customerOrgCache.Set(parentId, entity); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return entity; |
|
|
|
} |
|
|
|
@ -478,6 +511,19 @@ namespace Shentun.Peis |
|
|
|
/// <returns></returns>
|
|
|
|
private async Task<string> GetTopCustomerOrgNameInCustomerOrgIdAsync(Guid id) |
|
|
|
{ |
|
|
|
#region 获取单位显示模式 存缓存
|
|
|
|
string customerOrgDisplayMode = _customerOrgDisplayModeCache.Get("customer_org_display_mode"); |
|
|
|
if (string.IsNullOrWhiteSpace(customerOrgDisplayMode)) |
|
|
|
{ |
|
|
|
customerOrgDisplayMode = await _sysParmValueManager.GetSysParmValueAsync(Guid.Empty, "customer_org_display_mode"); |
|
|
|
if (string.IsNullOrWhiteSpace(customerOrgDisplayMode)) |
|
|
|
{ |
|
|
|
customerOrgDisplayMode = "0"; |
|
|
|
} |
|
|
|
_customerOrgDisplayModeCache.Set("customer_org_display_mode", customerOrgDisplayMode); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
var entity = (CustomerOrg)_customerOrgCache.Get(id); |
|
|
|
if (entity == null) |
|
|
|
{ |
|
|
|
@ -495,8 +541,14 @@ namespace Shentun.Peis |
|
|
|
return entity.DisplayName; |
|
|
|
} |
|
|
|
|
|
|
|
if (customerOrgDisplayMode == "0") |
|
|
|
{ |
|
|
|
entity = await _customerOrgRepository.GetAsync(o => o.PathCode == entity.PathCode.Substring(0, 5)); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
entity = await _customerOrgRepository.GetAsync(o => o.Id == entity.ParentId); |
|
|
|
} |
|
|
|
return entity.DisplayName; |
|
|
|
} |
|
|
|
|
|
|
|
|