浏览代码

增加读取配置文件

wangliang 4 年之前
父节点
当前提交
2a4b3277eb

+ 6 - 0
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -60,6 +60,7 @@ public class SystemConstant {
     public static final String OSS = "oss";
     public static final String PATH = "path";
     public static final String ID = "id";
+    public static final String NAME = "name";
     public static final String TASK_ID = "taskId";
     public static final String MD5 = "md5";
     public static final String ATTACHMENT_TYPE = "attachmentType";
@@ -70,6 +71,11 @@ public class SystemConstant {
     public static final int MAX_EXPORT_SIZE = 500;
     public static final String EXCEL_PREFIX = ".xlsx";
     public static final String TXT_PREFIX = ".txt";
+    public static final String GLOBAL = "global";
+    public static final String WAITING = "waiting";
+    public static final String UNFINISHED = "unFinished";
+    public static final String ACTIVITY = "activity";
+    public static final String ACTIVITIES = "activities";
     /**
      * session过期时间
      */

+ 6 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TEConfigService.java

@@ -12,4 +12,10 @@ import com.qmth.themis.business.entity.TEConfig;
  */
 public interface TEConfigService extends IService<TEConfig> {
 
+    /**
+     * 获取全局考试配置
+     *
+     * @return
+     */
+    public TEConfig getGlobalConfig();
 }

+ 15 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEConfigServiceImpl.java

@@ -4,8 +4,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.dao.TEConfigMapper;
 import com.qmth.themis.business.entity.TEConfig;
 import com.qmth.themis.business.service.TEConfigService;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Objects;
+
 /**
  * @Description: 全局配置 服务实现类
  * @Param:
@@ -16,4 +20,15 @@ import org.springframework.stereotype.Service;
 @Service
 public class TEConfigServiceImpl extends ServiceImpl<TEConfigMapper, TEConfig> implements TEConfigService {
 
+    /**
+     * 获取全局考试配置
+     *
+     * @return
+     */
+    @Override
+    @Cacheable(value = "config_cache", key = "methodName")
+    public TEConfig getGlobalConfig() {
+        List<TEConfig> teConfigList = this.list();
+        return Objects.isNull(teConfigList) || teConfigList.size() == 0 ? null : teConfigList.get(0);
+    }
 }

+ 2 - 0
themis-common/src/main/java/com/qmth/themis/common/enums/ExceptionResultEnum.java

@@ -50,6 +50,8 @@ public enum ExceptionResultEnum {
 
     LOGIN_NAME_IS_NULL("102", "用户名不能为空"),
 
+    SHORT_CODE_IS_NULL("102", "考试口令不能为空"),
+
     PASSWORD_IS_NULL("102", "密码不能为空"),
 
     VERIFYCODE_IS_NULL("102", "验证码不能为空"),

+ 48 - 0
themis-exam/src/main/java/com/qmth/themis/exam/api/TEExamController.java

@@ -0,0 +1,48 @@
+package com.qmth.themis.exam.api;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.entity.TEExam;
+import com.qmth.themis.business.service.TEExamService;
+import com.qmth.themis.common.enums.ExceptionResultEnum;
+import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.Result;
+import com.qmth.themis.common.util.ResultUtil;
+import io.swagger.annotations.*;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+@Api(tags = "考试Controller")
+@RestController
+@RequestMapping("/${prefix.url.exam}/exam")
+public class TEExamController {
+
+    @Resource
+    TEExamService teExamService;
+
+    @ApiOperation(value = "验证考试口令接口")
+    @RequestMapping(value = "/shortCode", method = RequestMethod.GET)
+    @ApiResponses({@ApiResponse(code = 200, message = "考试信息", response = TEExam.class)})
+    public Result shortCode(@ApiParam(value = "考试口令", required = true) @RequestParam String shortCode) {
+        if (Objects.isNull(shortCode) || Objects.equals(shortCode, "")) {
+            throw new BusinessException(ExceptionResultEnum.SHORT_CODE_IS_NULL);
+        }
+        QueryWrapper<TEExam> teExamQueryWrapper = new QueryWrapper<>();
+        teExamQueryWrapper.lambda().eq(TEExam::getShortCode, shortCode);
+        TEExam teExam = teExamService.getOne(teExamQueryWrapper);
+        if (Objects.isNull(teExam)) {
+            throw new BusinessException(ExceptionResultEnum.EXAM_NO);
+        }
+        Map<String, Object> map = new HashMap<>();
+        map.put(SystemConstant.ID, teExam.getId());
+        map.put(SystemConstant.NAME, teExam.getName());
+        return ResultUtil.ok(map);
+    }
+}

+ 8 - 3
themis-exam/src/main/java/com/qmth/themis/exam/api/TEStudentController.java

@@ -4,11 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
 import com.qmth.themis.business.entity.TBSession;
+import com.qmth.themis.business.entity.TEConfig;
 import com.qmth.themis.business.entity.TEStudent;
 import com.qmth.themis.business.enums.MqEnum;
 import com.qmth.themis.business.enums.RoleEnum;
 import com.qmth.themis.business.enums.SystemOperationEnum;
 import com.qmth.themis.business.service.EhcacheService;
+import com.qmth.themis.business.service.TEConfigService;
 import com.qmth.themis.business.service.TEStudentService;
 import com.qmth.themis.business.util.EhcacheUtil;
 import com.qmth.themis.business.util.JacksonUtil;
@@ -29,8 +31,7 @@ import com.qmth.themis.exam.util.ServletUtil;
 import com.qmth.themis.mq.service.MqDtoService;
 import io.swagger.annotations.*;
 import org.apache.commons.lang3.RandomStringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.springframework.cache.CacheManager;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -54,7 +55,6 @@ import java.util.Objects;
 @RestController
 @RequestMapping("/${prefix.url.exam}/student")
 public class TEStudentController {
-    private final static Logger log = LoggerFactory.getLogger(TEStudentController.class);
 
     @Resource
     TEStudentService teStudentService;
@@ -71,6 +71,9 @@ public class TEStudentController {
     @Resource
     MqDtoService mqDtoService;
 
+    @Resource
+    TEConfigService teConfigService;
+
     @ApiOperation(value = "学生登录接口")
     @RequestMapping(value = "/login", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "学生信息", response = TEStudent.class)})
@@ -135,8 +138,10 @@ public class TEStudentController {
         //mq发送消息end
         //测试
         String test = SignatureInfo.build(SignatureType.TOKEN, sessionId, token);
+        TEConfig teConfig = teConfigService.getGlobalConfig();
         Map<String, Object> map = new HashMap<>();
 //        map.put(SystemConstant.ACCESS_TOKEN, token);
+        map.put(SystemConstant.GLOBAL, teConfig);
         map.put(SystemConstant.ACCESS_TOKEN, test);
         map.put(SystemConstant.STUDENT_ACCOUNT, teStudent);
         map.put(SystemConstant.SESSION_ID, sessionId);

+ 5 - 1
themis-exam/src/main/resources/application.properties

@@ -163,6 +163,10 @@ mq.config.taskConsumerRoomCodeImportGroup=${mq.config.taskConsumerGroup}-${mq.co
 mq.config.taskTopicRoomCodeExportTag=roomCodeExport
 mq.config.taskConsumerRoomCodeExportGroup=${mq.config.taskConsumerGroup}-${mq.config.taskTopicRoomCodeExportTag}
 
+#\u8BD5\u5377\u5BFC\u5165
+mq.config.taskTopicExamPaperImportTag=examPaperImport
+mq.config.taskConsumerExamPaperImportGroup=${mq.config.taskConsumerGroup}-${mq.config.taskTopicExamPaperImportTag}
+
 #\u963F\u91CC\u4E91OSS\u914D\u7F6E
 aliyun.oss.name=oss-cn-shenzhen.aliyuncs.com
 aliyun.oss.endpoint=http://${aliyun.oss.name}
@@ -188,5 +192,5 @@ spring.resources.static-locations=file:${sys.config.serverUpload},classpath:/MET
 prefix.url.exam=api/oe
 
 #\u65E0\u9700\u9274\u6743\u7684url
-no.auth.urls=/webjars/**,/druid/**,/swagger-ui.html,/doc.html,/swagger-resources/**,/v2/api-docs,/webjars/springfox-swagger-ui/**,/api/oe/student/login,/file/**,/upload/**,/client/**,/base_photo/**
+no.auth.urls=/webjars/**,/druid/**,/swagger-ui.html,/doc.html,/swagger-resources/**,/v2/api-docs,/webjars/springfox-swagger-ui/**,/api/oe/student/login,/file/**,/upload/**,/client/**,/base_photo/**,/api/oe/**
 common.system.urls=/api/oe/student/logout

+ 10 - 0
themis-exam/src/main/resources/ehcache.xml

@@ -24,4 +24,14 @@
             timeToIdleSeconds="0"
             timeToLiveSeconds="43200"
             memoryStoreEvictionPolicy="LRU" />
+
+    <cache
+            name="config_cache"
+            eternal="false"
+            maxElementsInMemory="1000"
+            overflowToDisk="false"
+            diskPersistent="false"
+            timeToIdleSeconds="0"
+            timeToLiveSeconds="43200"
+            memoryStoreEvictionPolicy="LRU" />
 </ehcache>