| | |
| | | using FlexJobApi.Core; |
| | | using Furion.DatabaseAccessor; |
| | | using Furion.FriendlyException; |
| | | using Mapster; |
| | | using MediatR; |
| | | using Microsoft.EntityFrameworkCore; |
| | |
| | | /// </summary> |
| | | public class DictionaryDatasQueryHandler( |
| | | IRepository<DictionaryData> rep |
| | | ) : IRequestHandler<GetDictionaryDatasQuery, PagedListQueryResult<GetDictionaryDatasQueryResultItem>> |
| | | ) : IRequestHandler<GetDictionaryDatasQuery, PagedListQueryResult<GetDictionaryDatasQueryResultItem>>, |
| | | IRequestHandler<GetDictionaryDataSelectQuery, List<SelectOption<Guid, GetDictionaryDataSelectQueryResultOption>>> |
| | | { |
| | | private readonly IRepository<DictionaryData> rep = rep; |
| | | |
| | |
| | | /// <returns></returns> |
| | | public Task<PagedListQueryResult<GetDictionaryDatasQueryResultItem>> Handle(GetDictionaryDatasQuery request, CancellationToken cancellationToken) |
| | | { |
| | | return request.PageModel.ToPagedListAsync<DictionaryData, GetDictionaryDatasQueryResultItem>( |
| | | return request.PageModel.GetPagedListAsync<DictionaryData, GetDictionaryDatasQueryResultItem>( |
| | | q => |
| | | { |
| | | q = q.OrderBy(it => it.Sort).ThenBy(it => it.CreatedTime); |
| | | if (request.CategoryId.HasValue) |
| | | { |
| | | q = q.Where(it => it.CategoryId == request.CategoryId); |
| | | } |
| | | else if (request.CategoryCode.IsNotNull()) |
| | | { |
| | | q = q.Where(it => it.Category.Code == request.CategoryCode); |
| | | } |
| | | else |
| | | { |
| | | throw Oops.Oh(EnumErrorCodeType.s400, "请填写类别Id或编号"); |
| | | } |
| | | if (request.Keywords.IsNotNull()) |
| | | { |
| | |
| | | return q; |
| | | }, cancellationToken: cancellationToken); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 查询数据字典选择器 |
| | | /// </summary> |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public Task<List<SelectOption<Guid, GetDictionaryDataSelectQueryResultOption>>> Handle(GetDictionaryDataSelectQuery request, CancellationToken cancellationToken) |
| | | { |
| | | return request.GetSelect<DictionaryData, Guid, GetDictionaryDataSelectQueryResultOption>( |
| | | it => it.Id, |
| | | it => it.Content, |
| | | q => |
| | | { |
| | | q = q |
| | | .OrderBy(it => it.Sort).ThenBy(it => it.CreatedTime) |
| | | .Where(it => |
| | | it.ParentId == request.ParentId |
| | | && !it.IsDisabled); |
| | | if (request.CategoryId.HasValue) |
| | | { |
| | | q = q.Where(it => it.CategoryId == request.CategoryId); |
| | | } |
| | | else if (request.CategoryCode.IsNotNull()) |
| | | { |
| | | q = q.Where(it => it.Category.Code == request.CategoryCode); |
| | | } |
| | | else |
| | | { |
| | | throw Oops.Oh(EnumErrorCodeType.s400, "请填写类别Id或编号"); |
| | | } |
| | | return q; |
| | | }, |
| | | cancellationToken); |
| | | } |
| | | } |
| | | } |