WANG 5 年 前
コミット
f31196810b

+ 1 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/cache/OrgCache.java

@@ -28,6 +28,7 @@ public class OrgCache extends RandomObjectRedisCache<OrgCacheBean> {
 		b.setName(e.getName());
 		b.setParentId(e.getParentId());
 		b.setRootId(e.getRootId());
+		b.setDomainName(e.getDomainName());
 
 		return b;
 	}

+ 31 - 17
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/AuthServiceImpl.java

@@ -48,6 +48,9 @@ import cn.com.qmth.examcloud.core.basic.service.SmsCodeService;
 import cn.com.qmth.examcloud.core.basic.service.SystemPropertyService;
 import cn.com.qmth.examcloud.core.basic.service.UserService;
 import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
+import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
+import cn.com.qmth.examcloud.support.cache.bean.RootOrgCacheBean;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
@@ -158,24 +161,36 @@ public class AuthServiceImpl implements AuthService {
 		}
 
 		Long rootOrgId = loginInfo.getRootOrgId();
-		OrgEntity rootOrg = null;
+		String domain = loginInfo.getDomain();
+		String rootOrgName = null;
+		Boolean rootOrgEnable = null;
+
 		if (null == rootOrgId) {
-			if (StringUtils.isBlank(loginInfo.getDomain())) {
+			if (StringUtils.isBlank(domain)) {
 				throw new StatusException("003003", "domain,rootOrgId 必须有一个不为空");
 			}
-			rootOrg = orgRepo.findByParentIdIsNullAndDomainName(loginInfo.getDomain());
-			if (null == rootOrg) {
-				throw new StatusException("003003", "机构不存在");
+			RootOrgCacheBean rootOrgCacheBean = CacheHelper.getRootOrg(domain);
+			if (null == rootOrgCacheBean) {
+				throw new StatusException("003003", "顶级机构不存在");
 			}
-			rootOrgId = rootOrg.getId();
+			rootOrgId = rootOrgCacheBean.getId();
+			rootOrgName = rootOrgCacheBean.getName();
+			rootOrgEnable = rootOrgCacheBean.getEnable();
 		} else {
-			rootOrg = GlobalHelper.getEntity(orgRepo, Long.valueOf(rootOrgId), OrgEntity.class);
-			if (null == rootOrg) {
-				throw new StatusException("003003", "机构不存在");
+			OrgCacheBean orgCacheBean = CacheHelper.getOrg(rootOrgId);
+			if (null == orgCacheBean) {
+				throw new StatusException("003003", "顶级机构不存在");
+			}
+			if (null != orgCacheBean.getParentId()) {
+				throw new StatusException("003003", "顶级机构ID错误");
 			}
+
+			domain = orgCacheBean.getDomainName();
+			rootOrgName = orgCacheBean.getName();
+			rootOrgEnable = orgCacheBean.getEnable();
 		}
 
-		if (!rootOrg.getEnable()) {
+		if (!rootOrgEnable) {
 			throw new StatusException("003003", "顶级机构被禁用");
 		}
 
@@ -183,15 +198,15 @@ public class AuthServiceImpl implements AuthService {
 				.get("ACCESSIBLE_ROOT_ORG_LIST");
 		if (StringUtils.isNotBlank(accessibleRootOrgIds)) {
 			accessibleRootOrgIds = "," + accessibleRootOrgIds + ",";
-			if (!accessibleRootOrgIds.contains("," + rootOrg.getId() + ",")) {
+			if (!accessibleRootOrgIds.contains("," + rootOrgId + ",")) {
 				throw new StatusException("003101", "系统维护中... ...");
 			}
 		}
 
 		User user = new User();
-		user.setRootOrgId(rootOrg.getId());
-		user.setRootOrgName(rootOrg.getName());
-		user.setRootOrgDomain(rootOrg.getDomainName());
+		user.setRootOrgId(rootOrgId);
+		user.setRootOrgName(rootOrgName);
+		user.setRootOrgDomain(domain);
 		Long orgId = null;
 
 		// 常规账户登录
@@ -241,7 +256,7 @@ public class AuthServiceImpl implements AuthService {
 			// 学生学号登录
 			if (AccountType.STUDENT_CODE.equals(accountTypeEnum)) {
 				StudentCodeEntity scEntity = studentCodeRepo
-						.findByStudentCodeAndRootOrgId(accountValue, rootOrg.getId());
+						.findByStudentCodeAndRootOrgId(accountValue, rootOrgId);
 				if (null == scEntity) {
 					throw new StatusException("003009", "账号或密码错误");
 				}
@@ -250,8 +265,7 @@ public class AuthServiceImpl implements AuthService {
 			}
 			// 学生身份证号登录
 			else if (AccountType.STUDENT_IDENTITY_NUMBER.equals(accountTypeEnum)) {
-				student = studentRepo.findByIdentityNumberAndRootOrgId(accountValue,
-						rootOrg.getId());
+				student = studentRepo.findByIdentityNumberAndRootOrgId(accountValue, rootOrgId);
 			}
 
 			if (null == student) {