【8.3.3】【dataScope】更新数据范围sql拼接的表达式

pull/62/head
stylefeng 2025-01-25 23:28:41 +08:00
parent 7e50b7d650
commit 8f94db520d
1 changed files with 22 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.handler.MultiDataPermissionHan
import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue; import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.Parenthesis; import net.sf.jsqlparser.expression.Parenthesis;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo; import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList; import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.InExpression; import net.sf.jsqlparser.expression.operators.relational.InExpression;
@ -52,14 +53,35 @@ public class ProjectDataScopeHandler implements MultiDataPermissionHandler {
return null; return null;
} }
Expression dataScopeExpression = null;
// 如果是需要校验仅创建人数据 // 如果是需要校验仅创建人数据
if (dataScopeConfig.isDoCreateUserValidate()) { if (dataScopeConfig.isDoCreateUserValidate()) {
// 获取创建人ID
Long currentUserId = dataScopeConfig.getUserId();
// 生成创建人条件表达式
dataScopeExpression = getEqualsTo(dataScopeConfig.getUserIdFieldName(), currentUserId);
} }
// 如果是需要校验指定部门数据 // 如果是需要校验指定部门数据
if (dataScopeConfig.isDoOrgScopeValidate()) { if (dataScopeConfig.isDoOrgScopeValidate()) {
// 获取组织范围条件表达式
InExpression orgScopeCondition = getInExpression(dataScopeConfig);
// 如果已经有创建人条件,需要合并
if (dataScopeExpression != null) {
// 使用 OrExpression 合并条件
dataScopeExpression = new AndExpression(dataScopeExpression, orgScopeCondition);
} else {
// 否则仅使用组织范围条件
dataScopeExpression = orgScopeCondition;
}
} }
return dataScopeExpression;
} }
/** /**