| | |
| | | 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 {
|
| | |
| | | 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);
|
| | | }
|
| | |
| | | * @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);
|
| | |
| | | * @return
|
| | | */
|
| | | public boolean canAddToUpdateQueue(Long auctionId) {
|
| | | String key = "tb-u-q-" + auctionId;
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoQueue, auctionId + "");
|
| | | String value = redisManager.getCommonString(key);
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | return true;
|
| | |
| | | * @param auctionId
|
| | | */
|
| | | public void addAddToQueueHistory(Long auctionId) {
|
| | | String key = "tb-u-q-" + auctionId;
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoQueue, auctionId + "");
|
| | | redisManager.cacheCommonString(key, "1", 60 * 60 * 2);// 有效期2个小时
|
| | | }
|
| | |
|
| | |
| | | * @return
|
| | | */
|
| | | public boolean needUpdate(Long actionId) {
|
| | | String key = "tb-u-" + actionId;
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoUpdate, actionId + "");
|
| | | String value = redisManager.getCommonString(key);
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | return true;
|
| | |
| | | * @return
|
| | | */
|
| | | public void addUpdateHistory(Long actionId) {
|
| | | String key = "tb-u-" + actionId;
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoUpdate, actionId + "");
|
| | | redisManager.cacheCommonString(key, "1", 60 * 60 * 1);// 有效期1个小时
|
| | | }
|
| | |
|
| | |
| | | // TODO 凌晨删除缓存记录
|
| | | }
|
| | |
|
| | | /**
|
| | | * 保存口令对应的商品ID
|
| | | * |
| | | * @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分钟
|
| | | }
|
| | |
|
| | | /**
|
| | | * 通过口令获取商品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;
|
| | | }
|
| | |
|
| | | }
|