fix
This commit is contained in:
parent
69aa6e2bf8
commit
20469e5e53
@ -7,29 +7,10 @@ package com.sunyard.chsm.utils;
|
|||||||
*/
|
*/
|
||||||
public abstract class DateFormatPattern {
|
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 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_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 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";
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +1,5 @@
|
|||||||
package com.sunyard.chsm.dto;
|
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 com.sunyard.chsm.model.PageQuery;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@ -61,7 +59,6 @@ public abstract class CryptoServiceDTO {
|
|||||||
/**
|
/**
|
||||||
* 密码服务Id
|
* 密码服务Id
|
||||||
*/
|
*/
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
|
||||||
private Long id;
|
private Long id;
|
||||||
/**
|
/**
|
||||||
* 密码服务名称
|
* 密码服务名称
|
||||||
@ -71,7 +68,6 @@ public abstract class CryptoServiceDTO {
|
|||||||
/**
|
/**
|
||||||
* 设备组id
|
* 设备组id
|
||||||
*/
|
*/
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
|
||||||
private Long deviceGroupId;
|
private Long deviceGroupId;
|
||||||
/**
|
/**
|
||||||
* 设备组名称
|
* 设备组名称
|
||||||
@ -96,7 +92,6 @@ public abstract class CryptoServiceDTO {
|
|||||||
/**
|
/**
|
||||||
* 密码服务创建人id
|
* 密码服务创建人id
|
||||||
*/
|
*/
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
|
||||||
private Long creatorId;
|
private Long creatorId;
|
||||||
/**
|
/**
|
||||||
* 备注
|
* 备注
|
||||||
|
@ -37,7 +37,7 @@ public class WebConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void beforeRequest(HttpServletRequest request, String message) {
|
protected void afterRequest(HttpServletRequest request, String message) {
|
||||||
logger.info(message);
|
logger.info(message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -47,7 +47,7 @@ public class WebConfig {
|
|||||||
loggingFilter.setIncludeQueryString(true);
|
loggingFilter.setIncludeQueryString(true);
|
||||||
loggingFilter.setIncludePayload(true);
|
loggingFilter.setIncludePayload(true);
|
||||||
loggingFilter.setMaxPayloadLength(2000);
|
loggingFilter.setMaxPayloadLength(2000);
|
||||||
loggingFilter.setBeforeMessagePrefix("http request [");
|
loggingFilter.setAfterMessagePrefix("http request [");
|
||||||
return loggingFilter;
|
return loggingFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.sunyard.ssp.common.exception;
|
package com.sunyard.ssp.common.exception;
|
||||||
|
|
||||||
import com.sunyard.chsm.model.R;
|
import com.sunyard.chsm.model.R;
|
||||||
import com.sunyard.chsm.utils.ThrowableUtils;
|
|
||||||
import com.sunyard.ssp.common.Result;
|
import com.sunyard.ssp.common.Result;
|
||||||
import com.sunyard.ssp.utils.ResultUtil;
|
import com.sunyard.ssp.utils.ResultUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.ResponseBody;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.IllegalFormatException;
|
import java.util.IllegalFormatException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局controller异常处理
|
* 全局controller异常处理
|
||||||
|
*
|
||||||
* @auther: ZS
|
* @auther: ZS
|
||||||
* @description:
|
* @description:
|
||||||
* @param:
|
* @param:
|
||||||
@ -80,24 +81,49 @@ public class GlobalExceptionResolver {
|
|||||||
UnsupportedOperationException.class);
|
UnsupportedOperationException.class);
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public R<?> exceptionHandler(Exception ex) {
|
public R<?> exceptionHandler(Exception ex, HttpServletRequest request) {
|
||||||
String errorMessage = ThrowableUtils.buildErrorMessage(ex);
|
String errorMessage = buildErrorMessage(ex);
|
||||||
SspwebException serviceException = ThrowableUtils.findException(SspwebException.class, ex);
|
SspwebException serviceException = findException(SspwebException.class, ex);
|
||||||
if (serviceException != null) {
|
if (serviceException != null) {
|
||||||
log.warn("Validation failed -> {}, errorMessage: \n {}", serviceException.getMessage(), errorMessage);
|
log.warn("Validation failed -> {}, errorMessage: \n {}", serviceException.getMessage(), errorMessage);
|
||||||
return R.error(400, serviceException.getMessage());
|
return R.error(400, serviceException.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Class<? extends Exception> eClass : EX_CLASS) {
|
for (Class<? extends Exception> eClass : EX_CLASS) {
|
||||||
Exception exception = ThrowableUtils.findException(eClass, ex);
|
Exception exception = findException(eClass, ex);
|
||||||
if (exception == null) {
|
if (exception == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
log.warn("Validation failed -> {} ", errorMessage);
|
log.warn("Validation failed -> {} ", errorMessage);
|
||||||
return R.error(400, exception.getMessage());
|
return R.error(400, exception.getMessage());
|
||||||
}
|
}
|
||||||
log.error("系统异常 -> ", ex);
|
log.error("request: {} - {}, 系统异常 -> ", request.getMethod(), request.getRequestURI(), ex);
|
||||||
return R.error("系统异常");
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user