mirror of
https://github.com/mfish-qf/mfish-nocode.git
synced 2026-10-28 02:42:09 +08:00
feat: 租户数据权限增加指定值
This commit is contained in:
+1
-6
@@ -1,7 +1,6 @@
|
||||
package cn.com.mfish.common.ds.config;
|
||||
|
||||
import cn.com.mfish.common.core.exception.MyRuntimeException;
|
||||
import cn.com.mfish.common.core.utils.StringUtils;
|
||||
import cn.com.mfish.common.ds.annotation.DataScope;
|
||||
import cn.com.mfish.common.ds.common.DataScopeUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -57,11 +56,7 @@ public class SelectInterceptor implements Interceptor {
|
||||
if (!oriSql.toLowerCase().contains(tableName.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
if (!StringUtils.isEmpty(scope.fieldName())) {
|
||||
oriSql = scope.type().getHandle().sqlChange(oriSql, tableName, scope.fieldName());
|
||||
} else {
|
||||
oriSql = scope.type().getHandle().sqlChange(oriSql, tableName, "");
|
||||
}
|
||||
oriSql = scope.type().getHandle().sqlChange(oriSql, tableName, scope.fieldName(), scope.value());
|
||||
}
|
||||
Field field = boundSql.getClass().getDeclaredField("sql");
|
||||
field.setAccessible(true);
|
||||
|
||||
+1
-1
@@ -7,5 +7,5 @@ package cn.com.mfish.common.ds.scope;
|
||||
*/
|
||||
public interface DataScopeHandle {
|
||||
|
||||
String sqlChange(String sql, String table, String fieldName);
|
||||
String sqlChange(String sql, String table, String fieldName, String value);
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ package cn.com.mfish.common.ds.scope;
|
||||
public class RoleDataScopeHandle implements DataScopeHandle {
|
||||
|
||||
@Override
|
||||
public String sqlChange(String sql, String table, String fieldName) {
|
||||
public String sqlChange(String sql, String table, String fieldName,String value) {
|
||||
//todo 补充逻辑
|
||||
return sql;
|
||||
}
|
||||
|
||||
+3
-2
@@ -14,13 +14,14 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class TenantDataScopeHandle implements DataScopeHandle {
|
||||
@Override
|
||||
public String sqlChange(String sql, String table, String fieldName) {
|
||||
public String sqlChange(String sql, String table, String fieldName,String value) {
|
||||
fieldName = StringUtils.isEmpty(fieldName) ? "tenant_id" : fieldName;
|
||||
value = StringUtils.isEmpty(value) ? AuthInfoUtils.getCurrentTenantId() : value;
|
||||
List<DataScopeUtils.SqlSplit> list = DataScopeUtils.splitSql(sql, table);
|
||||
for (DataScopeUtils.SqlSplit split : list) {
|
||||
if (split.isHaveTable()) {
|
||||
split.setStatement(split.getStatement().replaceAll(table
|
||||
, "(select * from " + table + " where " + fieldName + "='" + AuthInfoUtils.getCurrentTenantId() + "')"));
|
||||
, "(select * from " + table + " where " + fieldName + "='" + value + "')"));
|
||||
if (split.isHaveAlias()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user