Example #1
0
        public virtual async Task <PagingResponseMessage <ShopListSearchResponse> > SearchRecommend(string userId, ShopListSearchCondition condition, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }
            PagingResponseMessage <ShopListSearchResponse> pagingResponse = new PagingResponseMessage <ShopListSearchResponse>();

            var q = _shopsStore.GetDetailQuery().Where(a => !a.IsDeleted && a.ExamineStatus == (int)Models.ExamineStatusEnum.Approved);

            if (condition?.BuildingIds?.Count > 0)
            {
                q = q.Where(a => condition.BuildingIds.Contains(a.BuildingId));
            }

            if (!string.IsNullOrEmpty(condition?.CustomerId))
            {
                var shopsid = (await _shopsStore.ListNotShopsAsync(x => x.Where(y => y.CustomerId == condition.CustomerId))).Select(x => x.ShopsId);
                q = q.Where(a => !shopsid.Contains(a.Id));
            }
            if (condition?.SaleStatus?.Count > 0)
            {
                q = q.Where(a => condition.SaleStatus.Contains(a.ShopBaseInfo.SaleStatus));
            }
            if (condition?.UpperWater == true)
            {
                q = q.Where(a => a.ShopFacilities.UpperWater ?? true);
            }
            if (condition?.DownWater == true)
            {
                q = q.Where(a => a.ShopFacilities.DownWater ?? true);
            }
            if (condition?.Gas == true)
            {
                q = q.Where(a => a.ShopFacilities.Gas ?? true);
            }
            if (condition?.Chimney == true)
            {
                q = q.Where(a => a.ShopFacilities.Chimney ?? true);
            }
            if (condition?.Blowoff == true)
            {
                q = q.Where(a => a.ShopFacilities.Blowoff ?? true);
            }
            if (condition?.Split == true)
            {
                q = q.Where(a => a.ShopFacilities.Split ?? true);
            }
            if (condition?.Elevator == true)
            {
                q = q.Where(a => a.ShopFacilities.Elevator ?? true);
            }
            if (condition?.Staircase == true)
            {
                q = q.Where(a => a.ShopFacilities.Staircase ?? true);
            }
            if (condition?.Outside == true)
            {
                q = q.Where(a => a.ShopFacilities.Outside ?? true);
            }
            if (condition?.OpenFloor == true)
            {
                q = q.Where(a => a.ShopFacilities.OpenFloor ?? true);
            }
            if (condition?.ParkingSpace == true)
            {
                q = q.Where(a => a.ShopFacilities.ParkingSpace ?? true);
            }
            if (condition?.IsCorner == true)
            {
                q = q.Where(a => a.ShopBaseInfo.IsCorner ?? true);
            }
            if (condition?.IsFaceStreet == true)
            {
                q = q.Where(a => a.ShopBaseInfo.IsFaceStreet ?? true);
            }
            if (condition?.HasFree == true)
            {
                q = q.Where(a => a.ShopBaseInfo.HasFree ?? true);
            }
            if (condition?.HasStreet == true)
            {
                q = q.Where(a => a.ShopBaseInfo.HasStreet ?? true);
            }
            if (!string.IsNullOrEmpty(condition.KeyWord))
            {
                q = q.Where(a => a.ShopBaseInfo.Name.Contains(condition.KeyWord));
            }
            if (!string.IsNullOrEmpty(condition.City))
            {
                q = q.Where(a => a.Buildings.BuildingBaseInfo.City == condition.City);
            }
            if (!string.IsNullOrEmpty(condition.Area))
            {
                q = q.Where(a => a.Buildings.BuildingBaseInfo.Area == condition.Area);
            }
            if (!string.IsNullOrEmpty(condition.District))
            {
                q = q.Where(a => a.Buildings.BuildingBaseInfo.District == condition.District);
            }
            if (condition?.LowArea != null)
            {
                q = q.Where(a => a.ShopBaseInfo.BuildingArea >= condition.LowArea);
            }
            if (condition?.HighArea != null)
            {
                q = q.Where(a => a.ShopBaseInfo.BuildingArea <= condition.HighArea);
            }
            if (condition?.LowPrice != null)
            {
                q = q.Where(a => a.ShopBaseInfo.TotalPrice >= condition.LowPrice);
            }
            if (condition?.HighPrice != null)
            {
                q = q.Where(a => a.ShopBaseInfo.TotalPrice <= condition.HighPrice);
            }
            if (condition?.PriceIsAscSort == null && condition?.AreaIsAscSort == null)
            {
                q = q.OrderBy(a => a.ShopLeaseInfo.StartDate);
            }
            if (condition?.PriceIsAscSort == true)
            {
                q = q.OrderBy(a => (a.ShopBaseInfo.Price ?? 0));
            }
            if (condition?.PriceIsAscSort == false)
            {
                q = q.OrderByDescending(a => (a.ShopBaseInfo.Price ?? 0));
            }
            if (condition?.AreaIsAscSort == true)
            {
                q = q.OrderBy(a => (a.ShopBaseInfo.BuildingArea ?? 0));
            }
            if (condition?.AreaIsAscSort == false)
            {
                q = q.OrderByDescending(a => (a.ShopBaseInfo.BuildingArea ?? 0));
            }
            if (condition?.MinPrice != null)
            {
                q = q.Where(a => (a.ShopBaseInfo.TotalPrice >= condition.MinPrice));
            }
            if (condition?.MaxPrice != null)
            {
                q = q.Where(a => (a.ShopBaseInfo.TotalPrice <= condition.MaxPrice));
            }
            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 ShopListSearchResponse
            {
                Id           = a.Id,
                BuildingId   = a.BuildingId,
                BuildingName = a.Buildings.BuildingBaseInfo.Name,
                Address      = a.Buildings.BuildingBaseInfo.Address,
                AreaFullName = a.Buildings.BuildingBaseInfo.CityDefine.Name + "-" + a.Buildings.BuildingBaseInfo.DistrictDefine.Name + "-" + a.Buildings.BuildingBaseInfo.AreaDefine.Name,
                Price        = a.ShopBaseInfo.Price,
                Name         = a.ShopBaseInfo.Name,
                Depth        = a.ShopBaseInfo.Depth,
                Height       = a.ShopBaseInfo.Height,
                Width        = a.ShopBaseInfo.Width,
                BuildingArea = a.ShopBaseInfo.BuildingArea,
                BuildingNo   = a.ShopBaseInfo.BuildingNo,
                FloorNo      = a.ShopBaseInfo.FloorNo,
                Number       = a.ShopBaseInfo.Number,
                SaleStatus   = a.ShopBaseInfo.SaleStatus,
                Status       = a.ShopBaseInfo.Status,
                Icon         = string.IsNullOrEmpty(a.Icon) ? "" : fr + "/" + a.Icon.TrimStart('/'),
                UpperWater   = a.ShopFacilities.UpperWater,
                DownWater    = a.ShopFacilities.DownWater,
                Gas          = a.ShopFacilities.Gas,
                Chimney      = a.ShopFacilities.Chimney,
                Blowoff      = a.ShopFacilities.Blowoff,
                Split        = a.ShopFacilities.Split,
                Elevator     = a.ShopFacilities.Elevator,
                Staircase    = a.ShopFacilities.Staircase,
                Outside      = a.ShopFacilities.Outside,
                OpenFloor    = a.ShopFacilities.OpenFloor,
                ParkingSpace = a.ShopFacilities.ParkingSpace,
                IsCorner     = a.ShopBaseInfo.IsCorner,
                IsFaceStreet = a.ShopBaseInfo.IsFaceStreet,
                HasFree      = a.ShopBaseInfo.HasFree,
                HasStreet    = a.ShopBaseInfo.HasStreet,
                IsHot        = a.ShopBaseInfo.IsHot,
                TotalPrice   = a.ShopBaseInfo.TotalPrice,
                LockTime     = a.ShopBaseInfo.LockTime
            });


            if (condition.SequencingConditions != null)
            {
                foreach (var item in condition.SequencingConditions)
                {
                    if (item.Name == "BuildingNo")
                    {
                        resulte = item.Value ? resulte.OrderBy(x => x.BuildingNo).ToList() : resulte.OrderByDescending(x => x.BuildingNo).ToList();
                    }
                    else if (item.Name == "Number")
                    {
                        resulte = item.Value ? resulte.OrderBy(x => x.Number).ToList() : resulte.OrderByDescending(x => x.Number).ToList();
                    }
                }
            }

            pagingResponse.PageIndex = condition.PageIndex;
            pagingResponse.PageSize  = condition.PageSize;
            pagingResponse.Extension = resulte.ToList();
            return(pagingResponse);
        }
        public async Task <PagingResponseMessage <ShopListSearchResponse> > Search(UserInfo user, [FromBody] ShopListSearchCondition condition)
        {
            PagingResponseMessage <ShopListSearchResponse> response = new PagingResponseMessage <ShopListSearchResponse>();

            if (!ModelState.IsValid)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = ModelState.GetAllErrors();
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})查询商铺列表(Search)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (condition != null ? JsonHelper.ToJson(condition) : ""));
                return(response);
            }
            try
            {
                response = await _shopsManager.Search(user.Id, condition);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})查询商铺列表(Search)请求失败:\r\n{e.ToString()},\r\n请求参数为:\r\n" + (condition != null ? JsonHelper.ToJson(condition) : ""));
            }
            return(response);
        }