package com.yeshi.fanli.util.cache;
|
|
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.RedisManager;
|
import com.yeshi.fanli.util.StringUtil;
|
|
@Component
|
public class TaoBaoGoodsCacheUtil {
|
@Resource
|
private RedisManager redisManager;
|
|
/**
|
* 保存常规的淘宝商品详情(搜索,详情)
|
*
|
* @param goods
|
*/
|
public void saveCommonTaoBaoGoodsInfo(TaoBaoGoodsBrief goods) {
|
if (goods == null || goods.getAuctionId() == null)
|
return;
|
String key = "taobao-goods-common-" + goods.getAuctionId();
|
// 保存20分钟
|
redisManager.cacheCommonString(key, new Gson().toJson(goods), 60 * 20);
|
}
|
|
/**
|
* 获取缓存
|
*
|
* @param auctionId
|
* @return
|
*/
|
public TaoBaoGoodsBrief getCommonTaoBaoGoodsInfo(long auctionId) {
|
String key = "taobao-goods-common-" + auctionId;
|
String value = redisManager.getCommonString(key);
|
if (!StringUtil.isNullOrEmpty(value)) {
|
return new Gson().fromJson(value, TaoBaoGoodsBrief.class);
|
} else
|
return null;
|
}
|
|
/**
|
* 是否可以添加到更新队列中
|
*
|
* @param auctionId
|
* @return
|
*/
|
public boolean canAddToUpdateQueue(Long auctionId) {
|
String key = "tb-u-q-" + auctionId;
|
String value = redisManager.getCommonString(key);
|
if (StringUtil.isNullOrEmpty(value))
|
return true;
|
else
|
return false;
|
}
|
|
/**
|
* 增加添加到队列中的记录
|
*
|
* @param auctionId
|
*/
|
public void addAddToQueueHistory(Long auctionId) {
|
String key = "tb-u-q-" + auctionId;
|
redisManager.cacheCommonString(key, "1", 60 * 60 * 2);// 有效期2个小时
|
}
|
|
/**
|
* 查询商品是否需要更新
|
*
|
* @param actionId
|
* @return
|
*/
|
public boolean needUpdate(Long actionId) {
|
String key = "tb-u-" + 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 = "tb-u-" + actionId;
|
redisManager.cacheCommonString(key, "1", 60 * 60 * 1);// 有效期1个小时
|
}
|
|
/**
|
* 删除更新记录
|
*/
|
public void removeUpdateHistory() {
|
// TODO 凌晨删除缓存记录
|
}
|
|
}
|