update 优化冗余分隔符

This commit is contained in:
AprilWind
2026-06-04 15:08:13 +08:00
parent f52bb99419
commit e08160afb6
13 changed files with 196 additions and 197 deletions
@@ -23,6 +23,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
public static final String SLASH = "/";
public static final String COLON = ":";
private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();
@Deprecated
@@ -112,13 +112,13 @@ public class RateLimiterAspect {
key = expression.getValue(context, String.class);
}
StringBuilder stringBuffer = new StringBuilder(GlobalConstants.RATE_LIMIT_KEY);
stringBuffer.append(ServletUtils.getRequest().getRequestURI()).append(":");
stringBuffer.append(ServletUtils.getRequest().getRequestURI()).append(StringUtils.COLON);
if (rateLimiter.limitType() == LimitType.IP) {
// 获取请求ip
stringBuffer.append(ServletUtils.getClientIP()).append(":");
stringBuffer.append(ServletUtils.getClientIP()).append(StringUtils.COLON);
} else if (rateLimiter.limitType() == LimitType.CLUSTER) {
// 获取客户端实例id
stringBuffer.append(RedisUtils.getClient().getId()).append(":");
stringBuffer.append(RedisUtils.getClient().getId()).append(StringUtils.COLON);
}
return stringBuffer.append(key).toString();
}
@@ -62,7 +62,7 @@ public class RepeatSubmitAspect {
// 唯一值(没有消息头则使用请求地址)
String submitKey = StringUtils.trimToEmpty(request.getHeader(SaManager.getConfig().getTokenName()));
submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
submitKey = SecureUtil.md5(submitKey + StringUtils.COLON + nowParams);
// 唯一标识(指定key + url + 消息头)
String cacheRepeatKey = GlobalConstants.REPEAT_SUBMIT_KEY + url + submitKey;
if (RedisUtils.setObjectIfAbsent(cacheRepeatKey, "", Duration.ofMillis(interval))) {
@@ -21,7 +21,7 @@ public class KeyPrefixHandler implements NameMapper {
*/
public KeyPrefixHandler(String keyPrefix) {
//前缀为空 则返回空前缀
this.keyPrefix = StringUtils.isBlank(keyPrefix) ? "" : keyPrefix + ":";
this.keyPrefix = StringUtils.isBlank(keyPrefix) ? "" : keyPrefix + StringUtils.COLON;
}
/**
@@ -1,5 +1,6 @@
package org.dromara.common.redis.manager;
import org.dromara.common.core.utils.StringUtils;
import org.springframework.cache.Cache;
import java.util.concurrent.Callable;
@@ -55,7 +56,7 @@ public class CaffeineCacheDecorator implements Cache {
* @return 唯一键
*/
public String getUniqueKey(Object key) {
return name + ":" + key;
return name + StringUtils.COLON + key;
}
/**
@@ -175,7 +176,7 @@ public class CaffeineCacheDecorator implements Cache {
* 清理当前缓存命名空间下的本地一级缓存。
*/
private void clearLocalCache() {
String prefix = name + ":";
String prefix = name + StringUtils.COLON;
caffeine.asMap().keySet().removeIf(key -> key instanceof String cacheKey && cacheKey.startsWith(prefix));
}
@@ -4,6 +4,7 @@ import cn.dev33.satoken.dao.auto.SaTokenDaoBySessionFollowObject;
import cn.dev33.satoken.util.SaFoxUtil;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.redis.utils.RedisUtils;
import java.time.Duration;
@@ -157,7 +158,7 @@ public class PlusSaTokenDao implements SaTokenDaoBySessionFollowObject {
@Override
public List<String> searchData(String prefix, String keyword, int start, int size, boolean sortType) {
String pattern = prefix + "*" + keyword + "*";
String cacheKey = pattern + start + ":" + size + ":" + sortType;
String cacheKey = pattern + start + StringUtils.COLON + size + StringUtils.COLON + sortType;
return (List<String>) CAFFEINE.get(cacheKey, k -> {
Collection<String> keys = RedisUtils.keys(pattern);
List<String> list = new ArrayList<>(keys);
@@ -130,7 +130,7 @@ public class SecurityConfig implements WebMvcConfigurer {
return new SaServletFilter()
.addInclude("/actuator", "/actuator/**")
.setAuth(obj -> {
SaHttpBasicUtil.check(username + ":" + password);
SaHttpBasicUtil.check(username + StringUtils.COLON + password);
})
.setError(e -> {
HttpServletResponse response = ServletUtils.getResponse();
@@ -48,7 +48,7 @@ public class SysUserOnlineController extends BaseController {
// 获取所有未过期的 token
Collection<String> keys = RedisUtils.keys(CacheNames.ONLINE_TOKEN_KEY + "*");
List<Supplier<UserOnlineDTO>> suppliers = keys.stream().map(key -> (Supplier<UserOnlineDTO>) () -> {
String token = StringUtils.substringAfterLast(key, ":");
String token = StringUtils.substringAfterLast(key, StringUtils.COLON);
// 如果已经过期则跳过
if (StpUtil.stpLogic.getTokenActiveTimeoutByToken(token) < -1) {
return null;
@@ -10,6 +10,7 @@ import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
@@ -24,6 +25,8 @@ import java.util.List;
@TableName("sys_menu")
public class SysMenu extends BaseEntity {
@Serial
private static final long serialVersionUID = 6967394714839655267L;
/**
* 菜单ID
*/
@@ -195,7 +198,7 @@ public class SysMenu extends BaseEntity {
* 内链域名特殊字符替换
*/
public static String innerLinkReplaceEach(String path) {
return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, ".", ":"},
return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, ".", StringUtils.COLON},
new String[]{"", "", "", "/", "/"});
}
}
@@ -546,7 +546,7 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
}
// 角色关联的在线用户量过大会导致redis阻塞卡顿 谨慎操作
keys.parallelStream().forEach(key -> {
String token = StringUtils.substringAfterLast(key, ":");
String token = StringUtils.substringAfterLast(key, StringUtils.COLON);
// 如果已经过期则跳过
if (StpUtil.stpLogic.getTokenActiveTimeoutByToken(token) < -1) {
return;
@@ -582,7 +582,7 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
}
// 角色关联的在线用户量过大会导致redis阻塞卡顿 谨慎操作
keys.parallelStream().forEach(key -> {
String token = StringUtils.substringAfterLast(key, ":");
String token = StringUtils.substringAfterLast(key, StringUtils.COLON);
// 如果已经过期则跳过
if (StpUtil.stpLogic.getTokenActiveTimeoutByToken(token) < -1) {
return;
@@ -34,7 +34,6 @@ import org.dromara.workflow.service.IFlwNodeExtService;
import org.dromara.workflow.service.IFlwTaskService;
import org.springframework.stereotype.Component;
import java.io.Serial;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -51,10 +50,6 @@ import java.util.Set;
@RequiredArgsConstructor
public class WorkflowGlobalListener implements GlobalListener {
private static final String NODE_KEY_SEPARATOR = ":";
@Serial
private static final long serialVersionUID = -5133036757491932497L;
private final IFlwTaskService flwTaskService;
private final IFlwInstanceService flwInstanceService;
private final FlowProcessEventHandler flowProcessEventHandler;
@@ -145,7 +140,7 @@ public class WorkflowGlobalListener implements GlobalListener {
* @param taskStatus 任务状态
*/
private void processTaskPermission(Map<String, Object> variable, Task flowTask, String taskStatus) {
String nodeKey = taskStatus + NODE_KEY_SEPARATOR + flowTask.getNodeCode();
String nodeKey = taskStatus + StringUtils.COLON + flowTask.getNodeCode();
// 检查是否存在状态相关的变量
if (!variable.containsKey(nodeKey)) {
@@ -42,7 +42,6 @@ import java.util.stream.Collectors;
public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, HandlerSelectService {
private static final String DEFAULT_GROUP_NAME = "默认分组";
private static final String STORAGE_ID_SEPARATOR = ":";
private final TaskAssigneeService taskAssigneeService;
private final UserService userService;
@@ -313,11 +312,11 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
return Pair.of(TaskAssigneeEnum.SPEL, storageId);
}
try {
String[] parts = storageId.split(STORAGE_ID_SEPARATOR, 2);
String[] parts = storageId.split(StringUtils.COLON, 2);
if (parts.length < 2) {
return Pair.of(TaskAssigneeEnum.USER, parts[0]);
} else {
TaskAssigneeEnum type = TaskAssigneeEnum.fromCode(parts[0] + STORAGE_ID_SEPARATOR);
TaskAssigneeEnum type = TaskAssigneeEnum.fromCode(parts[0] + StringUtils.COLON);
return Pair.of(type, parts[1]);
}
} catch (Exception e) {
@@ -22,8 +22,8 @@ import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.query.QueryBuilder;
import org.dromara.common.mybatis.utils.IdGeneratorUtil;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.api.domain.UserDTO;
import org.dromara.system.api.UserService;
import org.dromara.system.api.domain.UserDTO;
import org.dromara.warm.flow.core.FlowEngine;
import org.dromara.warm.flow.core.dto.FlowParams;
import org.dromara.warm.flow.core.entity.*;
@@ -76,8 +76,6 @@ import static org.dromara.workflow.common.constant.FlowConstant.*;
@Service
public class FlwTaskServiceImpl implements IFlwTaskService {
private static final String NODE_KEY_SEPARATOR = ":";
private final TaskService taskService;
private final InsService insService;
private final DefService defService;
@@ -317,12 +315,12 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
List<String> variableUserIds = StringUtils.str2List(userIds, StringUtils.SEPARATOR, true, true);
hashSet.addAll(popUserIds);
hashSet.addAll(variableUserIds);
map.put(TaskStatusEnum.PASS.getStatus() + NODE_KEY_SEPARATOR + entry.getKey(), StringUtils.joinComma(hashSet));
map.put(TaskStatusEnum.BACK.getStatus() + NODE_KEY_SEPARATOR + entry.getKey(), StringUtils.joinComma(hashSet));
map.put(TaskStatusEnum.PASS.getStatus() + StringUtils.COLON + entry.getKey(), StringUtils.joinComma(hashSet));
map.put(TaskStatusEnum.BACK.getStatus() + StringUtils.COLON + entry.getKey(), StringUtils.joinComma(hashSet));
}
} else {
map.put(TaskStatusEnum.PASS.getStatus() + NODE_KEY_SEPARATOR + entry.getKey(), entry.getValue());
map.put(TaskStatusEnum.BACK.getStatus() + NODE_KEY_SEPARATOR + entry.getKey(), entry.getValue());
map.put(TaskStatusEnum.PASS.getStatus() + StringUtils.COLON + entry.getKey(), entry.getValue());
map.put(TaskStatusEnum.BACK.getStatus() + StringUtils.COLON + entry.getKey(), entry.getValue());
}
}
return map;