private FavoriteCollectionResponse Get(float version, int userId, PagerRequest pagerRequest, CoordinateInfo coordinate, FavoriteSortOrder sortOrder, SourceType sourceType)
        {
           
                  FavoriteCollectionResponse response;
                  int totalCount;
                  if (version >= 2.1)
                  {
                      var entitys = _favoriteRepository.Get(userId, pagerRequest, out totalCount, sortOrder, sourceType);

                      var list = MappingManager.FavoriteCollectionResponseMapping(entitys, coordinate);

                      response = new FavoriteCollectionResponse(pagerRequest, totalCount) { Favorites = list };
                  }
                  else
                  {
                      var entitys = _favoriteRepository.GetPagedList(userId, pagerRequest, out totalCount, sortOrder, sourceType);

                      response = MappingManager.FavoriteCollectionResponseMapping(entitys, coordinate);
                      response.Index = pagerRequest.PageIndex;
                      response.Size = pagerRequest.PageSize;
                      response.TotalCount = totalCount;
                  }

                  return response;
        }
        /// <summary>
        /// 获取收藏列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private ExecuteResult<FavoriteCollectionResponse> GetFavoriteList(FavoriteListRequest request)
        {
            var pagerRequest = new PagerRequest(request.Page, request.PageSize);

            CoordinateInfo coordinate = null;
            if (request.Lng > 0 || request.Lng < 0)
            {
                coordinate = new CoordinateInfo(request.Lng, request.Lat);
            }

            var response = Get(request.Version, request.UserModel.Id, pagerRequest, coordinate,
                                                      request.SortOrder, request.SType);

            return new ExecuteResult<FavoriteCollectionResponse>(response);
        }
        /// <summary>
        ///  已知A点 和距离差,求 B点经度
        /// </summary>
        /// <param name="coordinate1">经纬度 A</param>
        /// <param name="km">距离</param>
        /// <returns></returns>
        public static CoordinateInfo GetLngDistance(CoordinateInfo coordinate1, double km)
        {
            if (coordinate1 == null)
            {
                return null;
            }

            //纬度90度
            if (coordinate1.Latitude > 90 || coordinate1.Latitude < 90)
            {
                var lng2 = coordinate1.Longitude * 100000 - km * 1000 / Math.Cos(coordinate1.Latitude);

                return new CoordinateInfo(lng2 / 100000, coordinate1.Latitude);
            }

            return new CoordinateInfo(0, coordinate1.Latitude);
        }
Example #4
0
        public StoreInfoResponse StoreResponseMapping(StoreEntity source, CoordinateInfo coordinateInfo)
        {
            if (coordinateInfo == null)
            {
                return StoreResponseMapping(source);
            }

            var target = Mapper.Map<StoreEntity, StoreInfoResponse>(source);

            target.Distance = Distance(coordinateInfo, new CoordinateInfo((double)target.Longitude, (double)target.Latitude));

            return target;
        }
Example #5
0
        public IEnumerable<ItemsInfoResponse> ItemsInfoResponseMapping(IQueryable<ProductEntity> productEntities,
                                                                        IQueryable<PromotionEntity> promotionEntities, CoordinateInfo coordinateInfo, bool? hasBanner)
        {
            if (productEntities == null && promotionEntities == null)
            {
                return new List<ItemsInfoResponse>(0);
            }

            var linqProResponse = PromotionResponseMapping(promotionEntities, coordinateInfo, hasBanner).ToList();
            var linqProdResponse = ProductInfoResponseMapping(productEntities).ToList();


            var result = new List<ItemsInfoResponse>();

            if (productEntities != null)
            {
                foreach (var item in linqProdResponse)
                {
                    var target = ItemsInfoResponseMapping(item);
                    result.Add(target);
                }
            }

            if (promotionEntities != null)
            {
                foreach (var item in linqProResponse)
                {
                    var target = ItemsInfoResponseMapping(item);

                    result.Add(target);
                }
            }

            //排序
            return result;
        }
