Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
cms_sys
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
西魏
cms_sys
Commits
a50f0f7b
Commit
a50f0f7b
authored
Oct 31, 2020
by
sgjj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
抽离多租户
parent
4748d53a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
51 deletions
+6
-51
WebConfig.java
src/main/java/net/mingsoft/config/WebConfig.java
+6
-7
AppHandler.java
src/main/java/net/mingsoft/handler/AppHandler.java
+0
-44
No files found.
src/main/java/net/mingsoft/config/WebConfig.java
View file @
a50f0f7b
...
...
@@ -5,15 +5,16 @@ import com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator;
import
com.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer
;
import
com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler
;
import
com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor
;
import
com.baomidou.mybatisplus.extension.toolkit.JdbcUtils
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
net.mingsoft.basic.filter.XSSEscapeFilter
;
import
net.mingsoft.basic.interceptor.ActionInterceptor
;
import
net.mingsoft.handler.AppHandler
;
import
net.mingsoft.interceptor.DMInnerInterceptor
;
import
net.mingsoft.interceptor.MysqlInnerInterceptor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletListenerRegistrationBean
;
...
...
@@ -57,15 +58,13 @@ public class WebConfig implements WebMvcConfigurer {
public
ActionInterceptor
actionInterceptor
()
{
return
new
ActionInterceptor
();
}
@Bean
public
AppHandler
appHandler
()
{
return
new
AppHandler
();
}
@Bean
public
MybatisPlusInterceptor
mybatisPlusInterceptor
(
DataSource
dataSource
)
{
public
MybatisPlusInterceptor
mybatisPlusInterceptor
(
DataSource
dataSource
,
@Autowired
(
required
=
false
)
TenantLineHandler
tenantLineHandler
)
{
MybatisPlusInterceptor
interceptor
=
new
MybatisPlusInterceptor
();
interceptor
.
addInnerInterceptor
(
new
TenantLineInnerInterceptor
(
appHandler
()));
if
(
tenantLineHandler
!=
null
){
interceptor
.
addInnerInterceptor
(
new
TenantLineInnerInterceptor
(
tenantLineHandler
));
}
try
{
//mysql 添加转换sql
DbType
dbType
=
JdbcUtils
.
getDbType
(
dataSource
.
getConnection
().
getMetaData
().
getURL
());
...
...
src/main/java/net/mingsoft/handler/AppHandler.java
deleted
100644 → 0
View file @
4748d53a
package
net
.
mingsoft
.
handler
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler
;
import
com.github.pagehelper.Page
;
import
com.github.pagehelper.PageHelper
;
import
net.mingsoft.basic.util.BasicUtil
;
import
net.sf.jsqlparser.expression.Expression
;
import
net.sf.jsqlparser.expression.LongValue
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
public
class
AppHandler
implements
TenantLineHandler
{
@Value
(
"${ms.mwebsite.tables}"
)
private
String
[]
tables
;
@Override
public
Expression
getTenantId
()
{
//分页插件处理,会被执行两次,一次查询数量,一次查询结果,当查询到了数量之后当前线程变量就会被赋值,再次startPage就会丢失数量,所以判断拿到了数量就不再startPage
Page
<
Object
>
localPage
=
PageHelper
.
getLocalPage
();
if
(
localPage
!=
null
&&
localPage
.
getTotal
()==
0
){
PageHelper
.
clearPage
();
}
//int appId = BasicUtil.getAppId();
if
(
localPage
!=
null
&&
localPage
.
getTotal
()==
0
){
PageHelper
.
startPage
(
localPage
.
getPageNum
(),
localPage
.
getPageSize
(),
localPage
.
isCount
());
PageHelper
.
orderBy
(
localPage
.
getOrderBy
());
}
return
new
LongValue
(
1
);
}
@Override
public
String
getTenantIdColumn
()
{
return
"app_id"
;
}
@Override
public
boolean
ignoreTable
(
String
tableName
)
{
return
ArrayUtil
.
isEmpty
(
tables
)||
!
ArrayUtil
.
contains
(
tables
,
tableName
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment