From d23645e976981bc9b670eea1d469fe8a36be309c Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Wed, 17 Apr 2024 17:19:53 +0800
Subject: [PATCH] 55测试环境
---
src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java | 37 ++++++++++++++++++++++++++++++-------
1 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java b/src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java
index 8e1f8e4..637f5aa 100644
--- a/src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java
+++ b/src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java
@@ -1,19 +1,26 @@
package com.xcong.excoin.common.aop;
+import cn.hutool.http.HttpException;
import com.xcong.excoin.common.exception.GlobalException;
import com.xcong.excoin.common.system.bean.SysExceptionDetailEntity;
import com.xcong.excoin.modules.platform.dao.SysExceptionDetailDao;
+import com.xcong.excoin.utils.ThreadPoolUtils;
+import com.xcong.excoin.utils.dingtalk.DingTalkUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.client.ResourceAccessException;
+import javax.net.ssl.SSLException;
import javax.validation.ValidationException;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -37,13 +44,16 @@
@Autowired
private SysExceptionDetailDao sysExceptionDetailDao;
+ @Value("${spring.profiles.active}")
+ private String profiles;
+
@Pointcut("execution(* com.xcong.excoin..*.*(..))")
public void exceptionCatch() {
}
@AfterThrowing(pointcut = "exceptionCatch()", throwing = "ex")
public void afterThrows(JoinPoint jp, Exception ex) throws Exception {
- if (ex instanceof GlobalException || ex instanceof MethodArgumentNotValidException || ex instanceof ValidationException || ex instanceof DuplicateKeyException || ex instanceof BadCredentialsException) {
+ if (ex instanceof HttpException || ex instanceof ResourceAccessException || ex instanceof GlobalException || ex instanceof MethodArgumentNotValidException || ex instanceof ValidationException || ex instanceof DuplicateKeyException || ex instanceof BadCredentialsException || ex instanceof UsernameNotFoundException || ex instanceof SSLException) {
throw ex;
}
@@ -52,12 +62,25 @@
}
SysExceptionDetailEntity exceptionData = new SysExceptionDetailEntity();
- exceptionData.setCreateTime(new Date());
- exceptionData.setMachine(InetAddress.getLocalHost().getHostName());
- exceptionData.setAddress(InetAddress.getLocalHost().getHostAddress());
- exceptionData.setExceptionMsg(printStackTraceToString(ex.fillInStackTrace()));
- exceptionData.setSimpleMsg(ex.getMessage());
- sysExceptionDetailDao.insert(exceptionData);
+ String exStr = printStackTraceToString(ex);
+ ThreadPoolUtils.EXECUTOR.execute(new Runnable(){
+ @Override
+ public void run() {
+ try {
+ log.info("插入");
+ exceptionData.setCreateTime(new Date());
+ exceptionData.setMachine(InetAddress.getLocalHost().getHostName() + "-" + profiles);
+ exceptionData.setAddress(InetAddress.getLocalHost().getHostAddress());
+ exceptionData.setExceptionMsg(exStr);
+ exceptionData.setSimpleMsg(ex.getMessage());
+ sysExceptionDetailDao.insert(exceptionData);
+
+// DingTalkUtils.sendMsg(profiles + "--" + ex.getMessage(), exStr.substring(0, 200), exceptionData.getId());
+ } catch (Exception e) {
+ log.error("exception aop", e);
+ }
+ }
+ });
throw ex;
}
--
Gitblit v1.9.1