80 lines
2.9 KiB
C#
80 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Zxd.Core.Shared.Dto;
|
|
|
|
namespace Hg.Core.Domain
|
|
{
|
|
internal class DepartmentDomain : IDepartmentDomain
|
|
{
|
|
private readonly IBaseRepository<CompanyBaseConfDbContext> _companyBaseConfRepository;
|
|
private readonly IHttpClient _httpClient;
|
|
private readonly IMapper _mapper;
|
|
private readonly ICacheDomain _cacheDomain;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly IRedisManager _redisManager;
|
|
private readonly SystemConfig _systemConfig;
|
|
|
|
public DepartmentDomain(IConfiguration configuration,
|
|
IBaseRepository<CompanyBaseConfDbContext> companyBaseConfRepository,
|
|
IHttpClient httpClient,
|
|
IMapper mapper,
|
|
ICacheDomain cacheDomain,
|
|
IRedisManager redisManager
|
|
)
|
|
{
|
|
_systemConfig = configuration.GetSection("SystemConfig").Get<SystemConfig>();
|
|
_configuration = configuration;
|
|
_companyBaseConfRepository = companyBaseConfRepository;
|
|
_httpClient = httpClient;
|
|
_mapper = mapper;
|
|
_cacheDomain = cacheDomain;
|
|
_redisManager = redisManager;
|
|
}
|
|
|
|
public async Task<List<DeptmentDto>> GetDeptments(string? appid = null)
|
|
{
|
|
var key = CacheKeys.DeptmentList;
|
|
var data = new List<DeptmentDto>();
|
|
if (!await _redisManager.ExistsAsync(key))
|
|
{
|
|
var response = await _httpClient.GetAsync<ApiResult<List<DeptmentDto>>>(_systemConfig.GetZxdDepts());
|
|
if (response.Code == 0)
|
|
{
|
|
data = response.Data.Where(x => x.IsDept.HasValue && x.IsDept.Value)
|
|
.If(!string.IsNullOrEmpty(appid), x => x.Where(x => x.Appid == appid)).ToList();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
data = await _redisManager.GetListAsync<DeptmentDto>(key);
|
|
data = data.Where(x => x.IsDept.HasValue && x.IsDept.Value)
|
|
.If(!string.IsNullOrEmpty(appid), x => x.Where(x => x.Appid == appid)).ToList();
|
|
}
|
|
return data;
|
|
}
|
|
|
|
public async Task<List<DeptmentDto>> GetDeptmentAll()
|
|
{
|
|
var key = CacheKeys.DeptmentList;
|
|
var data = new List<DeptmentDto>();
|
|
if (!await _redisManager.ExistsAsync(key))
|
|
{
|
|
var response = await _httpClient.GetAsync<ApiResult<List<DeptmentDto>>>(_systemConfig.GetZxdDepts());
|
|
if (response.Code == 0)
|
|
{
|
|
data = response.Data;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
data = await _redisManager.GetListAsync<DeptmentDto>(key);
|
|
data = data.ToList();
|
|
}
|
|
return data;
|
|
}
|
|
}
|
|
}
|