xiatian 4 jaren geleden
bovenliggende
commit
57a45f06c2

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/bean/exam/AnswerSubmitBean.java

@@ -5,7 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
 
 @ApiModel("提交作答结果返回信息")
 public class AnswerSubmitBean {
-	@ApiModelProperty("updateTime")
+	@ApiModelProperty("version")
 	private Long version;
 
 	public Long getVersion() {

+ 65 - 0
themis-business/src/main/java/com/qmth/themis/business/bean/exam/MobileAnswerSubmitParamBean.java

@@ -0,0 +1,65 @@
+package com.qmth.themis.business.bean.exam;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel("移动端提交作答结果参数")
+public class MobileAnswerSubmitParamBean {
+	
+	@ApiModelProperty("考试记录id")
+	private Long recordId;
+	
+	@ApiModelProperty("大题号")
+	private Integer mainNumber;
+
+	@ApiModelProperty("小题号")
+	private Integer subNumber;
+	
+	@ApiModelProperty("套题子题序号")
+	private Integer subIndex;
+	
+	@ApiModelProperty("文件URL,多个URL用逗号分隔")
+	private String urls;
+
+	public Long getRecordId() {
+		return recordId;
+	}
+
+	public void setRecordId(Long recordId) {
+		this.recordId = recordId;
+	}
+
+	public Integer getMainNumber() {
+		return mainNumber;
+	}
+
+	public void setMainNumber(Integer mainNumber) {
+		this.mainNumber = mainNumber;
+	}
+
+	public Integer getSubNumber() {
+		return subNumber;
+	}
+
+	public void setSubNumber(Integer subNumber) {
+		this.subNumber = subNumber;
+	}
+
+	public Integer getSubIndex() {
+		return subIndex;
+	}
+
+	public void setSubIndex(Integer subIndex) {
+		this.subIndex = subIndex;
+	}
+
+	public String getUrls() {
+		return urls;
+	}
+
+	public void setUrls(String urls) {
+		this.urls = urls;
+	}
+	
+}
+

+ 20 - 0
themis-business/src/main/java/com/qmth/themis/business/bean/exam/MobileAnswerSubmitReponseBean.java

@@ -0,0 +1,20 @@
+package com.qmth.themis.business.bean.exam;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel("移动端提交作答结果返回信息")
+public class MobileAnswerSubmitReponseBean {
+	@ApiModelProperty("updateTime")
+	private Long updateTime;
+
+	public Long getUpdateTime() {
+		return updateTime;
+	}
+
+	public void setUpdateTime(Long updateTime) {
+		this.updateTime = updateTime;
+	}
+
+	
+}

+ 4 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TEMobileService.java

@@ -2,6 +2,7 @@ package com.qmth.themis.business.service;
 
 import java.security.NoSuchAlgorithmException;
 
+import com.qmth.themis.business.bean.exam.MobileAnswerSubmitReponseBean;
 import com.qmth.themis.business.bean.mobile.MobileAuthorizationBean;
 import com.qmth.themis.business.bean.mobile.MobileAuthorizationParamBean;
 
@@ -9,4 +10,7 @@ public interface TEMobileService {
 
 	public MobileAuthorizationBean authorization(MobileAuthorizationParamBean param) throws NoSuchAlgorithmException;
 
+	MobileAnswerSubmitReponseBean answerSubmit(Long studentId, Long recordId, Integer mainNumber, Integer subNumber,
+			Integer subIndex, String answer);
+
 }

+ 42 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEMobileServiceImpl.java

@@ -10,12 +10,15 @@ import javax.annotation.Resource;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.springframework.stereotype.Service;
 
+import com.qmth.themis.business.bean.exam.MobileAnswerSubmitReponseBean;
 import com.qmth.themis.business.bean.mobile.MobileAuthorizationBean;
 import com.qmth.themis.business.bean.mobile.MobileAuthorizationMonitorBean;
 import com.qmth.themis.business.bean.mobile.MobileAuthorizationParamBean;
 import com.qmth.themis.business.bean.mobile.MobileAuthorizationUploadBean;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.cache.MobileAuthCacheUtil;
+import com.qmth.themis.business.cache.RedisKeyHelper;
+import com.qmth.themis.business.cache.bean.ExamStudentAnswerCacheBean;
 import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
@@ -134,4 +137,43 @@ public class TEMobileServiceImpl implements TEMobileService {
 		ret.setSubIndex(subIndex);
 		return ret;
 	}
+	
+	@Override
+    public MobileAnswerSubmitReponseBean answerSubmit(Long studentId, Long recordId, Integer mainNumber, Integer subNumber, Integer subIndex,
+                                         String answer) {
+
+        // 校验当前登录用户和参数一致性
+        if (ExamRecordCacheUtil.getId(recordId) == null) {
+            throw new BusinessException("未找到考试记录");
+        }
+        Long examStudentId = ExamRecordCacheUtil.getExamStudentId(recordId);
+        ExamStudentCacheBean es = (ExamStudentCacheBean) redisUtil
+                .get(RedisKeyHelper.examStudentCacheKey(examStudentId));
+        if (es == null) {
+            throw new BusinessException("未找到考生");
+        }
+        if (!studentId.equals(es.getStudentId())) {
+            throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
+        }
+        ExamRecordStatusEnum sta=ExamRecordCacheUtil.getStatus(recordId);
+        if(ExamRecordStatusEnum.FINISHED.equals(sta)||ExamRecordStatusEnum.PERSISTED.equals(sta)) {
+			throw new BusinessException("该考试已结束");
+		}
+        ExamStudentAnswerCacheBean answerCache = (ExamStudentAnswerCacheBean) redisUtil.get(
+                RedisKeyHelper.examAnswerKey(recordId),
+                RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex));
+        if (answerCache == null) {
+            answerCache = new ExamStudentAnswerCacheBean();
+            answerCache.setMainNumber(mainNumber);
+            answerCache.setSubNumber(subNumber);
+            answerCache.setSubIndex(subIndex);
+            answerCache.setAnswer(answer);
+        }
+        // 更新考生作答
+        redisUtil.set(RedisKeyHelper.examAnswerKey(recordId),
+                RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex), answerCache);
+        MobileAnswerSubmitReponseBean ret = new MobileAnswerSubmitReponseBean();
+        ret.setUpdateTime(new Date().getTime());
+        return ret;
+    }
 }

