Skip to content

Commit

Permalink
set enrity id. next id Snowflake
Browse files Browse the repository at this point in the history
  • Loading branch information
vnobo committed Nov 28, 2023
1 parent 06c025f commit 3c87b48
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.platform.boot.commons.annotation;
package com.platform.boot.commons;

import com.google.common.collect.Lists;
import com.platform.boot.commons.ErrorResponse;
import com.platform.boot.commons.annotation.exception.ClientException;
import com.platform.boot.commons.annotation.exception.RestServerException;
import com.platform.boot.commons.exception.ClientException;
import com.platform.boot.commons.exception.RestServerException;
import io.r2dbc.spi.R2dbcException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -14,7 +13,6 @@
import org.springframework.r2dbc.BadSqlGrammarException;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.support.WebExchangeBindException;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.ServerWebInputException;
Expand All @@ -25,11 +23,11 @@
* @author <a href="https://github.com/vnobo">Alex bob</a>
*/
@ControllerAdvice
public class GlobalExceptionHandler {
public class ExceptionHandler {

private static final Log log = LogFactory.getLog(GlobalExceptionHandler.class);
private static final Log log = LogFactory.getLog(ExceptionHandler.class);

@ExceptionHandler(ServerWebInputException.class)
@org.springframework.web.bind.annotation.ExceptionHandler(ServerWebInputException.class)
public ResponseEntity<ErrorResponse> handleBindException(ServerWebExchange exchange, ServerWebInputException ex) {
List<String> errors = Lists.newArrayList(ex.getLocalizedMessage());
if (ex instanceof WebExchangeBindException bindException) {
Expand All @@ -52,7 +50,7 @@ public ResponseEntity<ErrorResponse> handleBindException(ServerWebExchange excha
4170, "请求参数验证失败!", errors));
}

@ExceptionHandler({DataAccessException.class, R2dbcException.class})
@org.springframework.web.bind.annotation.ExceptionHandler({DataAccessException.class, R2dbcException.class})
public ResponseEntity<ErrorResponse> handleFailureException(ServerWebExchange exchange, RuntimeException ex) {
List<String> errors = Lists.newArrayList(ex.getLocalizedMessage());
if (ex instanceof R2dbcException r2dbcException) {
Expand All @@ -74,7 +72,7 @@ public ResponseEntity<ErrorResponse> handleFailureException(ServerWebExchange ex
5070, "数据库操作错误!", errors));
}

@ExceptionHandler(ClientException.class)
@org.springframework.web.bind.annotation.ExceptionHandler(ClientException.class)
public ResponseEntity<ErrorResponse> handleClientException(ServerWebExchange exchange, ClientException ex) {
log.error("%s内部服务访问错误! 信息: %s".formatted(exchange.getLogPrefix(), ex.getMessage()));
if (log.isDebugEnabled()) {
Expand All @@ -85,7 +83,7 @@ public ResponseEntity<ErrorResponse> handleClientException(ServerWebExchange exc
ex.getCode(), ex.getServiceId() + "内部服务访问错误!", ex.getMsg()));
}

@ExceptionHandler(RestServerException.class)
@org.springframework.web.bind.annotation.ExceptionHandler(RestServerException.class)
public ResponseEntity<ErrorResponse> handleRestServerException(ServerWebExchange exchange, RestServerException ex) {
log.error("%s服务器自定义错误! 信息: %s".formatted(exchange.getLogPrefix(), ex.getMessage()));
if (log.isDebugEnabled()) {
Expand All @@ -96,7 +94,7 @@ public ResponseEntity<ErrorResponse> handleRestServerException(ServerWebExchange
ex.getCode(), "服务自定义错误!", ex.getMsg()));
}

@ExceptionHandler(Exception.class)
@org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleException(ServerWebExchange exchange, Exception ex) {
log.error("%s服务器未知错误! 信息: %s".formatted(exchange.getLogPrefix(), ex.getMessage()));
if (log.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.platform.boot.commons;

import com.platform.boot.commons.annotation.exception.RestServerException;
import com.platform.boot.commons.exception.RestServerException;

import java.io.Serializable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.platform.boot.commons.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.platform.boot.commons.utils.ContextUtils;
import com.platform.boot.commons.utils.CriteriaUtils;
import org.springframework.data.domain.Persistable;
import org.springframework.data.relational.core.query.Criteria;
Expand Down Expand Up @@ -42,7 +43,7 @@ default void setCode(String code) {
default boolean isNew() {
boolean isNew = ObjectUtils.isEmpty(getId());
if (isNew) {
setCode(String.valueOf(getId()));
setCode(ContextUtils.nextId());
}
return isNew;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.platform.boot.commons.annotation.exception;
package com.platform.boot.commons.exception;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.platform.boot.commons.annotation.exception;
package com.platform.boot.commons.exception;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Define the package name
package com.platform.boot.commons.annotation.exception;
package com.platform.boot.commons.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.google.common.collect.Maps;
import com.platform.boot.commons.annotation.exception.JsonException;
import com.platform.boot.commons.annotation.exception.RestServerException;
import com.platform.boot.commons.exception.JsonException;
import com.platform.boot.commons.exception.RestServerException;
import org.springframework.util.ObjectUtils;
import org.springframework.util.unit.DataSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.platform.boot.commons.Snowflake;
import com.platform.boot.commons.annotation.exception.JsonException;
import com.platform.boot.commons.annotation.exception.RestServerException;
import com.platform.boot.commons.exception.JsonException;
import com.platform.boot.commons.exception.RestServerException;
import com.platform.boot.security.SecurityDetails;
import com.platform.boot.security.core.UserAuditor;
import com.platform.boot.security.core.user.UsersService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.platform.boot.config;

import com.platform.boot.commons.annotation.exception.RestServerException;
import com.platform.boot.commons.exception.RestServerException;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.platform.boot.commons.annotation.exception.JsonException;
import com.platform.boot.commons.exception.JsonException;
import com.platform.boot.commons.utils.ContextUtils;
import io.r2dbc.postgresql.codec.Json;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.platform.boot.converters;

import com.fasterxml.jackson.databind.JsonNode;
import com.platform.boot.commons.annotation.exception.JsonException;
import com.platform.boot.commons.exception.JsonException;
import com.platform.boot.commons.utils.ContextUtils;
import io.r2dbc.postgresql.codec.Json;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.platform.boot.commons.annotation.exception.JsonException;
import com.platform.boot.commons.exception.JsonException;
import com.platform.boot.commons.utils.ContextUtils;
import com.platform.boot.relational.logger.LoggerRequest;
import com.platform.boot.relational.logger.LoggersService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.platform.boot.relational.menus;


import com.platform.boot.commons.annotation.exception.RestServerException;
import com.platform.boot.commons.base.AbstractDatabase;
import com.platform.boot.commons.exception.RestServerException;
import com.platform.boot.commons.utils.ContextUtils;
import com.platform.boot.security.core.group.authority.GroupAuthoritiesRepository;
import com.platform.boot.security.core.user.authority.UserAuthoritiesRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.platform.boot.security;

import com.platform.boot.commons.annotation.exception.RestServerException;
import com.platform.boot.commons.exception.RestServerException;
import com.platform.boot.commons.utils.ContextUtils;
import com.platform.boot.security.core.AuthenticationToken;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.platform.boot.security.core.user;

import com.platform.boot.commons.annotation.exception.RestServerException;
import com.platform.boot.commons.base.AbstractDatabase;
import com.platform.boot.commons.exception.RestServerException;
import com.platform.boot.commons.query.ParamSql;
import com.platform.boot.commons.query.QueryJson;
import com.platform.boot.commons.utils.BeanUtils;
Expand Down

0 comments on commit 3c87b48

Please sign in to comment.