From a6fb88d74c20cc28043d75e8a5097fce49cf9a78 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期五, 15 十月 2021 15:19:42 +0800 Subject: [PATCH] update [重大更新]全业务 增加 接口文档注解 格式化代码 --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java | 41 ++++++++++++++++++++++++----------------- 1 files changed, 24 insertions(+), 17 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 66749ef..ef81c99 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,8 +1,12 @@ package com.ruoyi.web.controller.monitor; -import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.StringUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; +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; @@ -15,35 +19,38 @@ /** * 缂撳瓨鐩戞帶 * - * @author ruoyi + * @author Lion Li */ +@Api(value = "缂撳瓨鐩戞帶", tags = {"缂撳瓨鐩戞帶绠$悊"}) +@RequiredArgsConstructor(onConstructor_ = @Autowired) @RestController @RequestMapping("/monitor/cache") -public class CacheController -{ - @Autowired - private RedisTemplate<String, String> redisTemplate; +public class CacheController { + private final RedisTemplate<String, String> redisTemplate; + + @ApiOperation("鑾峰彇缂撳瓨鐩戞帶璇︾粏淇℃伅") @PreAuthorize("@ss.hasPermi('monitor:cache:list')") @GetMapping() - public AjaxResult getInfo() throws Exception - { - Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info()); + public AjaxResult<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.removeStart(key, "cmdstat_")); - data.put("value", StringUtils.substringBetween(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); } -- Gitblit v1.9.3