sonarqube质量修复

This commit is contained in:
gaoqr
2024-10-09 12:04:54 +08:00
parent 2e96dd8173
commit 220d0ff28a
36 changed files with 242 additions and 513 deletions
@@ -1,7 +1,8 @@
package com.cf.imes.framework.redis.core;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
@@ -28,11 +29,11 @@ public class TimeoutRedisCacheManager extends RedisCacheManager {
@Override
protected RedisCache createRedisCache(String name, RedisCacheConfiguration cacheConfig) {
if (StrUtil.isEmpty(name)) {
if (CharSequenceUtil.isEmpty(name)) {
return super.createRedisCache(name, cacheConfig);
}
// 如果使用 # 分隔,大小不为 2,则说明不使用自定义过期时间
String[] names = StrUtil.splitToArray(name, SPLIT);
String[] names = CharSequenceUtil.splitToArray(name, SPLIT);
if (names.length != 2) {
return super.createRedisCache(name, cacheConfig);
}
@@ -40,7 +41,7 @@ public class TimeoutRedisCacheManager extends RedisCacheManager {
// 核心:通过修改 cacheConfig 的过期时间,实现自定义过期时间
if (cacheConfig != null) {
// 移除 # 后面的 : 以及后面的内容,避免影响解析
names[1] = StrUtil.subBefore(names[1], StrUtil.COLON, false);
names[1] = CharSequenceUtil.subBefore(names[1], StrPool.COLON, false);
// 解析时间
Duration duration = parseDuration(names[1]);
cacheConfig = cacheConfig.entryTtl(duration);
@@ -55,7 +56,7 @@ public class TimeoutRedisCacheManager extends RedisCacheManager {
* @return 过期时间 Duration
*/
private Duration parseDuration(String ttlStr) {
String timeUnit = StrUtil.subSuf(ttlStr, -1);
String timeUnit = CharSequenceUtil.subSuf(ttlStr, -1);
switch (timeUnit) {
case "d":
return Duration.ofDays(removeDurationSuffix(ttlStr));
@@ -77,7 +78,7 @@ public class TimeoutRedisCacheManager extends RedisCacheManager {
* @return 时间
*/
private Long removeDurationSuffix(String ttlStr) {
return NumberUtil.parseLong(StrUtil.sub(ttlStr, 0, ttlStr.length() - 1));
return NumberUtil.parseLong(CharSequenceUtil.sub(ttlStr, 0, ttlStr.length() - 1));
}
}