2025-03-16 03:17:36 +08:00

31 lines
878 B
C#

using Microsoft.Extensions.DependencyInjection;
using Seyounth.Hyosung.Data.Entities;
using Seyounth.Hyosung.Data.Repositories;
using SqlSugar;
namespace Seyounth.Hyosung.Data.Services;
public class DictService : IDictService
{
private readonly IRepository<DictEntity> _repository;
private readonly List<DictEntity> _cache;
public DictService(IServiceProvider provider)
{
_repository = provider.CreateScope()
.ServiceProvider.GetRequiredService<IRepository<DictEntity>>();
_cache = _repository.GetList();
}
public async Task<string> GetKeyAsync(string type, string name)
{
return _cache.FirstOrDefault(d => d.Type == type && d.Value == name)?.Value ?? "";
}
public async Task<List<DictEntity>> GetDictsByTypeAsync(string type)
{
return _cache.Where(d => d.Type == type).ToList();
}
}