package com.tourism.common.flow.online.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 主要用于拦截FlowTransactionBusinessDataListener监听器类抛出的异常。
 *
 * @author 吃饭睡觉
 * @date 2024-09-06
 */
@Aspect
@Component
@Order(1)
@Slf4j
public class FlowMultiDatabaseWriteExAspect {

    @Pointcut("execution(public * com.tourism.common.flow.online.service.impl..*(..)) " +
            "&& @annotation(com.tourism.common.core.annotation.MultiDatabaseWriteMethod)")
    public void multiDatabaseWriteMethodPointCut() {
        // 空注释，避免sonar警告
    }

    @Around("multiDatabaseWriteMethodPointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            return joinPoint.proceed();
        } catch (Exception e) {
            log.error("FlowMultiDatabaseWriteExAspect throw", e);
            throw e;
        }
    }
}
