44 lines
1.4 KiB
C#
44 lines
1.4 KiB
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>>();
|
|
//_repository = provider.GetService<IRepository<DictEntity>>();
|
|
_cache = _repository.GetList();
|
|
}
|
|
|
|
|
|
public async Task<string> GetKeyAsync(string type, string name)
|
|
{
|
|
return _cache.FirstOrDefault(d => d.Type == type && d.Value == name)?.Key ?? "";
|
|
}
|
|
|
|
public async Task<List<DictEntity>> GetDictsByTypeAsync(string type)
|
|
{
|
|
return _cache.Where(d => d.Type == type).ToList();
|
|
}
|
|
|
|
public async Task SetValue(string type, string key, string value)
|
|
{
|
|
await _repository.CopyNew().AsUpdateable()
|
|
.Where(x => x.Type == type && x.Key == key).SetColumns(x => x.Value, value).ExecuteCommandAsync(); ;
|
|
}
|
|
|
|
public async Task<string> GetValue(string type, string key)
|
|
{
|
|
var dict = await _repository.CopyNew().GetFirstAsync(x => x.Type == type && x.Key == key);
|
|
return dict.Value;
|
|
}
|
|
} |