mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-11-04 10:57:10 +08:00 
			
		
		
		
	style: 适配 Java 14 新特性
1.增强 switch(Java 12 预览特性 => Java 14 标准特性) 详情请参阅:https://docs.oracle.com/en/java/javase/14/language/switch-expressions.html 2.@Serial(类似于 @Override 的检查注解,用于检查序列化)
This commit is contained in:
		@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.base;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
 | 
			
		||||
@@ -34,6 +35,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 | 
			
		||||
@Data
 | 
			
		||||
public class BaseDO implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.base;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
@@ -34,6 +35,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 | 
			
		||||
@Data
 | 
			
		||||
public class BaseDetailVO extends BaseVO {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.base;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
import jakarta.validation.groups.Default;
 | 
			
		||||
@@ -31,6 +32,7 @@ import lombok.Data;
 | 
			
		||||
@Data
 | 
			
		||||
public class BaseRequest implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.base;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
 | 
			
		||||
@@ -36,6 +37,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
 | 
			
		||||
@Data
 | 
			
		||||
public class BaseVO implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -184,18 +184,11 @@ public class GlobalExceptionHandler {
 | 
			
		||||
    @ExceptionHandler(NotLoginException.class)
 | 
			
		||||
    public R handleNotLoginException(NotLoginException e, HttpServletRequest request) {
 | 
			
		||||
        log.error("请求地址 [{}],认证失败,无法访问系统资源。", request.getRequestURI(), e);
 | 
			
		||||
        String errorMsg;
 | 
			
		||||
        switch (e.getType()) {
 | 
			
		||||
            case NotLoginException.KICK_OUT:
 | 
			
		||||
                errorMsg = "您已被踢下线";
 | 
			
		||||
                break;
 | 
			
		||||
            case NotLoginException.BE_REPLACED_MESSAGE:
 | 
			
		||||
                errorMsg = "您已被顶下线";
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                errorMsg = "登录状态已过期,请重新登录";
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
        String errorMsg = switch (e.getType()) {
 | 
			
		||||
            case NotLoginException.KICK_OUT -> "您已被踢下线";
 | 
			
		||||
            case NotLoginException.BE_REPLACED_MESSAGE -> "您已被顶下线";
 | 
			
		||||
            default -> "登录状态已过期,请重新登录";
 | 
			
		||||
        };
 | 
			
		||||
        LogContextHolder.setErrorMsg(errorMsg);
 | 
			
		||||
        return R.fail(HttpStatus.UNAUTHORIZED.value(), errorMsg);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.model.dto;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
 | 
			
		||||
@@ -30,6 +31,7 @@ import lombok.Data;
 | 
			
		||||
@Data
 | 
			
		||||
public class LogContext implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.model.dto;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
@@ -35,6 +36,7 @@ import top.charles7c.cnadmin.common.constant.SysConsts;
 | 
			
		||||
@Data
 | 
			
		||||
public class LoginUser implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.model.dto;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
@@ -31,6 +32,7 @@ import top.charles7c.cnadmin.common.enums.DataScopeEnum;
 | 
			
		||||
@Data
 | 
			
		||||
public class RoleDTO implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,8 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.model.query;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
 | 
			
		||||
import jakarta.validation.constraints.Min;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
@@ -46,6 +48,7 @@ import cn.hutool.core.util.StrUtil;
 | 
			
		||||
@Schema(description = "分页查询条件")
 | 
			
		||||
public class PageQuery extends SortQuery {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.model.query;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
@@ -43,6 +44,7 @@ import top.charles7c.cnadmin.common.constant.StringConsts;
 | 
			
		||||
@Schema(description = "排序查询条件")
 | 
			
		||||
public class SortQuery implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.model.request;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
import jakarta.validation.constraints.NotNull;
 | 
			
		||||
@@ -36,6 +37,7 @@ import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
 | 
			
		||||
@Schema(description = "修改状态信息")
 | 
			
		||||
public class UpdateStatusRequest implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.model.vo;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
@@ -34,6 +35,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
 | 
			
		||||
@Schema(description = "验证码信息")
 | 
			
		||||
public class CaptchaVO implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.model.vo;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
@@ -37,6 +38,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
 | 
			
		||||
@Schema(description = "键值对信息")
 | 
			
		||||
public class LabelValueVO<V> implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.model.vo;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
@@ -43,6 +44,7 @@ import cn.hutool.core.collection.CollUtil;
 | 
			
		||||
@Schema(description = "分页信息")
 | 
			
		||||
public class PageDataVO<V> implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
 | 
			
		||||
package top.charles7c.cnadmin.common.model.vo;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
import lombok.AccessLevel;
 | 
			
		||||
@@ -37,6 +38,7 @@ import org.springframework.http.HttpStatus;
 | 
			
		||||
@Schema(description = "响应信息")
 | 
			
		||||
public class R<V> implements Serializable {
 | 
			
		||||
 | 
			
		||||
    @Serial
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /** 是否成功 */
 | 
			
		||||
 
 | 
			
		||||
@@ -144,57 +144,34 @@ public class QueryHelper {
 | 
			
		||||
        String columnName = StrUtil.toUnderlineCase(fieldName);
 | 
			
		||||
        Query.Type queryType = queryAnnotation.type();
 | 
			
		||||
        switch (queryType) {
 | 
			
		||||
            case EQUAL:
 | 
			
		||||
                queryWrapper.eq(columnName, fieldValue);
 | 
			
		||||
                break;
 | 
			
		||||
            case NOT_EQUAL:
 | 
			
		||||
                queryWrapper.ne(columnName, fieldValue);
 | 
			
		||||
                break;
 | 
			
		||||
            case GREATER_THAN:
 | 
			
		||||
                queryWrapper.gt(columnName, fieldValue);
 | 
			
		||||
                break;
 | 
			
		||||
            case LESS_THAN:
 | 
			
		||||
                queryWrapper.lt(columnName, fieldValue);
 | 
			
		||||
                break;
 | 
			
		||||
            case GREATER_THAN_OR_EQUAL:
 | 
			
		||||
                queryWrapper.ge(columnName, fieldValue);
 | 
			
		||||
                break;
 | 
			
		||||
            case LESS_THAN_OR_EQUAL:
 | 
			
		||||
                queryWrapper.le(columnName, fieldValue);
 | 
			
		||||
                break;
 | 
			
		||||
            case BETWEEN:
 | 
			
		||||
            case EQUAL -> queryWrapper.eq(columnName, fieldValue);
 | 
			
		||||
            case NOT_EQUAL -> queryWrapper.ne(columnName, fieldValue);
 | 
			
		||||
            case GREATER_THAN -> queryWrapper.gt(columnName, fieldValue);
 | 
			
		||||
            case LESS_THAN -> queryWrapper.lt(columnName, fieldValue);
 | 
			
		||||
            case GREATER_THAN_OR_EQUAL -> queryWrapper.ge(columnName, fieldValue);
 | 
			
		||||
            case LESS_THAN_OR_EQUAL -> queryWrapper.le(columnName, fieldValue);
 | 
			
		||||
            case BETWEEN -> {
 | 
			
		||||
                List<Object> between = new ArrayList<>((List<Object>)fieldValue);
 | 
			
		||||
                if (between.size() >= 2) {
 | 
			
		||||
                    queryWrapper.between(columnName, between.get(0), between.get(1));
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            case LEFT_LIKE:
 | 
			
		||||
                queryWrapper.likeLeft(columnName, fieldValue);
 | 
			
		||||
                break;
 | 
			
		||||
            case INNER_LIKE:
 | 
			
		||||
                queryWrapper.like(columnName, fieldValue);
 | 
			
		||||
                break;
 | 
			
		||||
            case RIGHT_LIKE:
 | 
			
		||||
                queryWrapper.likeRight(columnName, fieldValue);
 | 
			
		||||
                break;
 | 
			
		||||
            case IN:
 | 
			
		||||
            }
 | 
			
		||||
            case LEFT_LIKE -> queryWrapper.likeLeft(columnName, fieldValue);
 | 
			
		||||
            case INNER_LIKE -> queryWrapper.like(columnName, fieldValue);
 | 
			
		||||
            case RIGHT_LIKE -> queryWrapper.likeRight(columnName, fieldValue);
 | 
			
		||||
            case IN -> {
 | 
			
		||||
                if (CollUtil.isNotEmpty((List<Object>)fieldValue)) {
 | 
			
		||||
                    queryWrapper.in(columnName, (List<Object>)fieldValue);
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            case NOT_IN:
 | 
			
		||||
            }
 | 
			
		||||
            case NOT_IN -> {
 | 
			
		||||
                if (CollUtil.isNotEmpty((List<Object>)fieldValue)) {
 | 
			
		||||
                    queryWrapper.notIn(columnName, (List<Object>)fieldValue);
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            case IS_NULL:
 | 
			
		||||
                queryWrapper.isNull(columnName);
 | 
			
		||||
                break;
 | 
			
		||||
            case IS_NOT_NULL:
 | 
			
		||||
                queryWrapper.isNotNull(columnName);
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                throw new IllegalArgumentException(String.format("暂不支持 [%s] 查询类型", queryType));
 | 
			
		||||
            }
 | 
			
		||||
            case IS_NULL -> queryWrapper.isNull(columnName);
 | 
			
		||||
            case IS_NOT_NULL -> queryWrapper.isNotNull(columnName);
 | 
			
		||||
            default -> throw new IllegalArgumentException(String.format("暂不支持 [%s] 查询类型", queryType));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user