From 0a6752e79b3cb7e1b9bcb2caba55933dd1e4044a Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期一, 25 十一月 2019 11:06:50 +0800
Subject: [PATCH] 红包封禁查询
---
fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java | 310 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 289 insertions(+), 21 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 5047bbe..2ba1493 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
@@ -6,26 +6,32 @@
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;
+import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.common.ImageInfo;
+import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.taobao.PidUser;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoShopInfo;
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.jd.JDApiUtil;
+import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
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;
import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.params.SetParams;
//鎶㈢孩鍖呴噰鐢ㄧ殑redis
@Component
@@ -39,8 +45,9 @@
@Resource
private TaoBaoUnionConfigService taoBaoUnionConfigService;
-
-
+
+ @Resource
+ private ConfigService configService;
/**
* 缂撳瓨瀛楃涓�
@@ -50,10 +57,12 @@
*/
private void setString(String key, String value) {
Jedis jedis = jedisPool.getResource();
+ SetParams params=new SetParams().nx().ex(60);
+ jedis.set(key, value, params);
try {
jedis.set(key, value);
} finally {
- jedisPool.returnResource(jedis);
+ jedis.close();
}
}
@@ -69,7 +78,7 @@
try {
jedis.del(key);
} finally {
- jedisPool.returnResource(jedis);
+ jedis.close();
}
}
@@ -87,7 +96,7 @@
try {
jedis.setex(key, seconds, value);
} finally {
- jedisPool.returnResource(jedis);
+ jedis.close();
}
}
@@ -96,7 +105,25 @@
try {
return jedis.get(key);
} finally {
- jedisPool.returnResource(jedis);
+ jedis.close();
+ }
+ }
+
+ public void increase(String key) {
+ Jedis jedis = jedisPool.getResource();
+ try {
+ jedis.incr(key);
+ } finally {
+ jedis.close();
+ }
+ }
+
+ public void expire(String key, int seconds) {
+ Jedis jedis = jedisPool.getResource();
+ try {
+ jedis.expire(key, seconds);
+ } finally {
+ jedis.close();
}
}
@@ -117,15 +144,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;
}
/**
@@ -171,7 +210,7 @@
if (StringUtil.isNullOrEmpty(value)) {
List<ImageInfo> list = null;
try {
- list = TaoBaoUtil.getTBDetailImageWithSizev2(auctionId);
+ list = TaoBaoUtil.getTBDetailImageWithSizev2(auctionId, configService.getTaoBaoProxyIP());
} catch (Exception e) {
e.printStackTrace();
}
@@ -221,12 +260,28 @@
long count = jedis.incr(key);
if (count == 1)
jedis.expire(key, 5);
- if (count >= 100)
+ if (count >= 10)
return true;
else
return false;
} finally {
- jedisPool.returnResource(jedis);
+ jedis.close();
+ }
+ }
+
+ public boolean frequencyLimit(String key, int timeS, int num) {
+ key = "frequency-" + key;
+ Jedis jedis = jedisPool.getResource();
+ try {
+ long count = jedis.incr(key);
+ if (count == 1)
+ jedis.expire(key, timeS);
+ if (count >= num)
+ return true;
+ else
+ return false;
+ } finally {
+ jedis.close();
}
}
@@ -270,19 +325,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;
}
}
@@ -333,8 +407,6 @@
*/
public void saveSMSVCode(String phone, int type, String code) {
- if (!Constant.IS_OUTNET)
- return;
String key = "smscode-" + phone + "-" + type;
// 淇濆瓨2鍒嗛挓
setString(key, code, 120);
@@ -347,8 +419,8 @@
* @return
*/
public String getSMSVCode(String phone, int type) {
- if (!Constant.IS_OUTNET)
- return "";
+ // if (!Constant.IS_OUTNET)
+ // return "";
String key = "smscode-" + phone + "-" + type;
// 淇濆瓨2鍒嗛挓
return getString(key);
@@ -362,8 +434,8 @@
* @param code
*/
public void clearSMSVCode(String phone, int type) {
- if (!Constant.IS_OUTNET)
- return;
+ // if (!Constant.IS_OUTNET)
+ // return;
String key = "smscode-" + phone + "-" + type;
removeKey(key);
}
@@ -389,4 +461,200 @@
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;
+ }
+
+ /**
+ * 淇濆瓨娣樼ぜ閲戠殑鍙d护
+ *
+ * @param url
+ * @param token
+ */
+ public void saveTLJToken(String url, String token) {
+ String key = "taobao-tlj-token-" + StringUtil.Md5(url);
+ if (Constant.IS_OUTNET) {
+ if (!StringUtil.isNullOrEmpty(token)) {
+ // 鍙d护缂撳瓨10澶�
+ cacheCommonString(key, token, 60 * 60 * 24 * 10);
+ }
+ }
+ }
+
+ /**
+ * 鑾峰彇娣樼ぜ閲戝彛浠�
+ *
+ * @param url
+ * @return
+ */
+ public String getTLJToken(String url) {
+ String key = "taobao-common-token-" + StringUtil.Md5(url);
+
+ if (Constant.IS_OUTNET) {
+ return getCommonString(key);
+ }
+ 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);
+ }
+
+ public JDGoods getJDGoods(long goodsId) {
+ String key = "jingdong-goods-" + goodsId;
+
+ String value = getCommonString(key);
+ if (StringUtil.isNullOrEmpty(value)) {
+ JDGoods jdGoods = JDApiUtil.queryGoodsDetail(goodsId);
+ if (jdGoods == null) {
+ jdGoods = JDApiUtil.getGoodsDetail(goodsId);
+ }
+
+ // 缂撳瓨20鍒嗛挓
+ if (jdGoods != null)
+ cacheCommonString(key, JsonUtil.getSimpleGson().toJson(jdGoods), 60 * 20);
+
+ return jdGoods;
+ } else {// 鐩存帴鍙栫紦瀛�
+ return JsonUtil.getSimpleGson().fromJson(value, JDGoods.class);
+ }
+ }
+
+ public PDDGoodsDetail getPDDGoodsDetail(long goodsId) {
+ String key = "pinduoduo-goods-" + goodsId;
+
+ String value = getCommonString(key);
+ if (StringUtil.isNullOrEmpty(value)) {
+ PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(goodsId);
+
+ // 缂撳瓨20鍒嗛挓
+ if (pddGoods != null)
+ cacheCommonString(key, JsonUtil.getSimpleGson().toJson(pddGoods), 60 * 20);
+
+ return pddGoods;
+ } else {// 鐩存帴鍙栫紦瀛�
+ return JsonUtil.getSimpleGson().fromJson(value, PDDGoodsDetail.class);
+ }
+ }
+
}
--
Gitblit v1.8.0