修改异常处理+模板修改
This commit is contained in:
parent
bb859aa36a
commit
5804dd1fb9
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.ebts.common.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 18209
|
||||||
|
* @Date 2021/6/7 23:32
|
||||||
|
* @Email clay@hchyun.com
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
public class EBTSException extends RuntimeException {
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
private RuntimeException exception;
|
||||||
|
|
||||||
|
public EBTSException(String opError, RuntimeException e) {
|
||||||
|
this.msg = opError;
|
||||||
|
this.exception = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return exception.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -124,6 +124,9 @@ public class LogAspect {
|
||||||
public void getControllerMethodDescription(JoinPoint joinPoint, Log log, OperLog operLog) throws Exception {
|
public void getControllerMethodDescription(JoinPoint joinPoint, Log log, OperLog operLog) throws Exception {
|
||||||
// 设置action动作
|
// 设置action动作
|
||||||
operLog.setBusinessType(log.businessType().ordinal());
|
operLog.setBusinessType(log.businessType().ordinal());
|
||||||
|
if (!operLog.getJsonResult().contains(":200")){
|
||||||
|
operLog.setStatus(1);
|
||||||
|
}
|
||||||
// 设置标题
|
// 设置标题
|
||||||
operLog.setTitle(log.title());
|
operLog.setTitle(log.title());
|
||||||
// 设置操作人类别
|
// 设置操作人类别
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
package com.ebts.framework.web.exception;
|
package com.ebts.framework.web.exception;
|
||||||
|
|
||||||
|
import com.ebts.common.constant.HttpStatus;
|
||||||
|
import com.ebts.common.core.entity.AjaxResult;
|
||||||
|
import com.ebts.common.exception.BaseException;
|
||||||
|
import com.ebts.common.exception.CustomException;
|
||||||
|
import com.ebts.common.exception.DemoModeException;
|
||||||
|
import com.ebts.common.exception.EBTSException;
|
||||||
|
import com.ebts.common.utils.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
|
|
@ -10,12 +17,6 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
import org.springframework.web.servlet.NoHandlerFoundException;
|
||||||
import com.ebts.common.constant.HttpStatus;
|
|
||||||
import com.ebts.common.core.entity.AjaxResult;
|
|
||||||
import com.ebts.common.exception.BaseException;
|
|
||||||
import com.ebts.common.exception.CustomException;
|
|
||||||
import com.ebts.common.exception.DemoModeException;
|
|
||||||
import com.ebts.common.utils.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局异常处理器
|
* 全局异常处理器
|
||||||
|
|
@ -33,6 +34,13 @@ public class GlobalExceptionHandler {
|
||||||
public AjaxResult baseException(BaseException e) {
|
public AjaxResult baseException(BaseException e) {
|
||||||
return AjaxResult.error(e.getMessage());
|
return AjaxResult.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* EBTS基础异常
|
||||||
|
*/
|
||||||
|
@ExceptionHandler(EBTSException.class)
|
||||||
|
public AjaxResult ebtsException(EBTSException e) {
|
||||||
|
return AjaxResult.error(e.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务异常
|
* 业务异常
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import com.ebts.common.constant.ReturnConstants;
|
||||||
import com.ebts.common.core.controller.BaseController;
|
import com.ebts.common.core.controller.BaseController;
|
||||||
import com.ebts.common.core.entity.AjaxResult;
|
import com.ebts.common.core.entity.AjaxResult;
|
||||||
import com.ebts.common.enums.BusinessType;
|
import com.ebts.common.enums.BusinessType;
|
||||||
|
import com.ebts.common.exception.EBTSException;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
@ -42,7 +43,7 @@ public class ${ClassName}Controller extends BaseController{
|
||||||
@ApiOperation("${column.itDescribe}")
|
@ApiOperation("${column.itDescribe}")
|
||||||
#if($column.isPermission.equals("1"))
|
#if($column.isPermission.equals("1"))
|
||||||
@PreAuthorize("@ebts.hasPermi('${prefix}:${column.requrl}')")
|
@PreAuthorize("@ebts.hasPermi('${prefix}:${column.requrl}')")
|
||||||
@Log(title = "${column.itDescribe}", businessType = BusinessType.INSERT)
|
@Log(title = "${column.itDescribe}", businessType = BusinessType.OTHER)
|
||||||
#end
|
#end
|
||||||
@${column.method}Mapping("/${column.requrl}")
|
@${column.method}Mapping("/${column.requrl}")
|
||||||
#if($column.method.equals("Get"))
|
#if($column.method.equals("Get"))
|
||||||
|
|
@ -54,7 +55,7 @@ public class ${ClassName}Controller extends BaseController{
|
||||||
return AjaxResult.success("${column.itDescribe}测试!");
|
return AjaxResult.success("${column.itDescribe}测试!");
|
||||||
}catch (RuntimeException e){
|
}catch (RuntimeException e){
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return AjaxResult.error(ReturnConstants.DB_EX);
|
throw new EBTSException(ReturnConstants.OP_ERROR,e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.ebts.common.annotation.Log;
|
import com.ebts.common.annotation.Log;
|
||||||
import com.ebts.common.core.entity.AjaxResult;
|
import com.ebts.common.core.entity.AjaxResult;
|
||||||
import com.ebts.common.enums.BusinessType;
|
import com.ebts.common.enums.BusinessType;
|
||||||
|
import com.ebts.common.exception.EBTSException;
|
||||||
import ${packageName}.entity.${ClassName};
|
import ${packageName}.entity.${ClassName};
|
||||||
import ${packageName}.service.${ClassName}Service;
|
import ${packageName}.service.${ClassName}Service;
|
||||||
import com.ebts.common.utils.poi.ExcelUtil;
|
import com.ebts.common.utils.poi.ExcelUtil;
|
||||||
|
|
@ -74,7 +75,7 @@ public class ${ClassName}Controller extends EBTSController {
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
throw new EBTSException(ReturnConstants.SYS_ERROR,e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,7 +97,7 @@ public class ${ClassName}Controller extends EBTSController {
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
throw new EBTSException(ReturnConstants.SYS_ERROR,e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,7 +118,7 @@ public class ${ClassName}Controller extends EBTSController {
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
throw new EBTSException(ReturnConstants.SYS_ERROR,e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,7 +140,7 @@ public class ${ClassName}Controller extends EBTSController {
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
throw new EBTSException(ReturnConstants.SYS_ERROR,e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -161,7 +162,7 @@ public class ${ClassName}Controller extends EBTSController {
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
throw new EBTSException(ReturnConstants.SYS_ERROR,e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -186,7 +187,7 @@ public class ${ClassName}Controller extends EBTSController {
|
||||||
}
|
}
|
||||||
}catch (RuntimeException e){
|
}catch (RuntimeException e){
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return AjaxResult.error(ReturnConstants.SYS_ERROR);
|
throw new EBTSException(ReturnConstants.SYS_ERROR,e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue