mirror of
https://github.com/chillzhuang/blade-tool
synced 2024-12-12 12:19:27 +08:00
🎉 2.1.0.RELEASE
This commit is contained in:
parent
ae17db974f
commit
f4bde35ff6
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<version>2.0.8</version>
|
<version>2.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
|
|||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springblade.core.launch.constant.AppConstant;
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
import org.springblade.core.mp.BladeMetaObjectHandler;
|
import org.springblade.core.mp.BladeMetaObjectHandler;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
@ -36,6 +37,7 @@ import org.springframework.context.annotation.Profile;
|
|||||||
public class MybatisPlusConfiguration {
|
public class MybatisPlusConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(PaginationInterceptor.class)
|
||||||
public PaginationInterceptor paginationInterceptor() {
|
public PaginationInterceptor paginationInterceptor() {
|
||||||
return new PaginationInterceptor();
|
return new PaginationInterceptor();
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>2.0.8</version>
|
<version>2.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>2.0.8</version>
|
<version>2.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>2.0.8</version>
|
<version>2.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>2.0.8</version>
|
<version>2.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>2.0.8</version>
|
<version>2.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -31,10 +31,15 @@ public class BladeUser implements Serializable {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主键
|
* 用户id
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(hidden = true)
|
@ApiModelProperty(hidden = true)
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
|
/**
|
||||||
|
* 租户编号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(hidden = true)
|
||||||
|
private String tenantCode;
|
||||||
/**
|
/**
|
||||||
* 昵称
|
* 昵称
|
||||||
*/
|
*/
|
||||||
|
@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springblade.core.secure.utils.SecureUtil;
|
import org.springblade.core.secure.utils.SecureUtil;
|
||||||
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.api.R;
|
||||||
import org.springblade.core.tool.api.ResultCode;
|
import org.springblade.core.tool.api.ResultCode;
|
||||||
|
import org.springblade.core.tool.constant.BladeConstant;
|
||||||
import org.springblade.core.tool.jackson.JsonUtil;
|
import org.springblade.core.tool.jackson.JsonUtil;
|
||||||
import org.springblade.core.tool.utils.StringPool;
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
import org.springblade.core.tool.utils.WebUtil;
|
import org.springblade.core.tool.utils.WebUtil;
|
||||||
@ -46,7 +47,7 @@ public class SecureInterceptor extends HandlerInterceptorAdapter {
|
|||||||
log.warn("签名认证失败,请求接口:{},请求IP:{},请求参数:{}", request.getRequestURI(), WebUtil.getIP(request), JsonUtil.toJson(request.getParameterMap()));
|
log.warn("签名认证失败,请求接口:{},请求IP:{},请求参数:{}", request.getRequestURI(), WebUtil.getIP(request), JsonUtil.toJson(request.getParameterMap()));
|
||||||
R result = R.fail(ResultCode.UN_AUTHORIZED);
|
R result = R.fail(ResultCode.UN_AUTHORIZED);
|
||||||
response.setCharacterEncoding(StringPool.UTF_8);
|
response.setCharacterEncoding(StringPool.UTF_8);
|
||||||
response.setHeader("Content-type", MediaType.APPLICATION_JSON_UTF8_VALUE);
|
response.setHeader(BladeConstant.CONTENT_TYPE_NAME, MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
try {
|
try {
|
||||||
response.getWriter().write(Objects.requireNonNull(JsonUtil.toJson(result)));
|
response.getWriter().write(Objects.requireNonNull(JsonUtil.toJson(result)));
|
||||||
|
@ -42,8 +42,10 @@ public class SecureRegistry {
|
|||||||
this.defaultExcludePatterns.add("/auth/**");
|
this.defaultExcludePatterns.add("/auth/**");
|
||||||
this.defaultExcludePatterns.add("/token/**");
|
this.defaultExcludePatterns.add("/token/**");
|
||||||
this.defaultExcludePatterns.add("/log/**");
|
this.defaultExcludePatterns.add("/log/**");
|
||||||
this.defaultExcludePatterns.add("/user/userInfo");
|
this.defaultExcludePatterns.add("/user/user-info");
|
||||||
|
this.defaultExcludePatterns.add("/menu/auth-routes");
|
||||||
this.defaultExcludePatterns.add("/error/**");
|
this.defaultExcludePatterns.add("/error/**");
|
||||||
|
this.defaultExcludePatterns.add("/assets/**");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,7 +28,10 @@ import org.springblade.core.tool.utils.WebUtil;
|
|||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
import java.util.*;
|
import java.util.Base64;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Secure工具类
|
* Secure工具类
|
||||||
@ -45,8 +48,9 @@ public class SecureUtil {
|
|||||||
public final static String ROLE_ID = "roleId";
|
public final static String ROLE_ID = "roleId";
|
||||||
public final static String USER_NAME = "userName";
|
public final static String USER_NAME = "userName";
|
||||||
public final static String ROLE_NAME = "roleName";
|
public final static String ROLE_NAME = "roleName";
|
||||||
|
public final static String TENANT_CODE = "tenantCode";
|
||||||
public final static Integer AUTH_LENGTH = 7;
|
public final static Integer AUTH_LENGTH = 7;
|
||||||
private static String BASE64_SECURITY = Base64.getEncoder().encodeToString("SpringBlade".getBytes(Charsets.UTF_8));
|
public static String BASE64_SECURITY = Base64.getEncoder().encodeToString("BladeX".getBytes(Charsets.UTF_8));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户信息
|
* 获取用户信息
|
||||||
@ -79,14 +83,18 @@ public class SecureUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Integer userId = Func.toInt(claims.get(SecureUtil.USER_ID));
|
Integer userId = Func.toInt(claims.get(SecureUtil.USER_ID));
|
||||||
|
String tenantCode = Func.toStr(claims.get(SecureUtil.TENANT_CODE));
|
||||||
String roleId = Func.toStr(claims.get(SecureUtil.ROLE_ID));
|
String roleId = Func.toStr(claims.get(SecureUtil.ROLE_ID));
|
||||||
String account = Func.toStr(claims.get(SecureUtil.ACCOUNT));
|
String account = Func.toStr(claims.get(SecureUtil.ACCOUNT));
|
||||||
String roleName = Func.toStr(claims.get(SecureUtil.ROLE_NAME));
|
String roleName = Func.toStr(claims.get(SecureUtil.ROLE_NAME));
|
||||||
|
String userName = Func.toStr(claims.get(SecureUtil.USER_NAME));
|
||||||
BladeUser bladeUser = new BladeUser();
|
BladeUser bladeUser = new BladeUser();
|
||||||
bladeUser.setAccount(account);
|
|
||||||
bladeUser.setUserId(userId);
|
bladeUser.setUserId(userId);
|
||||||
|
bladeUser.setTenantCode(tenantCode);
|
||||||
|
bladeUser.setAccount(account);
|
||||||
bladeUser.setRoleId(roleId);
|
bladeUser.setRoleId(roleId);
|
||||||
bladeUser.setRoleName(roleName);
|
bladeUser.setRoleName(roleName);
|
||||||
|
bladeUser.setUserName(userName);
|
||||||
return bladeUser;
|
return bladeUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +141,48 @@ public class SecureUtil {
|
|||||||
return (null == user) ? StringPool.EMPTY : user.getAccount();
|
return (null == user) ? StringPool.EMPTY : user.getAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户名
|
||||||
|
*
|
||||||
|
* @return userName
|
||||||
|
*/
|
||||||
|
public static String getUserName() {
|
||||||
|
BladeUser user = getUser();
|
||||||
|
return (null == user) ? StringPool.EMPTY : user.getUserName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户名
|
||||||
|
*
|
||||||
|
* @param request request
|
||||||
|
* @return userName
|
||||||
|
*/
|
||||||
|
public static String getUserName(HttpServletRequest request) {
|
||||||
|
BladeUser user = getUser(request);
|
||||||
|
return (null == user) ? StringPool.EMPTY : user.getUserName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取租户编号
|
||||||
|
*
|
||||||
|
* @return tenantCode
|
||||||
|
*/
|
||||||
|
public static String getTenantCode() {
|
||||||
|
BladeUser user = getUser();
|
||||||
|
return (null == user) ? StringPool.EMPTY : user.getTenantCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取租户编号
|
||||||
|
*
|
||||||
|
* @param request request
|
||||||
|
* @return tenantCode
|
||||||
|
*/
|
||||||
|
public static String getTenantCode(HttpServletRequest request) {
|
||||||
|
BladeUser user = getUser(request);
|
||||||
|
return (null == user) ? StringPool.EMPTY : user.getTenantCode();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取Claims
|
* 获取Claims
|
||||||
*
|
*
|
||||||
@ -157,7 +207,7 @@ public class SecureUtil {
|
|||||||
* @return header
|
* @return header
|
||||||
*/
|
*/
|
||||||
public static String getHeader() {
|
public static String getHeader() {
|
||||||
return getHeader(Objects.requireNonNull(WebUtil.getRequest()));
|
return getHeader(WebUtil.getRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<version>2.0.8</version>
|
<version>2.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
25
blade-core-tenant/pom.xml
Normal file
25
blade-core-tenant/pom.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?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>blade-tool</artifactId>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>blade-core-tenant</artifactId>
|
||||||
|
<name>${project.artifactId}</name>
|
||||||
|
<version>${blade.tool.version}</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springblade</groupId>
|
||||||
|
<artifactId>blade-core-mybatis</artifactId>
|
||||||
|
<version>${blade.tool.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.gnu.org/licenses/lgpl.html
|
||||||
|
* <p>
|
||||||
|
* 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.tenant;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.sf.jsqlparser.expression.Expression;
|
||||||
|
import net.sf.jsqlparser.expression.StringValue;
|
||||||
|
import org.springblade.core.secure.utils.SecureUtil;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户信息处理器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BladeTenantHandler implements TenantHandler {
|
||||||
|
|
||||||
|
private final BladeTenantProperties properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取租户编号
|
||||||
|
*
|
||||||
|
* @return 租户编号
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Expression getTenantId() {
|
||||||
|
return new StringValue(SecureUtil.getTenantCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取租户字段名称
|
||||||
|
*
|
||||||
|
* @return 租户字段名称
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getTenantIdColumn() {
|
||||||
|
return properties.getColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过滤租户表
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return 是否进行过滤
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean doTableFilter(String tableName) {
|
||||||
|
return (properties.getTables().size() > 0 && !properties.getTables().contains(tableName)) || !properties.getBladeTables().contains(tableName) || StringUtil.isBlank(SecureUtil.getTenantCode());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.gnu.org/licenses/lgpl.html
|
||||||
|
* <p>
|
||||||
|
* 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.tenant;
|
||||||
|
|
||||||
|
import org.springblade.core.tool.utils.RandomType;
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* blade租户id生成器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public class BladeTenantId implements TenantId {
|
||||||
|
@Override
|
||||||
|
public String generate() {
|
||||||
|
return StringUtil.random(6, RandomType.INT);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.gnu.org/licenses/lgpl.html
|
||||||
|
* <p>
|
||||||
|
* 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.tenant;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多租户配置
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ConfigurationProperties(prefix = "blade.tenant")
|
||||||
|
public class BladeTenantProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多租户字段名称
|
||||||
|
*/
|
||||||
|
private String column = "tenant_code";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多租户数据表
|
||||||
|
*/
|
||||||
|
private List<String> tables = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多租户系统数据表
|
||||||
|
*/
|
||||||
|
private List<String> bladeTables = Arrays.asList("blade_notice", "blade_log_api", "blade_log_error", "blade_log_usual");
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.gnu.org/licenses/lgpl.html
|
||||||
|
* <p>
|
||||||
|
* 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.tenant;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||||
|
import com.baomidou.mybatisplus.core.parser.ISqlParser;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多租户配置类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@AllArgsConstructor
|
||||||
|
@AutoConfigureBefore(MybatisConfiguration.class)
|
||||||
|
@EnableConfigurationProperties(BladeTenantProperties.class)
|
||||||
|
public class TenantConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多租户配置类
|
||||||
|
*/
|
||||||
|
private final BladeTenantProperties properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义租户处理器
|
||||||
|
*
|
||||||
|
* @return TenantHandler
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(TenantHandler.class)
|
||||||
|
public TenantHandler bladeTenantHandler() {
|
||||||
|
return new BladeTenantHandler(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义租户id生成器
|
||||||
|
*
|
||||||
|
* @return TenantId
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(TenantId.class)
|
||||||
|
public TenantId tenantId() {
|
||||||
|
return new BladeTenantId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页插件
|
||||||
|
*
|
||||||
|
* @param tenantHandler 自定义租户处理器
|
||||||
|
* @return PaginationInterceptor
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public PaginationInterceptor paginationInterceptor(TenantHandler tenantHandler) {
|
||||||
|
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
|
||||||
|
List<ISqlParser> sqlParserList = new ArrayList<>();
|
||||||
|
TenantSqlParser tenantSqlParser = new TenantSqlParser();
|
||||||
|
tenantSqlParser.setTenantHandler(tenantHandler);
|
||||||
|
sqlParserList.add(tenantSqlParser);
|
||||||
|
paginationInterceptor.setSqlParserList(sqlParserList);
|
||||||
|
return paginationInterceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.gnu.org/licenses/lgpl.html
|
||||||
|
* <p>
|
||||||
|
* 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.tenant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户id生成器
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
public interface TenantId {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成自定义租户id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String generate();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.gnu.org/licenses/lgpl.html
|
||||||
|
* <p>
|
||||||
|
* 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.tenant.mp;
|
||||||
|
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springblade.core.mp.base.BaseEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户基础实体类
|
||||||
|
*
|
||||||
|
* @author Chill
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TenantEntity extends BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户编号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "租户编号")
|
||||||
|
private String tenantCode;
|
||||||
|
|
||||||
|
}
|
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<version>2.0.8</version>
|
<version>2.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -27,10 +27,15 @@ public interface BladeConstant {
|
|||||||
*/
|
*/
|
||||||
String UTF_8 = "UTF-8";
|
String UTF_8 = "UTF-8";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* contentType
|
||||||
|
*/
|
||||||
|
String CONTENT_TYPE_NAME = "Content-type";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON 资源
|
* JSON 资源
|
||||||
*/
|
*/
|
||||||
String CONTENT_TYPE = "application/json; charset=utf-8";
|
String CONTENT_TYPE = "application/json;charset=utf-8";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色前缀
|
* 角色前缀
|
||||||
@ -47,10 +52,7 @@ public interface BladeConstant {
|
|||||||
*/
|
*/
|
||||||
int DB_STATUS_NORMAL = 1;
|
int DB_STATUS_NORMAL = 1;
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否删除字段名
|
|
||||||
*/
|
|
||||||
String IS_DELETED_FIELD = "is_deleted";
|
|
||||||
/**
|
/**
|
||||||
* 删除状态[0:正常,1:删除]
|
* 删除状态[0:正常,1:删除]
|
||||||
*/
|
*/
|
||||||
@ -63,6 +65,11 @@ public interface BladeConstant {
|
|||||||
int DB_ADMIN_NON_LOCKED = 0;
|
int DB_ADMIN_NON_LOCKED = 0;
|
||||||
int DB_ADMIN_LOCKED = 1;
|
int DB_ADMIN_LOCKED = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员对应的租户编号
|
||||||
|
*/
|
||||||
|
String ADMIN_TENANT_CODE = "000000";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志默认状态
|
* 日志默认状态
|
||||||
*/
|
*/
|
||||||
|
@ -22,7 +22,7 @@ package org.springblade.core.tool.constant;
|
|||||||
*/
|
*/
|
||||||
public class RoleConstant {
|
public class RoleConstant {
|
||||||
|
|
||||||
public static final String ADMIN = "admin";
|
public static final String ADMIN = "administrator";
|
||||||
|
|
||||||
public static final String HAS_ROLE_ADMIN = "hasRole('" + ADMIN + "')";
|
public static final String HAS_ROLE_ADMIN = "hasRole('" + ADMIN + "')";
|
||||||
|
|
||||||
|
5
pom.xml
5
pom.xml
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>org.springblade</groupId>
|
<groupId>org.springblade</groupId>
|
||||||
<artifactId>blade-tool</artifactId>
|
<artifactId>blade-tool</artifactId>
|
||||||
<version>2.0.8</version>
|
<version>2.1.0</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>blade-tool</name>
|
<name>blade-tool</name>
|
||||||
<description>
|
<description>
|
||||||
@ -36,7 +36,7 @@
|
|||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<blade.tool.version>2.0.8</blade.tool.version>
|
<blade.tool.version>2.1.0</blade.tool.version>
|
||||||
|
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<maven.plugin.version>3.8.0</maven.plugin.version>
|
<maven.plugin.version>3.8.0</maven.plugin.version>
|
||||||
@ -68,6 +68,7 @@
|
|||||||
<module>blade-core-mybatis</module>
|
<module>blade-core-mybatis</module>
|
||||||
<module>blade-core-swagger</module>
|
<module>blade-core-swagger</module>
|
||||||
<module>blade-core-cloud</module>
|
<module>blade-core-cloud</module>
|
||||||
|
<module>blade-core-tenant</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
Loading…
Reference in New Issue
Block a user