99 lines
3.1 KiB
C#
99 lines
3.1 KiB
C#
using DG.EntityFramework;
|
|
using DG.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Zxd.Crm.Domain.Dto;
|
|
using Zxd.Crm.Domain.Impl;
|
|
using Zxd.Domain.Config;
|
|
using Zxd.Entity.Zxd;
|
|
using Zxd.EntityFramework;
|
|
|
|
namespace Zxd.Crm.Domain
|
|
{
|
|
public class CacheDomain : ICacheDomain
|
|
{
|
|
private readonly IRedisManager _redisManager;
|
|
private readonly IBaseRepository<ZxdDbContext> _repository;
|
|
|
|
public CacheDomain(IRedisManager redisManager,
|
|
IBaseRepository<ZxdDbContext> repository)
|
|
{
|
|
_redisManager = redisManager;
|
|
_repository = repository;
|
|
}
|
|
|
|
private async Task<List<BAS_PARAMETER>> GetParameterList()
|
|
{
|
|
if (!await _redisManager.ExistsAsync(CacheKeys.ParameterList))
|
|
{
|
|
var list = await _repository.GetRepository<BAS_PARAMETER>().QueryListAsync();
|
|
await _redisManager.SetAsync(CacheKeys.ParameterList, list);
|
|
return list;
|
|
}
|
|
else
|
|
{
|
|
return await _redisManager.GetListAsync<BAS_PARAMETER>(CacheKeys.ParameterList);
|
|
}
|
|
}
|
|
|
|
public async Task<string> GetValueParameter(string key)
|
|
{
|
|
var list = await GetParameterList();
|
|
return list.FirstOrDefault(x => x.PARAKEY == key)?.PARAVALUE ?? "";
|
|
}
|
|
|
|
public async Task<List<DeptMentReturnModel>> GetDeptMapList()
|
|
{
|
|
var key = CacheKeys.UserDeptMapList;
|
|
if (await _redisManager.ExistsAsync(key))
|
|
{
|
|
try
|
|
{
|
|
return await _redisManager.GetListAsync<DeptMentReturnModel>(key);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await _redisManager.RemoveAsync(key);
|
|
}
|
|
}
|
|
return new List<DeptMentReturnModel>();
|
|
}
|
|
|
|
public async Task AddDeptMapInfo(List<DeptMentReturnModel> deptList)
|
|
{
|
|
var key = CacheKeys.UserDeptMapList;
|
|
if (!await _redisManager.ExistsAsync(key))
|
|
{
|
|
await _redisManager.SetAsync(key, deptList, TimeSpan.FromMinutes(30));
|
|
}
|
|
else
|
|
{
|
|
var list = await _redisManager.GetListAsync<DeptMentReturnModel>(key);
|
|
list.AddRange(deptList);
|
|
await _redisManager.SetAsync(key, list, TimeSpan.FromMinutes(30));
|
|
}
|
|
}
|
|
|
|
public async Task UpdateDeptMapInfo(List<DeptMentReturnModel> deptList)
|
|
{
|
|
var key = CacheKeys.UserDeptMapList;
|
|
if (deptList == null || deptList.Count == 0)
|
|
{
|
|
await _redisManager.RemoveAsync(key);
|
|
return;
|
|
}
|
|
|
|
if (!await _redisManager.ExistsAsync(key))
|
|
{
|
|
await _redisManager.SetAsync(key, deptList);
|
|
}
|
|
else
|
|
{
|
|
await _redisManager.SetAsync(key, deptList, TimeSpan.FromMinutes(30));
|
|
}
|
|
}
|
|
}
|
|
} |