| | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy; |
| | | import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper; |
| | | import jakarta.servlet.http.HttpServletRequest; |
| | | import lombok.AccessLevel; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.dromara.common.core.constant.GlobalConstants; |
| | | import org.dromara.common.core.utils.ServletUtils; |
| | | import org.dromara.common.core.utils.SpringUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.core.utils.reflect.ReflectUtils; |
| | |
| | | } |
| | | String cacheKey = DYNAMIC_TENANT_KEY + ":" + LoginHelper.getUserId(); |
| | | RedisUtils.setCacheObject(cacheKey, tenantId); |
| | | ServletUtils.getRequest().setAttribute(cacheKey, tenantId); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (StringUtils.isNotBlank(tenantId)) { |
| | | return tenantId; |
| | | } |
| | | HttpServletRequest request = ServletUtils.getRequest(); |
| | | String cacheKey = DYNAMIC_TENANT_KEY + ":" + LoginHelper.getUserId(); |
| | | tenantId = (String) request.getAttribute(cacheKey); |
| | | // 如果为 -1 说明已经查过redis并且不存在值 则直接返回null |
| | | if (StringUtils.isNotBlank(tenantId)) { |
| | | return tenantId.equals("-1") ? null : tenantId; |
| | | } |
| | | tenantId = RedisUtils.getCacheObject(cacheKey); |
| | | request.setAttribute(cacheKey, StringUtils.isBlank(tenantId) ? "-1" : tenantId); |
| | | return tenantId; |
| | | } |
| | | |
| | |
| | | TEMP_DYNAMIC_TENANT.remove(); |
| | | String cacheKey = DYNAMIC_TENANT_KEY + ":" + LoginHelper.getUserId(); |
| | | RedisUtils.deleteObject(cacheKey); |
| | | ServletUtils.getRequest().removeAttribute(cacheKey); |
| | | } |
| | | |
| | | /** |