You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
744 lines
27 KiB
744 lines
27 KiB
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Caching.Distributed;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using NPOI.HPSF;
|
|
using NPOI.SS.Formula.Functions;
|
|
using Shentun.Pacs.Enums;
|
|
using Shentun.Pacs.Models;
|
|
using Shentun.Pacs.MyUser;
|
|
using Shentun.Pacs.SysParmValues;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.DependencyInjection;
|
|
using Volo.Abp.Domain.Entities;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.Identity;
|
|
|
|
namespace Shentun.Pacs
|
|
{
|
|
public class CacheService : ISingletonDependency
|
|
{
|
|
private readonly IDistributedCache<IdentityUser, Guid> _userCache;
|
|
private readonly IMemoryCache _customerOrgCache;
|
|
//private readonly IDistributedCache<CustomerOrg, Guid> _customerOrgCache;
|
|
private readonly IDistributedCache<string, Guid> _customerOrgTopNameCache;
|
|
private readonly IDistributedCache<Nation, string> _nationCache;
|
|
private readonly IDistributedCache<Sex, char> _sexCache;
|
|
private readonly IDistributedCache<MaritalStatus, char> _maritalStatusCache;
|
|
private readonly IDistributedCache<ForSex, char> _forSexCache;
|
|
private readonly IDistributedCache<DeviceType, Guid> _deviceTypeCache;
|
|
private readonly IDistributedCache<MedicalType, Guid> _medicalTypeCache;
|
|
private readonly IDistributedCache<PersonnelType, Guid> _personnelTypeCache;
|
|
private readonly IMemoryCache _asbitemCache;
|
|
private readonly IMemoryCache _itemTypeCache;
|
|
//private readonly IDistributedCache<ItemType, Guid> _itemTypeCache;
|
|
private readonly IRepository<IdentityUser, Guid> _userRepository;
|
|
private readonly IRepository<Nation> _nationRepository;
|
|
private readonly IRepository<Sex> _sexRepository;
|
|
private readonly IRepository<ForSex> _forSexRepository;
|
|
private readonly IRepository<DeviceType, Guid> _deviceTypeRepository;
|
|
private readonly IRepository<Asbitem, Guid> _asbitemRepository;
|
|
|
|
private readonly IRepository<ItemType, Guid> _itemTypeRepository;
|
|
private readonly IRepository<CustomerOrg, Guid> _customerOrgRepository;
|
|
private readonly IRepository<MaritalStatus> _maritalStatusRepository;
|
|
private readonly IRepository<MedicalType, Guid> _medicalTypeRepository;
|
|
private readonly IRepository<PersonnelType, Guid> _personnelTypeRepository;
|
|
|
|
private readonly IDistributedCache<SampleType, Guid> _sampleTypeCache;
|
|
private readonly IRepository<SampleType, Guid> _sampleTypeRepository;
|
|
|
|
private readonly SysParmValueManager _sysParmValueManager;
|
|
|
|
private readonly IDistributedCache<DiagnosisLevel, short> _diagnosisLevelCache;
|
|
private readonly IRepository<DiagnosisLevel, short> _diagnosisLevelRepository;
|
|
|
|
|
|
private readonly IDistributedCache<string, string> _customerOrgDisplayModeCache;
|
|
|
|
private readonly IMemoryCache _userExtensionCache;
|
|
|
|
public CacheService(
|
|
IDistributedCache<IdentityUser, Guid> userCache,
|
|
IMemoryCache customerOrgCache,
|
|
IDistributedCache<Nation, string> nationCache,
|
|
IRepository<IdentityUser, Guid> userRepository,
|
|
IDistributedCache<Sex, char> sexCache,
|
|
IMemoryCache asbitemCache,
|
|
IMemoryCache itemTypeCache,
|
|
IDistributedCache<MaritalStatus, char> maritalStatusCache,
|
|
IDistributedCache<MedicalType, Guid> medicalTypeCache,
|
|
IDistributedCache<PersonnelType, Guid> personnelTypeCache,
|
|
IRepository<Sex> sexRepository,
|
|
IDistributedCache<DeviceType, Guid> deviceTypeCache,
|
|
IRepository<DeviceType, Guid> deviceTypeRepository,
|
|
IDistributedCache<ForSex, char> forSexCache,
|
|
IRepository<ForSex> forSexRepository,
|
|
IRepository<Asbitem, Guid> asbitemRepository,
|
|
IRepository<ItemType, Guid> itemTypeRepository,
|
|
IRepository<Nation> nationRepository,
|
|
IRepository<CustomerOrg, Guid> customerOrgRepository,
|
|
IRepository<MaritalStatus> maritalStatusRepository,
|
|
IRepository<MedicalType, Guid> medicalTypeRepository,
|
|
IRepository<PersonnelType, Guid> personnelTypeRepository,
|
|
IDistributedCache<string, Guid> customerOrgTopNameCache,
|
|
IDistributedCache<SampleType, Guid> sampleTypeCache,
|
|
IRepository<SampleType, Guid> sampleTypeRepository,
|
|
SysParmValueManager sysParmValueManager,
|
|
IDistributedCache<string, string> customerOrgDisplayModeCache,
|
|
IDistributedCache<DiagnosisLevel, short> diagnosisLevelCache,
|
|
IRepository<DiagnosisLevel, short> diagnosisLevelRepository,
|
|
IMemoryCache userExtensionCache)
|
|
{
|
|
_userCache = userCache;
|
|
_userRepository = userRepository;
|
|
|
|
_sexCache = sexCache;
|
|
_sexRepository = sexRepository;
|
|
|
|
_forSexCache = forSexCache;
|
|
_forSexRepository = forSexRepository;
|
|
|
|
_deviceTypeCache = deviceTypeCache;
|
|
_deviceTypeRepository = deviceTypeRepository;
|
|
|
|
_asbitemCache = asbitemCache;
|
|
_asbitemRepository = asbitemRepository;
|
|
|
|
_itemTypeCache = itemTypeCache;
|
|
_itemTypeRepository = itemTypeRepository;
|
|
|
|
_nationCache = nationCache;
|
|
_nationRepository = nationRepository;
|
|
|
|
_customerOrgCache = customerOrgCache;
|
|
_customerOrgRepository = customerOrgRepository;
|
|
|
|
_maritalStatusCache = maritalStatusCache;
|
|
_maritalStatusRepository = maritalStatusRepository;
|
|
|
|
_medicalTypeCache = medicalTypeCache;
|
|
_medicalTypeRepository = medicalTypeRepository;
|
|
|
|
_personnelTypeCache = personnelTypeCache;
|
|
_personnelTypeRepository = personnelTypeRepository;
|
|
_customerOrgTopNameCache = customerOrgTopNameCache;
|
|
_sampleTypeCache = sampleTypeCache;
|
|
_sampleTypeRepository = sampleTypeRepository;
|
|
_sysParmValueManager = sysParmValueManager;
|
|
_customerOrgDisplayModeCache = customerOrgDisplayModeCache;
|
|
_diagnosisLevelCache = diagnosisLevelCache;
|
|
_diagnosisLevelRepository = diagnosisLevelRepository;
|
|
_userExtensionCache = userExtensionCache;
|
|
}
|
|
|
|
private async Task<IdentityUser> GetUserAsync(Guid id)
|
|
{
|
|
|
|
var entity = await _userCache.GetOrAddAsync(
|
|
id, //缓存键
|
|
async () =>
|
|
{
|
|
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 dataEntity;
|
|
}
|
|
);
|
|
return entity;
|
|
}
|
|
|
|
public async Task<string> GetSurnameAsync(Guid? id)
|
|
{
|
|
if (id == null || id == default(Guid) || !id.HasValue)
|
|
{
|
|
return "";
|
|
}
|
|
var entity = await GetUserAsync((Guid)id);
|
|
if (entity != null)
|
|
return entity.Surname;
|
|
else
|
|
return "";
|
|
}
|
|
|
|
public async Task<string> GetSurnameAsync(string id)
|
|
{
|
|
Guid newId;
|
|
|
|
if (string.IsNullOrWhiteSpace(id) || !Guid.TryParse(id, out newId))
|
|
{
|
|
return "";
|
|
}
|
|
var entity = await GetUserAsync(newId);
|
|
if (entity != null)
|
|
return entity.Surname;
|
|
else
|
|
return "";
|
|
}
|
|
|
|
public async Task<string> GetUserSignAsync(Guid? id)
|
|
{
|
|
if (id == null || id == default(Guid) || !id.HasValue)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (userExtension == null)
|
|
{
|
|
return "";
|
|
}
|
|
else
|
|
{
|
|
return userExtension.UserSign;
|
|
}
|
|
}
|
|
private async Task<Sex> GetSexAsync(char id)
|
|
{
|
|
|
|
var entity = await _sexCache.GetOrAddAsync(
|
|
id, //缓存键
|
|
async () => (await _sexRepository.GetQueryableAsync()).Where(o => o.Id == id).Single()
|
|
);
|
|
return entity;
|
|
}
|
|
public async Task<string> GetSexNameAsync(char id)
|
|
{
|
|
|
|
var entity = await GetSexAsync(id);
|
|
return entity.DisplayName;
|
|
}
|
|
|
|
private async Task<ForSex> GetForSexAsync(char id)
|
|
{
|
|
|
|
var entity = await _forSexCache.GetOrAddAsync(
|
|
id, //缓存键
|
|
async () => (await _forSexRepository.GetQueryableAsync()).Where(o => o.Id == id).Single()
|
|
);
|
|
return entity;
|
|
}
|
|
public async Task<string> GetForSexNameAsync(char id)
|
|
{
|
|
|
|
var entity = await GetForSexAsync(id);
|
|
return entity.DisplayName;
|
|
}
|
|
|
|
private async Task<MaritalStatus> GetMaritalStatusAsync(char id)
|
|
{
|
|
|
|
var maritalStatusEntity = await _maritalStatusCache.GetAsync(id);
|
|
if (maritalStatusEntity == null)
|
|
{
|
|
maritalStatusEntity = await _maritalStatusRepository.FirstOrDefaultAsync(f => f.Id == id);
|
|
}
|
|
|
|
return maritalStatusEntity;
|
|
|
|
//var entity = await _maritalStatusCache.GetOrAddAsync(
|
|
// id, //缓存键
|
|
// async () => (await _maritalStatusRepository.GetQueryableAsync()).Where(o => o.Id == id).Single()
|
|
//);
|
|
//return entity;
|
|
}
|
|
public async Task<string> GetMaritalStatusNameAsync(char id)
|
|
{
|
|
|
|
var entity = await GetMaritalStatusAsync(id);
|
|
return entity.DisplayName;
|
|
}
|
|
|
|
private async Task<DeviceType> GetDeviceTypeAsync(Guid id)
|
|
{
|
|
|
|
var entity = await _deviceTypeCache.GetOrAddAsync(
|
|
id, //缓存键
|
|
async () => await _deviceTypeRepository.GetAsync(id)
|
|
|
|
);
|
|
return entity;
|
|
}
|
|
public async Task<string> GetDeviceTypeNameAsync(Guid? id)
|
|
{
|
|
if (id == null || id == default(Guid) || !id.HasValue)
|
|
{
|
|
return "";
|
|
}
|
|
var entity = await GetDeviceTypeAsync((Guid)id);
|
|
return entity.DisplayName;
|
|
}
|
|
|
|
private async Task<MedicalType> GetMedicalTypeAsync(Guid id)
|
|
{
|
|
|
|
var entity = await _medicalTypeCache.GetOrAddAsync(
|
|
id, //缓存键
|
|
async () => await _medicalTypeRepository.GetAsync(id)
|
|
|
|
);
|
|
return entity;
|
|
}
|
|
public async Task<string> GetMedicalTypeNameAsync(Guid? id)
|
|
{
|
|
if (id == null || id == default(Guid) || !id.HasValue)
|
|
{
|
|
return "";
|
|
}
|
|
var entity = await GetMedicalTypeAsync((Guid)id);
|
|
return entity.DisplayName;
|
|
}
|
|
private async Task<PersonnelType> GetPersonnelTypeAsync(Guid id)
|
|
{
|
|
|
|
var entity = await _personnelTypeCache.GetOrAddAsync(
|
|
id, //缓存键
|
|
async () => await _personnelTypeRepository.GetAsync(id)
|
|
|
|
);
|
|
return entity;
|
|
}
|
|
public async Task<string> GetPersonnelTypeNameAsync(Guid? id)
|
|
{
|
|
if (id == null || id == default(Guid) || !id.HasValue)
|
|
{
|
|
return "";
|
|
}
|
|
var entity = await GetPersonnelTypeAsync((Guid)id);
|
|
return entity.DisplayName;
|
|
}
|
|
|
|
public async Task<Asbitem> GetAsbitemAsync(Guid id)
|
|
{
|
|
var entity = (Asbitem)_asbitemCache.Get(id);
|
|
if (entity == null)
|
|
{
|
|
entity = await _asbitemRepository.GetAsync(o => o.Id == id);
|
|
_asbitemCache.Set(id, entity);
|
|
//entity = (CustomerOrg)_customerOrgCache.Get(id);
|
|
}
|
|
|
|
return entity;
|
|
|
|
|
|
//var entity = await _asbitemCache.GetOrAddAsync(
|
|
// id, //缓存键
|
|
// async () => await _asbitemRepository.GetAsync(id)
|
|
|
|
//);
|
|
//return entity;
|
|
}
|
|
|
|
public async Task<ItemType> GetItemTypeAsync(Guid id)
|
|
{
|
|
|
|
var entity = (ItemType)_itemTypeCache.Get(id);
|
|
if (entity == null)
|
|
{
|
|
entity = await _itemTypeRepository.GetAsync(o => o.Id == id);
|
|
_itemTypeCache.Set(id, entity);
|
|
//entity = (CustomerOrg)_customerOrgCache.Get(id);
|
|
}
|
|
|
|
//var entity = await _itemTypeCache.GetOrAddAsync(
|
|
// id, //缓存键
|
|
// async () => (ItemType) _itemTypeRepository.Get(id)
|
|
|
|
//);
|
|
return entity;
|
|
}
|
|
|
|
public async Task<Nation> GetNationAsync(string id)
|
|
{
|
|
|
|
var entity = await _nationCache.GetOrAddAsync(
|
|
id, //缓存键
|
|
async () => await _nationRepository.GetAsync(o => o.Id == id)
|
|
|
|
);
|
|
return entity;
|
|
}
|
|
|
|
public async Task<string> GetNationNameAsync(string id)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(id))
|
|
{
|
|
return "";
|
|
}
|
|
var entity = await GetNationAsync(id);
|
|
return entity.DisplayName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取部门名称
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public async Task<CustomerOrg> GetCustomerOrgAsync(Guid id)
|
|
{
|
|
var entity = (CustomerOrg)_customerOrgCache.Get(id);
|
|
if (entity == null)
|
|
{
|
|
entity = await _customerOrgRepository.GetAsync(o => o.Id == id);
|
|
_customerOrgCache.Set(id, entity);
|
|
//entity = (CustomerOrg)_customerOrgCache.Get(id);
|
|
}
|
|
|
|
return entity;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取部门名称
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public async Task<string> GetCustomerOrgNameAsync(Guid? id)
|
|
{
|
|
if (id == null || id == default(Guid) || !id.HasValue)
|
|
{
|
|
return "";
|
|
}
|
|
var entity = await GetCustomerOrgAsync((Guid)id);
|
|
return entity.DisplayName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取一级单位
|
|
/// </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)
|
|
{
|
|
entity = await _customerOrgRepository.GetAsync(o => o.Id == id);
|
|
_customerOrgCache.Set(id, entity);
|
|
}
|
|
|
|
if (entity.ParentId != null && entity.ParentId != Guid.Empty)
|
|
{
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取单位简称 一级单位 简称如果没有显示全称
|
|
/// </summary>
|
|
/// <param name="CustomerOrgId"></param>
|
|
/// <returns></returns>
|
|
public async Task<string> GetTopCustomerOrgShortNameAsync(Guid CustomerOrgId)
|
|
{
|
|
var customerOrgEnt = await GetTopCustomerOrgAsync(CustomerOrgId);
|
|
if (string.IsNullOrWhiteSpace(customerOrgEnt.ShortName))
|
|
return customerOrgEnt.DisplayName;
|
|
else
|
|
return customerOrgEnt.ShortName;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取部门简称 简称如果没有显示全称
|
|
/// </summary>
|
|
/// <param name="CustomerOrgId"></param>
|
|
/// <returns></returns>
|
|
public async Task<string> GetCustomerOrgShortNameAsync(Guid CustomerOrgId)
|
|
{
|
|
var customerOrgEnt = await GetCustomerOrgAsync(CustomerOrgId);
|
|
if (string.IsNullOrWhiteSpace(customerOrgEnt.ShortName))
|
|
return customerOrgEnt.DisplayName;
|
|
else
|
|
return customerOrgEnt.ShortName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有部门名称
|
|
/// </summary>
|
|
/// <param name="CustomerOrgId"></param>
|
|
/// <returns></returns>
|
|
public async Task<string> GetAllDepartmentNameAsync(Guid CustomerOrgId)
|
|
{
|
|
var departmentDisplayMode = await _sysParmValueManager.GetSysParmValueAsync(Guid.Empty, "department_display_mode");
|
|
if (departmentDisplayMode == "1")
|
|
{
|
|
List<string> customerOrgNames = new List<string>();
|
|
await GetAllDepartmentNameAsync(customerOrgNames, CustomerOrgId);
|
|
|
|
if (customerOrgNames.Count > 1)
|
|
{
|
|
customerOrgNames.RemoveAt(0);
|
|
return string.Join("\\", customerOrgNames);
|
|
}
|
|
else
|
|
{
|
|
//无部门
|
|
return "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//兼容不设置系统参数的
|
|
return await GetCustomerOrgNameAsync(CustomerOrgId);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 遍历获取单位数据
|
|
/// </summary>
|
|
/// <param name="customerOrgNames"></param>
|
|
/// <param name="customerOrgId"></param>
|
|
/// <returns></returns>
|
|
public async Task GetAllDepartmentNameAsync(List<string> customerOrgNames, Guid? customerOrgId)
|
|
{
|
|
if (customerOrgId != null)
|
|
{
|
|
var customerOrgEnt = await GetCustomerOrgAsync(customerOrgId.Value);
|
|
if (customerOrgEnt != null)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(customerOrgEnt.ShortName))
|
|
customerOrgNames.AddFirst(customerOrgEnt.DisplayName);
|
|
else
|
|
customerOrgNames.AddFirst(customerOrgEnt.ShortName);
|
|
|
|
await GetAllDepartmentNameAsync(customerOrgNames, customerOrgEnt.ParentId);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 缓存取单位名称
|
|
/// </summary>
|
|
/// <param name="CustomerOrgId">部门ID</param>
|
|
/// <returns></returns>
|
|
public async Task<string> GetTopCustomerOrgNameAsync(Guid CustomerOrgId)
|
|
{
|
|
string topCustomerOrgName = await _customerOrgTopNameCache.GetOrAddAsync(
|
|
CustomerOrgId, //缓存键
|
|
async () => await GetTopCustomerOrgNameInCustomerOrgIdAsync(CustomerOrgId)
|
|
|
|
);
|
|
|
|
return topCustomerOrgName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据部门ID 按PathCode码查询单位名称
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <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)
|
|
{
|
|
entity = await _customerOrgRepository.GetAsync(o => o.Id == id);
|
|
_customerOrgCache.Set(id, entity);
|
|
}
|
|
|
|
|
|
if (entity.Id == GuidFlag.PersonCustomerOrgId)
|
|
{
|
|
return entity.DisplayName;
|
|
}
|
|
if (entity.PathCode.Length == 5)
|
|
{
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取顶级单位ID 直取,不按配置来,用登记界面做单位比较
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public async Task<Guid> GetTopCustomerOrgIdAsync(Guid id)
|
|
{
|
|
Guid topCustomerOrgId = id;
|
|
|
|
|
|
var entity = (CustomerOrg)_customerOrgCache.Get(id);
|
|
if (entity == null)
|
|
{
|
|
entity = await _customerOrgRepository.GetAsync(o => o.Id == id);
|
|
_customerOrgCache.Set(id, entity);
|
|
}
|
|
|
|
if (entity.PathCode.Length > 5)
|
|
{
|
|
entity = await _customerOrgRepository.GetAsync(o => o.PathCode == entity.PathCode.Substring(0, 5));
|
|
topCustomerOrgId = entity.Id;
|
|
}
|
|
|
|
|
|
return topCustomerOrgId;
|
|
}
|
|
|
|
|
|
private async Task<SampleType> GetSampleTypeAsync(Guid id)
|
|
{
|
|
|
|
var entity = await _sampleTypeCache.GetOrAddAsync(
|
|
id, //缓存键
|
|
async () => await _sampleTypeRepository.GetAsync(id)
|
|
|
|
);
|
|
return entity;
|
|
}
|
|
public async Task<string> GetSampleTypeNameAsync(Guid? id)
|
|
{
|
|
if (id == null || id == default(Guid) || !id.HasValue)
|
|
{
|
|
return "";
|
|
}
|
|
var entity = await GetSampleTypeAsync((Guid)id);
|
|
return entity.DisplayName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取诊断级别名称
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public async Task<string> GetDiagnosisLevelNameAsync(short? id)
|
|
{
|
|
if (id != null)
|
|
{
|
|
var diagnosisLevelEntity = await _diagnosisLevelCache.GetAsync(id.Value);
|
|
if (diagnosisLevelEntity == null)
|
|
{
|
|
diagnosisLevelEntity = await _diagnosisLevelRepository.FirstOrDefaultAsync(f => f.Id == id);
|
|
}
|
|
|
|
return diagnosisLevelEntity.DisplayName;
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|