Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
707abaf3
提交
707abaf3
编写于
5月 17, 2021
作者:
xignzi006
🇨🇳
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SaaS表达式中租户列补充
上级
2a8773f2
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
90 行增加
和
28 行删除
+90
-28
SaaSTenantSqlParser.java.ftl
...YS_PKGPATH%/core/util/config/SaaSTenantSqlParser.java.ftl
+90
-28
未找到文件。
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/util/config/SaaSTenantSqlParser.java.ftl
浏览文件 @
707abaf3
...
...
@@ -6,10 +6,14 @@ package ${pub.getPKGCodeName()}.core.util.config;
import
com
.
baomidou
.
mybatisplus
.
core
.
toolkit
.
StringPool
;
import
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
tenant
.
TenantSqlParser
;
import
net
.
sf
.
jsqlparser
.
expression
.
Expression
;
import
net
.
sf
.
jsqlparser
.
expression
.
Function
;
import
net
.
sf
.
jsqlparser
.
expression
.*;
import
net
.
sf
.
jsqlparser
.
expression
.
operators
.
arithmetic
.
Addition
;
import
net
.
sf
.
jsqlparser
.
expression
.
operators
.
arithmetic
.
Division
;
import
net
.
sf
.
jsqlparser
.
expression
.
operators
.
arithmetic
.
Multiplication
;
import
net
.
sf
.
jsqlparser
.
expression
.
operators
.
arithmetic
.
Subtraction
;
import
net
.
sf
.
jsqlparser
.
expression
.
operators
.
conditional
.
AndExpression
;
import
net
.
sf
.
jsqlparser
.
expression
.
operators
.
conditional
.
OrExpression
;
import
net
.
sf
.
jsqlparser
.
expression
.
operators
.
relational
.*;
import
net
.
sf
.
jsqlparser
.
schema
.
Column
;
import
net
.
sf
.
jsqlparser
.
schema
.
Table
;
import
net
.
sf
.
jsqlparser
.
statement
.
select
.*;
...
...
@@ -24,7 +28,9 @@ public class SaaSTenantSqlParser extends TenantSqlParser {
*
@
param
plainSelect
ignore
*
@
param
addColumn
是否添加租户列
,
insert
into
select
语句中需要
*/
@
Override
protected
void
processPlainSelect
(
PlainSelect
plainSelect
,
boolean
addColumn
)
{
//
处理
selectItem
表达式
processSelectItem
(
plainSelect
);
FromItem
fromItem
=
plainSelect
.
getFromItem
();
if
(
fromItem
instanceof
Table
)
{
...
...
@@ -32,10 +38,11 @@ public class SaaSTenantSqlParser extends TenantSqlParser {
if
(
!this.getTenantHandler().doTableFilter(fromTable.getName())) {
plainSelect
.
setWhere
(
builderExpression
(
plainSelect
.
getWhere
(),
fromTable
));
if
(
addColumn
)
{
if
(
fromItem
.
getAlias
()
!= null)
if
(
fromItem
.
getAlias
()
!= null)
{
plainSelect
.
getSelectItems
().
add
(
new
SelectExpressionItem
(
new
Column
(
fromItem
.
getAlias
().
getName
()
+
StringPool
.
DOT
+
this
.
getTenantHandler
().
getTenantIdColumn
())));
else
}
else
{
plainSelect
.
getSelectItems
().
add
(
new
SelectExpressionItem
(
new
Column
(
this
.
getTenantHandler
().
getTenantIdColumn
())));
}
}
}
}
else
{
...
...
@@ -48,27 +55,90 @@ public class SaaSTenantSqlParser extends TenantSqlParser {
processFromItem
(
j
.
getRightItem
());
});
}
processWhere
(
plainSelect
.
getWhere
());
//
处理
where
表达式
processExcepression
(
plainSelect
.
getWhere
());
}
/**
*
where
条件中包含
function
中
select
添加租户
id
*
exception
表达式处理
*/
protected
void
process
Where
(
Expression
where
)
{
if
(
where
==
null
)
protected
void
process
Excepression
(
Expression
exception
)
{
if
(
exception
==
null
)
{
return
;
if
(
where
instanceof
AndExpression
)
{
processWhere
(((
AndExpression
)
where
).
getLeftExpression
());
processWhere
(((
AndExpression
)
where
).
getRightExpression
());
}
else
if
(
where
instanceof
OrExpression
)
{
processWhere
(((
OrExpression
)
where
).
getLeftExpression
());
processWhere
(((
OrExpression
)
where
).
getRightExpression
());
}
else
if
(
where
instanceof
Function
)
{
for
(
Expression
e
:
((
Function
)
where
).
getParameters
().
getExpressions
())
{
if
(
e
instanceof
SubSelect
)
{
this
.
processSelectBody
(((
SubSelect
)
e
).
getSelectBody
());
}
else
if
(
exception
instanceof
AndExpression
)
{
processExcepression
(((
AndExpression
)
exception
).
getLeftExpression
());
processExcepression
(((
AndExpression
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
OrExpression
)
{
processExcepression
(((
OrExpression
)
exception
).
getLeftExpression
());
processExcepression
(((
OrExpression
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
Parenthesis
)
{
processExcepression
(((
Parenthesis
)
exception
).
getExpression
());
}
else
if
(
exception
instanceof
NotExpression
)
{
processExcepression
(((
NotExpression
)
exception
).
getExpression
());
}
else
if
(
exception
instanceof
InExpression
)
{
processExcepression
(((
InExpression
)
exception
).
getLeftExpression
());
if
(((
InExpression
)
exception
).
getRightItemsList
()
instanceof
SubSelect
)
{
this
.
processSelectBody
(((
SubSelect
)
((
InExpression
)
exception
).
getRightItemsList
()).
getSelectBody
());
}
}
else
if
(
exception
instanceof
EqualsTo
)
{
processExcepression
(((
EqualsTo
)
exception
).
getLeftExpression
());
processExcepression
(((
EqualsTo
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
ExistsExpression
)
{
processExcepression
(((
ExistsExpression
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
GreaterThan
)
{
processExcepression
(((
GreaterThan
)
exception
).
getLeftExpression
());
processExcepression
(((
GreaterThan
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
GreaterThanEquals
)
{
processExcepression
(((
GreaterThanEquals
)
exception
).
getLeftExpression
());
processExcepression
(((
GreaterThanEquals
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
MinorThan
)
{
processExcepression
(((
MinorThan
)
exception
).
getLeftExpression
());
processExcepression
(((
MinorThan
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
MinorThanEquals
)
{
processExcepression
(((
MinorThanEquals
)
exception
).
getLeftExpression
());
processExcepression
(((
MinorThanEquals
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
NotEqualsTo
)
{
processExcepression
(((
NotEqualsTo
)
exception
).
getLeftExpression
());
processExcepression
(((
NotEqualsTo
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
IsBooleanExpression
)
{
processExcepression
(((
IsBooleanExpression
)
exception
).
getLeftExpression
());
}
else
if
(
exception
instanceof
IsNullExpression
)
{
processExcepression
(((
IsNullExpression
)
exception
).
getLeftExpression
());
}
else
if
(
exception
instanceof
LikeExpression
)
{
processExcepression
(((
LikeExpression
)
exception
).
getLeftExpression
());
processExcepression
(((
LikeExpression
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
Between
)
{
processExcepression
(((
Between
)
exception
).
getLeftExpression
());
processExcepression
(((
Between
)
exception
).
getBetweenExpressionStart
());
processExcepression
(((
Between
)
exception
).
getBetweenExpressionEnd
());
}
else
if
(
exception
instanceof
Function
)
{
if
(
null
!= ((Function) exception).getParameters()) {
for
(
Expression
e
:
((
Function
)
exception
).
getParameters
().
getExpressions
())
{
processExcepression
(
e
);
}
}
}
else
if
(
exception
instanceof
CaseExpression
)
{
CaseExpression
caseExpression
=
(
CaseExpression
)
exception
;
processExcepression
(
caseExpression
.
getElseExpression
());
processExcepression
(
caseExpression
.
getSwitchExpression
());
for
(
WhenClause
whenClause
:
caseExpression
.
getWhenClauses
())
{
processExcepression
(
whenClause
.
getWhenExpression
());
processExcepression
(
whenClause
.
getThenExpression
());
}
}
else
if
(
exception
instanceof
Subtraction
){
processExcepression
(((
Subtraction
)
exception
).
getLeftExpression
());
processExcepression
(((
Subtraction
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
Multiplication
){
processExcepression
(((
Multiplication
)
exception
).
getLeftExpression
());
processExcepression
(((
Multiplication
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
Addition
){
processExcepression
(((
Addition
)
exception
).
getLeftExpression
());
processExcepression
(((
Addition
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
Division
){
processExcepression
(((
Division
)
exception
).
getLeftExpression
());
processExcepression
(((
Division
)
exception
).
getRightExpression
());
}
else
if
(
exception
instanceof
SubSelect
)
{
this
.
processSelectBody
(((
SubSelect
)
exception
).
getSelectBody
());
}
}
...
...
@@ -79,18 +149,10 @@ public class SaaSTenantSqlParser extends TenantSqlParser {
List
<
SelectItem
>
selectItems
=
plainSelect
.
getSelectItems
();
for
(
SelectItem
selectItem
:
selectItems
)
{
if
(
selectItem
instanceof
SelectExpressionItem
)
{
if
(((
SelectExpressionItem
)
selectItem
).
getExpression
()
instanceof
SubSelect
){
this
.
processSelectBody
(((
SubSelect
)
((
SelectExpressionItem
)
selectItem
).
getExpression
()).
getSelectBody
());
}
}
else
if
(
selectItem
instanceof
Function
)
{
for
(
Expression
e
:
((
Function
)
selectItem
).
getParameters
().
getExpressions
())
{
if
(
e
instanceof
SubSelect
)
{
this
.
processSelectBody
(((
SubSelect
)
e
).
getSelectBody
());
}
}
Expression
selectExcepression
=
((
SelectExpressionItem
)
selectItem
).
getExpression
();
processExcepression
(
selectExcepression
);
}
}
}
}
</#
if
>
\ No newline at end of file
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录