This commit is contained in:
liulu 2024-10-28 15:07:19 +08:00
parent 69aa6e2bf8
commit 20469e5e53
5 changed files with 36 additions and 75 deletions

View File

@ -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";
}

View File

@ -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 extends Exception> T findException(Class<T> 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;
}
}

View File

@ -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;
/**
* 备注

View File

@ -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;
}

View File

@ -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,6 +12,7 @@ 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;
@ -20,6 +20,7 @@ import java.util.Optional;
/**
* 全局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<? extends Exception> 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 extends Exception> T findException(Class<T> 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();
}
}