|
@@ -1,18 +1,13 @@
|
|
|
package com.ruoyi.framework.aspectj;
|
|
|
|
|
|
-import com.alibaba.fastjson2.JSON;
|
|
|
+
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.exception.tenantdatassource.TenantDataSource;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
-import com.ruoyi.common.utils.ServletUtils;
|
|
|
-import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.reflect.ReflectUtils;
|
|
|
-import com.ruoyi.framework.web.service.TokenService;
|
|
|
import org.apache.ibatis.executor.statement.StatementHandler;
|
|
|
import org.apache.ibatis.plugin.*;
|
|
|
-import org.aspectj.lang.annotation.Before;
|
|
|
|
|
|
-import java.lang.reflect.InvocationTargetException;
|
|
|
import java.sql.Connection;
|
|
|
import java.util.Properties;
|
|
|
|
|
@@ -27,26 +22,20 @@ import java.util.Properties;
|
|
|
public class SqlInterceptor implements Interceptor {
|
|
|
|
|
|
@Override
|
|
|
- public Object intercept(Invocation invocation) throws Throwable {
|
|
|
+ public Object intercept(Invocation invocation) throws Throwable, TenantDataSource {
|
|
|
StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
|
|
|
String sql = statementHandler.getBoundSql().getSql();
|
|
|
- if (SecurityUtils.getUsername().equals("admin")) {
|
|
|
+ // 修改SQL语句
|
|
|
+ String modifiedSql = BeforeSQL(sql);
|
|
|
+ if (modifiedSql.equals("error")) {
|
|
|
+ // 终止程序
|
|
|
+ return AjaxResult.error("当前用户没有数据源信息!");
|
|
|
+ } else {
|
|
|
+ // 将修改后的SQL语句设置回StatementHandler
|
|
|
+ ReflectUtils.setFieldValue(statementHandler.getBoundSql(), "sql", modifiedSql);
|
|
|
+ invocation.proceed();
|
|
|
ReflectUtils.setFieldValue(statementHandler.getBoundSql(), "sql", sql);
|
|
|
return invocation.proceed();
|
|
|
- } else {
|
|
|
- // 修改SQL语句
|
|
|
- String modifiedSql = BeforeSQL(sql);
|
|
|
- if (modifiedSql.equals("error")) {
|
|
|
- throw new TenantDataSource("数据源");
|
|
|
- // 终止程序
|
|
|
-// return AjaxResult.error("当前用户没有数据源信息!");
|
|
|
- } else {
|
|
|
- // 将修改后的SQL语句设置回StatementHandler
|
|
|
- ReflectUtils.setFieldValue(statementHandler.getBoundSql(), "sql", modifiedSql);
|
|
|
- invocation.proceed();
|
|
|
- ReflectUtils.setFieldValue(statementHandler.getBoundSql(), "sql", sql);
|
|
|
- return invocation.proceed();
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|