From c5410b7f48a774e4ecd50019b46bc9173f2483ae Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 08 五月 2019 11:33:37 +0800
Subject: [PATCH] 转大淘客为普通商品详情

---
 fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java |  177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 169 insertions(+), 8 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java b/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
index 36f58bf..02e0788 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
@@ -5,7 +5,9 @@
 
 import javax.annotation.Resource;
 
+import org.apache.poi.ss.formula.functions.T;
 import org.springframework.stereotype.Component;
+import org.yeshi.utils.JsonUtil;
 
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
@@ -22,7 +24,6 @@
 import com.yeshi.fanli.util.taobao.TaoBaoCouponUtil;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
 import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
-import org.yeshi.utils.JsonUtil;
 
 import net.sf.json.JSONArray;
 import redis.clients.jedis.Jedis;
@@ -39,7 +40,7 @@
 	private TaoBaoShopService taoBaoShopService;
 
 	@Resource
-	private TaoBaoUnionConfigService taoBaoUnionConfigService;
+	private TaoBaoUnionConfigService taoBaoUnionConfigService;
 
 	@Resource
 	private ConfigService configService;
@@ -102,6 +103,24 @@
 		}
 	}
 
+	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);
 	}
@@ -119,15 +138,27 @@
 	}
 
 	/**
-	 * 灏嗕俊鎭案涔呬繚瀛樺埌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;
 	}
 
 	/**
@@ -223,7 +254,7 @@
 			long count = jedis.incr(key);
 			if (count == 1)
 				jedis.expire(key, 5);
-			if (count >= 100)
+			if (count >= 10)
 				return true;
 			else
 				return false;
@@ -272,19 +303,38 @@
 		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;
 		}
 	}
 
@@ -391,4 +441,115 @@
 		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)) {
+				// 鍙d护缂撳瓨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;
+	}
+
+	/**
+	 * 淇濆瓨瀵硅薄
+	 * 
+	 * @param T
+	 * @param key
+	 * @param seconds
+	 */
+	public void save(Class<?> clazz, String key, Integer seconds) {
+		if (clazz == null)
+			return;
+		String value = new Gson().toJson(clazz);
+		if (seconds != null)
+			cacheCommonString(key, value, seconds);
+		else
+			cacheCommonString(key, value);
+	}
+
+	public void saveList(List<Class<?>> clazzList, String key, Integer seconds) {
+		if (clazzList == null)
+			return;
+		String value = new Gson().toJson(clazzList);
+		if (seconds != null)
+			cacheCommonString(key, value, seconds);
+		else
+			cacheCommonString(key, value);
+	}
+
+	public Class<?> getObj(Class<?> clazz, String key) {
+		String value = getCommonString(key);
+		return new Gson().fromJson(value, clazz);
+	}
+
+	public List<T> getObjList(Class<T> clazz, String key) {
+		List<T> list = new ArrayList<>();
+		String value = getCommonString(key);
+		JSONArray array = JSONArray.fromObject(value);
+		for (int i = 0; i < array.size(); i++) {
+			list.add(new Gson().fromJson(array.optJSONObject(i).toString(), clazz));
+		}
+		return list;
+	}
+
 }

--
Gitblit v1.8.0