From 453603b6ad3089291e80a6cbf2977e4ada366485 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 13 Dec 2022 10:37:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20SQL=20=E6=9D=A1=E4=BB=B6=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E7=BC=BA=E5=B0=91=E6=8B=AC=E5=8F=B7=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rule/dept/DeptDataPermissionRule.java | 6 ++--- .../framework/expression/AndExpressionX.java | 24 +++++++++++++++++++ .../framework/expression/OrExpressionX.java | 24 +++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/AndExpressionX.java create mode 100644 yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/OrExpressionX.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java b/yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java index 7f9a74a61..ae73963c4 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.datapermission.core.rule.DataPermissionRule; +import cn.iocoder.yudao.framework.expression.OrExpressionX; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.framework.security.core.LoginUser; @@ -20,7 +21,6 @@ import net.sf.jsqlparser.expression.Alias; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.LongValue; import net.sf.jsqlparser.expression.NullValue; -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.InExpression; @@ -143,8 +143,8 @@ public class DeptDataPermissionRule implements DataPermissionRule { if (userExpression == null) { return deptExpression; } - // 目前,如果有指定部门 + 可查看自己,采用 OR 条件。即,WHERE dept_id IN ? OR user_id = ? - return new OrExpression(deptExpression, userExpression); + // 目前,如果有指定部门 + 可查看自己,采用 OR 条件。即,WHERE (dept_id IN ? OR user_id = ?) + return new OrExpressionX(deptExpression, userExpression); } private Expression buildDeptExpression(String tableName, Alias tableAlias, Set deptIds) { diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/AndExpressionX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/AndExpressionX.java new file mode 100644 index 000000000..56fefbce5 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/AndExpressionX.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.framework.expression; + +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.operators.conditional.AndExpression; + +/** + * AndExpression 的扩展类(会在原有表达式两端加上括号) + */ +public class AndExpressionX extends AndExpression { + + public AndExpressionX() { + } + + public AndExpressionX(Expression leftExpression, Expression rightExpression) { + this.setLeftExpression(leftExpression); + this.setRightExpression(rightExpression); + } + + @Override + public String toString() { + return "(" + this.getLeftExpression() + " " + this.getStringExpression() + " " + this.getRightExpression() + ")"; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/OrExpressionX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/OrExpressionX.java new file mode 100644 index 000000000..53b7e684d --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/OrExpressionX.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.framework.expression; + +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.operators.conditional.OrExpression; + +/** + * OrExpression 的扩展类(会在原有表达式两端加上括号) + */ +public class OrExpressionX extends OrExpression { + + public OrExpressionX() { + } + + public OrExpressionX(Expression leftExpression, Expression rightExpression) { + this.setLeftExpression(leftExpression); + this.setRightExpression(rightExpression); + } + + @Override + public String toString() { + return "(" + this.getLeftExpression() + " " + this.getStringExpression() + " " + this.getRightExpression() + ")"; + } + +} From 766b74f040c9a89a2112420a0a9052479dcd86b6 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Wed, 14 Dec 2022 08:57:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20SQL=20=E6=9D=A1=E4=BB=B6=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E7=BC=BA=E5=B0=91=E6=8B=AC=E5=8F=B7=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/iocoder/yudao/framework/expression/AndExpressionX.java | 2 +- .../cn/iocoder/yudao/framework/expression/OrExpressionX.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/AndExpressionX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/AndExpressionX.java index 56fefbce5..54198e496 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/AndExpressionX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/AndExpressionX.java @@ -18,7 +18,7 @@ public class AndExpressionX extends AndExpression { @Override public String toString() { - return "(" + this.getLeftExpression() + " " + this.getStringExpression() + " " + this.getRightExpression() + ")"; + return "(" + super.toString() + ")"; } } diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/OrExpressionX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/OrExpressionX.java index 53b7e684d..19b4695cf 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/OrExpressionX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/expression/OrExpressionX.java @@ -18,7 +18,7 @@ public class OrExpressionX extends OrExpression { @Override public String toString() { - return "(" + this.getLeftExpression() + " " + this.getStringExpression() + " " + this.getRightExpression() + ")"; + return "(" + super.toString() + ")"; } }