| @@ -7,8 +7,10 @@ import java.util.Date; | |||||
| import com.iformall.domain.po.MallUserInfo; | import com.iformall.domain.po.MallUserInfo; | ||||
| import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
| import com.iformall.enums.EnumGroupSupport; | |||||
| import com.iformall.shiro.UserSession; | import com.iformall.shiro.UserSession; | ||||
| import com.iformall.utils.IPUtil; | import com.iformall.utils.IPUtil; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.apache.shiro.SecurityUtils; | import org.apache.shiro.SecurityUtils; | ||||
| import org.apache.shiro.session.Session; | import org.apache.shiro.session.Session; | ||||
| import org.springframework.web.bind.WebDataBinder; | import org.springframework.web.bind.WebDataBinder; | ||||
| @@ -53,24 +55,29 @@ public class BaseController { | |||||
| return userId; | return userId; | ||||
| } | } | ||||
| @Deprecated | |||||
| public String getTenantId(){ | |||||
| String tenantId = (String)SecurityUtils.getSubject().getSession().getAttribute(UserSession.tenantId); | |||||
| return tenantId; | |||||
| } | |||||
| // @Deprecated | |||||
| // public String getTenantId(){ | |||||
| // String tenantId = (String)SecurityUtils.getSubject().getSession().getAttribute(UserSession.tenantId); | |||||
| // return tenantId; | |||||
| // } | |||||
| /** | /** | ||||
| * 返回租户信息 | * 返回租户信息 | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| public TenantEntity getTenantInfo(){ | public TenantEntity getTenantInfo(){ | ||||
| TenantEntity tenantEntity = new TenantEntity(); | |||||
| Session session = SecurityUtils.getSubject().getSession(); | Session session = SecurityUtils.getSubject().getSession(); | ||||
| String isParent = (String)session.getAttribute(UserSession.isParent); | |||||
| String tenantId = (String)session.getAttribute(UserSession.tenantId); | String tenantId = (String)session.getAttribute(UserSession.tenantId); | ||||
| String parentTenantId = (String)session.getAttribute(UserSession.parentTenantId); | String parentTenantId = (String)session.getAttribute(UserSession.parentTenantId); | ||||
| TenantEntity tenantEntity = new TenantEntity(){{ | |||||
| setTenantId(tenantId); | |||||
| setParentTenantId(parentTenantId); | |||||
| }}; | |||||
| if(StringUtils.isNotBlank(isParent) && isParent.equalsIgnoreCase(EnumGroupSupport.SUPPORT.getCode().toString())){ | |||||
| tenantEntity.setTenantId(null); | |||||
| tenantEntity.setParentTenantId(tenantId); | |||||
| }else{ | |||||
| tenantEntity.setTenantId(tenantId); | |||||
| tenantEntity.setParentTenantId(parentTenantId); | |||||
| } | |||||
| return tenantEntity; | return tenantEntity; | ||||
| } | } | ||||
| @@ -161,6 +161,10 @@ public class HomeController extends BaseController { | |||||
| Map map = new HashMap(); | Map map = new HashMap(); | ||||
| if (mall.getGroupSupport().equals(EnumGroupSupport.SUPPORT.getCode()) && | if (mall.getGroupSupport().equals(EnumGroupSupport.SUPPORT.getCode()) && | ||||
| StringUtils.isBlank(info.getParentTenantId())) { | StringUtils.isBlank(info.getParentTenantId())) { | ||||
| Session session = SecurityUtils.getSubject().getSession(); | |||||
| session.setAttribute(UserSession.isParent, EnumGroupSupport.SUPPORT.getCode()); | |||||
| // 集团用户获取子商场 | // 集团用户获取子商场 | ||||
| List<WxMall> mallList = mallService.getSubByParentTenantId(info.getTenantId()); | List<WxMall> mallList = mallService.getSubByParentTenantId(info.getTenantId()); | ||||
| map.put("subMalls", JSON.toJSONString(mallList)); | map.put("subMalls", JSON.toJSONString(mallList)); | ||||
| @@ -198,6 +202,7 @@ public class HomeController extends BaseController { | |||||
| logger.debug(map.toString()); | logger.debug(map.toString()); | ||||
| String tenantId = map.get("tenantId"); | String tenantId = map.get("tenantId"); | ||||
| String subTenantId = map.get("subTenantId"); | |||||
| String parentTenantId = map.get("parentTenantId"); | String parentTenantId = map.get("parentTenantId"); | ||||
| if (StringUtils.isBlank(tenantId)) { | if (StringUtils.isBlank(tenantId)) { | ||||
| @@ -207,10 +212,11 @@ public class HomeController extends BaseController { | |||||
| MallUserInfo userInfo = getUser(); | MallUserInfo userInfo = getUser(); | ||||
| if (userInfo.getTenantId().equalsIgnoreCase(tenantId)) { | if (userInfo.getTenantId().equalsIgnoreCase(tenantId)) { | ||||
| Session session = SecurityUtils.getSubject().getSession(); | Session session = SecurityUtils.getSubject().getSession(); | ||||
| session.setAttribute(UserSession.tenantId, tenantId); | |||||
| if (StringUtils.isNotBlank(parentTenantId)) { | |||||
| session.setAttribute(UserSession.parentTenantId, parentTenantId); | |||||
| if (StringUtils.isNotBlank(subTenantId)) { | |||||
| session.setAttribute(UserSession.tenantId, subTenantId); | |||||
| session.setAttribute(UserSession.parentTenantId, tenantId); | |||||
| } else { | } else { | ||||
| session.setAttribute(UserSession.tenantId, tenantId); | |||||
| session.setAttribute(UserSession.parentTenantId, null); | session.setAttribute(UserSession.parentTenantId, null); | ||||
| } | } | ||||
| } | } | ||||
| @@ -10,4 +10,6 @@ public class UserSession { | |||||
| public static String parentTenantId ="PARENT_TENANT_ID"; | public static String parentTenantId ="PARENT_TENANT_ID"; | ||||
| public static String isParent ="IS_PARENT"; | |||||
| } | } | ||||
| @@ -92,7 +92,7 @@ public class MultiTenancy implements Interceptor { | |||||
| } | } | ||||
| public Object intercept(Invocation invocation) throws Throwable { | public Object intercept(Invocation invocation) throws Throwable { | ||||
| if (getTenantInfo().getTenantId() != null) { | |||||
| if (getTenantInfo().getTenantId() != null || getTenantInfo().getParentTenantId() != null) { | |||||
| // 能从cookie或者session获取到tenantId | // 能从cookie或者session获取到tenantId | ||||
| mod(invocation); | mod(invocation); | ||||
| } | } | ||||