/// <summary> /// https://github.com/2881099/FreeSql/wiki/%e8%bf%94%e5%9b%9e%e6%9f%a5%e8%af%a2%e7%9a%84%e6%95%b0%e6%8d%ae 返回更为复杂的结构 /// </summary> /// <param name="searchDto"></param> /// <returns></returns> public PagedResultDto <UserDto> GetUserList(UserSearchDto searchDto) { ISelect <LinUser> select = _userRepository.Select .Where(r => r.Admin == (int)UserAdmin.Common) .WhereIf(searchDto.GroupId != null, r => r.GroupId == searchDto.GroupId); List <UserDto> linUsers = select .OrderByDescending(r => r.Id) .From <LinGroup>((a, b) => a.LeftJoin(c => c.GroupId == b.Id) ) .Page(searchDto.Page + 1, searchDto.Count) .ToList((a, b) => new { user = a, GroupName = b.Name }).Select(r => { UserDto userDto = _mapper.Map <UserDto>(r.user); userDto.GroupName = r.GroupName; return(userDto); }).ToList(); long totalNums = select.Count(); return(new PagedResultDto <UserDto>(linUsers, totalNums)); }
/// <summary> /// 用户列表 /// </summary> /// <typeparam name="UserListModel">用户列表实体</typeparam> /// <param name="searchDto">用户列表查询实体</param> /// <returns></returns> public PageDataView <UserListDto> GetList(UserSearchDto searchDto) { PageDataView <UserListDto> result = new PageDataView <UserListDto>() { }; StringBuilder select = new StringBuilder(); StringBuilder where = new StringBuilder(); DynamicParameters parameters = new DynamicParameters(); select.Append("SELECT * FROM [User] "); where.Append("WHERE 1=1 "); if (!string.IsNullOrEmpty(searchDto.DomainAccount)) { where.Append($"AND DomainAccount LIKE @DomainAccount "); parameters.Add("@DomainAccount", "%" + searchDto.DomainAccount + "%"); } if (!string.IsNullOrEmpty(searchDto.RealName)) { where.Append($"AND RealName LIKE @RealName "); parameters.Add("@RealName", "%" + searchDto.RealName + "%"); } Dictionary <string, bool> ordery = new Dictionary <string, bool>(); ordery.Add("createdAt", false); result = _unitOfWork.GetPageData <UserListDto>(select.ToString() + where.ToString(), ordery, searchDto.PageIndex, searchDto.PageSize, parameters); return(result); }
public async Task <ActionResult> GetUserList([FromBody] UserSearchDto userSearchDto) { List <User> users = new List <User>(); if (userSearchDto.OrganizationId != null) { users = await _context.Users.Where(u => u.OrganizationId == userSearchDto.OrganizationId).ToListAsync(); } else if (userSearchDto.FacilityId != null) { users = await _context.Users.Where(u => u.FacilityId == userSearchDto.FacilityId).ToListAsync(); } else if (userSearchDto.DepartmentId != null) { users = await _context.Users.Where(u => u.DepartmentId == userSearchDto.DepartmentId).ToListAsync(); } else if (userSearchDto.StoreId != null) { users = await _context.Users.Where(u => u.StoreId == userSearchDto.StoreId).ToListAsync(); } else { users = await _context.Users.Where(u => u.OrganizationId == null).ToListAsync(); } return(Ok(users)); }
public async Task <ISearchResponse <User> > SearchAsync(UserSearchDto searchDto) { var descriptor = new SearchDescriptor <User>() .Index("user") .Query(x => BuildQuery(searchDto)) .From(0) .Take(100); if (!String.IsNullOrWhiteSpace(searchDto.Query)) { descriptor = descriptor .MinScore(0.15) .TrackScores(); } else { descriptor = descriptor.Sort(s => s.Descending(x => x.SortableName) ); } descriptor = descriptor.WriteToLog(); return(await SearchClient.SearchAsync <User>(descriptor)); }
public PaginationDto <UserDto> GetUsers(UserSearchDto searchDto) { var query = _context.Users.AsQueryable(); if (!string.IsNullOrEmpty(searchDto.FullName)) { query = query.Where(c => c.FullName.Contains(searchDto.FullName)); } if (!string.IsNullOrEmpty(searchDto.PhoneNumber)) { query = query.Where(c => c.PhoneNumber.Contains(searchDto.PhoneNumber)); } if (searchDto.IsFemale && !searchDto.IsMan) { query = query.Where(c => c.Gender == GenderType.Female); } if (!searchDto.IsFemale && searchDto.IsMan) { query = query.Where(c => c.Gender == GenderType.Man); } IOrderedQueryable <User> queryOrderd = null; if (searchDto.OrderType == OrderType.Ascending) { if (searchDto.SearchType == UserSearchType.FullName) { queryOrderd = query.OrderBy(c => c.FullName); } else { queryOrderd = query.OrderBy(c => c.RegisterDate); } } else { if (searchDto.SearchType == UserSearchType.FullName) { queryOrderd = query.OrderByDescending(c => c.FullName); } else { queryOrderd = query.OrderByDescending(c => c.RegisterDate); } } var users = queryOrderd.ToPaginated(searchDto.PageNumber, searchDto.PageSize); return(users.ToDto()); }
public static UserSearchDto ToUserSearchDto(UserListSearchRequest request) { var dto = new UserSearchDto { Account = request.Account?.Trim(), Name = request.Name?.Trim(), Limit = request.Limit, Page = request.Page }; return(dto); }
public PagedResultDto <UserDto> GetUserListByGroupId(UserSearchDto searchDto) { List <UserDto> linUsers = _userRepository.Select .IncludeMany(r => r.LinGroups) .WhereIf(searchDto.GroupId != null, r => r.LinUserGroups.AsSelect().Any(u => u.GroupId == searchDto.GroupId)) .OrderByDescending(r => r.Id) .ToPagerList(searchDto, out long totalCount) .Select(r => { UserDto userDto = Mapper.Map <UserDto>(r); userDto.Groups = Mapper.Map <List <GroupDto> >(r.LinGroups); return(userDto); }).ToList(); return(new PagedResultDto <UserDto>(linUsers, totalCount)); }
public async Task <PageModelDto <UserDto> > GetPaged(UserSearchDto searchDto) { Expression <Func <SysUser, bool> > whereCondition = x => true; if (searchDto.Account.IsNotNullOrWhiteSpace()) { whereCondition = whereCondition.And(x => x.Account.Contains(searchDto.Account)); } if (searchDto.Name.IsNotNullOrWhiteSpace()) { whereCondition = whereCondition.And(x => x.Name.Contains(searchDto.Name)); } var pagedModel = await _userRepository.PagedAsync(searchDto.PageIndex, searchDto.PageSize, whereCondition, x => x.ID, false); var result = _mapper.Map <PageModelDto <UserDto> >(pagedModel); result.XData = await _deptAppService.GetSimpleList(); if (result.Count > 0) { var deptIds = result.Data.Where(d => d.DeptId != null).Select(d => d.DeptId).Distinct().ToList(); //var depts = await _deptRepository.SelectAsync(d => new { d.ID, d.FullName }, x => deptIds.Contains(x.ID)); var depts = (await _deptAppService.GetAllFromCache()) .Where(x => deptIds.Contains(x.ID)) .Select(d => new { d.ID, d.FullName }); //var roles = await _roleRepository.SelectAsync(r => new { r.ID, r.Name }, x => true); var roles = (await _roleAppService.GetAllFromCache()) .Select(r => new { r.ID, r.Name }); foreach (var user in result.Data) { user.DeptName = depts.FirstOrDefault(x => x.ID == user.DeptId)?.FullName; var roleIds = string.IsNullOrWhiteSpace(user.RoleId) ? new List <long>() : user.RoleId.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)) ; user.RoleName = string.Join(',', roles.Where(x => roleIds.Contains(x.ID)).Select(x => x.Name)); } } return(result); }
public async Task <PagedModel <AccountProfileDto> > GetPagedList(UserSearchDto criteria) { // 排除"应用系统"用户 Expression <Func <SysUser, bool> > condition = it => it.Id > 0; if (!string.IsNullOrWhiteSpace(criteria.Account)) { condition = condition.And(it => it.Account.Contains(criteria.Account)); } if (!string.IsNullOrWhiteSpace(criteria.Name)) { condition = condition.And(it => it.Name.Contains(criteria.Name)); } var result = await _unitOfWork.UserRepository.PagedAsync( criteria.Page, criteria.Limit, condition, it => it.Id, true); var dto = UserMapper.ToAccountProfileDto(result); if (dto.Count <= 0) { return(dto); } foreach (var item in dto.Data) { var dept = await _deptService.GetById(item.Deptid); var roleIds = SplitId(item.Roleid); var roles = await _roleService.GetListByIds(roleIds); // mapping item.Dept = dept?.Fullname; item.DeptName = dept?.Simplename; item.RoleName = string.Join(',', roles.Select(it => it.Name)); } return(dto); }
public List <User> Search(UserSearchDto dto) { var dataSource = DataDbContext.Set <User>().AsQueryable(); if (!string.IsNullOrEmpty(dto.Keywords)) { dataSource = dataSource.Where(m => (m.RealName != null && m.RealName.Contains(dto.Keywords)) || (m.NickName != null && m.NickName.Contains(dto.Keywords)) || (m.MobilePhoneNumber != null && m.MobilePhoneNumber.Contains(dto.Keywords))); } dataSource = dataSource.WhereDateTime(nameof(Customer.CreatorTime), dto.StartCreatorTime, dto.EndCreatorTime); dataSource = dataSource.OrderByDescending(m => m.LastModifyTime); if (dto.IsGetTotalCount) { dto.TotalCount = dataSource.Count(); } return(dataSource.Skip(dto.StartIndex).Take(dto.PageSize).ToList()); }
public async Task <ActionResult <PageModelDto <UserDto> > > GetPaged([FromQuery] UserSearchDto searchModel) { return(Result(await _userService.GetPaged(searchModel))); }
public PagedResultDto <UserDto> GetUserListByGroupId([FromQuery] UserSearchDto searchDto) { return(_userSevice.GetUserListByGroupId(searchDto)); }
public IActionResult Get([FromQuery] UserSearchDto search) { return(Ok()); }
/// <summary> /// This is required to perform the initial base query. This should /// be a relatively simple search since most filters will be applied /// using the post filter. /// </summary> protected virtual QueryContainer BuildQuery(UserSearchDto searchDto) { #region Term query var userQuery = (QueryContainer)null; if (searchDto.UserId.HasValue) { userQuery = Query <User> .Term(t => t.Field(f => f.Id).Value(searchDto.UserId.Value)); } #endregion #region Freetext query var freeTextQuery = (QueryContainer)null; if (!String.IsNullOrWhiteSpace(searchDto.Query)) { freeTextQuery = new BoolQuery { Should = new[] { Query <User> .Prefix(x => x .Value(searchDto.Query) .Field(f => f.DisplayName) .Boost(10) ), Query <User> .Fuzzy(x => x .Value(searchDto.Query) .Field(f => f.DisplayName) .Boost(5) .Fuzziness(Fuzziness.Auto) .MaxExpansions(30) ), Query <User> .QueryString(q => q .Query(searchDto.Query) .Boost(3) .Fields(fs => fs.Field(f => f.Description)) ), Query <User> .QueryString(q => q .Query(searchDto.Query) .Fields(fs => fs .Field(f => f.FullAddress) .Field(f => f.Country) ) ) } }; } #endregion #region Numeric range query var followerMinimumQuery = (QueryContainer)null; if (searchDto.FollowerMinimum.HasValue) { followerMinimumQuery = Query <User> .Nested(n => n .Path(p => p.SocialChannels) .Query(q => q .Exists(r => r.Field("socialChannels.followers")) & q .Range(r => r .Field("socialChannels.followers") .GreaterThanOrEquals(searchDto.FollowerMinimum.Value) ) )); } #endregion #region Distance query var locationQuery = (QueryContainer)null; if (searchDto.Latitude.HasValue && searchDto.Longitude.HasValue && searchDto.Distance.HasValue) { locationQuery = Query <User> .GeoDistance(g => g .Field(x => x.GeoPoint) .Location(searchDto.Latitude.Value, searchDto.Longitude.Value) .Distance(Distance.Kilometers(searchDto.Distance.Value)) ); } #endregion return(new BoolQuery { Must = new[] { userQuery, freeTextQuery, followerMinimumQuery, locationQuery } }); }
public JsonResult GetList(UserSearchDto userSearch) { var result = _IUserService.GetUserPageList(userSearch); return(Json(result)); }