zouxuan 3 years ago
parent
commit
cf2d357dca

+ 0 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/TenantInfoService.java

@@ -67,8 +67,6 @@ public interface TenantInfoService extends IService<TenantInfo> {
      */
      */
     TenantInfo queryTenantInfoByOrgan(Integer organId);
     TenantInfo queryTenantInfoByOrgan(Integer organId);
 
 
-    Boolean testEmail();
-
     void updatePhone(String newPhone, String oldPhone);
     void updatePhone(String newPhone, String oldPhone);
 
 
     void checkTenantState();
     void checkTenantState();

+ 0 - 17
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java

@@ -60,7 +60,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     }
     }
 
 
     @Autowired
     @Autowired
-    @Lazy
     private SysUserFeignService sysUserFeignService;
     private SysUserFeignService sysUserFeignService;
     @Autowired
     @Autowired
     private EmployeeService employeeService;
     private EmployeeService employeeService;
@@ -917,20 +916,4 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         return baseMapper.queryTenantInfoByOrgan(organId);
         return baseMapper.queryTenantInfoByOrgan(organId);
     }
     }
 
 
-    @Override
-    public Boolean testEmail() {
-        SysUser user = sysUserFeignService.queryUserInfo();
-        Map<Integer, String> receivers = new HashMap<>();
-        receivers.put(user.getId(), "yanite1234@sina.com");
-        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL, MessageTypeEnum.EMAIL_TENANT_ACTIVATION_SUCCESSFUL, receivers, null, 0, null, "SYSTEM", "小风乐团1", "xiaofeng", "this is password");
-
-        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL, MessageTypeEnum.EMAIL_TENANT_RENEWAL_SUCCESSFUL, receivers, null, 0, null, "SYSTEM", "小风乐团2", "xiaofeng", "this is password");
-
-        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL, MessageTypeEnum.EMAIL_TENANT_EXPIRATION_REMINDERS, receivers, null, 0, null, "SYSTEM", "小风乐团3", "xiaofeng", "this is password");
-
-        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL, MessageTypeEnum.EMAIL_TENANT_INSUFFICIENT_BALANCE, receivers, null, 0, null, "SYSTEM", "小风乐团4", "xiaofeng", "this is password");
-
-        return false;
-    }
-
 }
 }

+ 32 - 1
mec-teacher/src/main/java/com/ym/mec/teacher/interceptor/TenantInterceptor.java

@@ -1,7 +1,12 @@
 package com.ym.mec.teacher.interceptor;
 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.biz.service.TenantInfoService;
+import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.common.tenant.TenantContextHolder;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@@ -14,10 +19,36 @@ public class TenantInterceptor extends HandlerInterceptorAdapter {
 
 
 	@Autowired
 	@Autowired
 	private TenantInfoService tenantInfoService;
 	private TenantInfoService tenantInfoService;
+	@Autowired
+	private SysUserFeignService sysUserFeignService;
 
 
 	@Override
 	@Override
 	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
 	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
-		tenantInfoService.saveTenantContextHolder(request);
+		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("机构服务已停用,请联系机构管理员");
+				}
+			}
+		}
 		return true;
 		return true;
 	}
 	}