diff --git a/src/Shentun.Peis.Application.Contracts/CommonChars/CommonCharDto.cs b/src/Shentun.Peis.Application.Contracts/CommonChars/CommonCharDto.cs index 6b7236b..9919c60 100644 --- a/src/Shentun.Peis.Application.Contracts/CommonChars/CommonCharDto.cs +++ b/src/Shentun.Peis.Application.Contracts/CommonChars/CommonCharDto.cs @@ -19,7 +19,7 @@ namespace Shentun.Peis.CommonChars public string SimpleCode { get; set; } public int DisplayOrder { get; set; } - public string CommonCharName { get; set; } + public string CommonCharTypeName { get; set; } } diff --git a/src/Shentun.Peis.Application.Contracts/CommonChars/GetCommonCharListRequestDto.cs b/src/Shentun.Peis.Application.Contracts/CommonChars/GetCommonCharListRequestDto.cs new file mode 100644 index 0000000..c8eb19a --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/CommonChars/GetCommonCharListRequestDto.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.CommonChars +{ + public class GetCommonCharListRequestDto + { + /// + /// 搜索名称 支持名称跟简码 + /// + public string Filter { get; set; } + + /// + /// 常用字符类别ID + /// + public Guid? CommonCharTypeId { get; set; } + } +} diff --git a/src/Shentun.Peis.Application/CommonChars/CommonCharAppService.cs b/src/Shentun.Peis.Application/CommonChars/CommonCharAppService.cs index 8ebfb5d..8610c31 100644 --- a/src/Shentun.Peis.Application/CommonChars/CommonCharAppService.cs +++ b/src/Shentun.Peis.Application/CommonChars/CommonCharAppService.cs @@ -34,14 +34,17 @@ namespace Shentun.Peis.CommonChars { private readonly IRepository _userRepository; private readonly CommonCharManager _manager; + private readonly CacheService _cacheService; public CommonCharAppService( IRepository repository, IRepository userRepository, - CommonCharManager manager) + CommonCharManager manager, + CacheService cacheService) : base(repository) { _userRepository = userRepository; _manager = manager; + _cacheService = cacheService; } /// /// 获取通过主键 @@ -69,31 +72,25 @@ namespace Shentun.Peis.CommonChars /// - /// 获取列表 常用字符 带搜索 + /// 获取列表 常用字符 带搜索 可按常用字符类别搜索 /// /// /// - public async Task> GetListInFilterAsync(GetListInFilterDto input) + [HttpPost("api/app/CommonChar/GetCommonCharList")] + public async Task> GetCommonCharListAsync(GetCommonCharListRequestDto input) { - int totalCount = 0; - if (!string.IsNullOrEmpty(input.Filter)) - totalCount = (await Repository.GetListAsync()).Where(m => m.DisplayName.Contains(input.Filter)).Count(); - else - totalCount = await Repository.CountAsync(); + var query = (await Repository.GetQueryableAsync()).Include(x => x.CommonCharType).AsQueryable(); + if (!string.IsNullOrWhiteSpace(input.Filter)) + query = query.Where(m => (!string.IsNullOrEmpty(m.DisplayName) && m.DisplayName.Contains(input.Filter)) + || (!string.IsNullOrEmpty(m.SimpleCode) && m.SimpleCode.Contains(input.Filter))); - var entlist = Repository.GetDbSetAsync().Result.Include(c => c.CommonCharType).ToList(); - - if (!string.IsNullOrEmpty(input.Filter)) - entlist = entlist.Where(m => m.DisplayName.Contains(input.Filter)).ToList(); - - //分页 - entlist = entlist.OrderBy(m => m.DisplayOrder).Skip(input.SkipCount * input.MaxResultCount).Take(input.MaxResultCount).ToList(); - - var userList = await _userRepository.GetListAsync(); - - var entdto = entlist.Select(s => new CommonCharDto + if (input.CommonCharTypeId != null) + { + query = query.Where(m => m.CommonCharTypeId == input.CommonCharTypeId); + } + var entListDto = query.Select(s => new CommonCharDto { CreationTime = s.CreationTime, CreatorId = s.CreatorId, @@ -104,12 +101,12 @@ namespace Shentun.Peis.CommonChars LastModifierId = s.LastModifierId, SimpleCode = s.SimpleCode, CommonCharTypeId = s.CommonCharTypeId, - CommonCharName = s.CommonCharType.DisplayName, - CreatorName = EntityHelper.GetUserNameNoSql(userList, s.CreatorId), - LastModifierName = EntityHelper.GetUserNameNoSql(userList, s.LastModifierId) + CommonCharTypeName = s.CommonCharType.DisplayName, + CreatorName = _cacheService.GetUserNameAsync(s.CreatorId).Result, + LastModifierName = _cacheService.GetUserNameAsync(s.LastModifierId).Result }).ToList(); - return new PagedResultDto(totalCount, entdto); + return entListDto; } @@ -151,7 +148,7 @@ namespace Shentun.Peis.CommonChars return base.DeleteAsync(id); } - + /// /// 修改排序 置顶,置底