匹配新的rediskey前缀
This commit is contained in:
Vendored
+2
-8
@@ -1,6 +1,5 @@
|
||||
package xtools.app.common.cache.enums;
|
||||
|
||||
import xtools.app.common.config.AppCommonConfig;
|
||||
import xtools.boot.cache.redis.enums.BaseCacheEnum;
|
||||
import xtools.core.extend.TemplateUtils;
|
||||
|
||||
@@ -61,11 +60,6 @@ public enum AppCache implements BaseCacheEnum {
|
||||
// 系统日志按级别按天统计数
|
||||
COUNT_SYS_LOG("count:sys-log:{}:{}", 3 * 24 * 60 * 60L);
|
||||
|
||||
/**
|
||||
* 系统缓存前缀
|
||||
*/
|
||||
private final static String SYS_CACHE_PREFIX = AppCommonConfig.APP_CACHE_PREFIX;
|
||||
|
||||
/**
|
||||
* key
|
||||
*/
|
||||
@@ -94,7 +88,7 @@ public enum AppCache implements BaseCacheEnum {
|
||||
* @return 缓存 key
|
||||
*/
|
||||
public String key(Object... param) {
|
||||
return SYS_CACHE_PREFIX + TemplateUtils.format(key, param);
|
||||
return TemplateUtils.format(key, param);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +98,7 @@ public enum AppCache implements BaseCacheEnum {
|
||||
*/
|
||||
@Override
|
||||
public String key() {
|
||||
return SYS_CACHE_PREFIX + key;
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
-5
@@ -18,9 +18,4 @@ public class AppCommonConfig {
|
||||
*/
|
||||
public static final String APP_SYS_LOG_ES_INDEX_NAME = "sys-log";
|
||||
|
||||
/**
|
||||
* 系统缓存前缀
|
||||
*/
|
||||
public final static String APP_CACHE_PREFIX = "xtools-app:";
|
||||
|
||||
}
|
||||
|
||||
+5
-4
@@ -33,11 +33,12 @@ public interface LogBusService {
|
||||
String total();
|
||||
|
||||
/**
|
||||
* 获取指定日期的日志统计数据(按级别,从Redis读取)
|
||||
* 获取指定日期的日志统计数据
|
||||
*
|
||||
* @param time 时间
|
||||
* @return 日志级别编码 -> 数量
|
||||
* @param time 时间
|
||||
* @param deleteKey 删除缓存
|
||||
* @return 统计数据
|
||||
*/
|
||||
Map<Integer, Long> getTotalByDay(Instant time);
|
||||
Map<Integer, Long> getTotalByDay(Instant time, boolean deleteKey);
|
||||
|
||||
}
|
||||
|
||||
@@ -24,3 +24,7 @@ spring:
|
||||
max-wait: -1
|
||||
# 连接池中的最小空闲连接
|
||||
min-idle: 5
|
||||
# 自定义Redis配置
|
||||
redis:
|
||||
# key前缀
|
||||
key-prev: ${REDIS_KEY_PREV:xtools-app}
|
||||
+7
-3
@@ -177,7 +177,7 @@ public class LogBusServiceImpl implements LogBusService {
|
||||
// 前一天时间
|
||||
Instant yesterday = CalendarUtils.yesterday();
|
||||
// 获取前一天的统计数据
|
||||
Map<Integer, Long> totalMap = getTotalByDay(yesterday);
|
||||
Map<Integer, Long> totalMap = getTotalByDay(yesterday, true);
|
||||
if (CollectionUtils.isEmpty(totalMap)) {
|
||||
return "执行完成,前一天日志统计数据为空";
|
||||
}
|
||||
@@ -204,11 +204,12 @@ public class LogBusServiceImpl implements LogBusService {
|
||||
/**
|
||||
* 获取指定日期的日志统计数据
|
||||
*
|
||||
* @param time 时间
|
||||
* @param time 时间
|
||||
* @param deleteKey 删除缓存
|
||||
* @return 统计数据
|
||||
*/
|
||||
@Override
|
||||
public Map<Integer, Long> getTotalByDay(Instant time) {
|
||||
public Map<Integer, Long> getTotalByDay(Instant time, boolean deleteKey) {
|
||||
Map<Integer, Long> result = new HashMap<>(CP_NUM16);
|
||||
if (Objects.isNull(time)) {
|
||||
return result;
|
||||
@@ -221,6 +222,9 @@ public class LogBusServiceImpl implements LogBusService {
|
||||
// 获取数量
|
||||
Long count = redisService.get(key, Long.class);
|
||||
result.put(level.code(), Objects.nonNull(count) ? count : 0L);
|
||||
if (deleteKey) {
|
||||
redisService.del(key);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ public class SysLogTotalServiceImpl implements SysLogTotalService {
|
||||
|
||||
/**
|
||||
* 获取统计信息
|
||||
* <p>小于今天的数据从数据库获取;包含今天的数据从Redis获取(今天尚未落库)</p>
|
||||
* 小于今天的数据从数据库获取;包含今天的数据从Redis获取(今天尚未落库)
|
||||
*
|
||||
* @param req 统计请求(时间范围)
|
||||
* @return 统计信息
|
||||
@@ -71,7 +71,7 @@ public class SysLogTotalServiceImpl implements SysLogTotalService {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now >= startTime.toEpochMilli() && now <= endTime.toEpochMilli()) {
|
||||
Instant day = LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant();
|
||||
Map<Integer, Long> totalMap = logBusService.getTotalByDay(day);
|
||||
Map<Integer, Long> totalMap = logBusService.getTotalByDay(day, false);
|
||||
Long defCount = 0L;
|
||||
// 今天的数据追加到末尾
|
||||
list.add(SysLogTotalStatsResp.builder()
|
||||
|
||||
Reference in New Issue
Block a user