package org.jeecg.config.transactional; 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.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * 功能描述: * * @Author: chenchuang * @Date: 2022/3/31 16:50 */ @Aspect @Component public class MultiTransactionAop { private final ComboTransaction comboTransaction; @Autowired public MultiTransactionAop(ComboTransaction comboTransaction) { this.comboTransaction = comboTransaction; } @Pointcut("@annotation(org.jeecg.config.transactional.MultiTransactional)") public void pointCut() { } @Around("pointCut() && @annotation(multiTransactional)") public Object inMultiTransactions(ProceedingJoinPoint pjp, MultiTransactional multiTransactional) { return comboTransaction.inCombinedTx(() -> { try { return pjp.proceed(); } catch (Throwable throwable) { if (throwable instanceof RuntimeException) { throw (RuntimeException) throwable; } throw new RuntimeException(throwable); } }, multiTransactional.value()); } }