|
@@ -1,13 +1,17 @@
|
|
|
package com.smcic.api.hotrank.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.benmanes.caffeine.cache.Cache;
|
|
|
+import com.github.benmanes.caffeine.cache.Caffeine;
|
|
|
import com.smcic.api.hotrank.dto.HotRankDTO;
|
|
|
import com.smcic.api.hotrank.entity.HotRank;
|
|
|
import com.smcic.api.hotrank.mapper.HotRankMapper;
|
|
|
import com.smcic.api.hotrank.service.IHotRankService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -20,9 +24,14 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
public class HotRankServiceImpl extends ServiceImpl<HotRankMapper, HotRank> implements IHotRankService {
|
|
|
+
|
|
|
+ private final Cache<String[], List<HotRankDTO>> cache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build();
|
|
|
+
|
|
|
public List<HotRankDTO> todayRank(String rank){
|
|
|
String dt = baseMapper.getLastDt(rank);
|
|
|
- return lambdaQuery().eq(HotRank::getDt, dt).eq(HotRank::getPlatform, rank).orderByAsc(HotRank::getId).last("limit 50").list()
|
|
|
- .stream().map(data -> new HotRankDTO(data.getContent(), data.getRk())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return cache.get(new String[]{rank,dt}, (key) -> lambdaQuery().eq(HotRank::getDt, key[1]).eq(HotRank::getPlatform, key[0]).orderByAsc(HotRank::getId).last("limit 50").list()
|
|
|
+ .stream().map(data -> new HotRankDTO(data.getContent(), data.getRk())).collect(Collectors.toList()));
|
|
|
+
|
|
|
}
|
|
|
}
|