Example #6
0
        public FavoriteCollectionResponse FavoriteCollectionResponseMapping(List<FavoriteEntity> source,
                                                                                   CoordinateInfo coordinateInfo)
        {
            if (source == null || source.Count == 0)
            {
                return new FavoriteCollectionResponse(new PagerRequest(1, 1)) { Favorites = new List<FavoriteInfoResponse>(0) };
            }

            //var storeids = source.Select(v => v.Store_Id).Distinct().Where(v => v != 0);
            //var dic = new Dictionary<int, List<int>>();
            var ms = source.Where(v => v.FavoriteSourceType == (int)SourceType.Promotion).Select(s => s.FavoriteSourceId).Distinct().ToList();
            var ps = source.Where(v => v.FavoriteSourceType == (int)SourceType.Product).Select(s => s.FavoriteSourceId).Distinct().ToList();

            //var stores = StoreResponseMapping(_storeRepository.GetListByIds(storeids.ToList()), coordinateInfo).ToList();
            var promotions = _promotionRepository.GetList(ms);
            var products = _productRepository.GetList(ps);

            var items = ItemsInfoResponseMapping(products, promotions).ToList();

            var t = new List<FavoriteInfoResponse>(items.Count);
            foreach (var i in items)
            {
                var a = Mapper.Map<ItemsInfoResponse, FavoriteInfoResponse>(i);
                a.FavoriteSourceId = i.Id;
                a.FavoriteSourceName = i.Name;
                a.FavoriteSourceType = i.SourceType;
                var r = source.FirstOrDefault(v => v.FavoriteSourceId == i.Id && v.FavoriteSourceType == i.SourceType);

                a.Id = r == null ? 0 : r.Id;
                a.StoreId = i.Store_Id;
                t.Add(a);
            }


            //TODO: 产品这个需要优化
            var result = new FavoriteCollectionResponse(new PagerRequest(1, source.Count), source.Count)
            {
                Favorites = t
            };

            return result;

            ////pp rs

            //var productResource = ResourceInfoResponsesMapping(GetListResourceEntities(SourceType.Product, ps)).ToList();
            //var msresource = ResourceInfoResponsesMapping(GetListResourceEntities(SourceType.Promotion, ms)).ToList();

            ////TODO: 产品这个需要优化
            //var result = new FavoriteCollectionResponse(new PagerRequest(1, source.Count), source.Count)
            //{
            //    Favorites = new List<FavoriteInfoResponse>(source.Count)
            //};
            //foreach (var s in source)
            //{
            //    //var n = String.Empty;
            //    FavoriteInfoResponse response = null;
            //    switch (s.FavoriteSourceType)
            //    {
            //        case (int)SourceType.Promotion:
            //            var p = promotions.FirstOrDefault(v => v.Id == s.FavoriteSourceId);
            //            response = FavoriteInfoResponseMapping(s, p);

            //            response.Resources = p == null ? new List<ResourceInfoResponse>(0) : msresource.Where(v => v.SourceId == p.Id && v.SourceType == (int)SourceType.Promotion).ToList();
            //            break;
            //        case (int)SourceType.Product:
            //            var t = products.FirstOrDefault(v => v.Id == s.FavoriteSourceId);
            //            response = FavoriteInfoResponseMapping(s, t);

            //            response.Resources = t == null ? new List<ResourceInfoResponse>(0) :
            //                productResource.Where(v => v.SourceId == t.Id && v.SourceType == (int)SourceType.Product).ToList();

            //            break;
            //    }

            //    if (response != null)
            //    {
            //        var store = stores.SingleOrDefault(v => v.Id == s.Store_Id);
            //        response.Store = store;
            //        response.StoreId = store == null ? 0 : store.Id;

            //        result.Favorites.Add(response);
            //    }
            //}

            //return result;
        }
Example #7
0
        public List<FavoriteInfoResponse> FavoriteCollectionResponseMapping(IQueryable<FavoriteEntity> source,
                                                                                   CoordinateInfo coordinateInfo)
        {
            if (source == null)
            {
                return new List<FavoriteInfoResponse>(0);
            }

            var linq = source;

            var prolist = _promotionRepository.Get(new PromotionFilter
                {
                    DataStatus = DataStatus.Normal,
                });
            var prodList = _productRepository.Get(null, new ProductFilter
                {
                    DataStatus = DataStatus.Normal,
                });

            var linqPro = linq.Where(v => v.FavoriteSourceType == (int)SourceType.Promotion)
                              .Join(prolist, p => p.FavoriteSourceId,
                                    f => f.Id,
                                    (p, f) =>
                                    new
                                        {
                                            Favor = p,
                                            Pro = f
                                        }
                );
            var linqProd = linq.Where(v => v.FavoriteSourceType == (int)SourceType.Product)
                              .Join(prodList, p => p.FavoriteSourceId,
                                    f => f.Id,
                                    (p, f) =>
                                                                        new
                                                                        {
                                                                            Favor = p,
                                                                            Prod = f
                                                                        }
                );

            var itemRepoonse = ItemsInfoResponseMapping(linqProd.Select(v => v.Prod), linqPro.Select(v => v.Pro), coordinateInfo, false);

            //sort
            //itemRepoonse = itemRepoonse.OrderByDescending(v => v.CreatedDate);
            var s = source.ToDictionary(v => String.Concat(v.FavoriteSourceId, "_", v.FavoriteSourceType), v => v);
            var list = FavoriteInfoResponseMapping(itemRepoonse, s);

            return list.OrderByDescending(v => v.CreatedDate).ToList();
        }
