From 788deca1b4a24f8a24e49c24f7d89975a1d74bbe Mon Sep 17 00:00:00 2001 From: admin <2780501319@qq.com> Date: 星期日, 03 十一月 2019 23:31:25 +0800 Subject: [PATCH] 商城订单退款处理 --- fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java | 134 +++++++++++++++++++++++++++++++++++++++----- 1 files changed, 118 insertions(+), 16 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 69bbcd6..883fac8 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java @@ -5,13 +5,14 @@ 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; +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; @@ -21,6 +22,8 @@ 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; @@ -263,6 +266,22 @@ } } + 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 { + jedisPool.returnResource(jedis); + } + } + /** * 鑾峰彇娣樺疂鍥剧墖 * @@ -385,8 +404,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); @@ -399,8 +416,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); @@ -414,8 +431,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); } @@ -511,13 +528,44 @@ } /** + * 淇濆瓨娣樼ぜ閲戠殑鍙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 save(Class<?> clazz, String key, Integer seconds) { + public void saveObj(Class<?> clazz, String key, Integer seconds) { if (clazz == null) return; String value = new Gson().toJson(clazz); @@ -527,29 +575,83 @@ cacheCommonString(key, value); } - public void saveList(List<Class<?>> clazzList, String key, Integer seconds) { + /** + * 淇濆瓨鍒楄〃 + * + * @param clazzList + * @param key + * @param seconds + */ + public <T> T saveObjList(List<T> clazzList, String key, Integer seconds) { if (clazzList == null) - return; + 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); } - public List<T> getObjList(Class<T> clazz, String key) { - List<T> list = new ArrayList<>(); + /** + * 鑾峰彇鍒楄〃 + * + * @param clazz + * @param key + * @return + */ + public <T> List<T> getObjList(Class<T> clazz, String key) { 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 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); } - return list; + } + + 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