|
@@ -23,6 +23,8 @@ import lombok.*;
|
|
|
import net.sf.jsqlparser.expression.Expression;
|
|
|
import net.sf.jsqlparser.statement.select.PlainSelect;
|
|
|
import net.sf.jsqlparser.statement.select.Select;
|
|
|
+import net.sf.jsqlparser.statement.select.SelectBody;
|
|
|
+import net.sf.jsqlparser.statement.select.SetOperationList;
|
|
|
import org.apache.ibatis.executor.Executor;
|
|
|
import org.apache.ibatis.mapping.BoundSql;
|
|
|
import org.apache.ibatis.mapping.MappedStatement;
|
|
@@ -30,6 +32,7 @@ import org.apache.ibatis.session.ResultHandler;
|
|
|
import org.apache.ibatis.session.RowBounds;
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 数据权限处理器
|
|
@@ -55,8 +58,24 @@ public class DataPermissionInterceptor extends JsqlParserSupport implements Inne
|
|
|
|
|
|
@Override
|
|
|
protected void processSelect(Select select, int index, String sql, Object obj) {
|
|
|
- PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
|
|
|
- Expression sqlSegment = dataPermissionHandler.getSqlSegment(plainSelect.getWhere(), (String) obj);
|
|
|
+ SelectBody selectBody = select.getSelectBody();
|
|
|
+ if (selectBody instanceof PlainSelect) {
|
|
|
+ this.setWhere((PlainSelect) selectBody, (String) obj);
|
|
|
+ } else if (selectBody instanceof SetOperationList) {
|
|
|
+ SetOperationList setOperationList = (SetOperationList) selectBody;
|
|
|
+ List<SelectBody> selectBodyList = setOperationList.getSelects();
|
|
|
+ selectBodyList.forEach(s -> this.setWhere((PlainSelect) s, (String) obj));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置 where 条件
|
|
|
+ *
|
|
|
+ * @param plainSelect 查询对象
|
|
|
+ * @param whereSegment 查询条件片段
|
|
|
+ */
|
|
|
+ protected void setWhere(PlainSelect plainSelect, String whereSegment) {
|
|
|
+ Expression sqlSegment = dataPermissionHandler.getSqlSegment(plainSelect.getWhere(), whereSegment);
|
|
|
if (null != sqlSegment) {
|
|
|
plainSelect.setWhere(sqlSegment);
|
|
|
}
|