Skip to content

Commit

Permalink
style: 优化常量命名风格,XxxConsts => XxxConstants
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Nov 22, 2023
1 parent a40e609 commit ec28705
Show file tree
Hide file tree
Showing 49 changed files with 164 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
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;

/**
* 控制器基类
Expand Down Expand Up @@ -212,7 +212,7 @@ public void export(Q query, SortQuery sortQuery, HttpServletResponse response) {
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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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 配置
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
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 枚举基类转换器
Expand Down Expand Up @@ -63,7 +63,7 @@ public IBaseEnum convertToJavaData(ReadCellData<?> cellData, ExcelContentPropert
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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;
Expand All @@ -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));
}

Expand All @@ -58,7 +58,7 @@ public void cache(String key, String value) {
*/
@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));
}

Expand All @@ -71,7 +71,7 @@ public void cache(String key, String value, long timeout) {
*/
@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));
}

/**
Expand All @@ -83,6 +83,6 @@ public String get(String key) {
*/
@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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @since 2022/12/22 19:30
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CacheConsts {
public class CacheConstants {

/**
* 登录用户键
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @since 2023/1/2 21:19
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class FileConsts {
public class FileConstants {

/**
* 头像支持的图片类型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @since 2023/1/10 20:06
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class RegexConsts implements RegexPool {
public class RegexConstants implements RegexPool {

/**
* 用户名正则(长度为 4 到 64 位,可以包含字母、数字,下划线,以字母开头)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import top.charles7c.continew.starter.core.constant.StringConsts;
import top.charles7c.continew.starter.core.constant.StringConstants;

/**
* 系统相关常量
Expand All @@ -28,7 +28,7 @@
* @since 2023/2/9 22:11
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SysConsts {
public class SysConstants {

/**
* 管理员角色编码
Expand All @@ -48,7 +48,7 @@ public class SysConsts {
/**
* 全部权限标识
*/
public static final String ALL_PERMISSION = StringConsts.ASTERISK;
public static final String ALL_PERMISSION = StringConstants.ASTERISK;

/**
* 默认密码
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @since 2023/9/17 14:12
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UIConsts {
public class UIConstants {

/**
* 主色(极致蓝)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import lombok.RequiredArgsConstructor;

import top.charles7c.cnadmin.common.base.IBaseEnum;
import top.charles7c.cnadmin.common.constant.UIConsts;
import top.charles7c.cnadmin.common.constant.UIConstants;

/**
* 启用/禁用状态枚举
Expand All @@ -33,10 +33,10 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import lombok.RequiredArgsConstructor;

import top.charles7c.cnadmin.common.base.IBaseEnum;
import top.charles7c.cnadmin.common.constant.UIConsts;
import top.charles7c.cnadmin.common.constant.UIConstants;

/**
* 消息类型枚举
Expand All @@ -33,7 +33,7 @@
public enum MessageTypeEnum implements IBaseEnum<Integer> {

/** 系统消息 */
SYSTEM(1, "系统消息", UIConsts.COLOR_PRIMARY),;
SYSTEM(1, "系统消息", UIConstants.COLOR_PRIMARY),;

private final Integer value;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import lombok.RequiredArgsConstructor;

import top.charles7c.cnadmin.common.base.IBaseEnum;
import top.charles7c.cnadmin.common.constant.UIConsts;
import top.charles7c.cnadmin.common.constant.UIConstants;

/**
* 成功/失败状态枚举
Expand All @@ -33,10 +33,10 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import cn.hutool.core.collection.CollUtil;

import top.charles7c.cnadmin.common.constant.SysConsts;
import top.charles7c.cnadmin.common.constant.SysConstants;

/**
* 登录用户信息
Expand Down Expand Up @@ -103,6 +103,6 @@ public boolean isAdmin() {
if (CollUtil.isEmpty(roleCodes)) {
return false;
}
return roleCodes.contains(SysConsts.ADMIN_ROLE_CODE);
return roleCodes.contains(SysConstants.ADMIN_ROLE_CODE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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;

/**
* 排序查询条件
Expand Down Expand Up @@ -62,10 +62,10 @@ public Sort getSort() {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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;

/**
* 邮件工具类
Expand Down Expand Up @@ -233,10 +233,10 @@ private static List<String> splitAddress(String addresses) {
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import cn.hutool.core.collection.CollUtil;

import top.charles7c.continew.starter.core.constant.StringConsts;
import top.charles7c.continew.starter.core.constant.StringConstants;

/**
* Stream 工具类
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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;
Expand Down Expand Up @@ -65,10 +65,10 @@ public static String login(LoginUser loginUser) {
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;
}

Expand All @@ -78,16 +78,16 @@ public static String login(LoginUser loginUser) {
* @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;
}
SaSession tokenSession = StpUtil.getTokenSession();
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;
}

Expand All @@ -103,7 +103,7 @@ public static LoginUser getLoginUser(String token) {
if (null == tokenSession) {
return null;
}
return (LoginUser)tokenSession.get(CacheConsts.LOGIN_USER_KEY);
return (LoginUser)tokenSession.get(CacheConstants.LOGIN_USER_KEY);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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)
Expand Down Expand Up @@ -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);
}

Expand Down
Loading

0 comments on commit ec28705

Please sign in to comment.