diff --git a/chsm-common/src/main/java/com/sunyard/chsm/utils/DateFormatPattern.java b/chsm-common/src/main/java/com/sunyard/chsm/utils/DateFormatPattern.java index d379b11..8066c62 100644 --- a/chsm-common/src/main/java/com/sunyard/chsm/utils/DateFormatPattern.java +++ b/chsm-common/src/main/java/com/sunyard/chsm/utils/DateFormatPattern.java @@ -7,29 +7,10 @@ package com.sunyard.chsm.utils; */ public abstract class DateFormatPattern { - public static final String YYYY = "yyyy"; - public static final String YYYYMMDD = "yyyyMMdd"; public static final String YYYY_MM_DD = "yyyy-MM-dd"; - public static final String YYYYIMMIDD = "yyyy/MM/dd"; - public static final String YYYYMMDDHHMM = "yyyyMMddHHmm"; - public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; - public static final String YYYYMMDD_HHMMSS = "yyyyMMdd HHmmss"; public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; - public static final String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm"; - public static final String YYYYMMDDHHMMSS_SS = "yyyyMMddHHmmssSSS"; - public static final String HHMMSS_TIME_FORMAT = "HHmmss"; - public static final String YYYY_MM_DD_T_HH_MM_SS_Z = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - public static final String YYYY_MM_DD_HH24_MM_SS = "yyyy-MM-d hh24:mm:ss"; - public static final String HH_MM = "HH:mm"; - public static final String HHMM = "HHmm"; public static final String HH_MM_SS = "HH:mm:ss"; - public static final String ZERO_HH_MM_SS = " 00:00:00"; - public static final String YYMMDD = "yyMMdd"; - public static final String YYYY_CN_MM_CN_DD_CN = "yyyy年 MM 月 dd 日"; - public static final String MM_CN_DD_CN = "MM 月 dd 日"; - public static final String BEGIN_OF_DAY = "yyyy-MM-dd 00:00:00"; - public static final String END_OF_DAY = "yyyy-MM-dd 23:59:59"; - public static final String YYYYIMMIDDHHMMSS = "yyyy/MM/dd HH:mm:ss"; + } diff --git a/chsm-common/src/main/java/com/sunyard/chsm/utils/ThrowableUtils.java b/chsm-common/src/main/java/com/sunyard/chsm/utils/ThrowableUtils.java deleted file mode 100644 index 93e3be2..0000000 --- a/chsm-common/src/main/java/com/sunyard/chsm/utils/ThrowableUtils.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.sunyard.chsm.utils; - -/** - * @author liulu - * @version V1.0 - * @since 2020/11/16 - */ -public abstract class ThrowableUtils { - - private ThrowableUtils() { - } - - - public static String buildErrorMessage(Throwable ex) { - StringBuilder sb = new StringBuilder(); - sb.append(ex.getMessage()); - StackTraceElement[] stackTrace = ex.getStackTrace(); - int i = 0; - for (StackTraceElement stackTraceElement : stackTrace) { - if (i++ >= 5) { - break; - } - sb.append("\n\t").append(stackTraceElement.toString()); - } - return sb.toString(); - } - - - public static T findException(Class exClass, Throwable ex) { - for (int i = 0; ex != null && i < 3; i++) { - if (exClass.isAssignableFrom(ex.getClass())) { - //noinspection unchecked - return (T) ex; - } - ex = ex.getCause(); - } - return null; - } - - -} diff --git a/chsm-web-manage/src/main/java/com/sunyard/chsm/dto/CryptoServiceDTO.java b/chsm-web-manage/src/main/java/com/sunyard/chsm/dto/CryptoServiceDTO.java index 68560b2..0fe1e86 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/chsm/dto/CryptoServiceDTO.java +++ b/chsm-web-manage/src/main/java/com/sunyard/chsm/dto/CryptoServiceDTO.java @@ -1,7 +1,5 @@ package com.sunyard.chsm.dto; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.sunyard.chsm.model.PageQuery; import lombok.Data; import lombok.EqualsAndHashCode; @@ -61,7 +59,6 @@ public abstract class CryptoServiceDTO { /** * 密码服务Id */ - @JsonSerialize(using = ToStringSerializer.class) private Long id; /** * 密码服务名称 @@ -71,7 +68,6 @@ public abstract class CryptoServiceDTO { /** * 设备组id */ - @JsonSerialize(using = ToStringSerializer.class) private Long deviceGroupId; /** * 设备组名称 @@ -96,7 +92,6 @@ public abstract class CryptoServiceDTO { /** * 密码服务创建人id */ - @JsonSerialize(using = ToStringSerializer.class) private Long creatorId; /** * 备注 diff --git a/chsm-web-manage/src/main/java/com/sunyard/config/WebConfig.java b/chsm-web-manage/src/main/java/com/sunyard/config/WebConfig.java index 7fddeee..951f285 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/config/WebConfig.java +++ b/chsm-web-manage/src/main/java/com/sunyard/config/WebConfig.java @@ -37,7 +37,7 @@ public class WebConfig { } @Override - protected void beforeRequest(HttpServletRequest request, String message) { + protected void afterRequest(HttpServletRequest request, String message) { logger.info(message); } }; @@ -47,7 +47,7 @@ public class WebConfig { loggingFilter.setIncludeQueryString(true); loggingFilter.setIncludePayload(true); loggingFilter.setMaxPayloadLength(2000); - loggingFilter.setBeforeMessagePrefix("http request ["); + loggingFilter.setAfterMessagePrefix("http request ["); return loggingFilter; } diff --git a/chsm-web-manage/src/main/java/com/sunyard/ssp/common/exception/GlobalExceptionResolver.java b/chsm-web-manage/src/main/java/com/sunyard/ssp/common/exception/GlobalExceptionResolver.java index 67903af..327ff4c 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/ssp/common/exception/GlobalExceptionResolver.java +++ b/chsm-web-manage/src/main/java/com/sunyard/ssp/common/exception/GlobalExceptionResolver.java @@ -1,7 +1,6 @@ package com.sunyard.ssp.common.exception; import com.sunyard.chsm.model.R; -import com.sunyard.chsm.utils.ThrowableUtils; import com.sunyard.ssp.common.Result; import com.sunyard.ssp.utils.ResultUtil; import lombok.extern.slf4j.Slf4j; @@ -13,13 +12,15 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestControllerAdvice; +import javax.servlet.http.HttpServletRequest; import java.util.Arrays; import java.util.IllegalFormatException; import java.util.List; import java.util.Optional; /** - * 全局controller异常处理 + * 全局controller异常处理 + * * @auther: ZS * @description: * @param: @@ -80,24 +81,49 @@ public class GlobalExceptionResolver { UnsupportedOperationException.class); @ExceptionHandler(Exception.class) - public R exceptionHandler(Exception ex) { - String errorMessage = ThrowableUtils.buildErrorMessage(ex); - SspwebException serviceException = ThrowableUtils.findException(SspwebException.class, ex); + public R exceptionHandler(Exception ex, HttpServletRequest request) { + String errorMessage = buildErrorMessage(ex); + SspwebException serviceException = findException(SspwebException.class, ex); if (serviceException != null) { log.warn("Validation failed -> {}, errorMessage: \n {}", serviceException.getMessage(), errorMessage); return R.error(400, serviceException.getMessage()); } for (Class eClass : EX_CLASS) { - Exception exception = ThrowableUtils.findException(eClass, ex); + Exception exception = findException(eClass, ex); if (exception == null) { continue; } log.warn("Validation failed -> {} ", errorMessage); return R.error(400, exception.getMessage()); } - log.error("系统异常 -> ", ex); + log.error("request: {} - {}, 系统异常 -> ", request.getMethod(), request.getRequestURI(), ex); return R.error("系统异常"); } + public static T findException(Class exClass, Throwable ex) { + for (int i = 0; ex != null && i < 3; i++) { + if (exClass.isAssignableFrom(ex.getClass())) { + //noinspection unchecked + return (T) ex; + } + ex = ex.getCause(); + } + return null; + } + + public static String buildErrorMessage(Throwable ex) { + StringBuilder sb = new StringBuilder(); + sb.append(ex.getMessage()); + StackTraceElement[] stackTrace = ex.getStackTrace(); + int i = 0; + for (StackTraceElement stackTraceElement : stackTrace) { + if (i++ >= 5) { + break; + } + sb.append("\n\t").append(stackTraceElement.toString()); + } + return sb.toString(); + } + }