| @@ -3,7 +3,11 @@ package com.iformall.interceptor; | |||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.iformall.domain.po.WxMall; | |||||
| import com.iformall.service.WxMallService; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
| import org.springframework.web.method.HandlerMethod; | import org.springframework.web.method.HandlerMethod; | ||||
| import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | ||||
| @@ -21,12 +25,37 @@ import com.iformall.utils.Constant; | |||||
| @Component | @Component | ||||
| public class CurrentTenantInterceptor extends HandlerInterceptorAdapter { | public class CurrentTenantInterceptor extends HandlerInterceptorAdapter { | ||||
| @Autowired | |||||
| private WxMallService wxMallService; | |||||
| @Override | @Override | ||||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||||
| String tenantId = (String)request.getSession().getAttribute(UserSession.tenantId); | |||||
| String parenTenantId = (String)request.getSession().getAttribute(UserSession.parentTenantId); | |||||
| //集团版中针对某一商场的业务需要传递mallTenantId | |||||
| String mallTenantId = request.getHeader("mallTenantId"); | |||||
| if(StringUtils.isBlank(mallTenantId)){ | |||||
| mallTenantId = request.getParameter("mallTenantId"); | |||||
| } | |||||
| if(StringUtils.isBlank(mallTenantId)){ | |||||
| try{ | |||||
| String body = ((BodyReaderHttpServletRequestWrapper) request).getBody(); | |||||
| mallTenantId = JSONObject.parseObject(body).getString("mallTenantId"); | |||||
| }catch(Exception e){} | |||||
| } | |||||
| String tenantId = null; | |||||
| String parenTenantId = null; | |||||
| if(StringUtils.isNotBlank(mallTenantId)){ | |||||
| tenantId = mallTenantId; | |||||
| WxMall mall = wxMallService.getByTenantId(tenantId); | |||||
| if(StringUtils.isNotBlank(mall.getParentTenantId())){ | |||||
| parenTenantId = mall.getParentTenantId(); | |||||
| } | |||||
| }else{ | |||||
| tenantId = (String)request.getSession().getAttribute(UserSession.tenantId); | |||||
| parenTenantId = (String)request.getSession().getAttribute(UserSession.parentTenantId); | |||||
| } | |||||
| TenantThreadLocal.setCurrentThreadTenant(tenantId, parenTenantId); | TenantThreadLocal.setCurrentThreadTenant(tenantId, parenTenantId); | ||||
| TenantIgnore annotation = null; | TenantIgnore annotation = null; | ||||