Example #1
0
        public Core.Data.QueryResult <CRestaurantDTO> GetRestaurantDTOByCondition(List <string> resUUID, string name, string address, string cityId, decimal?longitude, decimal?latitude, string alphabet, int startIndex, int count, bool containOutRange, List <int> state
                                                                                  , string loginName, string password)
        {
            IPredicate predicate = this.GetRestaurantsCondition(resUUID, name, address, cityId, alphabet, state, loginName, password);

            Core.Data.QueryResult <CRestaurantPO> resultRest = CRestaurantPOManager.Instance.GetRestaurantWithTotalCountByPredicate(predicate, startIndex, count, null);
            if (longitude.HasValue && latitude.HasValue)
            {
                //resultRest = CRestaurantPOManager.Instance.GetRestaurantWithTotalCountByPredicate(predicate, startIndex, (int)resultRest.TotalCount, null);
                List <CRestaurantDTO> listCrest = GetCRestaurantList(resUUID, name, address, cityId, alphabet, state);
                resultRest.TotalCount = listCrest.Count;
                resultRest.Items      = DtoToPoList(listCrest).ToArray();
            }

            Core.Data.QueryResult <CRestaurantDTO> resultRestDto = new Core.Data.QueryResult <CRestaurantDTO>();
            resultRestDto.TotalCount = resultRest.TotalCount;

            List <CRestaurantDTO> listRestaurant = new List <CRestaurantDTO>();

            if (longitude.HasValue && latitude.HasValue && resultRest.Items != null && resultRest.Items.Length > 0)
            {
                CoordinateTool AppCoordinateTool = new CoordinateTool((double)longitude.Value, (double)latitude.Value);
                foreach (var item in resultRest.Items)
                {
                    CRestaurantDTO cRestDto = PoToDto(item);
                    if (item == null)
                    {
                        continue;
                    }
                    CoordinateTool restCoordinateTool = new CoordinateTool((double)item.Longitude, (double)item.Latitude);
                    cRestDto.DouDistance = (decimal)restCoordinateTool.Distance(AppCoordinateTool);
                    listRestaurant.Add(cRestDto);
                }
            }
            else if (resultRest.Items != null && resultRest.Items.Length > 0)
            {
                listRestaurant = PoToDtoList(resultRest.Items.ToList()).ToList();
            }
            if (containOutRange == false)
            {
                //改为多边形坐标序列 开始
                //listRestaurant = listRestaurant.Where(x => x.AllowedDistance >= x.DouDistance).ToList();
                List <CRestaurantDTO> listRestaurantNew = new List <CRestaurantDTO>();
                listRestaurant.ForEach(x =>
                {
                    List <CResCoordinatePO> listResCoordinate = CResCoordinateManager.Instance.GetCResCoordinateList(null, x.ResUUID, null, null, null);
                    if (Contains(listResCoordinate, latitude, longitude) == true)
                    {
                        listRestaurantNew.Add(x);
                    }
                });
                listRestaurant = listRestaurantNew;
                //改为多边形坐标序列 结束
                resultRestDto.TotalCount = listRestaurant.Count;
                listRestaurant           = (from res in listRestaurant orderby res.DouDistance ascending, res.Id ascending select res).Skip(startIndex - 1).Take(count).ToList();
            }

            listRestaurant      = listRestaurant.OrderBy(x => x.DouDistance).ToList();
            resultRestDto.Items = listRestaurant.ToArray();

            return(resultRestDto);
        }
 public double Distance(CoordinateTool coordinateTool)
 {
     return(GetDistance(this.Latitude, this.Longitude, coordinateTool.Latitude, coordinateTool.Longitude));
 }