/// <summary> /// 分页列表 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <BasePageQueryOutput <QueryUserDto> > GetPageList(QueryUsersInput input) { var list = new List <User>(); var totalNumber = 0; var query = await _dbContext.Queryable <User>() .WhereIF(input.DeptId.HasValue, o => o.DeptId == input.DeptId.Value) .WhereIF(input.Account.IsNotNullAndWhiteSpace(), o => o.Account == input.Account) .WhereIF(input.RealName.IsNotNullAndWhiteSpace(), o => o.RealName == input.RealName) .WhereIF(input.Mobile.IsNotNullAndWhiteSpace(), o => o.Mobile == input.Mobile) .WhereIF(input.Email.IsNotNullAndWhiteSpace(), o => o.Email == input.Email) .WhereIF(input.Status.HasValue, o => o.Status == input.Status.Value) .ToPageListAsync(input.Page, input.PageSize, totalNumber); list = query.Key; totalNumber = query.Value; var result = new List <QueryUserDto>(); if (list != null && list.Count > 0) { list.ForEach(o => { var parent = _dbContext.Queryable <Organize>().First(it => it.KeyId == o.DeptId); result.Add(new QueryUserDto { DeptName = parent?.Name, KeyId = o.KeyId, Account = o.Account, CreateTime = o.CreateTime, DeptId = o.DeptId, Email = o.Email, HeadPic = o.HeadPic, Mobile = o.Mobile, NickName = o.NickName, RealName = o.RealName, Sex = o.Sex, Status = o.Status, UpLoginDate = o.UpLoginDate, StatusText = o.Status ? "启用" : "停用" }); }); } return(new BasePageQueryOutput <QueryUserDto> { Page = input.Page, Rows = result, Total = totalNumber }); }
/// <summary> /// 查询用户列表 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <QueryUsersOutput> QueryUsers(QueryUsersInput input) { var list = new List <QueryUserDTO>(); var result = new QueryUsersOutput { Data = new List <QueryUserDTO>() }; var totalNumber = 0; if (input.RoleId > 0) { var query = await _dbContext.Queryable <UserInfo, UserRoleInfo>((u, urole) => new object[] { JoinType.Inner, u.Id == urole.Uid }) .Where((u, urole) => urole.RoleId == input.RoleId) .WhereIF(input.State > -1, (u, urole) => u.State == input.State) .WhereIF(!input.RealName.IsEmpty(), (u, urole) => u.RealName == input.RealName) .WhereIF(!input.UserName.IsEmpty(), (u, urole) => u.UserName == input.UserName) .WhereIF(!input.Mobile.IsEmpty(), (u, urole) => u.Mobile == input.Mobile) .Select((u, urole) => new QueryUserDTO { Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email }) .ToPageListAsync(input.PageIndex, input.PageSize, totalNumber); list = query.Key; totalNumber = query.Value; } else if (!input.PlatformKey.IsEmpty()) { // 项目角色Id数组 var prlist = _dbContext.Queryable <RoleInfo>().Where(it => it.PlatformKey == input.PlatformKey && it.IsDel == false).Select(it => new { it.Id }).ToList(); var roleIdArr = prlist.Select(it => it.Id).ToArray(); // 查询 var query = await _dbContext.Queryable <UserInfo, UserRoleInfo>((u, urole) => new object[] { JoinType.Inner, u.Id == urole.Uid }) .Where((u, urole) => roleIdArr.Contains(urole.RoleId)) .WhereIF(input.State > -1, (u, urole) => u.State == input.State) .WhereIF(!input.RealName.IsEmpty(), (u, urole) => u.RealName == input.RealName) .WhereIF(!input.UserName.IsEmpty(), (u, urole) => u.UserName == input.UserName) .WhereIF(!input.Mobile.IsEmpty(), (u, urole) => u.Mobile == input.Mobile) .GroupBy((u, urole) => u.Id) .Select((u, urole) => new QueryUserDTO { Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email }) .ToPageListAsync(input.PageIndex, input.PageSize, totalNumber); list = query.Key; totalNumber = query.Value; } else { var query = await _dbContext.Queryable <UserInfo>() .WhereIF(input.State > -1, f => f.State == input.State) .WhereIF(!input.RealName.IsEmpty(), f => f.RealName == input.RealName) .WhereIF(!input.UserName.IsEmpty(), f => f.UserName == input.UserName) .WhereIF(!input.Mobile.IsEmpty(), f => f.Mobile == input.Mobile) .Select(u => new QueryUserDTO { Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email }) .ToPageListAsync(input.PageIndex, input.PageSize, totalNumber); list = query.Key; totalNumber = query.Value; } var canUseRoleList = await _roleBusiness.QueryRoles(new QueryRolesInput()); var canUseRole = canUseRoleList.Data as List <RoleInfo>; result.CurrentPage = input.PageIndex; result.Total = totalNumber; result.Data = list; result.Data.ForEach(m => { var useRole = _dbContext.Queryable <UserRoleInfo>() .Where(it => it.Uid == m.Id) .Select(it => new { Id = it.RoleId }) .ToList(); var idList = useRole.GroupBy(p => p.Id).Select(it => it.First().Id).ToList(); m.RoleList = canUseRole.Where(it => idList.Contains(it.Id)).Select(it => new { Id = it.Id, ProjectName = it.PlatformKey, Name = it.Name }).ToList(); }); return(result); }
public async Task <QueryUsersOutput> QueryUsers(QueryUsersInput input) { return(await _userBusiness.QueryUsers(input)); }
public BasePageOutput <List <QueryUserDto> > QueryUsers([FromQuery] QueryUsersInput input) { var userList = new List <QueryUserDto>(); var totalNumber = 0; if (input.RoleId > 0) { userList = _adminDbContext.Queryable <UserModel, UserRoleModel>((u, urole) => new object[] { JoinType.Inner, u.Id == urole.Uid }) .Where((u, urole) => urole.RoleId == input.RoleId) .WhereIF(input.State > -1, (u, urole) => u.State == input.State) .WhereIF(!input.RealName.IsEmpty(), (u, urole) => u.RealName == input.RealName) .WhereIF(!input.UserName.IsEmpty(), (u, urole) => u.UserName == input.UserName) .WhereIF(!input.Mobile.IsEmpty(), (u, urole) => u.Mobile == input.Mobile) .Select((u, urole) => new QueryUserDto { Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email }) .ToPageList(input.PageIndex, input.PageSize, ref totalNumber); } else if (!input.PlatformKey.IsEmpty()) { // 项目角色Id数组 var roleIdList = _adminDbContext.Queryable <RoleModel>().Where(it => it.PlatformKey == input.PlatformKey && it.IsDel == false).Select(it => it.Id).ToList(); // 查询 userList = _adminDbContext.Queryable <UserModel, UserRoleModel>((u, urole) => new object[] { JoinType.Inner, u.Id == urole.Uid }) .Where((u, urole) => roleIdList.Contains(urole.RoleId)) .WhereIF(input.State > -1, (u, urole) => u.State == input.State) .WhereIF(!input.RealName.IsEmpty(), (u, urole) => u.RealName == input.RealName) .WhereIF(!input.UserName.IsEmpty(), (u, urole) => u.UserName == input.UserName) .WhereIF(!input.Mobile.IsEmpty(), (u, urole) => u.Mobile == input.Mobile) .GroupBy((u, urole) => u.Id) .Select((u, urole) => new QueryUserDto { Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email }) .ToPageList(input.PageIndex, input.PageSize, ref totalNumber); } else { userList = _adminDbContext.Queryable <UserModel>() .WhereIF(input.State > -1, f => f.State == input.State) .WhereIF(!input.RealName.IsEmpty(), f => f.RealName == input.RealName) .WhereIF(!input.UserName.IsEmpty(), f => f.UserName == input.UserName) .WhereIF(!input.Mobile.IsEmpty(), f => f.Mobile == input.Mobile) .Select(u => new QueryUserDto { Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email }) .ToPageList(input.PageIndex, input.PageSize, ref totalNumber); } // 当前所有用户id var userIdList = userList.Select(it => it.Id); // 查询用户及对应角色列表 var userRoleList = _adminDbContext.Queryable <RoleModel, UserRoleModel>((role, urole) => new object[] { JoinType.Inner, role.Id == urole.RoleId }) .Where((role, urole) => userIdList.Contains(urole.Uid)) .Select((role, urole) => new { role.Id, role.Name, ProjectName = role.PlatformKey, urole.Uid }) .ToList(); // 组合用户对应角色 userList.ForEach(m => { m.RoleList = userRoleList.Where(it => it.Uid == m.Id); }); return(new BasePageOutput <List <QueryUserDto> > { Data = userList, CurrentPage = input.PageIndex, Total = totalNumber }); }
public async Task <BasePageQueryOutput <QueryUserDto> > GetPageListAsync([FromQuery] QueryUsersInput input) { return(await _business.GetPageList(input)); }