using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Zxd.Core.Shared.Dto; namespace Hg.Internal.Domain { internal class CacheDomain : ICacheDomain { private readonly IMapper _mapper; private readonly IRedisManager _redisManager; private readonly IHttpClient _httpClient; private readonly SystemConfig _systemConfig; private readonly IConfiguration _configuration; public CacheDomain(IRedisManager redisManager, IMapper mapper, IHttpClient httpClient, IConfiguration configuration) { _redisManager = redisManager; _mapper = mapper; _httpClient = httpClient; _configuration = configuration; _systemConfig = configuration.GetSection("SystemConfig").Get(); } public async Task> GetDeptments(bool isdept=false) { var key = $"{CacheKeys.ZxdParameterList}"; if (!await _redisManager.ExistsAsync(key)) { var response = isdept ? await _httpClient.GetAsync>>($"{_systemConfig.ZxdCoreUrl}/Api/Deptment/Depts?isDept=true") : await _httpClient.GetAsync>>($"{_systemConfig.ZxdCoreUrl}/Api/Deptment/Depts"); if (response.Code == 0) { await _redisManager.SetAsync(key, response.Data, TimeSpan.FromDays(1)); return response.Data; } } else { return await _redisManager.GetListAsync(key); } return new List(); } } }