| | |
| | | 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.ParentId.HasValue) |
| | | { |
| | | q = q.Where(it => it.ParentId == request.ParentId); |
| | | } |
| | | 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.IsDisabled); |
| | | if (!request.All) |
| | | { |
| | | q = q.Where(it => it.ParentId == request.ParentId); |
| | | } |
| | | if (request.CategoryCode == "70" || request.CategoryId == new Guid("B21FE000-BB7F-4498-08E9-08DDD572EF73")) |
| | | { |
| | | q = q.Where(it => it.Deep <= 3); |
| | | } |
| | | if (request.Keywords.IsNotNull()) |
| | | { |
| | | q = q.Where(it => |
| | | it.Code.Contains(request.Keywords) |
| | | || it.Content.Contains(request.Keywords) |
| | | || it.Field1.Contains(request.Keywords) |
| | | || it.Field2.Contains(request.Keywords) |
| | | || it.Field3.Contains(request.Keywords) |
| | | || it.Field4.Contains(request.Keywords) |
| | | || it.Field5.Contains(request.Keywords)); |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | } |