diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/BladeTenantHandler.java b/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/BladeTenantHandler.java index 0780d47..031a206 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/BladeTenantHandler.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/BladeTenantHandler.java @@ -42,7 +42,7 @@ public class BladeTenantHandler implements TenantLineHandler { */ @Override public Expression getTenantId() { - return new StringValue(Func.toStr(SecureUtil.getTenantId(), TenantConstant.DEFAULT_TENANT_ID)); + return new StringValue(Func.toStr(TenantIdUtil.get(), properties.getDefaultTenantId())); } /** @@ -65,10 +65,10 @@ public class BladeTenantHandler implements TenantLineHandler { public boolean ignoreTable(String tableName) { return !( ( - (properties.getTables().size() > 0 && properties.getTables().contains(tableName)) + (!properties.getTables().isEmpty() && properties.getTables().contains(tableName)) || properties.getBladeTables().contains(tableName) ) - && StringUtil.isNotBlank(SecureUtil.getTenantId()) + && StringUtil.isNotBlank(TenantIdUtil.get()) ); } } diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/BladeTenantProperties.java b/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/BladeTenantProperties.java index ef7949a..2078415 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/BladeTenantProperties.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/BladeTenantProperties.java @@ -38,6 +38,11 @@ public class BladeTenantProperties { */ private String column = "tenant_id"; + /** + * 默认的租户id,默认为:000000 + */ + private String defaultTenantId = TenantConstant.DEFAULT_TENANT_ID; + /** * 多租户数据表 */ diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantIdUtil.java b/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantIdUtil.java new file mode 100644 index 0000000..28c3375 --- /dev/null +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantIdUtil.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.gnu.org/licenses/lgpl.html + *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springblade.core.boot.tenant;
+
+import org.springblade.core.secure.utils.SecureUtil;
+import org.springframework.util.Assert;
+
+import java.util.function.Supplier;
+
+/**
+ * TenantId 工具
+ *
+ * @author L.cm
+ */
+public class TenantIdUtil {
+ private static final ThreadLocal