|
|
@@ -0,0 +1,58 @@
|
|
|
+package com.jzg.config;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
|
|
+import org.apache.ibatis.executor.Executor;
|
|
|
+import org.apache.ibatis.executor.statement.StatementHandler;
|
|
|
+import org.apache.ibatis.mapping.MappedStatement;
|
|
|
+import org.apache.ibatis.plugin.*;
|
|
|
+import org.apache.ibatis.mapping.BoundSql;
|
|
|
+import org.apache.ibatis.reflection.MetaObject;
|
|
|
+import org.apache.ibatis.session.ResultHandler;
|
|
|
+import org.apache.ibatis.session.RowBounds;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.util.Properties;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 数据权限拦截器
|
|
|
+ */
|
|
|
+@Intercepts({
|
|
|
+ @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
|
|
|
+// @Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})
|
|
|
+})
|
|
|
+public class DataPermissionInterceptor implements InnerInterceptor {
|
|
|
+ private final RedissonClient redissonClient;
|
|
|
+
|
|
|
+ public DataPermissionInterceptor(RedissonClient redissonClient){
|
|
|
+ this.redissonClient = redissonClient;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
|
|
|
+ String currentUserDeptId = "123";
|
|
|
+
|
|
|
+// // 获取原始 SQL
|
|
|
+// String sql = boundSql.getSql();
|
|
|
+//
|
|
|
+// if (sql.toLowerCase().contains("select")) {
|
|
|
+// sql += " AND dept_id = '" + currentUserDeptId + "'";
|
|
|
+// Field field = null;
|
|
|
+// try {
|
|
|
+// field = BoundSql.class.getDeclaredField("sql");
|
|
|
+// } catch (NoSuchFieldException e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// }
|
|
|
+// field.setAccessible(true);
|
|
|
+// try {
|
|
|
+// field.set(boundSql, sql);
|
|
|
+// } catch (IllegalAccessException e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+}
|