mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-09 20:57:21 +08:00
style: 优化常量命名风格,XxxConsts => XxxConstants
This commit is contained in:
@@ -42,7 +42,7 @@ import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||
import top.charles7c.cnadmin.common.model.query.SortQuery;
|
||||
import top.charles7c.cnadmin.common.model.resp.PageDataResp;
|
||||
import top.charles7c.cnadmin.common.model.resp.R;
|
||||
import top.charles7c.continew.starter.core.constant.StringConsts;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
/**
|
||||
* 控制器基类
|
||||
@@ -212,7 +212,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
|
||||
private void checkPermission(Api api) {
|
||||
CrudRequestMapping crudRequestMapping = this.getClass().getDeclaredAnnotation(CrudRequestMapping.class);
|
||||
String path = crudRequestMapping.value();
|
||||
String permissionPrefix = String.join(StringConsts.COLON, StrUtil.splitTrim(path, StringConsts.SLASH));
|
||||
String permissionPrefix = String.join(StringConstants.COLON, StrUtil.splitTrim(path, StringConstants.SLASH));
|
||||
StpUtil.checkPermission(String.format("%s:%s", permissionPrefix, api.name().toLowerCase()));
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import top.charles7c.cnadmin.common.config.properties.LocalStorageProperties;
|
||||
import top.charles7c.continew.starter.core.constant.StringConsts;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
/**
|
||||
* Web MVC 配置
|
||||
@@ -52,8 +52,8 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
LocalStorageProperties.LocalStoragePath path = localStorageProperties.getPath();
|
||||
String avatarUtl = "file:" + path.getAvatar().replace(StringConsts.BACKSLASH, StringConsts.SLASH);
|
||||
String fileUrl = "file:" + path.getFile().replace(StringConsts.BACKSLASH, StringConsts.SLASH);
|
||||
String avatarUtl = "file:" + path.getAvatar().replace(StringConstants.BACKSLASH, StringConstants.SLASH);
|
||||
String fileUrl = "file:" + path.getFile().replace(StringConstants.BACKSLASH, StringConstants.SLASH);
|
||||
registry.addResourceHandler(localStorageProperties.getFilePattern()).addResourceLocations(fileUrl)
|
||||
.setCachePeriod(0);
|
||||
registry.addResourceHandler(localStorageProperties.getAvatarPattern()).addResourceLocations(avatarUtl)
|
||||
|
@@ -27,7 +27,7 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.IBaseEnum;
|
||||
import top.charles7c.continew.starter.core.constant.StringConsts;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
/**
|
||||
* Easy Excel 枚举基类转换器
|
||||
@@ -63,7 +63,7 @@ public class ExcelBaseEnumConverter implements Converter<IBaseEnum<Integer>> {
|
||||
public WriteCellData<String> convertToExcelData(IBaseEnum<Integer> value, ExcelContentProperty contentProperty,
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
if (null == value) {
|
||||
return new WriteCellData<>(StringConsts.EMPTY);
|
||||
return new WriteCellData<>(StringConstants.EMPTY);
|
||||
}
|
||||
return new WriteCellData<>(value.getDescription());
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ package top.charles7c.cnadmin.common.config.justauth;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import top.charles7c.cnadmin.common.constant.CacheConsts;
|
||||
import top.charles7c.cnadmin.common.constant.CacheConstants;
|
||||
import top.charles7c.continew.starter.cache.redisson.util.RedisUtils;
|
||||
|
||||
import me.zhyd.oauth.cache.AuthStateCache;
|
||||
@@ -42,7 +42,7 @@ public class JustAuthRedisStateCache implements AuthStateCache {
|
||||
@Override
|
||||
public void cache(String key, String value) {
|
||||
// 参考:在 JustAuth 中,内置了一个基于 map 的 state 缓存器,默认缓存有效期为 3 分钟
|
||||
RedisUtils.set(RedisUtils.formatKey(CacheConsts.SOCIAL_AUTH_STATE_KEY_PREFIX, key), value,
|
||||
RedisUtils.set(RedisUtils.formatKey(CacheConstants.SOCIAL_AUTH_STATE_KEY_PREFIX, key), value,
|
||||
Duration.ofMinutes(3));
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class JustAuthRedisStateCache implements AuthStateCache {
|
||||
*/
|
||||
@Override
|
||||
public void cache(String key, String value, long timeout) {
|
||||
RedisUtils.set(RedisUtils.formatKey(CacheConsts.SOCIAL_AUTH_STATE_KEY_PREFIX, key), value,
|
||||
RedisUtils.set(RedisUtils.formatKey(CacheConstants.SOCIAL_AUTH_STATE_KEY_PREFIX, key), value,
|
||||
Duration.ofMillis(timeout));
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class JustAuthRedisStateCache implements AuthStateCache {
|
||||
*/
|
||||
@Override
|
||||
public String get(String key) {
|
||||
return RedisUtils.get(RedisUtils.formatKey(CacheConsts.SOCIAL_AUTH_STATE_KEY_PREFIX, key));
|
||||
return RedisUtils.get(RedisUtils.formatKey(CacheConstants.SOCIAL_AUTH_STATE_KEY_PREFIX, key));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,6 +83,6 @@ public class JustAuthRedisStateCache implements AuthStateCache {
|
||||
*/
|
||||
@Override
|
||||
public boolean containsKey(String key) {
|
||||
return RedisUtils.hasKey(RedisUtils.formatKey(CacheConsts.SOCIAL_AUTH_STATE_KEY_PREFIX, key));
|
||||
return RedisUtils.hasKey(RedisUtils.formatKey(CacheConstants.SOCIAL_AUTH_STATE_KEY_PREFIX, key));
|
||||
}
|
||||
}
|
@@ -29,7 +29,7 @@ import top.charles7c.cnadmin.common.enums.DataScopeEnum;
|
||||
import top.charles7c.cnadmin.common.model.dto.LoginUser;
|
||||
import top.charles7c.cnadmin.common.model.dto.RoleDTO;
|
||||
import top.charles7c.cnadmin.common.util.helper.LoginHelper;
|
||||
import top.charles7c.continew.starter.core.constant.StringConsts;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.Function;
|
||||
@@ -75,8 +75,8 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
|
||||
public Expression getSqlSegment(Expression where, String mappedStatementId) {
|
||||
try {
|
||||
Class<?> clazz =
|
||||
Class.forName(mappedStatementId.substring(0, mappedStatementId.lastIndexOf(StringConsts.DOT)));
|
||||
String methodName = mappedStatementId.substring(mappedStatementId.lastIndexOf(StringConsts.DOT) + 1);
|
||||
Class.forName(mappedStatementId.substring(0, mappedStatementId.lastIndexOf(StringConstants.DOT)));
|
||||
String methodName = mappedStatementId.substring(mappedStatementId.lastIndexOf(StringConstants.DOT) + 1);
|
||||
Method[] methodArr = clazz.getMethods();
|
||||
for (Method method : methodArr) {
|
||||
DataPermission dataPermission = method.getAnnotation(DataPermission.class);
|
||||
|
@@ -26,7 +26,7 @@ import lombok.NoArgsConstructor;
|
||||
* @since 2022/12/22 19:30
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class CacheConsts {
|
||||
public class CacheConstants {
|
||||
|
||||
/**
|
||||
* 登录用户键
|
@@ -26,7 +26,7 @@ import lombok.NoArgsConstructor;
|
||||
* @since 2023/1/2 21:19
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class FileConsts {
|
||||
public class FileConstants {
|
||||
|
||||
/**
|
||||
* 头像支持的图片类型
|
@@ -28,7 +28,7 @@ import cn.hutool.core.lang.RegexPool;
|
||||
* @since 2023/1/10 20:06
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class RegexConsts implements RegexPool {
|
||||
public class RegexConstants implements RegexPool {
|
||||
|
||||
/**
|
||||
* 用户名正则(长度为 4 到 64 位,可以包含字母、数字,下划线,以字母开头)
|
@@ -19,7 +19,7 @@ package top.charles7c.cnadmin.common.constant;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import top.charles7c.continew.starter.core.constant.StringConsts;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
/**
|
||||
* 系统相关常量
|
||||
@@ -28,7 +28,7 @@ import top.charles7c.continew.starter.core.constant.StringConsts;
|
||||
* @since 2023/2/9 22:11
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class SysConsts {
|
||||
public class SysConstants {
|
||||
|
||||
/**
|
||||
* 管理员角色编码
|
||||
@@ -48,7 +48,7 @@ public class SysConsts {
|
||||
/**
|
||||
* 全部权限标识
|
||||
*/
|
||||
public static final String ALL_PERMISSION = StringConsts.ASTERISK;
|
||||
public static final String ALL_PERMISSION = StringConstants.ASTERISK;
|
||||
|
||||
/**
|
||||
* 默认密码
|
@@ -26,7 +26,7 @@ import lombok.NoArgsConstructor;
|
||||
* @since 2023/9/17 14:12
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class UIConsts {
|
||||
public class UIConstants {
|
||||
|
||||
/**
|
||||
* 主色(极致蓝)
|
@@ -20,7 +20,7 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.IBaseEnum;
|
||||
import top.charles7c.cnadmin.common.constant.UIConsts;
|
||||
import top.charles7c.cnadmin.common.constant.UIConstants;
|
||||
|
||||
/**
|
||||
* 启用/禁用状态枚举
|
||||
@@ -33,10 +33,10 @@ import top.charles7c.cnadmin.common.constant.UIConsts;
|
||||
public enum DisEnableStatusEnum implements IBaseEnum<Integer> {
|
||||
|
||||
/** 启用 */
|
||||
ENABLE(1, "启用", UIConsts.COLOR_SUCCESS),
|
||||
ENABLE(1, "启用", UIConstants.COLOR_SUCCESS),
|
||||
|
||||
/** 禁用 */
|
||||
DISABLE(2, "禁用", UIConsts.COLOR_ERROR),;
|
||||
DISABLE(2, "禁用", UIConstants.COLOR_ERROR),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
@@ -20,7 +20,7 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.IBaseEnum;
|
||||
import top.charles7c.cnadmin.common.constant.UIConsts;
|
||||
import top.charles7c.cnadmin.common.constant.UIConstants;
|
||||
|
||||
/**
|
||||
* 消息类型枚举
|
||||
@@ -33,7 +33,7 @@ import top.charles7c.cnadmin.common.constant.UIConsts;
|
||||
public enum MessageTypeEnum implements IBaseEnum<Integer> {
|
||||
|
||||
/** 系统消息 */
|
||||
SYSTEM(1, "系统消息", UIConsts.COLOR_PRIMARY),;
|
||||
SYSTEM(1, "系统消息", UIConstants.COLOR_PRIMARY),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
@@ -20,7 +20,7 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.IBaseEnum;
|
||||
import top.charles7c.cnadmin.common.constant.UIConsts;
|
||||
import top.charles7c.cnadmin.common.constant.UIConstants;
|
||||
|
||||
/**
|
||||
* 成功/失败状态枚举
|
||||
@@ -33,10 +33,10 @@ import top.charles7c.cnadmin.common.constant.UIConsts;
|
||||
public enum SuccessFailureStatusEnum implements IBaseEnum<Integer> {
|
||||
|
||||
/** 成功 */
|
||||
SUCCESS(1, "成功", UIConsts.COLOR_SUCCESS),
|
||||
SUCCESS(1, "成功", UIConstants.COLOR_SUCCESS),
|
||||
|
||||
/** 失败 */
|
||||
FAILURE(2, "失败", UIConsts.COLOR_ERROR),;
|
||||
FAILURE(2, "失败", UIConstants.COLOR_ERROR),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
@@ -25,7 +25,7 @@ import lombok.Data;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.constant.SysConsts;
|
||||
import top.charles7c.cnadmin.common.constant.SysConstants;
|
||||
|
||||
/**
|
||||
* 登录用户信息
|
||||
@@ -103,6 +103,6 @@ public class LoginUser implements Serializable {
|
||||
if (CollUtil.isEmpty(roleCodes)) {
|
||||
return false;
|
||||
}
|
||||
return roleCodes.contains(SysConsts.ADMIN_ROLE_CODE);
|
||||
return roleCodes.contains(SysConstants.ADMIN_ROLE_CODE);
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ import org.springframework.data.domain.Sort;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import top.charles7c.continew.starter.core.constant.StringConsts;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
/**
|
||||
* 排序查询条件
|
||||
@@ -62,10 +62,10 @@ public class SortQuery implements Serializable {
|
||||
}
|
||||
|
||||
List<Sort.Order> orders = new ArrayList<>(sort.length);
|
||||
if (StrUtil.contains(sort[0], StringConsts.COMMA)) {
|
||||
if (StrUtil.contains(sort[0], StringConstants.COMMA)) {
|
||||
// e.g "sort=createTime,desc&sort=name,asc"
|
||||
for (String s : sort) {
|
||||
List<String> sortList = StrUtil.splitTrim(s, StringConsts.COMMA);
|
||||
List<String> sortList = StrUtil.splitTrim(s, StringConstants.COMMA);
|
||||
Sort.Order order =
|
||||
new Sort.Order(Sort.Direction.valueOf(sortList.get(1).toUpperCase()), sortList.get(0));
|
||||
orders.add(order);
|
||||
|
@@ -38,7 +38,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
|
||||
import top.charles7c.continew.starter.core.constant.StringConsts;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
/**
|
||||
* 邮件工具类
|
||||
@@ -233,10 +233,10 @@ public class MailUtils {
|
||||
}
|
||||
|
||||
List<String> result;
|
||||
if (StrUtil.contains(addresses, StringConsts.COMMA)) {
|
||||
result = StrUtil.splitTrim(addresses, StringConsts.COMMA);
|
||||
} else if (StrUtil.contains(addresses, StringConsts.SEMICOLON)) {
|
||||
result = StrUtil.splitTrim(addresses, StringConsts.SEMICOLON);
|
||||
if (StrUtil.contains(addresses, StringConstants.COMMA)) {
|
||||
result = StrUtil.splitTrim(addresses, StringConstants.COMMA);
|
||||
} else if (StrUtil.contains(addresses, StringConstants.SEMICOLON)) {
|
||||
result = StrUtil.splitTrim(addresses, StringConstants.SEMICOLON);
|
||||
} else {
|
||||
result = CollUtil.newArrayList(addresses);
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
|
||||
import top.charles7c.continew.starter.core.constant.StringConsts;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
/**
|
||||
* Stream 工具类
|
||||
@@ -53,7 +53,7 @@ public class StreamUtils {
|
||||
*/
|
||||
public static <E> String join(Collection<E> collection, Function<E, String> function, CharSequence delimiter) {
|
||||
if (CollUtil.isEmpty(collection)) {
|
||||
return StringConsts.EMPTY;
|
||||
return StringConstants.EMPTY;
|
||||
}
|
||||
return collection.stream().map(function).filter(Objects::nonNull).collect(Collectors.joining(delimiter));
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.extra.servlet.JakartaServletUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.constant.CacheConsts;
|
||||
import top.charles7c.cnadmin.common.constant.CacheConstants;
|
||||
import top.charles7c.cnadmin.common.model.dto.LogContext;
|
||||
import top.charles7c.cnadmin.common.model.dto.LoginUser;
|
||||
import top.charles7c.cnadmin.common.service.CommonUserService;
|
||||
@@ -65,10 +65,10 @@ public class LoginHelper {
|
||||
loginUser.setLoginTime(null != logContext ? logContext.getCreateTime() : LocalDateTime.now());
|
||||
// 登录并缓存用户信息
|
||||
StpUtil.login(loginUser.getId());
|
||||
SaHolder.getStorage().set(CacheConsts.LOGIN_USER_KEY, loginUser);
|
||||
SaHolder.getStorage().set(CacheConstants.LOGIN_USER_KEY, loginUser);
|
||||
String tokenValue = StpUtil.getTokenValue();
|
||||
loginUser.setToken(tokenValue);
|
||||
StpUtil.getTokenSession().set(CacheConsts.LOGIN_USER_KEY, loginUser);
|
||||
StpUtil.getTokenSession().set(CacheConstants.LOGIN_USER_KEY, loginUser);
|
||||
return tokenValue;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class LoginHelper {
|
||||
* @return 登录用户信息(获取 TokenSession 时如未登录,会抛出异常)
|
||||
*/
|
||||
public static LoginUser getLoginUser() {
|
||||
LoginUser loginUser = (LoginUser)SaHolder.getStorage().get(CacheConsts.LOGIN_USER_KEY);
|
||||
LoginUser loginUser = (LoginUser)SaHolder.getStorage().get(CacheConstants.LOGIN_USER_KEY);
|
||||
if (null != loginUser) {
|
||||
return loginUser;
|
||||
}
|
||||
@@ -86,8 +86,8 @@ public class LoginHelper {
|
||||
if (null == tokenSession) {
|
||||
return null;
|
||||
}
|
||||
loginUser = (LoginUser)tokenSession.get(CacheConsts.LOGIN_USER_KEY);
|
||||
SaHolder.getStorage().set(CacheConsts.LOGIN_USER_KEY, loginUser);
|
||||
loginUser = (LoginUser)tokenSession.get(CacheConstants.LOGIN_USER_KEY);
|
||||
SaHolder.getStorage().set(CacheConstants.LOGIN_USER_KEY, loginUser);
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class LoginHelper {
|
||||
if (null == tokenSession) {
|
||||
return null;
|
||||
}
|
||||
return (LoginUser)tokenSession.get(CacheConsts.LOGIN_USER_KEY);
|
||||
return (LoginUser)tokenSession.get(CacheConstants.LOGIN_USER_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.exception.ServiceException;
|
||||
import top.charles7c.continew.starter.core.constant.StringConsts;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
/**
|
||||
* 业务参数校验工具类(抛出 500 ServiceException)
|
||||
@@ -54,7 +54,7 @@ public class CheckUtils extends Validator {
|
||||
*/
|
||||
public static void throwIfNotExists(Object obj, String entityName, String fieldName, Object fieldValue) {
|
||||
String message = String.format("%s 为 [%s] 的 %s 记录已不存在", fieldName, fieldValue,
|
||||
StrUtil.replace(entityName, "DO", StringConsts.EMPTY));
|
||||
StrUtil.replace(entityName, "DO", StringConstants.EMPTY));
|
||||
throwIfNull(obj, message, EXCEPTION_TYPE);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user