Example #8
0
        /// <summary>
        /// M
        /// </summary>
        /// <param name="coordinateInfo1"></param>
        /// <param name="coordinateInfo2"></param>
        /// <returns></returns>
        protected static decimal Distance(CoordinateInfo coordinateInfo1, CoordinateInfo coordinateInfo2)
        {
            var d = CoordinatePositioningHelper.GetDistance(coordinateInfo1,
                                                    coordinateInfo2);

            return Convert.ToDecimal(d * 1000);
        }
Example #9
0
        public List<PromotionInfoResponse> PromotionResponseMapping(List<PromotionEntity> source, CoordinateInfo coordinateInfo)
        {
            // var userIds = source.Select(v => v.RecommendUser).Where(v => v > 0).Distinct();

            // var users = _customerRepository.GetListByIds(userIds.ToList());
            //  var responseUser = ShowCustomerInfoResponseMapping(users).ToList();
            var storeids = source.Select(v => v.Store_Id).Where(v => v > 0).Distinct();
            var stores = _storeRepository.GetListByIds(storeids.ToList());
            var storeResponse = StoreResponseMapping(stores, coordinateInfo).ToList();
            var list = new List<PromotionInfoResponse>();
            var ids = source.Select(v => v.Id).ToList();

            var resource = GetListResourceEntities(SourceType.Promotion, ids);
            //  var brandR = _promotionBrandRelationRepository.GetList(ids);

            List<ResourceInfoResponse> resourceResponse = null;
            if (resource != null)
            {
                resourceResponse = ResourceInfoResponsesMapping(resource).ToList();
            }

            foreach (var entity in source)
            {
                var entity1 = entity;
                // var b = brandR.Where(v => v.Promotion_Id == entity1.Id).Select(v => v.Brand_Id).ToList();
                var r = resourceResponse == null
                            ? new List<ResourceInfoResponse>(0)
                            : resourceResponse.Where(v => v.SourceId == entity1.Id).ToList();
                var s = storeResponse.FirstOrDefault(v => v.Id == entity.Store_Id);
                // var u = responseUser.FirstOrDefault(v => v.Id == entity.RecommendUser);
                // var target = PromotionResponseMapping(entity, coordinateInfo, b, r, s, u);
                var target = PromotionResponseMapping(entity, coordinateInfo, null, r, s, null);
                if (target == null)
                {
                    continue;
                }

                list.Add(target);
            }

            return list;
        }
Example #10
0
        public List<PromotionInfoResponse> PromotionResponseMapping(IQueryable<PromotionEntity> source,
                                                                    CoordinateInfo coordinateInfo, bool? isBanner)
        {
            //JOIN DIANPU
            if (source == null)
            {
                return new List<PromotionInfoResponse>(0);
            }

            var linq = source;

            var storeRepository = ServiceLocator.Current.Resolve<IStoreRepository>();
            var resouceRepository = ServiceLocator.Current.Resolve<IResourceRepository>();
            var sp = linq.Join(storeRepository.Get(DataStatus.Normal), p => p.Store_Id, f => f.Id, (p, f) =>
                    new
                        {
                            P = p,
                            S = f
                        }
                );

            var sourceTypes = new List<int>(2);

            if (isBanner != null && isBanner.Value)
            {
                sourceTypes.Add((int)SourceType.BannerPromotion);
            }
            else
            {
                sourceTypes.Add((int)SourceType.Promotion);
            }

            var rsp = sp.GroupJoin(resouceRepository.Get(v => v.Status == (int)DataStatus.Normal && sourceTypes.Any(s => s == v.SourceType)),
                              p => p.P.Id, f => f.SourceId, (p, f) => new
                                  {
                                      P = p.P,
                                      S = p.S,
                                      R = f.OrderByDescending(rf=>rf.SortOrder).FirstOrDefault()
                                  });

            var target = new Dictionary<int, PromotionInfoResponse>();

            foreach (var item in rsp)
            {
                if (item == null)
                {
                    continue;
                }

                var r = ResourceInfoResponsesMapping(item.R);

                if (target.Keys.Contains(item.P.Id))
                {
                    if (r == null)
                    {
                        continue;
                    }

                    target[item.P.Id].ResourceInfoResponses.Add(r);
                }
                else
                {
                    var store = StoreResponseMapping(item.S, coordinateInfo);

                    var t = PromotionResponseMapping(item.P, coordinateInfo, null,r==null?null:new List<ResourceInfoResponse> { r }, store, null);
                    if (t.ResourceInfoResponses == null)
                    {
                        t.ResourceInfoResponses = new List<ResourceInfoResponse>();
                    }

                    target.Add(item.P.Id, t);
                }

            }

            return target.Values.ToList();
        }
