|
|
@@ -1,20 +1,30 @@
|
|
|
package com.ruoyi.web.controller.monitor;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.ruoyi.common.annotation.Log;
|
|
|
import com.ruoyi.common.constant.CacheConstants;
|
|
|
import com.ruoyi.common.constant.CacheNames;
|
|
|
import com.ruoyi.common.core.domain.R;
|
|
|
+import com.ruoyi.common.core.domain.dto.UserOnlineDTO;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
+import com.ruoyi.common.enums.BusinessType;
|
|
|
import com.ruoyi.common.utils.JsonUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.common.utils.redis.CacheUtils;
|
|
|
import com.ruoyi.common.utils.redis.RedisUtils;
|
|
|
import com.ruoyi.system.domain.SysCache;
|
|
|
+import com.ruoyi.system.domain.SysUserOnline;
|
|
|
+import com.ruoyi.system.domain.vo.CacheDataVo;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.redisson.spring.data.connection.RedissonConnectionFactory;
|
|
|
import org.springframework.data.redis.connection.RedisConnection;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -72,6 +82,34 @@ public class CacheController {
|
|
|
return R.ok(result);
|
|
|
}
|
|
|
|
|
|
+ @Log(title = "缓存导出", businessType = BusinessType.EXPORT)
|
|
|
+ @PostMapping("/export")
|
|
|
+ public void export(HttpServletResponse response) {
|
|
|
+
|
|
|
+ RedisConnection connection = connectionFactory.getConnection();
|
|
|
+ Properties info = connection.info();
|
|
|
+ Properties commandStats = connection.info("commandstats");
|
|
|
+ Long dbSize = connection.dbSize();
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>(3);
|
|
|
+ result.put("info", info);
|
|
|
+ result.put("dbSize", dbSize);
|
|
|
+ List<CacheDataVo> cacheDataVoList = new ArrayList<>();
|
|
|
+
|
|
|
+// List<Map<String, String>> pieList = new ArrayList<>();
|
|
|
+ if (commandStats != null) {
|
|
|
+ commandStats.stringPropertyNames().forEach(key -> {
|
|
|
+ Map<String, String> data = new HashMap<>(2);
|
|
|
+ String property = commandStats.getProperty(key);
|
|
|
+ CacheDataVo vo = new CacheDataVo();
|
|
|
+ vo.setName(StringUtils.removeStart(key, "cmdstat_"));
|
|
|
+ vo.setValue(StringUtils.substringBetween(property, "calls=", ",usec"));
|
|
|
+ cacheDataVoList.add(vo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ ExcelUtil.exportExcel(cacheDataVoList, "用户数据", CacheDataVo.class, response);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取缓存监控缓存名列表
|
|
|
*/
|
|
|
@@ -81,6 +119,12 @@ public class CacheController {
|
|
|
return R.ok(CACHES);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Log(title = "缓存列表导出", businessType = BusinessType.EXPORT)
|
|
|
+ @PostMapping("/listexport")
|
|
|
+ public void exportlist(HttpServletResponse response) {
|
|
|
+ ExcelUtil.exportExcel(CACHES, "用户数据", SysCache.class, response);
|
|
|
+ }
|
|
|
/**
|
|
|
* 获取缓存监控Key列表
|
|
|
*
|
|
|
@@ -92,9 +136,12 @@ public class CacheController {
|
|
|
Collection<String> cacheKeys = new HashSet<>(0);
|
|
|
if (isCacheNames(cacheName)) {
|
|
|
Set<Object> keys = CacheUtils.keys(cacheName);
|
|
|
- if (CollUtil.isNotEmpty(keys)) {
|
|
|
- cacheKeys = keys.stream().map(Object::toString).collect(Collectors.toList());
|
|
|
- }
|
|
|
+ try{
|
|
|
+ if (CollUtil.isNotEmpty(keys)) {
|
|
|
+ cacheKeys = keys.stream().map(Object::toString).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }catch (Exception e){}
|
|
|
+
|
|
|
} else {
|
|
|
cacheKeys = RedisUtils.keys(cacheName + "*");
|
|
|
}
|