|
@@ -66,7 +66,20 @@ public class HomePageDataController {
|
|
|
@ApiOperation(value="设备在线情况", notes="设备在线情况")
|
|
|
@GetMapping(value = "/deviceOnline")
|
|
|
public Result<Map<String, Object>> deviceOnline() {
|
|
|
+ String cacheKey = "deviceOnline";
|
|
|
+
|
|
|
+ // 尝试从 Redis 获取缓存
|
|
|
+ Map<String, Object> cachedData = (Map<String, Object>) redisTemplate.opsForValue().get(cacheKey);
|
|
|
+ if (cachedData != null) {
|
|
|
+ return Result.OK(cachedData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果缓存中没有数据,则查询数据库
|
|
|
Map<String, Object> res = homePageDataService.deviceOnline();
|
|
|
+
|
|
|
+ // 存入 Redis,设置 5 分钟过期时间
|
|
|
+ redisTemplate.opsForValue().set(cacheKey, res, 5, TimeUnit.MINUTES);
|
|
|
+
|
|
|
return Result.OK(res);
|
|
|
}
|
|
|
|
|
@@ -80,7 +93,20 @@ public class HomePageDataController {
|
|
|
@ApiOperation(value="违规计量", notes="违规计量")
|
|
|
@GetMapping(value = "/illegalMetering")
|
|
|
public Result<List<Map<String, String>>> illegalMetering() {
|
|
|
+ String cacheKey = "illegalMetering";
|
|
|
+
|
|
|
+ // 尝试从 Redis 获取缓存
|
|
|
+ List<Map<String, String>> cachedData = (List<Map<String, String>>) redisTemplate.opsForValue().get(cacheKey);
|
|
|
+ if (cachedData != null) {
|
|
|
+ return Result.OK(cachedData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果缓存中没有数据,则查询数据库
|
|
|
List<Map<String, String>> res = homePageDataService.illegalMetering();
|
|
|
+
|
|
|
+ // 存入 Redis,设置 10 分钟过期时间
|
|
|
+ redisTemplate.opsForValue().set(cacheKey, res, 10, TimeUnit.MINUTES);
|
|
|
+
|
|
|
return Result.OK(res);
|
|
|
}
|
|
|
|
|
@@ -165,7 +191,20 @@ public class HomePageDataController {
|
|
|
@ApiOperation(value="实时报警", notes="实时报警")
|
|
|
@GetMapping(value = "/realAlarm")
|
|
|
public Result<List<Map<String, String>>> realAlarm() {
|
|
|
+ String cacheKey = "realAlarm";
|
|
|
+
|
|
|
+ // 尝试从 Redis 获取缓存
|
|
|
+ List<Map<String, String>> cachedData = (List<Map<String, String>>) redisTemplate.opsForValue().get(cacheKey);
|
|
|
+ if (cachedData != null) {
|
|
|
+ return Result.OK(cachedData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果缓存中没有数据,则查询数据库
|
|
|
List<Map<String, String>> res = homePageDataService.realAlarm();
|
|
|
+
|
|
|
+ // 存入 Redis,设置 5 分钟过期时间
|
|
|
+ redisTemplate.opsForValue().set(cacheKey, res, 5, TimeUnit.MINUTES);
|
|
|
+
|
|
|
return Result.OK(res);
|
|
|
}
|
|
|
|