public virtual async Task <PagingResponseMessage <BuildingSearchResponse> > Search(string userId, BuildingListSearchCondition condition, CancellationToken cancellationToken = default(CancellationToken)) { if (condition == null) { throw new ArgumentNullException(nameof(condition)); } PagingResponseMessage <BuildingSearchResponse> pagingResponse = new PagingResponseMessage <BuildingSearchResponse>(); var q = _buildingsStore.GetSimpleSerchQuery().Where(a => !a.IsDeleted && a.ExamineStatus == (int)Models.ExamineStatusEnum.Approved); if (condition?.HasBank == true) { q = q.Where(a => a.BuildingFacilities.HasBank ?? true); } if (condition?.HasBus == true) { q = q.Where(a => a.BuildingFacilities.HasBus ?? true); } if (condition?.HasKindergarten == true) { q = q.Where(a => a.BuildingFacilities.HasKindergarten ?? true); } if (condition?.HasMarket == true) { q = q.Where(a => a.BuildingFacilities.HasMarket ?? true); } if (condition?.HasMiddleSchool == true) { q = q.Where(a => a.BuildingFacilities.HasMiddleSchool ?? true); } if (condition?.HasOtherTraffic == true) { q = q.Where(a => a.BuildingFacilities.HasOtherTraffic ?? true); } if (condition?.HasPrimarySchool == true) { q = q.Where(a => a.BuildingFacilities.HasPrimarySchool ?? true); } if (condition?.HasRail == true) { q = q.Where(a => a.BuildingFacilities.HasRail ?? true); } if (condition?.HasSupermarket == true) { q = q.Where(a => a.BuildingFacilities.HasSupermarket ?? true); } if (condition?.HasUniversity == true) { q = q.Where(a => a.BuildingFacilities.HasUniversity ?? true); } if (!string.IsNullOrEmpty(condition.KeyWord)) { q = q.Where(a => a.BuildingBaseInfo.Name.Contains(condition.KeyWord)); } if (!string.IsNullOrEmpty(condition.City)) { q = q.Where(a => a.BuildingBaseInfo.City == condition.City); } if (!string.IsNullOrEmpty(condition.Area)) { q = q.Where(a => a.BuildingBaseInfo.Area == condition.Area); } if (!string.IsNullOrEmpty(condition.District)) { q = q.Where(a => a.BuildingBaseInfo.District == condition.District); } if (condition?.LowPrice != null && condition?.HighPrice != null) { q = q.Where(a => a.BuildingBaseInfo.MaxPrice > condition.LowPrice && a.BuildingBaseInfo.MinPrice < condition.HighPrice); //if (condition?.HighPrice != null) //{ // q = q.Where(a => a.BuildingBaseInfo.MaxPrice < condition.HighPrice &&); //} //else if (condition?.LowPrice != null) //{ // q = q.Where(a => a.BuildingBaseInfo.MinPrice > condition.LowPrice); //} //else //{ // q = q.Where(a => a.BuildingBaseInfo.MinPrice > condition.LowPrice && a.BuildingBaseInfo.MaxPrice > condition.LowPrice || a.BuildingBaseInfo.MaxPrice < condition.HighPrice); //} } else if (condition?.LowPrice != null && condition?.HighPrice == null) { q = q.Where(a => a.BuildingBaseInfo.MinPrice > condition.LowPrice); } //if (condition?.HighPrice != null) //{ // q = q.Where(a => a.BuildingBaseInfo.MaxPrice < condition.HighPrice); //} if (condition?.SaleStatus?.Count > 0) { q = q.Where(a => condition.SaleStatus.Contains(a.BuildingShopInfo.SaleStatus)); } if (condition?.PriceIsAscSort == null) { q = q.OrderBy(a => a.BuildingBaseInfo.OpenDate); } if (condition?.PriceIsAscSort == true) { q = q.OrderBy(a => (a.BuildingBaseInfo.MinPrice ?? 0 + a.BuildingBaseInfo.MinPrice ?? 0) / (decimal)2); } if (condition?.PriceIsAscSort == false) { q = q.OrderByDescending(a => (a.BuildingBaseInfo.MinPrice ?? 0 + a.BuildingBaseInfo.MinPrice ?? 0) / (decimal)2); } if (condition.IsReport) { q = q.Where(a => a.BuildingRule != null && (a.BuildingRule.ReportTime == null || a.BuildingRule.ReportTime != null && a.BuildingRule.ReportTime < DateTime.Now.AddDays(5)) /* && a.BuildingRule.IsUse*/); } string fr = ApplicationCore.ApplicationContext.Current.FileServerRoot; fr = (fr ?? "").TrimEnd('/'); pagingResponse.TotalCount = await q.CountAsync(cancellationToken); var qlist = await q.Skip(condition.PageIndex *condition.PageSize).Take(condition.PageSize).ToListAsync(cancellationToken); var resulte = qlist.Select(a => new BuildingSearchResponse { Id = a.Id, Address = a.BuildingBaseInfo.Address, AreaFullName = a.BuildingBaseInfo.CityDefine.Name + "-" + a.BuildingBaseInfo.DistrictDefine.Name + "-" + a.BuildingBaseInfo.AreaDefine.Name, MaxPrice = a.BuildingBaseInfo.MaxPrice, MinPrice = a.BuildingBaseInfo.MinPrice, Name = a.BuildingBaseInfo.Name, Icon = string.IsNullOrEmpty(a.Icon) ? "" : fr + "/" + a.Icon.TrimStart('/'), HasBus = a.BuildingFacilities.HasBus, HasRail = a.BuildingFacilities.HasRail, HasOtherTraffic = a.BuildingFacilities.HasOtherTraffic, HasKindergarten = a.BuildingFacilities.HasKindergarten, HasPrimarySchool = a.BuildingFacilities.HasPrimarySchool, HasMiddleSchool = a.BuildingFacilities.HasMiddleSchool, HasUniversity = a.BuildingFacilities.HasUniversity, HasMarket = a.BuildingFacilities.HasMarket, HasSupermarket = a.BuildingFacilities.HasSupermarket, HasBank = a.BuildingFacilities.HasBank, BeltLook = a.BuildingRule?.ReportTime }); pagingResponse.PageIndex = condition.PageIndex; pagingResponse.PageSize = condition.PageSize; pagingResponse.Extension = resulte.ToList(); return(pagingResponse); }
public async Task <PagingResponseMessage <BuildingSearchResponse> > GetBuildingList(UserInfo user, [FromBody] BuildingListSearchCondition condition) { PagingResponseMessage <BuildingSearchResponse> pagingResponse = new PagingResponseMessage <BuildingSearchResponse>(); if (!ModelState.IsValid) { pagingResponse.Code = ResponseCodeDefines.ModelStateInvalid; pagingResponse.Message = ModelState.GetAllErrors(); Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})获取楼盘列表(GetBuildingList)模型验证失败:\r\n{pagingResponse.Message ?? ""},\r\n请求参数为:\r\n" + (condition != null ? JsonHelper.ToJson(condition) : "")); return(pagingResponse); } try { return(await _buildingsManager.Search(user.Id, condition, HttpContext.RequestAborted)); } catch (Exception e) { pagingResponse.Code = ResponseCodeDefines.ServiceError; pagingResponse.Message = e.ToString(); Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})获取楼盘列表(GetBuildingList)报错:{e.ToString()},\r\n请求参数为:\r\n" + (condition != null ? JsonHelper.ToJson(condition) : "")); } return(pagingResponse); }