与若依数据权限联动

This commit is contained in:
Dftre 2024-04-30 03:02:24 +08:00
parent 8a89fec1d5
commit bb846dd269
3 changed files with 30 additions and 0 deletions

View File

@ -14,4 +14,6 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface EnableTableMap { public @interface EnableTableMap {
String name() default "t"; String name() default "t";
String dept() default "";
String user() default "";
} }

View File

@ -9,6 +9,7 @@ import java.util.stream.Collectors;
import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.AnnotationUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.mybatis.annotation.Column; import com.ruoyi.mybatis.annotation.Column;
import com.ruoyi.mybatis.annotation.ColumnMap; import com.ruoyi.mybatis.annotation.ColumnMap;
import com.ruoyi.mybatis.annotation.EnableTableMap; import com.ruoyi.mybatis.annotation.EnableTableMap;
@ -27,6 +28,7 @@ public class TableInfo {
private List<ColumnInfo> primaryKeys = new ArrayList<>(); private List<ColumnInfo> primaryKeys = new ArrayList<>();
private List<MapColumnInfo> mapColumns = new ArrayList<>(); private List<MapColumnInfo> mapColumns = new ArrayList<>();
private Set<String> joinSql = new HashSet<>(); private Set<String> joinSql = new HashSet<>();
boolean hasDataScopeValue = false;
public TableInfo(Class<?> cls) { public TableInfo(Class<?> cls) {
this.table = AnnotationUtils.findAnnotation(cls, Table.class); this.table = AnnotationUtils.findAnnotation(cls, Table.class);
@ -56,7 +58,25 @@ public class TableInfo {
+ join.target() + "." + join.targetColumn() + " = " + join.target() + "." + join.targetColumn() + " = "
+ this.getTableNameT() + "." + join.targetColumn()) + this.getTableNameT() + "." + join.targetColumn())
.forEach(joinSql::add); .forEach(joinSql::add);
if (this.enableTableMap != null) {
if (StringUtils.isNotEmpty(this.enableTableMap.user())) {
this.joinSql.add("sys_user " + this.enableTableMap.user() + " on "
+ this.enableTableMap.user() + ".user_id = "
+ this.getTableNameT() + "." + ".user_id");
this.hasDataScopeValue = true;
}
if (StringUtils.isNotEmpty(this.enableTableMap.dept())) {
this.joinSql.add("sys_dept " + this.enableTableMap.dept() + " on "
+ this.enableTableMap.dept() + ".dept_id = "
+ this.getTableNameT() + ".dept_id");
this.hasDataScopeValue = true;
}
}
}
public boolean hasDataScope() {
return this.hasDataScopeValue;
} }
public Set<String> getJoinSql() { public Set<String> getJoinSql() {

View File

@ -45,6 +45,10 @@ public class SQLUtil {
.map(ColumnInfo::getQuerySql) .map(ColumnInfo::getQuerySql)
.map(query -> tableInfo.getTableNameT() + "." + query) .map(query -> tableInfo.getTableNameT() + "." + query)
.forEach(sql::WHERE); .forEach(sql::WHERE);
if (tableInfo.hasDataScope()) {
sql.WHERE("1=1 ${params.dataScope}");
}
} else { } else {
tableInfo.getNotNullColumns(entity).stream() tableInfo.getNotNullColumns(entity).stream()
.map(ColumnInfo::getQuerySql) .map(ColumnInfo::getQuerySql)
@ -105,6 +109,10 @@ public class SQLUtil {
.map(column -> tableInfo.getTableNameT() + "." + column.getColumnName() + " = " .map(column -> tableInfo.getTableNameT() + "." + column.getColumnName() + " = "
+ column.getTemplate()) + column.getTemplate())
.forEach(sql::WHERE); .forEach(sql::WHERE);
if (tableInfo.hasDataScope()) {
sql.WHERE("1=1 ${params.dataScope}");
}
} else { } else {
tableInfo.getPrimaryKeys().stream() tableInfo.getPrimaryKeys().stream()
.map(column -> column.getColumnName() + " = " + column.getTemplate()) .map(column -> column.getColumnName() + " = " + column.getTemplate())