mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
add 同步ruoyi 新增缓存列表菜单功能
This commit is contained in:
@ -6,6 +6,7 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.enums.CaptchaType;
|
||||
@ -60,7 +61,7 @@ public class CaptchaController {
|
||||
if (smsProperties.getEnabled()) {
|
||||
R.fail("当前系统没有开启短信功能!");
|
||||
}
|
||||
String key = Constants.CAPTCHA_CODE_KEY + phonenumber;
|
||||
String key = CacheConstants.CAPTCHA_CODE_KEY + phonenumber;
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
// 验证码模板id 自行处理 (查数据库或写死均可)
|
||||
@ -90,7 +91,7 @@ public class CaptchaController {
|
||||
}
|
||||
// 保存验证码信息
|
||||
String uuid = IdUtil.simpleUUID();
|
||||
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
||||
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
|
||||
// 生成验证码
|
||||
CaptchaType captchaType = captchaProperties.getType();
|
||||
boolean isMath = CaptchaType.MATH == captchaType;
|
||||
|
@ -1,17 +1,17 @@
|
||||
package com.ruoyi.web.controller.monitor;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.SysCache;
|
||||
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.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -28,6 +28,19 @@ public class CacheController {
|
||||
|
||||
private final RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
private final static List<SysCache> CACHES = new ArrayList<>();
|
||||
|
||||
static {
|
||||
CACHES.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "用户信息"));
|
||||
CACHES.add(new SysCache(CacheConstants.ONLINE_TOKEN_KEY, "在线用户"));
|
||||
CACHES.add(new SysCache(CacheConstants.LOGIN_ERROR, "登陆错误"));
|
||||
CACHES.add(new SysCache(CacheConstants.SYS_CONFIG_KEY, "配置信息"));
|
||||
CACHES.add(new SysCache(CacheConstants.SYS_DICT_KEY, "数据字典"));
|
||||
CACHES.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "验证码"));
|
||||
CACHES.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交"));
|
||||
CACHES.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理"));
|
||||
}
|
||||
|
||||
@ApiOperation("获取缓存监控详细信息")
|
||||
@SaCheckPermission("monitor:cache:list")
|
||||
@GetMapping()
|
||||
@ -53,4 +66,55 @@ public class CacheController {
|
||||
result.put("commandStats", pieList);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@ApiOperation("获取缓存名称列表")
|
||||
@SaCheckPermission("monitor:cache:list")
|
||||
@GetMapping("/getNames")
|
||||
public R<List<SysCache>> cache() {
|
||||
return R.ok(CACHES);
|
||||
}
|
||||
|
||||
@ApiOperation("获取KEYS基于缓存名")
|
||||
@SaCheckPermission("monitor:cache:list")
|
||||
@GetMapping("/getKeys/{cacheName}")
|
||||
public R<Set<String>> getCacheKeys(@PathVariable String cacheName) {
|
||||
Set<String> cacheKyes = redisTemplate.keys(cacheName + "*");
|
||||
return R.ok(cacheKyes);
|
||||
}
|
||||
|
||||
@ApiOperation("获取值基于缓存名与KEY")
|
||||
@SaCheckPermission("monitor:cache:list")
|
||||
@GetMapping("/getValue/{cacheName}/{cacheKey}")
|
||||
public R<SysCache> getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey) {
|
||||
String cacheValue = redisTemplate.opsForValue().get(cacheKey);
|
||||
SysCache sysCache = new SysCache(cacheName, cacheKey, cacheValue);
|
||||
return R.ok(sysCache);
|
||||
}
|
||||
|
||||
@ApiOperation("清空缓存名")
|
||||
@SaCheckPermission("monitor:cache:list")
|
||||
@DeleteMapping("/clearCacheName/{cacheName}")
|
||||
public R<Void> clearCacheName(@PathVariable String cacheName) {
|
||||
Collection<String> cacheKeys = redisTemplate.keys(cacheName + "*");
|
||||
redisTemplate.delete(cacheKeys);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("清空缓存KEY")
|
||||
@SaCheckPermission("monitor:cache:list")
|
||||
@DeleteMapping("/clearCacheKey/{cacheKey}")
|
||||
public R<Void> clearCacheKey(@PathVariable String cacheKey) {
|
||||
redisTemplate.delete(cacheKey);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("清空所有缓存")
|
||||
@SaCheckPermission("monitor:cache:list")
|
||||
@DeleteMapping("/clearCacheAll")
|
||||
public R<Void> clearCacheAll() {
|
||||
Collection<String> cacheKeys = redisTemplate.keys("*");
|
||||
redisTemplate.delete(cacheKeys);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.domain.dto.UserOnlineDTO;
|
||||
@ -43,12 +43,12 @@ public class SysUserOnlineController extends BaseController {
|
||||
List<String> keys = StpUtil.searchTokenValue("", -1, 0);
|
||||
List<UserOnlineDTO> userOnlineDTOList = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
String token = key.replace(Constants.LOGIN_TOKEN_KEY, "");
|
||||
String token = key.replace(CacheConstants.LOGIN_TOKEN_KEY, "");
|
||||
// 如果已经过期则踢下线
|
||||
if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < 0) {
|
||||
continue;
|
||||
}
|
||||
userOnlineDTOList.add(RedisUtils.getCacheObject(Constants.ONLINE_TOKEN_KEY + token));
|
||||
userOnlineDTOList.add(RedisUtils.getCacheObject(CacheConstants.ONLINE_TOKEN_KEY + token));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) {
|
||||
userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline ->
|
||||
|
Reference in New Issue
Block a user