From 5804dd1fb9de2ecec50f703e6c3f4606bb0f56bc Mon Sep 17 00:00:00 2001 From: "20932067@zju.edu.cn" Date: Tue, 8 Jun 2021 00:10:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86+=E6=A8=A1=E6=9D=BF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ebts/common/exception/EBTSException.java | 32 +++++++++++++++++++ .../com/ebts/framework/aspectj/LogAspect.java | 3 ++ .../web/exception/GlobalExceptionHandler.java | 20 ++++++++---- .../src/main/resources/vm/java/class.java.vm | 5 +-- .../main/resources/vm/java/controller.java.vm | 13 ++++---- 5 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 ebts/ebts-common/src/main/java/com/ebts/common/exception/EBTSException.java diff --git a/ebts/ebts-common/src/main/java/com/ebts/common/exception/EBTSException.java b/ebts/ebts-common/src/main/java/com/ebts/common/exception/EBTSException.java new file mode 100644 index 0000000..cafd39b --- /dev/null +++ b/ebts/ebts-common/src/main/java/com/ebts/common/exception/EBTSException.java @@ -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(); + } +} diff --git a/ebts/ebts-framework/src/main/java/com/ebts/framework/aspectj/LogAspect.java b/ebts/ebts-framework/src/main/java/com/ebts/framework/aspectj/LogAspect.java index b9c0ff1..2cdfe53 100644 --- a/ebts/ebts-framework/src/main/java/com/ebts/framework/aspectj/LogAspect.java +++ b/ebts/ebts-framework/src/main/java/com/ebts/framework/aspectj/LogAspect.java @@ -124,6 +124,9 @@ public class LogAspect { public void getControllerMethodDescription(JoinPoint joinPoint, Log log, OperLog operLog) throws Exception { // 设置action动作 operLog.setBusinessType(log.businessType().ordinal()); + if (!operLog.getJsonResult().contains(":200")){ + operLog.setStatus(1); + } // 设置标题 operLog.setTitle(log.title()); // 设置操作人类别 diff --git a/ebts/ebts-framework/src/main/java/com/ebts/framework/web/exception/GlobalExceptionHandler.java b/ebts/ebts-framework/src/main/java/com/ebts/framework/web/exception/GlobalExceptionHandler.java index 91fa259..d9fa1b0 100644 --- a/ebts/ebts-framework/src/main/java/com/ebts/framework/web/exception/GlobalExceptionHandler.java +++ b/ebts/ebts-framework/src/main/java/com/ebts/framework/web/exception/GlobalExceptionHandler.java @@ -1,5 +1,12 @@ 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.LoggerFactory; 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.RestControllerAdvice; 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) { return AjaxResult.error(e.getMessage()); } + /** + * EBTS基础异常 + */ + @ExceptionHandler(EBTSException.class) + public AjaxResult ebtsException(EBTSException e) { + return AjaxResult.error(e.getMsg()); + } /** * 业务异常 diff --git a/ebts/ebts-generator/src/main/resources/vm/java/class.java.vm b/ebts/ebts-generator/src/main/resources/vm/java/class.java.vm index 1a4d8da..f641072 100644 --- a/ebts/ebts-generator/src/main/resources/vm/java/class.java.vm +++ b/ebts/ebts-generator/src/main/resources/vm/java/class.java.vm @@ -12,6 +12,7 @@ import com.ebts.common.constant.ReturnConstants; import com.ebts.common.core.controller.BaseController; import com.ebts.common.core.entity.AjaxResult; import com.ebts.common.enums.BusinessType; +import com.ebts.common.exception.EBTSException; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; @@ -42,7 +43,7 @@ public class ${ClassName}Controller extends BaseController{ @ApiOperation("${column.itDescribe}") #if($column.isPermission.equals("1")) @PreAuthorize("@ebts.hasPermi('${prefix}:${column.requrl}')") - @Log(title = "${column.itDescribe}", businessType = BusinessType.INSERT) + @Log(title = "${column.itDescribe}", businessType = BusinessType.OTHER) #end @${column.method}Mapping("/${column.requrl}") #if($column.method.equals("Get")) @@ -54,7 +55,7 @@ public class ${ClassName}Controller extends BaseController{ return AjaxResult.success("${column.itDescribe}测试!"); }catch (RuntimeException e){ logger.error(e.getMessage()); - return AjaxResult.error(ReturnConstants.DB_EX); + throw new EBTSException(ReturnConstants.OP_ERROR,e); } } #end diff --git a/ebts/ebts-generator/src/main/resources/vm/java/controller.java.vm b/ebts/ebts-generator/src/main/resources/vm/java/controller.java.vm index 6e1a67f..3913280 100644 --- a/ebts/ebts-generator/src/main/resources/vm/java/controller.java.vm +++ b/ebts/ebts-generator/src/main/resources/vm/java/controller.java.vm @@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.RestController; import com.ebts.common.annotation.Log; import com.ebts.common.core.entity.AjaxResult; import com.ebts.common.enums.BusinessType; +import com.ebts.common.exception.EBTSException; import ${packageName}.entity.${ClassName}; import ${packageName}.service.${ClassName}Service; import com.ebts.common.utils.poi.ExcelUtil; @@ -74,7 +75,7 @@ public class ${ClassName}Controller extends EBTSController { } } catch (RuntimeException e) { 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) { 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) { 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) { 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) { 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){ logger.error(e.getMessage()); - return AjaxResult.error(ReturnConstants.SYS_ERROR); + throw new EBTSException(ReturnConstants.SYS_ERROR,e); } } }