예제 #1
0
 /// <summary>
 /// 生成优惠券到redis集合set,成功返回true,失败返回false
 /// </summary>
 /// <param name="couponCode"></param>
 /// <param name="isFirst"></param>
 /// <returns></returns>
 private bool CreateCouponToRedisSet(string couponCode, bool isFirst)
 {
     //首次添加查询是否存在key
     if (isFirst)
     {
         var redisCacheService = new RedisCacheService();
         if (!redisCacheService.HasKey(RedisConsts.OrderCouponIdSet))
         {
             AddCouponArrayToRedis();
         }
     }
     return(AddCouponToRedis(couponCode));
 }
예제 #2
0
        /// <summary>
        /// 更新远程redis缓存到本地
        /// </summary>
        /// <param name="key"></param>
        public void UpdateLocalConfig(string key)
        {
            var redisCacheService = new RedisCacheService();

            if (!redisCacheService.HasKey(key))
            {
                throw new YuanbeiException("config key {0} not existed in redis", key);
            }

            string val = redisCacheService.Get <string>(key);

            _localCache.Set(key, val, _configLastMinutes);
        }
예제 #3
0
        public string GetConfig(string key)
        {
            if (_localCache.IsSet(key))
            {
                return(_localCache.Get <string>(key));
            }

            var redisCacheService = new RedisCacheService();

            if (!redisCacheService.HasKey(key))
            {
                throw new YuanbeiException("config key {0} not existed in redis", key);
            }

            string val = redisCacheService.Get <string>(key);

            _localCache.Set(key, val, _configLastMinutes);
            return(val);
        }
        /// <summary>
        /// redis获取商品详情
        /// </summary>
        /// <param name="goodsId"></param>
        /// <returns></returns>
        private MaterialGoodsInfo GetMaterialGoodsDetails(int goodsId)
        {
            MaterialGoodsInfo entity;
            string            key = RedisConsts.MaterialGoodsInfo + goodsId;
            var redisCacheService = new RedisCacheService();

            if (redisCacheService.HasKey(key))
            {
                entity = redisCacheService.Get <MaterialGoodsInfo>(key);
            }
            else
            {
                entity = GetMaterialGoodsDb(goodsId);
                //Insert Cache 7days
                Task.Factory.StartNew(() =>
                {
                    redisCacheService.Set(key, entity, 60 * 60 * 24 * 7);
                });
            }
            return(entity);
        }
        /// <summary>
        /// redis获取商品列表
        /// </summary>
        /// <returns></returns>
        private IEnumerable <MaterialGoodsListRedisItem> GetMaterialGoodsIdList()
        {
            IEnumerable <MaterialGoodsListRedisItem> rModel;
            string key = RedisConsts.MaterialGoodsList;
            var    redisCacheService = new RedisCacheService();

            if (redisCacheService.HasKey(key))
            {
                rModel = redisCacheService.Get <List <MaterialGoodsListRedisItem> >(key);
            }
            else
            {
                rModel = Mapper.Map <IEnumerable <T_MaterialGoods2>, IEnumerable <MaterialGoodsListRedisItem> >(_materialGoods.FindAll());

                //Insert Cache 7days
                Task.Factory.StartNew(() =>
                {
                    redisCacheService.Set(key, rModel, 60 * 60 * 24 * 7);
                });
            }
            return(rModel);
        }
예제 #6
0
        /// <summary>
        /// 获取广告详情
        /// </summary>
        /// <returns></returns>
        public ResponseModel GetAdvertDetail(string positionCode, int accountId = -1, UserContext userContext = null)
        {
            var adverApi = new Entity.Api.Advert.Advert();

            string key = RedisConsts.StationAdvertKey + positionCode.ToLower();

            var redisCacheService = new RedisCacheService();

            if (redisCacheService.HasKey(key))
            {
                adverApi = redisCacheService.Get <Entity.Api.Advert.Advert>(key);
            }
            else
            {
                var advertModel =
                    _advertDataRepository.FindAll(ad => ad.AdPositionCode == positionCode &&
                                                  ad.Enable == 1 &&
                                                  ad.StartDate <= DateTime.Now &&
                                                  ad.EndDate >= DateTime.Now
                                                  ).OrderByDescending(o => o.Id).FirstOrDefault();

                if (advertModel == null)
                {
                    //throw new YuanbeiException("获取站内广告信息失败,未找到对应信息");
                    return(new ResponseModel
                    {
                        Code = 0,
                        Message = "无数据",
                        Data = null
                    });
                }

                var adverResourcesList = _advertResourcesDataRepository.FindAll(ad => ad.AdId == advertModel.Id &&
                                                                                ad.State == 1)
                                         .OrderByDescending(o => o.Id);

                //TO DTO
                adverApi.title   = advertModel.AdTitle;
                adverApi.display = advertModel.DisplayMode;
                adverApi.width   = advertModel.AdWidth;
                adverApi.height  = advertModel.AdHieght;
                adverApi.items   = new List <Entity.Api.Advert.AdvertResources>();
                foreach (var advertResourcese in adverResourcesList)
                {
                    var advertResourceApi = new Entity.Api.Advert.AdvertResources();
                    //advertResourceApi.link = advertResourcese.AdLink;
                    advertResourceApi.link = WebConfigSetting.Instance.AdvertTransferUrl +
                                             string.Format("?adresid={0}&turl={1}", advertResourcese.Id,
                                                           HttpUtility.UrlEncode(advertResourcese.AdLink));
                    advertResourceApi.image = WebConfigSetting.Instance.ImageServer + advertResourcese.AdImageUrl;

                    adverApi.items.Add(advertResourceApi);
                }

                //Insert Cache 7days
                redisCacheService.Set(key, adverApi, 60 * 60 * 24 * 7);
            }

            //Insert View Log
            Task.Factory.StartNew(() =>
            {
                var advertModel =
                    _advertDataRepository.FindAll(ad => ad.AdPositionCode == positionCode &&
                                                  ad.Enable == 1 &&
                                                  ad.StartDate <= DateTime.Now &&
                                                  ad.EndDate >= DateTime.Now
                                                  ).OrderByDescending(o => o.Id).FirstOrDefault();

                AdvertLog advertLog = new AdvertLog();
                advertLog.AdId      = advertModel.Id;
                advertLog.AccountId = accountId;
                if (userContext != null)
                {
                    advertLog.Ip = userContext.IpAddress;
                }
                advertLog.Type       = 1;
                advertLog.CreateTime = DateTime.Now;
                _advertLogDataRepository.Insert(advertLog);
            });

            //TODO 店铺权限判断
            if (accountId != -1)
            {
            }

            //2.返回查询结果
            return(new ResponseModel
            {
                Code = 0,
                Message = "获取数据成功",
                Data = adverApi
            });
        }