From 362ab3c925233da05f47888c46a737eec371b793 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期五, 24 五月 2019 15:44:03 +0800
Subject: [PATCH] 动态商品更新
---
fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java | 114 +++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 99 insertions(+), 15 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 f7f2401..0f48288 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
@@ -6,6 +6,7 @@
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
+import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@@ -22,7 +23,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;
@@ -102,6 +102,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);
}
@@ -116,18 +134,6 @@
public void removeCommonString(String key) {
removeKey(key);
- }
-
- /**
- * 灏嗕俊鎭案涔呬繚瀛樺埌Redis
- *
- * @param goods
- */
- public void saveTaoBaoGoodsBriefForever(TaoBaoGoodsBrief goods) {
- String key = "taobao-goods-" + goods.getAuctionId();
- if (Constant.IS_OUTNET) {
- cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods));
- }
}
/**
@@ -247,7 +253,7 @@
long count = jedis.incr(key);
if (count == 1)
jedis.expire(key, 5);
- if (count >= 100)
+ if (count >= 10)
return true;
else
return false;
@@ -296,19 +302,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;
}
}
@@ -484,4 +509,63 @@
return null;
}
+ /**
+ * 淇濆瓨瀵硅薄
+ *
+ * @param T
+ * @param key
+ * @param seconds
+ */
+ public void saveObj(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);
+ }
+
+ /**
+ * 淇濆瓨鍒楄〃
+ *
+ * @param clazzList
+ * @param key
+ * @param seconds
+ */
+ public <T> T saveObjList(List<T> clazzList, String key, Integer seconds) {
+ if (clazzList == null)
+ return null;
+ String value = new Gson().toJson(clazzList);
+ if (seconds != null)
+ cacheCommonString(key, value, seconds);
+ else
+ cacheCommonString(key, value);
+ return null;
+ }
+
+ /**
+ * 鑾峰彇瀵硅薄
+ *
+ * @param clazz
+ * @param key
+ * @return
+ */
+ public Class<?> getObj(Class<?> clazz, String key) {
+ String value = getCommonString(key);
+ return (Class<?>) new Gson().fromJson(value, clazz);
+ }
+
+ /**
+ * 鑾峰彇鍒楄〃
+ *
+ * @param clazz
+ * @param key
+ * @return
+ */
+ public <T> List<T> getObjList(Class<T> clazz, String key) {
+ String value = getCommonString(key);
+ return JsonUtil.jsonToList(value, clazz);
+ }
+
}
--
Gitblit v1.8.0