KKSU
2024-04-17 d23645e976981bc9b670eea1d469fe8a36be309c
src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java
@@ -1,8 +1,10 @@
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;
@@ -16,7 +18,9 @@
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;
@@ -49,7 +53,7 @@
    @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 || ex instanceof UsernameNotFoundException) {
        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;
        }
@@ -58,14 +62,25 @@
        }
        SysExceptionDetailEntity exceptionData = new SysExceptionDetailEntity();
        exceptionData.setCreateTime(new Date());
        exceptionData.setMachine(InetAddress.getLocalHost().getHostName()+"-"+profiles);
        exceptionData.setAddress(InetAddress.getLocalHost().getHostAddress());
        exceptionData.setExceptionMsg(printStackTraceToString(ex));
        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.sendActionCard(6);
//                    DingTalkUtils.sendMsg(profiles + "--" + ex.getMessage(), exStr.substring(0, 200), exceptionData.getId());
                } catch (Exception e) {
                    log.error("exception aop", e);
                }
            }
        });
        throw ex;
    }