Browse Source

Merge remote-tracking branch 'origin/dev' into dev

wangliang 4 years ago
parent
commit
f9170f14be

+ 79 - 0
themis-business/src/main/java/com/qmth/themis/business/bean/exam/ExamPrepareBean.java

@@ -0,0 +1,79 @@
+package com.qmth.themis.business.bean.exam;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel("考试候考试卷信息")
+public class ExamPrepareBean {
+	@ApiModelProperty("考试记录id")
+	private Long recordId;
+	@ApiModelProperty("试卷数据包下载地址")
+	private String paperUrl;
+	@ApiModelProperty("试卷结构下载地址")
+	private String structUrl;
+	@ApiModelProperty("是否开启客观题乱序")
+	private Boolean objectiveShuffle;
+	@ApiModelProperty("是否开启选项乱序")
+	private Boolean optionShuffle;
+	@ApiModelProperty("是否有音频")
+	private Boolean hasAudio;
+	@ApiModelProperty("音频题播放次数")
+	private Integer audioPlayTime;
+
+	public Long getRecordId() {
+		return recordId;
+	}
+
+	public void setRecordId(Long recordId) {
+		this.recordId = recordId;
+	}
+
+	public String getPaperUrl() {
+		return paperUrl;
+	}
+
+	public void setPaperUrl(String paperUrl) {
+		this.paperUrl = paperUrl;
+	}
+
+	public String getStructUrl() {
+		return structUrl;
+	}
+
+	public void setStructUrl(String structUrl) {
+		this.structUrl = structUrl;
+	}
+
+	public Boolean getObjectiveShuffle() {
+		return objectiveShuffle;
+	}
+
+	public void setObjectiveShuffle(Boolean objectiveShuffle) {
+		this.objectiveShuffle = objectiveShuffle;
+	}
+
+	public Boolean getOptionShuffle() {
+		return optionShuffle;
+	}
+
+	public void setOptionShuffle(Boolean optionShuffle) {
+		this.optionShuffle = optionShuffle;
+	}
+
+	public Boolean getHasAudio() {
+		return hasAudio;
+	}
+
+	public void setHasAudio(Boolean hasAudio) {
+		this.hasAudio = hasAudio;
+	}
+
+	public Integer getAudioPlayTime() {
+		return audioPlayTime;
+	}
+
+	public void setAudioPlayTime(Integer audioPlayTime) {
+		this.audioPlayTime = audioPlayTime;
+	}
+
+}

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

@@ -92,6 +92,8 @@ public class SystemConstant {
     public static final long REDIS_LOCK_WEBSOCKET_TIME_OUT = 1L;
     public static final String REDIS_CACHE = "cache:task:";
     public static final long REDIS_CACHE_TIME_OUT = 30L;
+    //学生锁
+    public static final String REDIS_LOCK_STUDENT_PREFIX = "lock:student:student_id_";
     /**
      * redis过期时间
      */

+ 8 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TEExamService.java

@@ -2,6 +2,7 @@ package com.qmth.themis.business.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.themis.business.bean.exam.ExamPrepareBean;
 import com.qmth.themis.business.entity.TEExam;
 import org.apache.ibatis.annotations.Param;
 
@@ -37,4 +38,11 @@ public interface TEExamService extends IService<TEExam> {
      * @return
      */
     public List<Map> getWaitingExam(Long studentId);
+
+	/** 开始候考
+	 * @param id
+	 * @param activityId
+	 * @return
+	 */
+	public ExamPrepareBean prepare(Long id, Long activityId);
 }

+ 7 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -2,6 +2,7 @@ package com.qmth.themis.business.service.impl;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.themis.business.bean.exam.ExamPrepareBean;
 import com.qmth.themis.business.dao.TEExamMapper;
 import com.qmth.themis.business.entity.TEExam;
 import com.qmth.themis.business.service.TEExamService;
@@ -50,4 +51,10 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
     public List<Map> getWaitingExam(Long studentId) {
         return teExamMapper.getWaitingExam(studentId);
     }
+
+	@Override
+	public ExamPrepareBean prepare(Long id, Long activityId) {
+		// TODO Auto-generated method stub
+		return null;
+	}
 }

+ 3 - 1
themis-common/src/main/java/com/qmth/themis/common/enums/ExceptionResultEnum.java

@@ -148,7 +148,9 @@ public enum ExceptionResultEnum {
 
     AUTHORIZATION_ERROR("401", "签名验证失败"),
 
-    AUTHORIZATION_SESSION_ERROR("401", "sessionId验证失败");
+    AUTHORIZATION_SESSION_ERROR("401", "sessionId验证失败"),
+	
+    REQUEST_AWAIT("500", "请求等待:请稍后重试");
 
     private String code;
     private String message;

+ 60 - 30
themis-exam/src/main/java/com/qmth/themis/exam/api/TEExamController.java

@@ -1,48 +1,78 @@
 package com.qmth.themis.exam.api;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.annotation.Resource;
+
+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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qmth.themis.business.bean.exam.ExamPrepareBean;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.entity.TEExam;
+import com.qmth.themis.business.entity.TEStudent;
 import com.qmth.themis.business.service.TEExamService;
+import com.qmth.themis.business.util.RedisUtil;
 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 com.qmth.themis.exam.util.ServletUtil;
 
-import javax.annotation.Resource;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
 
 @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);
-    }
+	@Resource
+	TEExamService teExamService;
+	@Resource
+	RedisUtil redisUtil;
+
+	@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);
+	}
+
+	@ApiOperation(value = "开始候考")
+	@RequestMapping(value = "/prepare", method = RequestMethod.POST)
+	@ApiResponses({ @ApiResponse(code = 200, message = "试卷信息") })
+	public ExamPrepareBean prepare(@ApiParam(value = "考试场次ID", required = true) @RequestParam Long activityId) {
+		TEStudent teStudent = (TEStudent) ServletUtil.getRequestStudentAccount();
+		String lockKey=SystemConstant.REDIS_LOCK_STUDENT_PREFIX+teStudent.getId();
+		Boolean lock=redisUtil.lock(lockKey, SystemConstant.REDIS_CACHE_TIME_OUT);
+		if(!lock) {
+			throw new BusinessException(ExceptionResultEnum.REQUEST_AWAIT);
+		}
+		try {
+			return teExamService.prepare(teStudent.getId(), activityId);
+		} finally {
+			redisUtil.releaseLock(lockKey);
+		}
+	}
 }