数据分离-未登录状态兼容

This commit is contained in:
attiya 2025-08-29 10:10:27 +08:00
parent 9b7c24ef7f
commit efdad0defb
2 changed files with 6 additions and 4 deletions

View File

@ -8,8 +8,9 @@ public class MyTenantFactory implements TenantFactory {
public Object[] getTenantIds() {
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
Long tenantId = (Long) attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST);
if (tenantId != null) {
Object attribute = attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST);
if (attribute != null) {
Long tenantId = Long.valueOf(attribute.toString());
return new Object[]{tenantId};
} else {
return new Object[]{};

View File

@ -4,14 +4,15 @@ import cn.dev33.satoken.stp.StpUtil;
import com.cdzy.common.model.StaffDto;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.servlet.HandlerInterceptor;
public class TenantInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request
, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(@NotNull HttpServletRequest request
, @NotNull HttpServletResponse response, @NotNull Object handler) throws Exception {
//通过 request 去获取租户 ID
if (StpUtil.isLogin()) {