parent
58d7980ea2
commit
54b731450c
@ -0,0 +1,13 @@
|
||||
package com.luoo.user.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import com.luoo.user.pojo.Carousel;
|
||||
|
||||
public interface CarouselDao extends JpaRepository<Carousel, Integer> {
|
||||
@Query(value = "select * from tb_carousel where status=1 order by publish_time desc limit 5", nativeQuery = true)
|
||||
public List<Carousel> getValidCarousels();
|
||||
}
|
@ -1,24 +1,32 @@
|
||||
package com.luoo.user.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.luoo.user.dao.CarouselDao;
|
||||
import com.luoo.user.pojo.Carousel;
|
||||
|
||||
@Service
|
||||
public class CarouselService {
|
||||
private static final List<Carousel> DEFAULT_CAROUSEL_LIST=new ArrayList<>();
|
||||
static {
|
||||
DEFAULT_CAROUSEL_LIST.add(Carousel.builder().carouselId(1).imgPath("http://cdn.indie.cn/music/10016/07.jpg").objectType(0).objectId("1643965109602750464").outerLink(null).build());
|
||||
DEFAULT_CAROUSEL_LIST.add(Carousel.builder().carouselId(2).imgPath("http://cdn.indie.cn/music/00985/00.jpg").objectType(1).objectId("1635099768424370176").outerLink(null).build());
|
||||
DEFAULT_CAROUSEL_LIST.add(Carousel.builder().carouselId(3).imgPath("http://cdn.indie.cn/music/00984/00.jpg").objectType(1).objectId("1635099812296790016").outerLink(null).build());
|
||||
DEFAULT_CAROUSEL_LIST.add(Carousel.builder().carouselId(4).imgPath("http://cdn.indie.cn/music/00942/00.jpg").objectType(2).objectId(null).outerLink("http://116.62.145.60:3000/music").build());
|
||||
DEFAULT_CAROUSEL_LIST.add(Carousel.builder().carouselId(5).imgPath("http://cdn.indie.cn/music/00982/00.jpg").objectType(1).objectId("1635099717706846208").outerLink(null).build());
|
||||
}
|
||||
private static final String REDIS_KEY_CAROUSE = "carousels";
|
||||
@Autowired
|
||||
private CarouselDao carouselDao;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
public List<Carousel> loadCarousel() {
|
||||
return DEFAULT_CAROUSEL_LIST;
|
||||
List<Carousel> carousels = (List<Carousel>) redisTemplate.opsForValue().get(REDIS_KEY_CAROUSE);
|
||||
if (CollectionUtils.isEmpty(carousels)) {
|
||||
carousels = carouselDao.getValidCarousels();
|
||||
redisTemplate.opsForValue().set(REDIS_KEY_CAROUSE, carousels, 24, TimeUnit.HOURS);
|
||||
}
|
||||
return carousels;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue