|
@@ -1,12 +1,10 @@
|
|
package com.qmth.themis.business.service.impl;
|
|
package com.qmth.themis.business.service.impl;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
-import java.util.UUID;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
@@ -23,7 +21,9 @@ import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
|
|
import com.qmth.themis.business.cache.bean.ExamCourseCacheBean;
|
|
import com.qmth.themis.business.cache.bean.ExamCourseCacheBean;
|
|
import com.qmth.themis.business.cache.bean.ExamPaperCacheBean;
|
|
import com.qmth.themis.business.cache.bean.ExamPaperCacheBean;
|
|
import com.qmth.themis.business.cache.bean.ExamRecordCacheBean;
|
|
import com.qmth.themis.business.cache.bean.ExamRecordCacheBean;
|
|
|
|
+import com.qmth.themis.business.cache.bean.ExamStudentAnswerCacheBean;
|
|
import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
|
|
import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
|
|
|
|
+import com.qmth.themis.business.cache.bean.ExamStudentPaperStructCacheBean;
|
|
import com.qmth.themis.business.config.SystemConfig;
|
|
import com.qmth.themis.business.config.SystemConfig;
|
|
import com.qmth.themis.business.dao.TEExamMapper;
|
|
import com.qmth.themis.business.dao.TEExamMapper;
|
|
import com.qmth.themis.business.entity.TEExam;
|
|
import com.qmth.themis.business.entity.TEExam;
|
|
@@ -36,7 +36,6 @@ import com.qmth.themis.business.service.TOeExamRecordService;
|
|
import com.qmth.themis.business.util.OssUtil;
|
|
import com.qmth.themis.business.util.OssUtil;
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
-import com.qmth.themis.common.util.FileUtil;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 考试批次 服务实现类
|
|
* @Description: 考试批次 服务实现类
|
|
@@ -276,38 +275,61 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
- @Override
|
|
|
|
- public Long studentPaperStruct(Long studentId, Long recordId, String content) {
|
|
|
|
- ExamRecordCacheBean er = (ExamRecordCacheBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
|
- if (er == null) {
|
|
|
|
- throw new BusinessException("未找到考试记录");
|
|
|
|
- }
|
|
|
|
- ExamStudentCacheBean es = (ExamStudentCacheBean) redisUtil
|
|
|
|
- .get(RedisKeyHelper.examStudentCacheKey(er.getExamStudentId()));
|
|
|
|
- if (es == null) {
|
|
|
|
- throw new BusinessException("未找到考生");
|
|
|
|
- }
|
|
|
|
- if (studentId.equals(es.getStudentId())) {
|
|
|
|
- throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String tempDir = systemConfig.getProperty("sys.config.tempDataDir");
|
|
|
|
- File file = new File(tempDir + "/" + uuid() + ".json");
|
|
|
|
- try {
|
|
|
|
- FileUtil.saveAsFile(file.getAbsolutePath(), content);
|
|
|
|
- String filePath = "upload/" + sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
|
|
- er.setPaperStruct(filePath);
|
|
|
|
- er.setPaperStructUpload(1);
|
|
|
|
- OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, file);
|
|
|
|
- // 更新考试记录缓存
|
|
|
|
- redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), er);
|
|
|
|
- return new Date().getTime();
|
|
|
|
- } finally {
|
|
|
|
- FileUtil.deleteFile(file);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private String uuid() {
|
|
|
|
- return UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Long studentPaperStruct(Long studentId, Long recordId, String content) {
|
|
|
|
+ ExamRecordCacheBean er = (ExamRecordCacheBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
|
+ if (er == null) {
|
|
|
|
+ throw new BusinessException("未找到考试记录");
|
|
|
|
+ }
|
|
|
|
+ ExamStudentCacheBean es = (ExamStudentCacheBean) redisUtil
|
|
|
|
+ .get(RedisKeyHelper.examStudentCacheKey(er.getExamStudentId()));
|
|
|
|
+ if (es == null) {
|
|
|
|
+ throw new BusinessException("未找到考生");
|
|
|
|
+ }
|
|
|
|
+ if (studentId.equals(es.getStudentId())) {
|
|
|
|
+ throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
|
|
|
|
+ }
|
|
|
|
+ ExamStudentPaperStructCacheBean struct = new ExamStudentPaperStructCacheBean();
|
|
|
|
+ struct.setContent(content);
|
|
|
|
+ struct.setTime(new Date().getTime());
|
|
|
|
+ // 更新考生试卷结构
|
|
|
|
+ redisUtil.set(RedisKeyHelper.studentPaperStructKey(recordId), struct);
|
|
|
|
+ return struct.getTime();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public Long answerSubmit(Long studentId, Long recordId, Integer mainNumber, Integer subNumber, Integer subIndex,
|
|
|
|
+ String answer, Long version, Integer durationSeconds) {
|
|
|
|
+ ExamRecordCacheBean er = (ExamRecordCacheBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
|
+ if (er == null) {
|
|
|
|
+ throw new BusinessException("未找到考试记录");
|
|
|
|
+ }
|
|
|
|
+ ExamStudentCacheBean es = (ExamStudentCacheBean) redisUtil
|
|
|
|
+ .get(RedisKeyHelper.examStudentCacheKey(er.getExamStudentId()));
|
|
|
|
+ if (es == null) {
|
|
|
|
+ throw new BusinessException("未找到考生");
|
|
|
|
+ }
|
|
|
|
+ if (studentId.equals(es.getStudentId())) {
|
|
|
|
+ throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
|
|
|
|
+ }
|
|
|
|
+ ExamStudentAnswerCacheBean answerCache = (ExamStudentAnswerCacheBean) redisUtil
|
|
|
|
+ .get(RedisKeyHelper.examAnswerKey(er.getExamStudentId()),RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex));
|
|
|
|
+ if (answerCache == null) {
|
|
|
|
+ answerCache = new ExamStudentAnswerCacheBean();
|
|
|
|
+ answerCache.setContent(answer);
|
|
|
|
+ answerCache.setVersion(version);
|
|
|
|
+ answerCache.setDuration(durationSeconds);
|
|
|
|
+ }else {
|
|
|
|
+ if(version.longValue()<answerCache.getVersion().longValue()) {
|
|
|
|
+ throw new BusinessException("版本时间戳过期");
|
|
|
|
+ }
|
|
|
|
+ answerCache.setContent(answer);
|
|
|
|
+ answerCache.setVersion(version);
|
|
|
|
+ answerCache.setDuration(durationSeconds);
|
|
|
|
+ }
|
|
|
|
+ // 更新考生作答
|
|
|
|
+ redisUtil.set(RedisKeyHelper.examAnswerKey(er.getExamStudentId()),RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex), answerCache);
|
|
|
|
+ return version;
|
|
|
|
+ }
|
|
}
|
|
}
|