| | |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoCouponUtil;
|
| | |
| | |
|
| | | @Resource
|
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | /**
|
| | | * 缓存字符串
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public void increase(String key) {
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | try {
|
| | | jedis.incr(key);
|
| | | } finally {
|
| | | jedisPool.returnResource(jedis);
|
| | | }
|
| | | }
|
| | |
|
| | | public void expire(String key,int seconds) {
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | try {
|
| | | jedis.expire(key, seconds);
|
| | | } finally {
|
| | | jedisPool.returnResource(jedis);
|
| | | }
|
| | | }
|
| | |
|
| | | public void cacheCommonString(String key, String value, int seconds) {
|
| | | setString(key, value, seconds);
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 将信息永久保存到Redis
|
| | | * 临时存储淘宝的商品详情
|
| | | *
|
| | | * @param goods
|
| | | */
|
| | | public void saveTaoBaoGoodsBriefForever(TaoBaoGoodsBrief goods) {
|
| | | String key = "taobao-goods-" + goods.getAuctionId();
|
| | | public void saveTaoBaoGoodsBriefTemp(TaoBaoGoodsBrief goods) {
|
| | | if (goods == null)
|
| | | return;
|
| | | String key = "taobao-goods-temp-" + goods.getAuctionId();
|
| | | if (Constant.IS_OUTNET) {
|
| | | cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods));
|
| | | // 暂存4个小时的分享
|
| | | cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods), 60 * 60 * 4);
|
| | | }
|
| | | }
|
| | |
|
| | | public TaoBaoGoodsBrief getTaoBaoGoodsTemp(Long auctionId) {
|
| | | String key = "taobao-goods-temp-" + auctionId;
|
| | | String value = getCommonString(key);
|
| | | if (!StringUtil.isNullOrEmpty(value)) {
|
| | | return JsonUtil.getSimpleGson().fromJson(value, TaoBaoGoodsBrief.class);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | if (StringUtil.isNullOrEmpty(value)) {
|
| | | List<ImageInfo> list = null;
|
| | | try {
|
| | | list = TaoBaoUtil.getTBDetailImageWithSize(auctionId);
|
| | | list = TaoBaoUtil.getTBDetailImageWithSizev2(auctionId, configService.getTaoBaoProxyIP());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | if (list == null || list.size() == 0) {
|
| | | list = TaoBaoUtil.getTBDetailImageWithSize(auctionId);
|
| | | }
|
| | | if (list != null && list.size() > 0)
|
| | | // 缓存1天
|
| | |
| | | String value = "";
|
| | | if (Constant.IS_OUTNET)
|
| | | value = getCommonString(key);
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(value)) {
|
| | | TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
|
| | | goods.setShopTitle(shopTitle);
|
| | | goods.setSellerId(sellerId);
|
| | | goods.setAuctionId(auctionId);
|
| | | TaoBaoShopInfo info = taoBaoShopService.getTaoBaoShopInfo(goods);
|
| | |
|
| | | if (info != null) {
|
| | | String shopUrl = info.getShopUrl();
|
| | | if (shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) {
|
| | | shopUrl = "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
|
| | | info.setShopUrl(shopUrl);
|
| | | }
|
| | | }
|
| | |
|
| | | if (Constant.IS_OUTNET && info != null) {
|
| | | value = new Gson().toJson(info);
|
| | | cacheCommonString(key, value, 60 * 60 * 2);
|
| | | }
|
| | |
|
| | | return info;
|
| | | } else {
|
| | | return new Gson().fromJson(value, TaoBaoShopInfo.class);
|
| | | TaoBaoShopInfo info = new Gson().fromJson(value, TaoBaoShopInfo.class);
|
| | |
|
| | | String shopUrl = info.getShopUrl();
|
| | | if (shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) {
|
| | | shopUrl = "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
|
| | | info.setShopUrl(shopUrl);
|
| | | }
|
| | |
|
| | | return info;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | return !StringUtil.isNullOrEmpty(getString(key));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 缓存短连接1分钟
|
| | | * |
| | | * @param uid
|
| | | * @param shortlink
|
| | | */
|
| | | public void setInviteShortLink(long uid, String shortlink) {
|
| | | String value = "";
|
| | | String key = "invite-shortlink-" + uid;
|
| | |
|
| | | if (Constant.IS_OUTNET) {
|
| | |
|
| | | value = getCommonString(key);
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(value)) {
|
| | | cacheCommonString(key, shortlink, 60);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取用户短连接
|
| | | * |
| | | * @param uid
|
| | | * @return
|
| | | */
|
| | | public String getInviteShortLink(long uid) {
|
| | |
|
| | | String value = "";
|
| | | String key = "invite-shortlink-" + uid;
|
| | |
|
| | | if (Constant.IS_OUTNET)
|
| | | value = getCommonString(key);
|
| | |
|
| | | return value;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 保存淘口令
|
| | | * |
| | | * @param auctionId
|
| | | * @param token
|
| | | */
|
| | | public void saveCommonTaoToken(Long auctionId, String token) {
|
| | | String key = "taobao-common-token-" + auctionId;
|
| | | if (Constant.IS_OUTNET) {
|
| | | if (!StringUtil.isNullOrEmpty(token)) {
|
| | | // 口令缓存10天
|
| | | cacheCommonString(key, token, 60 * 60 * 24 * 10);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取用户短连接
|
| | | * |
| | | * @param uid
|
| | | * @return
|
| | | */
|
| | | public String getCommonTaoToken(Long auctionId) {
|
| | | String key = "taobao-common-token-" + auctionId;
|
| | |
|
| | | if (Constant.IS_OUTNET) {
|
| | | return getCommonString(key);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|