using Znyc.CloudCar.IRepository.Dictionary; using Znyc.CloudCar.IServices.CaChe; using Znyc.CloudCar.IServices.Dictionary; using Znyc.CloudCar.Model.Dtos.Dictionary; using Znyc.CloudCar.Model.ViewModels.ReportsCallBack; using Znyc.CloudCar.Utility.Extensions; namespace Znyc.CloudCar.Services.Dictionary { public class DictionaryService : IDictionaryService { private readonly ICacheService _cacheService; private readonly IDictionaryRepository _dictionaryRepository; public DictionaryService( IDictionaryRepository dictionaryRepository, ICacheService cacheService) { _dictionaryRepository = dictionaryRepository; _cacheService = cacheService; } /// /// 根据Id获取字典 /// /// /// public async Task GetByIdAsync(long id) { List list = await _cacheService.GetDictionaryAsync(); if (list.IsNull()) { list = await _dictionaryRepository.Select .Where(x => x.IsEnabled) .OrderBy(true, c => c.Sort) .ToListAsync(); await _cacheService.SetDictionaryAsync(list); } DictionaryOutput dictionary = list.Find(x => x.Id == id); return dictionary; } /// /// 根据ParentId查询数据字典列表 /// /// /// public async Task GetListByParentIdAsync(long pid) { var dictionarys = await _cacheService.GetDictionaryAsync(); if (dictionarys.IsNull()) { dictionarys = await _dictionaryRepository.Select .Where(x => x.IsEnabled) .OrderBy(true, x => x.Sort) .ToListAsync(); await _cacheService.SetDictionaryAsync(dictionarys); } ResponseOutput response = new ResponseOutput() { Data = dictionarys.Where(x => x.ParentId == pid).ToList(), Successed = true, Code = 1 }; return response; } /// /// 根据ParentId,Code查询数据字典列表 /// /// /// /// public async Task GetListByCodeAsync(long parentId, string code) { var dictionarys = await _dictionaryRepository .Where(x => x.ParentId == parentId && x.Code == code.ToUpper()) .OrderBy(x => x.Sort) .ToListAsync(); var response = new ResponseOutput(); response.Data = dictionarys; response.Successed = true; response.Code = 1; return response; } } }