| | |
| | | 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 |
| | | * @author Lion Li |
| | | */ |
| | | @Aspect |
| | | @Order(-500) |
| | |
| | | public class DataSourceAspect { |
| | | |
| | | @Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)" |
| | | + "|| @within(com.ruoyi.common.annotation.DataSource)") |
| | | + "|| @within(com.ruoyi.common.annotation.DataSource)") |
| | | public void dsPointCut() { |
| | | } |
| | | |
| | |
| | | public Object around(ProceedingJoinPoint point) throws Throwable { |
| | | DataSource dataSource = getDataSource(point); |
| | | |
| | | if (Validator.isNotNull(dataSource)) { |
| | | if (StringUtils.isNotNull(dataSource)) { |
| | | DynamicDataSourceContextHolder.poll(); |
| | | String source = dataSource.value().getSource(); |
| | | DynamicDataSourceContextHolder.push(source); |
| | |
| | | |
| | | return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class); |
| | | } |
| | | |
| | | } |