Browse Source

根据手机号获取学校ID

deason 5 năm trước cách đây
mục cha
commit
9ea3e1192e

+ 6 - 0
pom.xml

@@ -27,6 +27,12 @@
             <version>${examcloud.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>cn.com.qmth.examcloud.rpc</groupId>
+            <artifactId>examcloud-core-basic-api-client</artifactId>
+            <version>${examcloud.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>cn.com.qmth.examcloud</groupId>
             <artifactId>examcloud-support</artifactId>

+ 8 - 2
src/main/java/cn/com/qmth/examcloud/app/core/config/TokenFilter.java

@@ -87,9 +87,15 @@ public class TokenFilter implements Filter {
                 //ignore
             }
 
-            //先获取学校ID,下面“检查考试状态接口”必须带学校ID
             if (rootOrgId == null) {
-                rootOrgId = this.loadRootOrgId(request);
+                //rootOrgId = this.loadRootOrgId(request);
+                rootOrgId = authService.getRootOrgIdBySecurityPhone(account);
+            }
+
+            if (rootOrgId == null) {
+                reqContinue.yes = false;
+                this.renderError(response, new Result().error("学校ID不能为空!").toString());
+                return null;
             }
 
             boolean isOpen = authService.isOpenApp(rootOrgId);

+ 5 - 0
src/main/java/cn/com/qmth/examcloud/app/service/CoreAuthService.java

@@ -29,6 +29,11 @@ public interface CoreAuthService {
      */
     boolean isOpenApp(Long rootOrgId);
 
+    /**
+     * 根据手机号获取学校ID
+     */
+    Long getRootOrgIdBySecurityPhone(String securityPhone);
+
     /**
      * 用户登录
      *

+ 26 - 0
src/main/java/cn/com/qmth/examcloud/app/service/impl/CoreAuthServiceImpl.java

@@ -16,6 +16,9 @@ import cn.com.qmth.examcloud.app.core.utils.ThreadUtils;
 import cn.com.qmth.examcloud.app.model.*;
 import cn.com.qmth.examcloud.app.service.CoreAuthService;
 import cn.com.qmth.examcloud.app.service.RedisService;
+import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
+import cn.com.qmth.examcloud.core.basic.api.request.GetStudentReq;
+import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.bean.OrgPropertyCacheBean;
 import okhttp3.*;
@@ -48,6 +51,9 @@ public class CoreAuthServiceImpl implements CoreAuthService {
     @Autowired
     private RedisService redisService;
 
+    @Autowired
+    private StudentCloudService studentCloudService;
+
     @Override
     public boolean isDoingExam(Long rootOrgId, String accountType, String account) {
         if (rootOrgId == null) {
@@ -99,6 +105,11 @@ public class CoreAuthServiceImpl implements CoreAuthService {
 
     @Override
     public boolean isOpenApp(Long rootOrgId) {
+        if (rootOrgId == null) {
+            log.warn("[Check Open APP] rootOrgId is null");
+            return false;
+        }
+
         try {
             OrgPropertyCacheBean property = CacheHelper.getOrgProperty(rootOrgId, "APP_ENABLED");
 
@@ -111,6 +122,21 @@ public class CoreAuthServiceImpl implements CoreAuthService {
         return false;
     }
 
+    @Override
+    public Long getRootOrgIdBySecurityPhone(String securityPhone) {
+        GetStudentReq req = new GetStudentReq();
+        req.setSecurityPhone(securityPhone);
+
+        try {
+            GetStudentResp resp = studentCloudService.getStudent(req);
+            return resp.getStudentInfo().getRootOrgId();
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+
+        return null;
+    }
+
     @Override
     public Result<UserInfo> login(LoginInfo loginInfo) {
         Assert.notNull(loginInfo, "LoginInfo must be not null.");