| | |
| | | package com.ruoyi.framework.aspectj; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; |
| | | import com.ruoyi.common.annotation.DataSource; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.annotation.Around; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Aspect |
| | | @Order(1) |
| | | @Order(-500) |
| | | @Component |
| | | public class DataSourceAspect { |
| | | |
| | |
| | | public Object around(ProceedingJoinPoint point) throws Throwable { |
| | | DataSource dataSource = getDataSource(point); |
| | | |
| | | if (Validator.isNotNull(dataSource)) { |
| | | DynamicDataSourceContextHolder.push(dataSource.value().name()); |
| | | if (StringUtils.isNotNull(dataSource)) { |
| | | DynamicDataSourceContextHolder.poll(); |
| | | String source = dataSource.value().getSource(); |
| | | DynamicDataSourceContextHolder.push(source); |
| | | } |
| | | |
| | | try { |