feat(datapermission):优化部门数据权限规则生成逻辑

- 引入 GreaterThan 表达式支持更灵活的条件构建
- 使用 FIND_IN_SET 函数替换原有的 IN 表达式实现
- 支持多部门 ID 的逐个条件拼接,提升查询准确性
-保留原有括号包装与 OR 连接逻辑确保语义一致
- 统一代码缩进风格增强可读性
This commit is contained in:
2025-10-20 16:00:44 +08:00
parent 8840eccf41
commit 8558ff726e

View File

@@ -19,6 +19,7 @@ import net.sf.jsqlparser.expression.*;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.GreaterThan;
import net.sf.jsqlparser.expression.operators.relational.InExpression;
import javax.annotation.Resource;
@@ -195,14 +196,18 @@ public class DeptDataPermissionRule implements DataPermissionRule {
Expression returnExpression = null;
String[] columnNames = columnName.split(",");
for (String column : columnNames) {
Expression deptExpression = new InExpression(MyBatisUtils.buildColumn(tableName, tableAlias, column),
new ExpressionList(CollectionUtils.convertList(deptIds, LongValue::new)));
for (Long deptId : deptIds) {
Expression deptExpression = new GreaterThan()
.withLeftExpression(new Function().withName("FIND_IN_SET")
.withParameters(new ExpressionList(new StringValue(deptId.toString()), MyBatisUtils.buildColumn(tableName, tableAlias, column))))
.withRightExpression(new LongValue(0));
if (Objects.isNull(returnExpression)) {
returnExpression = deptExpression;
} else {
returnExpression = new Parenthesis(new OrExpression(returnExpression, deptExpression));
}
}
}
return returnExpression;
}