| @@ -1,26 +1,35 @@ | |||||
| package com.iformall.common; | package com.iformall.common; | ||||
| import org.springframework.web.context.request.RequestAttributes; | |||||
| import org.springframework.web.context.request.RequestContextHolder; | |||||
| public class TenantThreadLocal { | public class TenantThreadLocal { | ||||
| private static ThreadLocal<String> local = new ThreadLocal<String>(); | |||||
| private static ThreadLocal<String> parentLocal = new ThreadLocal<String>(); | |||||
| //private static ThreadLocal<String> local = new ThreadLocal<String>(); | |||||
| //private static ThreadLocal<String> parentLocal = new ThreadLocal<String>(); | |||||
| public static void setCurrentThreadTenant(String tenantId,String parentId) { | public static void setCurrentThreadTenant(String tenantId,String parentId) { | ||||
| local.set(tenantId); | |||||
| parentLocal.set(parentId); | |||||
| RequestContextHolder.currentRequestAttributes().setAttribute("tenaneId", tenantId, RequestAttributes.SCOPE_REQUEST); | |||||
| RequestContextHolder.currentRequestAttributes().setAttribute("parentTenaneId", parentId, RequestAttributes.SCOPE_REQUEST); | |||||
| //local.set(tenantId); | |||||
| //parentLocal.set(parentId); | |||||
| } | } | ||||
| public static String getTenantId() { | public static String getTenantId() { | ||||
| return local.get(); | |||||
| return (String)RequestContextHolder.currentRequestAttributes().getAttribute("tenaneId", RequestAttributes.SCOPE_REQUEST); | |||||
| //return local.get(); | |||||
| } | } | ||||
| public static String getParentTenantId() { | public static String getParentTenantId() { | ||||
| return parentLocal.get(); | |||||
| return (String)RequestContextHolder.currentRequestAttributes().getAttribute("parentTenaneId", RequestAttributes.SCOPE_REQUEST); | |||||
| //return parentLocal.get(); | |||||
| } | } | ||||
| public static void remove() { | public static void remove() { | ||||
| local.remove(); | |||||
| parentLocal.remove(); | |||||
| RequestContextHolder.currentRequestAttributes().removeAttribute("tenaneId", RequestAttributes.SCOPE_REQUEST); | |||||
| RequestContextHolder.currentRequestAttributes().removeAttribute("parentTenaneId", RequestAttributes.SCOPE_REQUEST); | |||||
| //local.remove(); | |||||
| //parentLocal.remove(); | |||||
| } | } | ||||
| } | } | ||||