Parcourir la source

学校是否开放APP功能

deason il y a 5 ans
Parent
commit
7ef9588db4

+ 6 - 0
pom.xml

@@ -45,6 +45,12 @@
             <version>1.9.6</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <version>3.11.1</version>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-freemarker</artifactId>

+ 11 - 0
src/main/java/cn/com/qmth/examcloud/app/core/config/TokenFilter.java

@@ -31,7 +31,9 @@ import static cn.com.qmth.examcloud.app.model.Constants.PLATFORM_SESSION_EXPIRE_
  * @since: 2018/8/1
  */
 public class TokenFilter implements Filter {
+
     private final static Logger log = LoggerFactory.getLogger(TokenFilter.class);
+
     private CoreAuthService authService;
 
     @Override
@@ -90,6 +92,14 @@ public class TokenFilter implements Filter {
                 rootOrgId = this.loadRootOrgId(request);
             }
 
+            boolean isOpen = authService.isOpenApp(rootOrgId);
+            log.info("[Check Open APP] Result is " + isOpen);
+            if (!isOpen) {
+                reqContinue.yes = false;
+                this.renderError(response, new Result().error("当前学校尚未开放APP功能!").toString());
+                return null;
+            }
+
             boolean isDoing = authService.isDoingExam(rootOrgId, accountType, account);
             log.info("[Check Doing Exam] Result is " + isDoing);
             if (isDoing) {
@@ -232,6 +242,7 @@ public class TokenFilter implements Filter {
     }
 
     class Continue {
+
         boolean yes = true;
     }
 

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

@@ -24,6 +24,11 @@ public interface CoreAuthService {
      */
     boolean isDoingExam(Long rootOrgId, String accountType, String account);
 
+    /**
+     * 检查学校是否开放APP功能
+     */
+    boolean isOpenApp(Long rootOrgId);
+
     /**
      * 用户登录
      *

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

@@ -16,6 +16,8 @@ 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.support.cache.CacheHelper;
+import cn.com.qmth.examcloud.support.cache.bean.OrgPropertyCacheBean;
 import okhttp3.*;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -95,6 +97,20 @@ public class CoreAuthServiceImpl implements CoreAuthService {
         return false;
     }
 
+    @Override
+    public boolean isOpenApp(Long rootOrgId) {
+        try {
+            OrgPropertyCacheBean property = CacheHelper.getOrgProperty(rootOrgId, "APP_ENABLED");
+
+            if ("true".equals(property.getValue())) {
+                return true;
+            }
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+        return false;
+    }
+
     @Override
     public Result<UserInfo> login(LoginInfo loginInfo) {
         Assert.notNull(loginInfo, "LoginInfo must be not null.");