|
@@ -1,48 +1,47 @@
|
|
-// package com.sd.framework.aspect;
|
|
|
|
-//
|
|
|
|
-// import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
|
-// 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.Ordered;
|
|
|
|
-// import org.springframework.core.annotation.Order;
|
|
|
|
-// import org.springframework.stereotype.Component;
|
|
|
|
-//
|
|
|
|
-// import java.util.Objects;
|
|
|
|
-//
|
|
|
|
-// @Aspect
|
|
|
|
-// @Component
|
|
|
|
-// @Order(Ordered.HIGHEST_PRECEDENCE)
|
|
|
|
-// public class DataSourceAspect {
|
|
|
|
-//
|
|
|
|
-// @Pointcut("execution (* com.*.*.service.*.*.*(..))")
|
|
|
|
-// public void pointcut() {
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// @Around(value = "pointcut()")
|
|
|
|
-// public Object before(ProceedingJoinPoint point) throws Throwable {
|
|
|
|
-// Object target = point.getTarget();
|
|
|
|
-// String name = target.getClass().getName();
|
|
|
|
-// String moduleName = name.split("\\.")[2];
|
|
|
|
-//
|
|
|
|
-// String peek = DynamicDataSourceContextHolder.peek();
|
|
|
|
-// if (Objects.equals(peek, moduleName)) {
|
|
|
|
-// return point.proceed();
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// if (moduleName.equals("")) {
|
|
|
|
-// try {
|
|
|
|
-// DynamicDataSourceContextHolder.push(moduleName);
|
|
|
|
-// return point.proceed();
|
|
|
|
-// } finally {
|
|
|
|
-// DynamicDataSourceContextHolder.poll();
|
|
|
|
-// }
|
|
|
|
-// } else {
|
|
|
|
-// return point.proceed();
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
|
|
+package com.sd.framework.aspect;
|
|
|
|
+
|
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
|
+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.Ordered;
|
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.util.Objects;
|
|
|
|
+
|
|
|
|
+@Aspect
|
|
|
|
+@Component
|
|
|
|
+@Order(Ordered.HIGHEST_PRECEDENCE)
|
|
|
|
+public class DataSourceAspect {
|
|
|
|
+
|
|
|
|
+ @Pointcut("execution (* com.*.*.service.*.*.*(..))")
|
|
|
|
+ public void pointcut() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Around(value = "pointcut()")
|
|
|
|
+ public Object before(ProceedingJoinPoint point) throws Throwable {
|
|
|
|
+ Object target = point.getTarget();
|
|
|
|
+ String name = target.getClass().getName();
|
|
|
|
+ String moduleName = name.split("\\.")[2];
|
|
|
|
+
|
|
|
|
+ String peek = DynamicDataSourceContextHolder.peek();
|
|
|
|
+ if (Objects.equals(peek, moduleName)) {
|
|
|
|
+ return point.proceed();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (moduleName.equals("")) {
|
|
|
|
+ try {
|
|
|
|
+ DynamicDataSourceContextHolder.push(moduleName);
|
|
|
|
+ return point.proceed();
|
|
|
|
+ } finally {
|
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return point.proceed();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|