refactor(dept):优化部门数据权限规则生成逻辑- 移除无用的GreaterThan导入

- 简化条件判断中的空格格式
- 使用InExpression替代FIND_IN_SET函数提高查询效率-保持代码风格一致性和可读性
This commit is contained in:
2025-10-20 20:50:35 +08:00
parent 136c2fa5aa
commit f3810d3126

View File

@@ -19,7 +19,6 @@ 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;
@@ -196,18 +195,14 @@ public class DeptDataPermissionRule implements DataPermissionRule {
Expression returnExpression = null;
String[] columnNames = columnName.split(",");
for (String column : columnNames) {
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));
Expression deptExpression = new InExpression(MyBatisUtils.buildColumn(tableName, tableAlias, column),
new ExpressionList(CollectionUtils.convertList(deptIds, LongValue::new)));
if (Objects.isNull(returnExpression)) {
returnExpression = deptExpression;
} else {
returnExpression = new Parenthesis(new OrExpression(returnExpression, deptExpression));
}
}
}
return returnExpression;
}