From 4cb8e239ae86c525c2087eaef8b8381c6b6663de Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期一, 13 六月 2022 17:31:45 +0800
Subject: [PATCH] !186 fix: 修复用户注销时,没有记录注销日志 Merge pull request !186 from 沫离/dev

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java |   48 +++++++++++++++++++++++++++---------------------
 1 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java
index 48e95dd..21fbd20 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java
@@ -1,11 +1,14 @@
 package com.ruoyi.web.controller.monitor;
 
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.core.domain.AjaxResult;
-import org.springframework.beans.factory.annotation.Autowired;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.redis.connection.RedisServerCommands;
 import org.springframework.data.redis.core.RedisCallback;
 import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -15,36 +18,39 @@
 /**
  * 缂撳瓨鐩戞帶
  *
- * @author ruoyi
+ * @author Lion Li
  */
+@Api(value = "缂撳瓨鐩戞帶", tags = {"缂撳瓨鐩戞帶绠$悊"})
+@RequiredArgsConstructor
 @RestController
 @RequestMapping("/monitor/cache")
-public class CacheController
-{
-    @Autowired
-    private RedisTemplate<String, String> redisTemplate;
+public class CacheController {
 
-    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+    private final RedisTemplate<String, String> redisTemplate;
+
+    @ApiOperation("鑾峰彇缂撳瓨鐩戞帶璇︾粏淇℃伅")
+    @SaCheckPermission("monitor:cache:list")
     @GetMapping()
-    public AjaxResult getInfo() throws Exception
-    {
-        Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info());
+    public R<Map<String, Object>> getInfo() throws Exception {
+        Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) RedisServerCommands::info);
         Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats"));
-        Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize());
+        Object dbSize = redisTemplate.execute((RedisCallback<Object>) RedisServerCommands::dbSize);
 
         Map<String, Object> result = new HashMap<>(3);
         result.put("info", info);
         result.put("dbSize", dbSize);
 
         List<Map<String, String>> pieList = new ArrayList<>();
-        commandStats.stringPropertyNames().forEach(key -> {
-            Map<String, String> data = new HashMap<>(2);
-            String property = commandStats.getProperty(key);
-            data.put("name", StringUtils.removePrefix(key, "cmdstat_"));
-            data.put("value", StringUtils.subBetween(property, "calls=", ",usec"));
-            pieList.add(data);
-        });
+        if (commandStats != null) {
+            commandStats.stringPropertyNames().forEach(key -> {
+                Map<String, String> data = new HashMap<>(2);
+                String property = commandStats.getProperty(key);
+                data.put("name", StringUtils.removeStart(key, "cmdstat_"));
+                data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
+                pieList.add(data);
+            });
+        }
         result.put("commandStats", pieList);
-        return AjaxResult.success(result);
+        return R.ok(result);
     }
 }

--
Gitblit v1.9.3