|
@@ -11,12 +11,12 @@ import org.jeecg.modules.homePageData.entity.IllegalResult;
|
|
|
import org.jeecg.modules.homePageData.service.IHomePageDataService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.data.redis.core.ValueOperations;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -125,13 +125,33 @@ public class HomePageDataController {
|
|
|
* @return
|
|
|
*/
|
|
|
@AutoLog(value = "峰平谷时间段用电量")
|
|
|
- @ApiOperation(value="峰平谷时间段用电量", notes="峰平谷时间段用电量")
|
|
|
+ @ApiOperation(value = "峰平谷时间段用电量", notes = "峰平谷时间段用电量")
|
|
|
@GetMapping(value = "/fpvTimeElectricity")
|
|
|
- public Result<Map<String, List>> fpvTimeElectricity(@RequestParam(name="modelId",required=false) String modelId) {
|
|
|
- if (oConvertUtils.isEmpty(modelId) || "0".equals(modelId)){
|
|
|
+ public Result<Map<String, List>> fpvTimeElectricity(@RequestParam(name = "modelId", required = false) String modelId) {
|
|
|
+ // 验证参数
|
|
|
+ if (oConvertUtils.isEmpty(modelId) || "0".equals(modelId)) {
|
|
|
return Result.error("查询失败,请设置模型!");
|
|
|
}
|
|
|
+
|
|
|
+ // 构建缓存的 Key
|
|
|
+ String cacheKey = "fpvTimeElectricity:" + modelId;
|
|
|
+ ValueOperations<String, Object> valueOps = redisTemplate.opsForValue();
|
|
|
+
|
|
|
+ // 尝试从 Redis 获取缓存数据
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ Map<String, List> cachedData = (Map<String, List>) valueOps.get(cacheKey);
|
|
|
+
|
|
|
+ if (cachedData != null) {
|
|
|
+ // 如果缓存存在,直接返回
|
|
|
+ return Result.OK(cachedData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 缓存不存在,调用服务查询
|
|
|
Map<String, List> res = homePageDataService.fpvTimeElectricity(modelId);
|
|
|
+
|
|
|
+ // 将查询结果存入 Redis 并设置过期时间为 10 分钟
|
|
|
+ valueOps.set(cacheKey, res, 10, TimeUnit.MINUTES);
|
|
|
+
|
|
|
return Result.OK(res);
|
|
|
}
|
|
|
|
|
@@ -156,10 +176,27 @@ public class HomePageDataController {
|
|
|
* @return
|
|
|
*/
|
|
|
@AutoLog(value = "实时设备运行")
|
|
|
- @ApiOperation(value="实时设备运行", notes="实时设备运行")
|
|
|
+ @ApiOperation(value = "实时设备运行", notes = "实时设备运行")
|
|
|
@GetMapping(value = "/realDeviceRun")
|
|
|
public Result<List<Map<String, String>>> realDeviceRun() {
|
|
|
+ String cacheKey = "realDeviceRun:data"; // 缓存的 key
|
|
|
+ ValueOperations<String, Object> valueOps = redisTemplate.opsForValue();
|
|
|
+
|
|
|
+ // 从 Redis 中尝试获取缓存数据
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<Map<String, String>> cachedData = (List<Map<String, String>>) valueOps.get(cacheKey);
|
|
|
+
|
|
|
+ if (cachedData != null) {
|
|
|
+ // 如果缓存中有数据,直接返回
|
|
|
+ return Result.OK(cachedData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果缓存中没有数据,查询数据库
|
|
|
List<Map<String, String>> res = homePageDataService.realDeviceRun();
|
|
|
+
|
|
|
+ // 将结果缓存到 Redis,设置过期时间为 10 分钟
|
|
|
+ valueOps.set(cacheKey, res, 10, TimeUnit.MINUTES);
|
|
|
+
|
|
|
return Result.OK(res);
|
|
|
}
|
|
|
|
|
@@ -198,10 +235,27 @@ public class HomePageDataController {
|
|
|
* @return
|
|
|
*/
|
|
|
@AutoLog(value = "尖峰时段违规启动设备统计")
|
|
|
- @ApiOperation(value="尖峰时段违规启动设备统计", notes="尖峰时段违规启动设备统计")
|
|
|
+ @ApiOperation(value = "尖峰时段违规启动设备统计", notes = "尖峰时段违规启动设备统计")
|
|
|
@GetMapping(value = "/illegalActivation")
|
|
|
public Result<Map<String, Integer>> illegalActivation() {
|
|
|
+ String cacheKey = "illegalActivation:statistics"; // 缓存的 key
|
|
|
+ ValueOperations<String, Object> valueOps = redisTemplate.opsForValue();
|
|
|
+
|
|
|
+ // 从 Redis 中尝试获取缓存数据
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ Map<String, Integer> cachedData = (Map<String, Integer>) valueOps.get(cacheKey);
|
|
|
+
|
|
|
+ if (cachedData != null) {
|
|
|
+ // 如果缓存中有数据,直接返回
|
|
|
+ return Result.OK(cachedData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果缓存中没有数据,查询服务
|
|
|
Map<String, Integer> res = homePageDataService.illegalActivation();
|
|
|
+
|
|
|
+ // 将结果缓存到 Redis,设置过期时间为 10 分钟
|
|
|
+ valueOps.set(cacheKey, res, 10, TimeUnit.MINUTES);
|
|
|
+
|
|
|
return Result.OK(res);
|
|
|
}
|
|
|
|
|
@@ -229,10 +283,27 @@ public class HomePageDataController {
|
|
|
* @return
|
|
|
*/
|
|
|
@AutoLog(value = "最新消息")
|
|
|
- @ApiOperation(value="最新消息", notes="最新消息")
|
|
|
+ @ApiOperation(value = "最新消息", notes = "最新消息")
|
|
|
@GetMapping(value = "/lastestMsg")
|
|
|
public Result<List<String>> lastestMsg() {
|
|
|
+ String cacheKey = "latestMsg:data"; // 缓存的 key
|
|
|
+ ValueOperations<String, Object> valueOps = redisTemplate.opsForValue();
|
|
|
+
|
|
|
+ // 尝试从 Redis 获取缓存数据
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<String> cachedData = (List<String>) valueOps.get(cacheKey);
|
|
|
+
|
|
|
+ if (cachedData != null) {
|
|
|
+ // 如果缓存存在,直接返回
|
|
|
+ return Result.OK(cachedData);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 缓存不存在,调用服务查询
|
|
|
List<String> res = homePageDataService.latestMsg();
|
|
|
+
|
|
|
+ // 将结果存入 Redis 并设置过期时间为 10 分钟
|
|
|
+ valueOps.set(cacheKey, res, 10, TimeUnit.MINUTES);
|
|
|
+
|
|
|
return Result.OK(res);
|
|
|
}
|
|
|
|