[AppleScript] 纯文本查看 复制代码
/**
* 刷新秒杀商品
*/
@Scheduled(cron="0 * * * * ?")
public void refreshSeckillGoods(){
System.out.println("执行了任务调度"+new Date());
//查询所有的秒杀商品键集合
List ids = new ArrayList( redisTemplate.boundHashOps("seckillGoods").keys());
//查询正在秒杀的商品列表
TbSeckillGoodsExample example=new TbSeckillGoodsExample();
Criteria criteria = example.createCriteria();
criteria.andStatusEqualTo("1");//审核通过
criteria.andStockCountGreaterThan(0);//剩余库存大于 0
criteria.andStartTimeLessThanOrEqualTo(new Date());//开始时间小于等于当前时间
criteria.andEndTimeGreaterThan(new Date());//结束时间大于当前时间
criteria.andIdNotIn(ids);//排除缓存中已经有的商品
List<TbSeckillGoods> seckillGoodsList=
seckillGoodsMapper.selectByExample(example);
//装入缓存
for( TbSeckillGoods seckill:seckillGoodsList ){
redisTemplate.boundHashOps("seckillGoods").put(seckill.getId(),
seckill);
}
System.out.println("将"+seckillGoodsList.size()+"条商品装入缓存");
}