From 744594ef1a2f530fc3e86ea9dc48b62247f79420 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 19 五月 2020 17:13:23 +0800 Subject: [PATCH] 饿了么绘图,添加口碑 --- fanli/src/main/java/com/yeshi/fanli/util/cache/TaoBaoGoodsCacheUtil.java | 125 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 123 insertions(+), 2 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/cache/TaoBaoGoodsCacheUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/cache/TaoBaoGoodsCacheUtil.java index 1206fc3..8fd7d08 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/cache/TaoBaoGoodsCacheUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/cache/TaoBaoGoodsCacheUtil.java @@ -1,13 +1,17 @@ package com.yeshi.fanli.util.cache; +import java.util.Calendar; + import javax.annotation.Resource; import org.springframework.stereotype.Component; import com.google.gson.Gson; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; +import com.yeshi.fanli.util.RedisKeyEnum; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.util.TimeUtil; @Component public class TaoBaoGoodsCacheUtil { @@ -22,7 +26,7 @@ public void saveCommonTaoBaoGoodsInfo(TaoBaoGoodsBrief goods) { if (goods == null || goods.getAuctionId() == null) return; - String key = "taobao-goods-common-" + goods.getAuctionId(); + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsCommon, goods.getAuctionId() + ""); // 淇濆瓨20鍒嗛挓 redisManager.cacheCommonString(key, new Gson().toJson(goods), 60 * 20); } @@ -34,7 +38,7 @@ * @return */ public TaoBaoGoodsBrief getCommonTaoBaoGoodsInfo(long auctionId) { - String key = "taobao-goods-common-" + auctionId; + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsCommon, auctionId + ""); String value = redisManager.getCommonString(key); if (!StringUtil.isNullOrEmpty(value)) { return new Gson().fromJson(value, TaoBaoGoodsBrief.class); @@ -42,4 +46,121 @@ return null; } + /** + * 鏄惁鍙互娣诲姞鍒版洿鏂伴槦鍒椾腑 + * + * @param auctionId + * @return + */ + public boolean canAddToUpdateQueue(Long auctionId) { + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoQueue, auctionId + ""); + String value = redisManager.getCommonString(key); + if (StringUtil.isNullOrEmpty(value)) + return true; + else + return false; + } + + /** + * 澧炲姞娣诲姞鍒伴槦鍒椾腑鐨勮褰� + * + * @param auctionId + */ + public void addAddToQueueHistory(Long auctionId) { + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoQueue, auctionId + ""); + redisManager.cacheCommonString(key, "1", 60 * 60 * 2);// 鏈夋晥鏈�2涓皬鏃� + } + + /** + * 鏌ヨ鍟嗗搧鏄惁闇�瑕佹洿鏂� + * + * @param actionId + * @return + */ + public boolean needUpdate(Long actionId) { + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoUpdate, actionId + ""); + String value = redisManager.getCommonString(key); + if (StringUtil.isNullOrEmpty(value)) + return true; + else + return false; + } + + /** + * 娣诲姞鏇存柊璁板綍鏁版嵁 + * + * @param actionId + * @return + */ + public void addUpdateHistory(Long actionId) { + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoUpdate, actionId + ""); + redisManager.cacheCommonString(key, "1", 60 * 60 * 1);// 鏈夋晥鏈�1涓皬鏃� + } + + /** + * 鍒犻櫎鏇存柊璁板綍 + */ + public void removeUpdateHistory() { + // TODO 鍑屾櫒鍒犻櫎缂撳瓨璁板綍 + } + + /** + * 淇濆瓨鍙d护瀵瑰簲鐨勫晢鍝両D + * + * @param token + * @param auctionId + */ + public void saveTokenGoodsIdMap(String token, Long auctionId) { + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenGoodsMap, StringUtil.Md5(token)); + redisManager.cacheCommonString(key, auctionId + "", 60 * 30);// 鏈夋晥鏈�30鍒嗛挓 + } + + /** + * 閫氳繃鍙d护鑾峰彇鍟嗗搧ID + * + * @param token + * @return + */ + public Long getGoodsIdByToken(String token) { + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenGoodsMap, StringUtil.Md5(token)); + String goodsId = redisManager.getCommonString(key); + if (StringUtil.isNullOrEmpty(goodsId)) + return null; + return Long.parseLong(goodsId); + } + + /** + * 缂撳瓨杞摼缁撴灉 + * @Title: cacheBaseConvertLink + * @Description: + * @param auctionId + * @param pid + * @param link + * void 杩斿洖绫诲瀷 + * @throws + */ + public void cacheBaseConvertLink(Long auctionId, String pid, String link) { + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoBaseLink, StringUtil.Md5(auctionId + "#" + pid)); + // + Calendar calendar = Calendar.getInstance(); + long now = calendar.getTimeInMillis(); + calendar.add(Calendar.HOUR, 1); + + Long time = TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(calendar.getTimeInMillis(), "yyyy-MM-dd HH"), + "yyyy-MM-dd HH"); + + int second = (int) ((time - now) / 1000); + if (second <= 0) + second = 1; + + redisManager.cacheCommonString(key, link, second);// 鏈夋晥鏈�30鍒嗛挓 + } + + public String getBaseConvertLink(Long auctionId, String pid) { + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoBaseLink, StringUtil.Md5(auctionId + "#" + pid)); + String url = redisManager.getCommonString(key); + + return StringUtil.isNullOrEmpty(url) ? null : url; + } + } -- Gitblit v1.8.0