|  | @@ -1,12 +1,7 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.teacher.interceptor;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import com.ym.mec.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  | -import com.ym.mec.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.TenantInfo;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.TenantInfoService;
 | 
	
		
			
				|  |  | -import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.tenant.TenantContextHolder;
 | 
	
		
			
				|  |  | -import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Component;
 | 
	
		
			
				|  |  |  import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 | 
	
	
		
			
				|  | @@ -19,36 +14,10 @@ public class TenantInterceptor extends HandlerInterceptorAdapter {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Autowired
 | 
	
		
			
				|  |  |  	private TenantInfoService tenantInfoService;
 | 
	
		
			
				|  |  | -	@Autowired
 | 
	
		
			
				|  |  | -	private SysUserFeignService sysUserFeignService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  |  	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
 | 
	
		
			
				|  |  | -		final String TENANT_ID = "tenantId";
 | 
	
		
			
				|  |  | -		String tenantId = request.getParameter(TENANT_ID);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		if (StringUtils.isBlank(tenantId)) {
 | 
	
		
			
				|  |  | -			tenantId = request.getHeader(TENANT_ID);
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		if (StringUtils.isBlank(tenantId)) {
 | 
	
		
			
				|  |  | -			SysUser sysUser = sysUserFeignService.queryUserInfo();
 | 
	
		
			
				|  |  | -			if (sysUser != null && sysUser.getTenantId() != null) {
 | 
	
		
			
				|  |  | -				tenantId = sysUser.getTenantId().toString();
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -		if (StringUtils.isNotBlank(tenantId)) {
 | 
	
		
			
				|  |  | -			TenantContextHolder.setTenantId(Integer.parseInt(tenantId));
 | 
	
		
			
				|  |  | -			if (Integer.parseInt(tenantId) != -1) {
 | 
	
		
			
				|  |  | -//				log.info("==> " + request.getRequestURL());
 | 
	
		
			
				|  |  | -				TenantInfo tenantInfo = tenantInfoService.baseMapper().getOpenTenant(Integer.parseInt(tenantId));
 | 
	
		
			
				|  |  | -				if (tenantInfo != null) {
 | 
	
		
			
				|  |  | -					request.setAttribute("datasourceId", tenantInfo.getDataSource());
 | 
	
		
			
				|  |  | -				} else {
 | 
	
		
			
				|  |  | -					throw new BizException("机构服务已停用,请联系机构管理员");
 | 
	
		
			
				|  |  | -				}
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | +		tenantInfoService.saveTenantContextHolder(request);
 | 
	
		
			
				|  |  |  		return true;
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 |