-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from huyuanzhi/master
租户基础代码
- Loading branch information
Showing
71 changed files
with
2,527 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...n/ballcat-admin-core/src/main/java/com/hccake/ballcat/admin/config/prop/DbProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.hccake.ballcat.admin.config.prop; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
/** | ||
* 数据库配置属性 | ||
* | ||
* @author huyuanzhi | ||
*/ | ||
@Data | ||
@ConfigurationProperties("ballcat.db") | ||
public class DbProperties { | ||
|
||
private Long maxLimit = 500L; | ||
|
||
private boolean optimizeJoin = false; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>ballcat-admin</artifactId> | ||
<groupId>com.hccake</groupId> | ||
<version>${revision}</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>ballcat-admin-tenant</artifactId> | ||
|
||
<properties> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.hccake</groupId> | ||
<artifactId>ballcat-tenant-controller</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.hccake</groupId> | ||
<artifactId>ballcat-spring-boot-starter-tenant</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
38 changes: 38 additions & 0 deletions
38
...t-admin-tenant/src/main/java/com/hccake/ballcat/admin/tenant/TenantAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.hccake.ballcat.admin.tenant; | ||
|
||
import com.hccake.ballcat.common.tenant.datasource.DataSourceDetailService; | ||
import com.hccake.ballcat.common.tenant.properties.TenantProperties; | ||
import com.hccake.ballcat.tenant.datasource.SysDataSourceDetailServiceImpl; | ||
import com.hccake.ballcat.tenant.service.SysDatasourceService; | ||
import com.hccake.ballcat.tenant.service.SysTenantDatasourceService; | ||
import com.hccake.ballcat.tenant.service.SysTenantService; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* 租戶注冊 | ||
* | ||
* @author huyuanzhi | ||
*/ | ||
@ComponentScan("com.hccake.ballcat.tenant") | ||
public class TenantAutoConfiguration { | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnProperty(prefix = TenantProperties.PREFIX, name = "enable", havingValue = "true") | ||
static class DataSourceDetailServiceConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
@ConditionalOnProperty(prefix = TenantProperties.PREFIX, name = "tenantType", havingValue = "DATASOURCE") | ||
public DataSourceDetailService dataSourceDetailService(SysTenantService sysTenantService, | ||
SysDatasourceService sysDatasourceService, SysTenantDatasourceService sysTenantDatasourceService) { | ||
return new SysDataSourceDetailServiceImpl(sysTenantService, sysDatasourceService, | ||
sysTenantDatasourceService); | ||
} | ||
|
||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
ballcat-admin/ballcat-admin-tenant/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
com.hccake.ballcat.admin.tenant.TenantAutoConfiguration | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>ballcat-common</artifactId> | ||
<groupId>com.hccake</groupId> | ||
<version>${revision}</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>ballcat-common-tenant</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>mybatis-plus-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>mybatis-plus-extension</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>cn.hutool</groupId> | ||
<artifactId>hutool-crypto</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
17 changes: 17 additions & 0 deletions
17
...llcat-common-tenant/src/main/java/com/hccake/ballcat/common/tenant/annotation/Tenant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.hccake.ballcat.common.tenant.annotation; | ||
|
||
import com.baomidou.dynamic.datasource.annotation.DS; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* 切换租户数据源 注意 租户数据源名称一定要是 master | ||
* @author huyuanzhi | ||
*/ | ||
@Target({ ElementType.TYPE, ElementType.METHOD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@DS("master") | ||
public @interface Tenant { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...cat-common-tenant/src/main/java/com/hccake/ballcat/common/tenant/core/DatasourceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.hccake.ballcat.common.tenant.core; | ||
|
||
/** | ||
* 数据源连接池类型 | ||
* @author huyuanzhi | ||
*/ | ||
public enum DatasourceType { | ||
|
||
/** | ||
* hikari连接池 | ||
*/ | ||
HIKARI, | ||
/** | ||
* druid连接池 | ||
*/ | ||
DRUID, | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...lcat-common-tenant/src/main/java/com/hccake/ballcat/common/tenant/core/TenantContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.hccake.ballcat.common.tenant.core; | ||
|
||
|
||
/** | ||
* 保存租户信息 | ||
* | ||
* @author huyuanzhi | ||
*/ | ||
public final class TenantContext { | ||
|
||
private static final ThreadLocal<String> THREAD_LOCAL = new InheritableThreadLocal<>(); | ||
|
||
private TenantContext() { | ||
} | ||
|
||
public static void set(String value) { | ||
THREAD_LOCAL.set(value); | ||
} | ||
|
||
public static void clear() { | ||
THREAD_LOCAL.remove(); | ||
} | ||
|
||
public static String get() { | ||
return THREAD_LOCAL.get(); | ||
} | ||
|
||
} |
Oops, something went wrong.