| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- using System.Linq.Expressions;
- using Abp.Dependency;
- using Abp.Domain.Repositories;
- using Abp.Runtime.Caching;
- using VberZero.BaseSystem;
- namespace VberZero.DomainService.States;
- public class SysStatesManager : ISysStatesManager, ISingletonDependency
- {
- private ICacheManager CacheManager { get; set; }
- private IRepository<SysState> Repository { get; set; }
- public SysStatesManager(
- ICacheManager cacheManage,
- IRepository<SysState> repository)
- {
- CacheManager = cacheManage;
- Repository = repository;
- }
- #region GetSelectList
- #region CodeFilter
- public async Task<string> GetSelectStrAsync(QueryStateDisplayValue input, params string[] codeFilter)
- {
- return await GetSelectStrAsync(input.CodeKey, codeFilter);
- }
- public async Task<string> GetSelectStrAsync(string codeKey, params string[] codeFilter)
- {
- var options = "";
- var list = await GetStateListAsync(codeKey, codeFilter);
- foreach (var l in list)
- {
- options += $"<option value=\"{l.CodeValue}\" >{l.DisplayValue}</option>\r\n";
- }
- return options;
- }
- #endregion CodeFilter
- #region CodeFilterReversal
- public async Task<string> GetSelectStrReversalAsync(QueryStateDisplayValue input, params string[] codeFilter)
- {
- return await GetSelectStrReversalAsync(input.CodeKey, codeFilter);
- }
- public async Task<string> GetSelectStrReversalAsync(string codeKey, params string[] codeFilter)
- {
- var options = "";
- var list = await GetStateListReversalAsync(codeKey, codeFilter);
- foreach (var l in list)
- {
- options += $"<option value=\"{l.CodeValue}\" >{l.DisplayValue}</option>\r\n";
- }
- return options;
- }
- #endregion CodeFilterReversal
- #region Exp
- public async Task<string> GetSelectStrAsync(QueryStateDisplayValue input, Expression<Func<SysState, bool>> exp = null)
- {
- return await GetSelectStrAsync(input.CodeKey, exp);
- }
- public async Task<string> GetSelectStrAsync(string codeKey, Expression<Func<SysState, bool>> exp = null)
- {
- var options = "";
- var list = await GetStateListAsync(codeKey, exp);
- foreach (var l in list)
- {
- options += $"<option value=\"{l.CodeValue}\" >{l.DisplayValue}</option>\r\n";
- }
- return options;
- }
- #endregion Exp
- #region StateDisplayDto
- public async Task<List<StateDisplayDto>> GetStateListAsync(QueryStateDisplayValue input, Expression<Func<SysState, bool>> exp = null)
- {
- return await GetStateListAsync(input.CodeKey, exp);
- }
- public async Task<List<StateDisplayDto>> GetStateListAsync(string codeKey, Expression<Func<SysState, bool>> exp = null)
- {
- var list = (await Repository.GetAllListAsync(a => a.CodeKey == codeKey))
- .AsQueryable();
- if (exp != null)
- {
- list = list.Where(exp);
- }
- var dtoList = list.Select(a => new StateDisplayDto()
- {
- CodeValue = a.CodeValue,
- DisplayValue = a.DisplayValue
- }).ToList();
- return dtoList;
- }
- public async Task<List<StateDisplayDto>> GetStateListAsync(string codeKey, params string[] codeFilter)
- {
- var list = await Repository.GetAllListAsync(a => a.CodeKey == codeKey);
- if (codeFilter.Any())
- {
- foreach (var code in codeFilter)
- {
- list = list.Where(a => a.CodeValue == code).ToList();
- }
- }
- var dtos = list.Select(a => new StateDisplayDto()
- {
- CodeValue = a.CodeValue,
- DisplayValue = a.DisplayValue
- }).ToList();
- return dtos;
- }
- public async Task<List<StateDisplayDto>> GetStateListReversalAsync(string codeKey, params string[] codeFilter)
- {
- var list = await Repository.GetAllListAsync(a => a.CodeKey == codeKey);
- if (codeFilter.Any())
- {
- foreach (var code in codeFilter)
- {
- list = list.Where(a => a.CodeValue != code).ToList();
- }
- }
- var dtos = list.Select(a => new StateDisplayDto()
- {
- CodeValue = a.CodeValue,
- DisplayValue = a.DisplayValue
- }).ToList();
- return dtos;
- }
- #endregion StateDisplayDto
- #endregion GetSelectList
- #region GetDisplayValue
- public async Task<string> GetDisplayValueAsync(QueryStateDisplayValue input)
- {
- return await GetDisplayValueAsync(input.CodeKey, input.CodeValue);
- }
- public async Task<string> GetDisplayValueAsync(string codeKey, string codeValue)
- {
- return await CacheManager.GetCache<string, string>(VzConsts.CacheSysState).GetAsync(
- codeKey + "." + codeValue, () => DisplayValueAsync(codeKey, codeValue));
- }
- private async Task<string> DisplayValueAsync(string codeKey, string codeValue)
- {
- var state = await Repository.FirstOrDefaultAsync(a =>
- a.CodeKey == codeKey && a.CodeValue == codeValue);
- return state?.DisplayValue;
- }
- public string GetDisplayValue(QueryStateDisplayValue input)
- {
- return GetDisplayValue(input.CodeKey, input.CodeValue);
- }
- public string GetDisplayValue(string codeKey, string codeValue)
- {
- return CacheManager.GetCache<string, string>(VzConsts.CacheSysState).Get(
- codeKey + "." + codeValue, () => DisplayValue(codeKey, codeValue));
- }
- private string DisplayValue(string codeKey, string codeValue)
- {
- var state = Repository.FirstOrDefault(a =>
- a.CodeKey == codeKey && a.CodeValue == codeValue);
- return state?.DisplayValue;
- }
- #endregion GetDisplayValue
- }
|