数据分离-未登录状态兼容
This commit is contained in:
parent
9b7c24ef7f
commit
efdad0defb
@ -8,8 +8,9 @@ public class MyTenantFactory implements TenantFactory {
|
|||||||
|
|
||||||
public Object[] getTenantIds() {
|
public Object[] getTenantIds() {
|
||||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||||
Long tenantId = (Long) attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST);
|
Object attribute = attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST);
|
||||||
if (tenantId != null) {
|
if (attribute != null) {
|
||||||
|
Long tenantId = Long.valueOf(attribute.toString());
|
||||||
return new Object[]{tenantId};
|
return new Object[]{tenantId};
|
||||||
} else {
|
} else {
|
||||||
return new Object[]{};
|
return new Object[]{};
|
||||||
|
|||||||
@ -4,14 +4,15 @@ import cn.dev33.satoken.stp.StpUtil;
|
|||||||
import com.cdzy.common.model.StaffDto;
|
import com.cdzy.common.model.StaffDto;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
|
|
||||||
public class TenantInterceptor implements HandlerInterceptor {
|
public class TenantInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request
|
public boolean preHandle(@NotNull HttpServletRequest request
|
||||||
, HttpServletResponse response, Object handler) throws Exception {
|
, @NotNull HttpServletResponse response, @NotNull Object handler) throws Exception {
|
||||||
|
|
||||||
//通过 request 去获取租户 ID
|
//通过 request 去获取租户 ID
|
||||||
if (StpUtil.isLogin()) {
|
if (StpUtil.isLogin()) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user