Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zlt2000
microservices-platform
提交
6cc797ef
microservices-platform
项目概览
zlt2000
/
microservices-platform
8 个月 前同步成功
通知
16
Star
4
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6cc797ef
编写于
5月 08, 2022
作者:
J
jarvis
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' of
https://gitee.com/zlt2000/microservices-platform
into dev
上级
c80cb0bd
f206ae93
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
64 addition
and
57 deletion
+64
-57
pom.xml
pom.xml
+1
-1
zlt-business/file-center/src/main/java/com/central/file/model/FileInfo.java
...center/src/main/java/com/central/file/model/FileInfo.java
+0
-5
zlt-commons/zlt-common-core/src/main/java/com/central/common/model/SuperEntity.java
...e/src/main/java/com/central/common/model/SuperEntity.java
+0
-5
zlt-commons/zlt-common-core/src/main/java/com/central/common/service/impl/SuperServiceImpl.java
...ava/com/central/common/service/impl/SuperServiceImpl.java
+1
-1
zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/MybatisPlusAutoConfigure.java
.../java/com/central/db/config/MybatisPlusAutoConfigure.java
+13
-16
zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/TenantAutoConfigure.java
.../main/java/com/central/db/config/TenantAutoConfigure.java
+5
-29
zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/interceptor/CustomTenantInterceptor.java
...a/com/central/db/interceptor/CustomTenantInterceptor.java
+44
-0
未找到文件。
pom.xml
浏览文件 @
6cc797ef
...
...
@@ -27,7 +27,7 @@
<redisson-starter.version>
3.16.1
</redisson-starter.version>
<easyCaptcha.version>
1.6.2
</easyCaptcha.version>
<hutool.version>
5.7.20
</hutool.version>
<mybatis-plus-boot-starter.version>
3.
4.0
</mybatis-plus-boot-starter.version>
<mybatis-plus-boot-starter.version>
3.
5.1
</mybatis-plus-boot-starter.version>
<aliyun-sdk-oss>
3.8.1
</aliyun-sdk-oss>
<qiniu-java-sdk>
7.2.28
</qiniu-java-sdk>
<easypoi.version>
4.1.3
</easypoi.version>
...
...
zlt-business/file-center/src/main/java/com/central/file/model/FileInfo.java
浏览文件 @
6cc797ef
...
...
@@ -56,9 +56,4 @@ public class FileInfo extends Model<FileInfo> {
private
Date
createTime
;
@TableField
(
fill
=
FieldFill
.
INSERT_UPDATE
)
private
Date
updateTime
;
@Override
protected
Serializable
pkVal
()
{
return
this
.
id
;
}
}
zlt-commons/zlt-common-core/src/main/java/com/central/common/model/SuperEntity.java
浏览文件 @
6cc797ef
...
...
@@ -27,9 +27,4 @@ public class SuperEntity<T extends Model<?>> extends Model<T> {
private
Date
createTime
;
@TableField
(
fill
=
FieldFill
.
INSERT_UPDATE
)
private
Date
updateTime
;
@Override
protected
Serializable
pkVal
()
{
return
this
.
id
;
}
}
zlt-commons/zlt-common-core/src/main/java/com/central/common/service/impl/SuperServiceImpl.java
浏览文件 @
6cc797ef
...
...
@@ -42,7 +42,7 @@ public class SuperServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M,
)
{
if
(
lock
!=
null
)
{
//判断记录是否已存在
int
count
=
super
.
count
(
countWrapper
);
long
count
=
super
.
count
(
countWrapper
);
if
(
count
==
0
)
{
return
super
.
save
(
entity
);
}
else
{
...
...
zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/MybatisPlusAutoConfigure.java
浏览文件 @
6cc797ef
package
com.central.db.config
;
import
c
n.hutool.core.collection.CollUtil
;
import
c
om.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.core.handlers.MetaObjectHandler
;
import
com.baomidou.mybatisplus.core.parser.ISqlParserFilter
;
import
com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler
;
import
com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser
;
import
com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler
;
import
com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor
;
import
com.central.common.properties.TenantProperties
;
import
com.central.db.interceptor.CustomTenantInterceptor
;
import
com.central.db.properties.MybatisPlusAutoFillProperties
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
...
...
@@ -26,10 +26,7 @@ import org.springframework.context.annotation.Bean;
@EnableConfigurationProperties
(
MybatisPlusAutoFillProperties
.
class
)
public
class
MybatisPlusAutoConfigure
{
@Autowired
private
TenantHandler
tenantHandler
;
@Autowired
private
ISqlParserFilter
sqlParserFilter
;
private
TenantLineHandler
tenantLineHandler
;
@Autowired
private
TenantProperties
tenantProperties
;
...
...
@@ -41,17 +38,17 @@ public class MybatisPlusAutoConfigure {
* 分页插件,自动识别数据库类型
*/
@Bean
public
PaginationInterceptor
paginationInterceptor
()
{
PaginationInterceptor
paginationInterceptor
=
new
PaginationInterceptor
();
public
MybatisPlusInterceptor
paginationInterceptor
()
{
MybatisPlusInterceptor
mpInterceptor
=
new
MybatisPlusInterceptor
();
mpInterceptor
.
addInnerInterceptor
(
new
PaginationInnerInterceptor
(
DbType
.
MYSQL
));
boolean
enableTenant
=
tenantProperties
.
getEnable
();
//是否开启多租户隔离
if
(
enableTenant
)
{
TenantSqlParser
tenantSqlParser
=
new
TenantSqlParser
()
.
setTenantHandler
(
tenantHandler
);
paginationInterceptor
.
setSqlParserList
(
CollUtil
.
toList
(
tenantSqlParser
));
paginationInterceptor
.
setSqlParserFilter
(
sqlParserFilter
);
CustomTenantInterceptor
tenantInterceptor
=
new
CustomTenantInterceptor
(
tenantLineHandler
,
tenantProperties
.
getIgnoreSqls
());
mpInterceptor
.
addInnerInterceptor
(
tenantInterceptor
);
}
return
pagination
Interceptor
;
return
mp
Interceptor
;
}
@Bean
...
...
zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/TenantAutoConfigure.java
浏览文件 @
6cc797ef
package
com.central.db.config
;
import
com.baomidou.mybatisplus.core.parser.ISqlParserFilter
;
import
com.baomidou.mybatisplus.core.parser.SqlParserHelper
;
import
com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler
;
import
com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler
;
import
com.central.common.context.TenantContextHolder
;
import
com.central.common.properties.TenantProperties
;
import
net.sf.jsqlparser.expression.Expression
;
import
net.sf.jsqlparser.expression.NullValue
;
import
net.sf.jsqlparser.expression.StringValue
;
import
org.apache.ibatis.mapping.MappedStatement
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -25,13 +22,13 @@ public class TenantAutoConfigure {
private
TenantProperties
tenantProperties
;
@Bean
public
Tenant
Handler
tenant
Handler
()
{
return
new
TenantHandler
()
{
public
Tenant
LineHandler
tenantLine
Handler
()
{
return
new
Tenant
Line
Handler
()
{
/**
* 获取租户id
*/
@Override
public
Expression
getTenantId
(
boolean
where
)
{
public
Expression
getTenantId
()
{
String
tenant
=
TenantContextHolder
.
getTenant
();
if
(
tenant
!=
null
)
{
return
new
StringValue
(
TenantContextHolder
.
getTenant
());
...
...
@@ -39,37 +36,16 @@ public class TenantAutoConfigure {
return
new
NullValue
();
}
/**
* 获取租户列名
*/
@Override
public
String
getTenantIdColumn
()
{
return
"tenant_id"
;
}
/**
* 过滤不需要根据租户隔离的表
* @param tableName 表名
*/
@Override
public
boolean
doTableFilter
(
String
tableName
)
{
public
boolean
ignoreTable
(
String
tableName
)
{
return
tenantProperties
.
getIgnoreTables
().
stream
().
anyMatch
(
(
e
)
->
e
.
equalsIgnoreCase
(
tableName
)
);
}
};
}
/**
* 过滤不需要根据租户隔离的MappedStatement
*/
@Bean
public
ISqlParserFilter
sqlParserFilter
()
{
return
metaObject
->
{
MappedStatement
ms
=
SqlParserHelper
.
getMappedStatement
(
metaObject
);
return
tenantProperties
.
getIgnoreSqls
().
stream
().
anyMatch
(
(
e
)
->
e
.
equalsIgnoreCase
(
ms
.
getId
())
);
};
}
}
zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/interceptor/CustomTenantInterceptor.java
0 → 100644
浏览文件 @
6cc797ef
package
com.central.db.interceptor
;
import
com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler
;
import
com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor
;
import
org.apache.ibatis.executor.Executor
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.mapping.MappedStatement
;
import
org.apache.ibatis.session.ResultHandler
;
import
org.apache.ibatis.session.RowBounds
;
import
java.sql.SQLException
;
import
java.util.List
;
/**
* MyBatis-plus租户拦截器
*
* @author zlt
* @version 1.0
* @date 2022/5/6
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
public
class
CustomTenantInterceptor
extends
TenantLineInnerInterceptor
{
private
List
<
String
>
ignoreSqls
;
public
CustomTenantInterceptor
(
TenantLineHandler
tenantLineHandler
,
List
<
String
>
ignoreSqls
)
{
super
(
tenantLineHandler
);
this
.
ignoreSqls
=
ignoreSqls
;
}
@Override
public
void
beforeQuery
(
Executor
executor
,
MappedStatement
ms
,
Object
parameter
,
RowBounds
rowBounds
,
ResultHandler
resultHandler
,
BoundSql
boundSql
)
throws
SQLException
{
if
(
isIgnoreMappedStatement
(
ms
.
getId
()))
{
return
;
}
super
.
beforeQuery
(
executor
,
ms
,
parameter
,
rowBounds
,
resultHandler
,
boundSql
);
}
private
boolean
isIgnoreMappedStatement
(
String
msId
)
{
return
ignoreSqls
.
stream
().
anyMatch
((
e
)
->
e
.
equalsIgnoreCase
(
msId
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录