Example #11
0
        public PromotionInfoResponse PromotionResponseMapping(PromotionEntity source, CoordinateInfo coordinateInfo, List<int> brandIds, List<ResourceInfoResponse> resourceInfoResponses, StoreInfoResponse storeInfoResponse, ShowCustomerInfoResponse showCustomerInfoResponse)
        {
            if (source == null)
            {
                return null;
            }

            var target = PromotionInfoResponseMapping(source);

            if (showCustomerInfoResponse != null)
            {
                target.ShowCustomer = showCustomerInfoResponse;
            }

            if (storeInfoResponse != null)
            {
                target.StoreInfoResponse = storeInfoResponse;
            }

            if (resourceInfoResponses != null)
            {
                target.ResourceInfoResponses = resourceInfoResponses;
            }

            if (brandIds != null)
            {
                target.BrandIds = brandIds;
            }

            return target;
        }
        private PromotionCollectionResponse GetList(PagerRequest pagerRequest, Timestamp timestamp, PromotionSortOrder sortOrder, CoordinateInfo coordinateInfo)
        {

            int totalCount;
            var entitys = Get(pagerRequest, timestamp, sortOrder, coordinateInfo, out totalCount);

            var response = new PromotionCollectionResponse(pagerRequest, totalCount)
            {
                Promotions = MappingManager.PromotionResponseMapping(entitys, coordinateInfo)
            };


            return response;
        }
        private List<PromotionEntity> Get(PagerRequest pageRequest, Timestamp timestamp, PromotionSortOrder sortOrder, CoordinateInfo coordinateInfo, out int totalCount)
        {
            List<PromotionEntity> entitys;

            switch (sortOrder)
            {
                case PromotionSortOrder.Near:
                    //先找 店铺地理位置,找到并且有促销的店铺
                    //根据店铺筛出商品
                    entitys = _promotionRepository.GetPagedList(pageRequest.PageIndex, pageRequest.PageSize, out totalCount,
                                                           (int)sortOrder, coordinateInfo.Longitude, coordinateInfo.Latitude, timestamp);
                    break;
                case PromotionSortOrder.New:
                    /*查询逻辑
                     * 1.今天开始的活动
                     * 2.以前开始,今天还自进行的活动
                     * 3.即将开始的活动,时间升序 24小时内的
                     * 
                     * logic 例 size40 
                     */

                    //1
                    entitys = _promotionRepository.GetPagedList(pageRequest, out totalCount, PromotionSortOrder.New, new DateTimeRangeInfo
                    {
                        StartDateTime = DateTime.Now,
                        EndDateTime = DateTime.Now

                    }, coordinateInfo, timestamp, null, PromotionFilterMode.New);

                    var t = pageRequest.PageIndex * pageRequest.PageSize;

                    var e2Size = 0;
                    var e2Index = 1;
                    List<PromotionEntity> e2;
                    var e2Count = 0;
                    var c = t - totalCount;
                    int? skipCount = null;
                    if (c <= 0)
                    {
                        e2Index = 1;
                        e2Size = 0;
                    }
                    else if (c > 0 && c < pageRequest.PageSize)
                    {
                        //1
                        e2Index = 1;
                        e2Size = c;
                    }
                    else
                    {
                        e2Index = (int)Math.Ceiling(c / (double)pageRequest.PageSize);
                        e2Size = pageRequest.PageSize;

                        if (e2Index > 1)
                        {
                            skipCount = c - (e2Index - 1) * e2Size + (pageRequest.PageSize * (e2Index - 2));
                        }
                    }

                    var p2 = new PagerRequest(e2Index, e2Size);

                    e2 = _promotionRepository.GetPagedList(p2, out e2Count, PromotionSortOrder.New, new DateTimeRangeInfo
                    {
                        StartDateTime = DateTime.Now,
                        EndDateTime = DateTime.Now
                    }, coordinateInfo, timestamp, null, PromotionFilterMode.BeginStart, skipCount);

                    if (e2.Count != 0 && e2Size != 0)
                    {
                        entitys.AddRange(e2);
                    }

                    //总记录数
                    totalCount = totalCount + e2Count;
                    //entitys = _promotionRepository.GetPagedList(pageRequest.PageIndex, pageRequest.PageSize,
                    //                    out totalCount, (int)request.SortOrder, timestamp);
                    break;
                default:
                    entitys = _promotionRepository.GetPagedList(pageRequest.PageIndex, pageRequest.PageSize,
                                                             out totalCount, (int)sortOrder, timestamp);
                    break;
            }

            return entitys;
        }
        /// <summary>
        /// 获取两点间距离 KM
        /// </summary>
        /// <param name="coordinate1"></param>
        /// <param name="coordinate2"></param>
        /// <returns></returns>
        public static double GetDistance(CoordinateInfo coordinate1, CoordinateInfo coordinate2)
        {
            if (coordinate1 == null || coordinate2 == null)
            {
                return 0;
            }

            return GetDistance(coordinate1.Longitude, coordinate1.Latitude, coordinate2.Longitude, coordinate2.Latitude);
        }
