| | |
| | | public class DictionaryDatasQueryHandler( |
| | | IRepository<DictionaryData> rep |
| | | ) : IRequestHandler<GetDictionaryDatasQuery, PagedListQueryResult<GetDictionaryDatasQueryResultItem>>, |
| | | IRequestHandler<GetDictionaryDataSelectQuery, List<SelectOption<string, GetDictionaryDataSelectQueryResultOption>>> |
| | | IRequestHandler<GetDictionaryDataSelectQuery, List<SelectOption<string, GetDictionaryDataSelectQueryResultOption>>>, |
| | | IRequestHandler<GetAreaSelectQuery, List<GetAreaSelectQueryResultOption>> |
| | | { |
| | | private readonly IRepository<DictionaryData> rep = rep; |
| | | |
| | |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public Task<List<SelectOption<string, GetDictionaryDataSelectQueryResultOption>>> Handle(GetDictionaryDataSelectQuery request, CancellationToken cancellationToken) |
| | | public async Task<List<SelectOption<string, GetDictionaryDataSelectQueryResultOption>>> Handle(GetDictionaryDataSelectQuery request, CancellationToken cancellationToken) |
| | | { |
| | | return request.GetSelect<DictionaryData, string, GetDictionaryDataSelectQueryResultOption>( |
| | | var models = await request.GetSelect<DictionaryData, string, GetDictionaryDataSelectQueryResultOption>( |
| | | it => it.Code, |
| | | it => it.Content, |
| | | q => |
| | | { |
| | | q = q |
| | | .OrderBy(it => it.Sort).ThenBy(it => it.CreatedTime) |
| | | .OrderBy(it => it.Sort) |
| | | .Where(it => !it.IsDisabled); |
| | | if (request.All != true) |
| | | { |
| | |
| | | return q; |
| | | }, |
| | | cancellationToken); |
| | | if (request.WithChildren) |
| | | { |
| | | var parents = models.Where(it => it.Data.ParentId == null).ToList(); |
| | | LoopChildrens(parents, models); |
| | | return parents; |
| | | } |
| | | return models; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 查询地区选择器 |
| | | /// </summary> |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public async Task<List<GetAreaSelectQueryResultOption>> Handle(GetAreaSelectQuery request, CancellationToken cancellationToken) |
| | | { |
| | | var models = await Handle(new GetDictionaryDataSelectQuery |
| | | { |
| | | CategoryCode = "70", |
| | | All = true, |
| | | MaxDeep = request.MaxDeep, |
| | | WithChildren = true |
| | | }, cancellationToken); |
| | | var result = models.Adapt<List<GetAreaSelectQueryResultOption>>(); |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 递归赋值下级 |
| | | /// </summary> |
| | | /// <param name="models"></param> |
| | | /// <param name="all"></param> |
| | | private void LoopChildrens(List<SelectOption<string, GetDictionaryDataSelectQueryResultOption>> models, List<SelectOption<string, GetDictionaryDataSelectQueryResultOption>> all) |
| | | { |
| | | foreach (var item in models) |
| | | { |
| | | item.Data.Children = all.Where(it => it.Data.ParentId == item.Data.Id).ToList(); |
| | | if (item.Data.Children.IsNotNull()) |
| | | { |
| | | LoopChildrens(item.Data.Children, all); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |