| | |
| | | using FlexJobApi.Core; |
| | | using Furion.DatabaseAccessor; |
| | | using Mapster; |
| | | using MediatR; |
| | | using Microsoft.EntityFrameworkCore; |
| | | using System; |
| | |
| | | /// <summary> |
| | | /// 查询角色分页列表 |
| | | /// </summary> |
| | | /// <param name="rep"></param> |
| | | /// <param name="repRole"></param> |
| | | public class GetRolesQueryHandler( |
| | | IRepository<Role> rep |
| | | IRepository<Role> repRole, |
| | | IRepository<UserInfoRole> repUserInfoRole |
| | | ) : IRequestHandler<GetRolesQuery, PagedListQueryResult<GetRolesQueryResultItem>> |
| | | { |
| | | private readonly IRepository<Role> rep = rep; |
| | | private readonly IRepository<Role> repRole = repRole; |
| | | private readonly IRepository<UserInfoRole> repUserInfoRole = repUserInfoRole; |
| | | |
| | | /// <inheritdoc/> |
| | | public Task<PagedListQueryResult<GetRolesQueryResultItem>> Handle(GetRolesQuery request, CancellationToken cancellationToken) |
| | | public async Task<PagedListQueryResult<GetRolesQueryResultItem>> Handle(GetRolesQuery request, CancellationToken cancellationToken) |
| | | { |
| | | var q = rep.AsQueryable().AsNoTracking(); |
| | | var q = repRole.AsQueryable().AsNoTracking(); |
| | | if (request.UserType.HasValue) |
| | | { |
| | | q = q.Where(it => it.UserType == request.UserType); |
| | |
| | | { |
| | | q = q.Where(it => it.ClientType == request.ClientType); |
| | | } |
| | | throw new NotImplementedException(); |
| | | var result = await q |
| | | .ProjectToType<GetRolesQueryResultItem>() |
| | | .ToPagedListAsync(request.PageModel, cancellationToken); |
| | | |
| | | if (result.Data.Any()) |
| | | { |
| | | var ids = result.Data.DistinctSelect(it => it.Id); |
| | | var userInfoRoles = await repUserInfoRole.AsQueryable().AsNoTracking() |
| | | .Where(it => ids.Contains(it.RoleId)) |
| | | .Select(it => new |
| | | { |
| | | it.UserInfoId, |
| | | it.RoleId |
| | | }) |
| | | .ToListAsync(); |
| | | foreach (var item in result.Data) |
| | | { |
| | | item.UserCount = userInfoRoles.Count(it => it.RoleId == item.Id); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | } |
| | | } |