+ 25 - 0
themis-exam/src/main/java/com/qmth/themis/exam/api/TEMobileController.java

@@ -7,6 +7,7 @@ import java.util.concurrent.ConcurrentHashMap;
 
 import javax.annotation.Resource;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -16,6 +17,8 @@ import org.springframework.web.multipart.MultipartFile;
 
 import com.qmth.themis.business.bean.exam.AnswerReadyParamBean;
 import com.qmth.themis.business.bean.exam.AnswerReadyResponseBean;
+import com.qmth.themis.business.bean.exam.MobileAnswerSubmitParamBean;
+import com.qmth.themis.business.bean.exam.MobileAnswerSubmitReponseBean;
 import com.qmth.themis.business.bean.mobile.MobileAuthorizationParamBean;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
@@ -123,5 +126,27 @@ public class TEMobileController {
         TEStudentCacheDto teStudent = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
         return ResultUtil.ok(examService.fileUpload(teStudent.getId(), recordId, file, suffix, md5));
     }
+    
+    @ApiOperation(value = "提交作答结果")
+    @RequestMapping(value = "/answer/submit", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "试卷信息")})
+    public Result answerSubmit(@RequestBody MobileAnswerSubmitParamBean param) {
+        TEStudentCacheDto teStudent = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
+        if (param.getRecordId() == null) {
+            throw new BusinessException("考试记录id不能为空");
+        }
+        if (param.getMainNumber() == null) {
+            throw new BusinessException("大题号不能为空");
+        }
+        if (param.getSubNumber() == null) {
+            throw new BusinessException("小题号不能为空");
+        }
+        if (StringUtils.isBlank(param.getUrls())) {
+            throw new BusinessException("答案不能为空");
+        }
+        MobileAnswerSubmitReponseBean ret = mobileService.answerSubmit(teStudent.getId(), param.getRecordId(), param.getMainNumber(),
+                param.getSubNumber(), param.getSubIndex(), param.getUrls());
+        return ResultUtil.ok(ret);
+    }
 
 }