|
@@ -37,22 +37,25 @@ public class SearchHistoryController {
|
|
|
@ApiOperation(value = "在redis中获取首页搜索记录")
|
|
|
@GetMapping("/businessTireNameHistory")
|
|
|
public R<List<String>> searchHistory(){
|
|
|
- Long userId = SecurityUtils.getUserId();
|
|
|
- List<String> searchList = new ArrayList<>();
|
|
|
- String key = CacheConstants.SEARCH_HISTORY_KEY + userId;
|
|
|
- long start = 1;
|
|
|
- long size = 10;
|
|
|
- Set<ZSetOperations.TypedTuple> historySet = redisTemplate.opsForZSet().reverseRangeWithScores(key, start - 1, size - 1);
|
|
|
- Iterator<ZSetOperations.TypedTuple> iterator = historySet.iterator();
|
|
|
- BigDecimal bigDecimal = null;
|
|
|
- while (iterator.hasNext()){
|
|
|
- ZSetOperations.TypedTuple next = iterator.next();
|
|
|
- BigDecimal decimal = BigDecimal.valueOf(next.getScore());
|
|
|
- if (next.getValue() != null){
|
|
|
- searchList.add(next.getValue().toString());
|
|
|
+ try {
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ List<String> searchList = new ArrayList<>();
|
|
|
+ String key = CacheConstants.SEARCH_HISTORY_KEY + userId;
|
|
|
+ long start = 1;
|
|
|
+ long size = 10;
|
|
|
+ Set<ZSetOperations.TypedTuple> historySet = redisTemplate.opsForZSet().reverseRangeWithScores(key, start - 1, size - 1);
|
|
|
+ Iterator<ZSetOperations.TypedTuple> iterator = historySet.iterator();
|
|
|
+ BigDecimal bigDecimal = null;
|
|
|
+ while (iterator.hasNext()){
|
|
|
+ ZSetOperations.TypedTuple next = iterator.next();
|
|
|
+ BigDecimal decimal = BigDecimal.valueOf(next.getScore());
|
|
|
+ if (next.getValue() != null){
|
|
|
+ searchList.add(next.getValue().toString());
|
|
|
+ }
|
|
|
}
|
|
|
+ return R.ok(searchList);
|
|
|
+ }catch (Exception e){
|
|
|
+ return R.ok();
|
|
|
}
|
|
|
- return R.ok(searchList);
|
|
|
}
|
|
|
-
|
|
|
}
|