Example #15
0
        public StoreInfoResponse StoreResponseMapping(StoreInfoResponse source, CoordinateInfo coordinateInfo)
        {
            if (coordinateInfo == null)
            {
                return source;
            }

            source.Distance = Distance(coordinateInfo, new CoordinateInfo((double)source.Longitude, (double)source.Latitude));

            return source;
        }
Example #16
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="source"></param>
 /// <param name="coordinateInfo"></param>
 /// <returns></returns>
 public IEnumerable<StoreInfoResponse> StoreResponseMapping(List<StoreEntity> source, CoordinateInfo coordinateInfo)
 {
     if (coordinateInfo == null)
     {
         foreach (var storeEntity in source)
         {
             yield return StoreResponseMapping(storeEntity);
         }
     }
     else
     {
         foreach (var storeEntity in source)
         {
             yield return StoreResponseMapping(storeEntity, coordinateInfo);
         }
     }
 }
Example #17
0
        /// <summary>
        /// 需要计算 距离
        /// </summary>
        /// <param name="source"></param>
        /// <param name="coordinateInfo">坐标</param>
        /// <returns></returns>
        public PromotionInfoResponse PromotionResponseMapping(PromotionEntity source, CoordinateInfo coordinateInfo)
        {
            if (source == null)
            {
                return null;
            }

            ShowCustomerInfoResponse showCustomer = null;
            StoreInfoResponse storeInfoResponse = null;
            List<ResourceInfoResponse> resourceInfoResponses = null;
            List<int> brandIds = null;
            if (source.RecommendUser > 0)
            {
                var userEntity = _customerRepository.GetItem(source.RecommendUser);
                if (userEntity != null)
                {
                    showCustomer = ShowCustomerInfoResponseMapping(userEntity);
                }
            }

            if (source.Store_Id > 0)
            {
                var store = _storeRepository.GetItem(source.Store_Id);
                storeInfoResponse = StoreResponseMapping(store, coordinateInfo);
            }

            var resource =
                _resourceRepository.Get(
                    v =>
                    v.Status == (int)DataStatus.Normal && v.SourceId == source.Id &&
                    (int)SourceType.Promotion == v.SourceType).OrderByDescending(r=>r.SortOrder).ToList();

            resourceInfoResponses = ResourceInfoResponsesMapping(resource).ToList();

            var brandids = _promotionBrandRelationRepository.GetList(source.Id).Select(v => v.Brand_Id).ToList();

            if (brandids.Count > 0)
            {
                brandIds = brandids;
            }

            return PromotionResponseMapping(source, coordinateInfo, brandIds, resourceInfoResponses, storeInfoResponse,
                                            showCustomer);
        }