From f3810d31263da49f79969efdada81a83b8f50a23 Mon Sep 17 00:00:00 2001 From: yang chen Date: Mon, 20 Oct 2025 20:50:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(dept):=E4=BC=98=E5=8C=96=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=E8=A7=84=E5=88=99?= =?UTF-8?q?=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91-=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E7=9A=84GreaterThan=E5=AF=BC=E5=85=A5=20-=20?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E7=A9=BA=E6=A0=BC=E6=A0=BC=E5=BC=8F=20-=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8InExpression=E6=9B=BF=E4=BB=A3FIND=5FIN=5FSET=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=8F=90=E9=AB=98=E6=9F=A5=E8=AF=A2=E6=95=88=E7=8E=87?= =?UTF-8?q?-=E4=BF=9D=E6=8C=81=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E6=80=A7=E5=92=8C=E5=8F=AF=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rule/dept/DeptDataPermissionRule.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/jeelowcode-tool/tool-spring-boot-starter-biz-data-permission/src/main/java/com/jeelowcode/tool/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java b/jeelowcode-tool/tool-spring-boot-starter-biz-data-permission/src/main/java/com/jeelowcode/tool/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java index d0571d4..ace750d 100644 --- a/jeelowcode-tool/tool-spring-boot-starter-biz-data-permission/src/main/java/com/jeelowcode/tool/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java +++ b/jeelowcode-tool/tool-spring-boot-starter-biz-data-permission/src/main/java/com/jeelowcode/tool/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java @@ -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; @@ -141,17 +140,17 @@ public class DeptDataPermissionRule implements DataPermissionRule { return customDeptExpression; } - if (Objects.nonNull(deptExpression) && Objects.nonNull(userExpression) && Objects.nonNull(customDeptExpression)) { + if(Objects.nonNull(deptExpression) && Objects.nonNull(userExpression) && Objects.nonNull(customDeptExpression)){ // 目前,如果有指定部门 + 可查看自己,采用 OR 条件。即,WHERE (dept_id IN ? OR user_id = ?) return new Parenthesis(new OrExpression(new OrExpression(deptExpression, userExpression), customDeptExpression)); } - if (Objects.nonNull(deptExpression) && Objects.nonNull(userExpression)) { + if(Objects.nonNull(deptExpression) && Objects.nonNull(userExpression)){ // 目前,如果有指定部门 + 可查看自己,采用 OR 条件。即,WHERE (dept_id IN ? OR user_id = ?) return new Parenthesis(new OrExpression(deptExpression, userExpression)); } - if (Objects.nonNull(deptExpression)) { + if(Objects.nonNull(deptExpression)){ // 目前,如果有指定部门 + 可查看自己,采用 OR 条件。即,WHERE (dept_id IN ? OR user_id = ?) return new Parenthesis(new OrExpression(deptExpression, customDeptExpression)); } @@ -196,16 +195,12 @@ 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)); - if (Objects.isNull(returnExpression)) { - returnExpression = deptExpression; - } else { - returnExpression = new Parenthesis(new OrExpression(returnExpression, deptExpression)); - } + 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;