This commit is contained in:
parent
36c80bd718
commit
3bae9504a9
|
|
@ -30,25 +30,6 @@ import java.util.stream.Collectors;
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CzgControllerAdvice {
|
public class CzgControllerAdvice {
|
||||||
@ResponseBody
|
|
||||||
@ExceptionHandler(value = Exception.class)
|
|
||||||
@ResponseStatus(HttpStatus.OK)
|
|
||||||
public CzgResult<Object> errorHandler(Exception ex) {
|
|
||||||
Throwable rootCause = ex;
|
|
||||||
while (rootCause.getCause() != null) {
|
|
||||||
rootCause = rootCause.getCause();
|
|
||||||
if (rootCause instanceof CzgException) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 处理自定义异常
|
|
||||||
if (rootCause instanceof CzgException czgException) {
|
|
||||||
return CzgResult.failure(czgException.getCode(), czgException.getMessage());
|
|
||||||
}
|
|
||||||
setErrorLog(ex);
|
|
||||||
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler(value = NoResourceFoundException.class)
|
@ExceptionHandler(value = NoResourceFoundException.class)
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
|
@ -113,9 +94,9 @@ public class CzgControllerAdvice {
|
||||||
return CzgResult.failure(ex.getCode(), ex.getMsg());
|
return CzgResult.failure(ex.getCode(), ex.getMsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
// @ResponseBody
|
||||||
@ExceptionHandler(OrderValidateException.class)
|
@ExceptionHandler(OrderValidateException.class)
|
||||||
@ResponseStatus(HttpStatus.OK)
|
// @ResponseStatus(HttpStatus.OK)
|
||||||
public CzgResult<Object> handleOrderValidateException(OrderValidateException ex) {
|
public CzgResult<Object> handleOrderValidateException(OrderValidateException ex) {
|
||||||
log.error("订单校验异常:{}", ex.getMessage());
|
log.error("订单校验异常:{}", ex.getMessage());
|
||||||
return CzgResult.failure(ex.getCode(), ex.getMsg());
|
return CzgResult.failure(ex.getCode(), ex.getMsg());
|
||||||
|
|
@ -161,6 +142,25 @@ public class CzgControllerAdvice {
|
||||||
return CzgResult.failure(CzgRespCode.RECORD_EXISTED);
|
return CzgResult.failure(CzgRespCode.RECORD_EXISTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@ExceptionHandler(value = Exception.class)
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
public CzgResult<Object> errorHandler(Exception ex) {
|
||||||
|
Throwable rootCause = ex;
|
||||||
|
while (rootCause.getCause() != null) {
|
||||||
|
rootCause = rootCause.getCause();
|
||||||
|
if (rootCause instanceof CzgException) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 处理自定义异常
|
||||||
|
if (rootCause instanceof CzgException czgException) {
|
||||||
|
return CzgResult.failure(czgException.getCode(), czgException.getMessage());
|
||||||
|
}
|
||||||
|
setErrorLog(ex);
|
||||||
|
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
private void setErrorLog(Exception ex) {
|
private void setErrorLog(Exception ex) {
|
||||||
log.error(ex.getMessage());
|
log.error(ex.getMessage());
|
||||||
log.error("错误", ex);
|
log.error("错误", ex);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.czg.exception;
|
||||||
|
|
||||||
import com.czg.resp.CzgRespCode;
|
import com.czg.resp.CzgRespCode;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义异常
|
* 自定义异常
|
||||||
*
|
*
|
||||||
|
|
@ -9,6 +11,7 @@ import com.czg.resp.CzgRespCode;
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class CzgException extends RuntimeException {
|
public class CzgException extends RuntimeException {
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private int code;
|
private int code;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ public class OrderValidateException extends RuntimeException{
|
||||||
private String msg;
|
private String msg;
|
||||||
|
|
||||||
public OrderValidateException(String msg) {
|
public OrderValidateException(String msg) {
|
||||||
super(msg);
|
// super(msg);
|
||||||
this.code = CzgRespCode.FAILURE.getCode();
|
this.code = CzgRespCode.FAILURE.getCode();
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -572,7 +572,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
|
|
||||||
|
|
||||||
@GlobalTransactional
|
@GlobalTransactional
|
||||||
protected void deepReward(ShopUser orderSourceShopUser, MkDistributionLevelConfig parentLevel, MkDistributionConfigVO config, MkDistributionUser currentDistributionUser, BigDecimal amount, Long sourceId, String type, String orderNo, Integer currentLevel) {
|
protected void deepReward(ShopUser orderSourceShopUser, MkDistributionLevelConfig parentLevel, MkDistributionConfigVO config,
|
||||||
|
MkDistributionUser currentDistributionUser, BigDecimal amount, Long sourceId, String type, String orderNo, Integer currentLevel) {
|
||||||
if (currentLevel > 2) {
|
if (currentLevel > 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue